1 |
from Tkinter import * |
from Tkinter import * |
2 |
from ScrolledText import * |
from ScrolledText import * |
3 |
|
from string import replace, find |
4 |
|
|
5 |
class Chat(Frame): |
class Chat(Frame): |
6 |
|
|
11 |
self.tellhandler = tellhandler # Tell or RoomTell |
self.tellhandler = tellhandler # Tell or RoomTell |
12 |
|
|
13 |
self.output = ScrolledText(self, state=DISABLED) |
self.output = ScrolledText(self, state=DISABLED) |
14 |
#self.output.tag_config("name", self.output.text.font.copy().config(weight=BOLD)) |
outputfont = "Arial 10" |
15 |
|
self.output.tag_config("normal", font=outputfont) |
16 |
|
self.output.tag_config("name", font=outputfont + " bold") |
17 |
|
self.output.tag_config("action", font=outputfont + " italic") |
18 |
self.output.grid(row=0, sticky=NE+SW) |
self.output.grid(row=0, sticky=NE+SW) |
19 |
|
|
20 |
self.input = Entry(self) |
self.input = Entry(self) |
32 |
|
|
33 |
def receive(self, source, speech): |
def receive(self, source, speech): |
34 |
self.output.config(state=NORMAL) |
self.output.config(state=NORMAL) |
35 |
self.output.insert(END, source, "name") |
# check for action (string beginning with "/me") |
36 |
self.output.insert(END, speech + "\n") |
action = 0 |
37 |
|
if find(speech, "/me", 0, 3) > -1: |
38 |
|
action = 1 |
39 |
|
# replace "/me" with user's name |
40 |
|
speech = replace(speech, "/me", source) |
41 |
|
if not action: |
42 |
|
self.output.insert(END, source + ": ", "name") |
43 |
|
self.output.insert(END, speech + "\n", "normal") |
44 |
|
else: |
45 |
|
self.output.insert(END, "***" + speech + "\n", "action") |
46 |
self.output.config(state=DISABLED) |
self.output.config(state=DISABLED) |