Revision: 4359 Author: russblau Date: 2007-09-24 19:05:17 +0000 (Mon, 24 Sep 2007)
Log Message: ----------- Text colorization.
Modified Paths: -------------- trunk/pywikipedia/userinterfaces/tkinter_interface.py
Modified: trunk/pywikipedia/userinterfaces/tkinter_interface.py =================================================================== --- trunk/pywikipedia/userinterfaces/tkinter_interface.py 2007-09-24 18:54:12 UTC (rev 4358) +++ trunk/pywikipedia/userinterfaces/tkinter_interface.py 2007-09-24 19:05:17 UTC (rev 4359) @@ -3,8 +3,11 @@ import time import re, sys, threading import tkMessageBox, tkSimpleDialog +import config from Tkinter import *
+color_pattern = re.compile(r"%s{(?P<colorname>\w+)}" % "\x03") + # we run the Tkinter mainloop in a separate thread so as not to block # the main bot code; however, this means that all communication with # the Tkinter interface has to be done through events that will be processed @@ -12,6 +15,7 @@ # interface code to call any of the Tkinter objects directly, except to # put events on their queue (e.g., .after_idle()).
+ class MainloopThread(threading.Thread): def __init__(self, window): threading.Thread.__init__(self) @@ -73,7 +77,6 @@ # display the menu # root.config(menu=menubar)
- def edit(self): return self.text
@@ -162,9 +165,31 @@ class OutputBox(Text): def __init__(self, parent, *args, **kwargs): Text.__init__(self, parent, *args, **kwargs) + # create color tags + # map Unix/ANSI color names to Tcl/Tk names + # because Tkinter background is white, we need darker colors + for ucolor, tcolor in ( + ('default', 'Black'), + ('lightblue', 'Blue'), + ('lightgreen', 'Green'), + ('lightaqua', 'DarkSeaGreen'), + ('lightred', 'Red'), + ('lightpurple', 'Violet'), + ('lightyellow', 'DarkOrange') + ): + self.tag_config(ucolor, foreground=tcolor)
def show(self, text): - self.insert(END, text) + global debugger + debugger = text + next_tag = 'default' + m = color_pattern.search(text) + while m: + self.insert(END, text[0:m.start()], next_tag) + next_tag = m.group("colorname") + text = text[m.end():] + m = color_pattern.search(text) + self.insert(END, text, next_tag) self.yview(END)
@@ -186,15 +211,12 @@ # put textarea into top frame, using all available space self.logBox.pack(anchor=CENTER, fill=BOTH) self.top_frame.pack(side=TOP) - self.logBox.tag_config(12, foreground='red') - self.logBox.tag_config(10, foreground='green')
-# self.parent.mainloop() MainloopThread(self.parent).start()
def output(self, text, urgency = 1, toStdout = False): """ - urgency levels: + urgency levels: (NOT IMPLEMENTED) 0 - Debug output. Won't be shown in normal mode. 1 - Will be shown in log window. 2 - Will be shown in error box.