modcopy - tips & tricks (original) (raw)
How do I use all methods available in the Tix Grid?
Tix Grid with full implementation of all methods
How do I create a multi-column Tix.HList?
import Tkinter as Tk
import Tix
root = Tix.Tk()
# setup HList
hl = Tix.HList(root, columns = 5, header = True)
hl.header_create(0, text = "File")
hl.header_create(1, text = "Date")
hl.header_create(1, text = "Size")
# create a multi-column row
hl.add("row1", text = "filename.txt")
hl.item_create(entry_path, 1, text = "2009-03-26 21:07:03")
hl.item_create(entry_path, 2, text = "200MiB")
How do I modify the style of a column?
style['header'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist, anchor=Tix.CENTER, padx=8, pady=2, font = boldfont )
hlist.header_create(0, itemtype=Tix.TEXT, text='Name', style=style['header'])
This is an excerpt from the example program SHList2.py in Tix8.4.3\Python\Demo\tix\samples.
How to implement Tk GUI with multiple threads?
Usually there are two options to make threads wait for an event:
- gui thread polling (lame)
see here how to use Tk.after() (actually a Tcl command) to poll
http://uucode.com/texts/pylongopgui/pyguiapp.html
see here how to imitate the Tk event loop to poll for non-Tk events (a socket, for example)
https://sourceforge.net/project/showfiles.php?group_id=5649&package_id=5704
Tix8.4.3-src.tar.gz, then look in /Tix8.4.3/Python/Demo/tix/tixwidgets.py, find loop(). - multithreaded with events (the option to choose)
Basically this uses bind and event_generate to send "Notify" messages to the Tk instance.
I suspect the following example failed due to not synchronising the event_generate call
http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-07/msg01479.html
Best practice
For multithreading Python Tk GUI applications the following rules apply:
- same thread calling Tk must do all subsequent GUI calls,
- other threads may send events with send_event to the root Tk instance,
- with threading problems you might try to synchronise access to event_generate(). Using event_generate() with only one non-GUI thread has found not to be safe