73 lines
2.6 KiB
Plaintext
73 lines
2.6 KiB
Plaintext
From: arcege at shore.net (Michael P. Reilly)
|
|
Date: Fri, 07 May 1999 13:42:06 GMT
|
|
Subject: Tk communications between frames?
|
|
References: <pe8X2.124$AZ2.445@newsr2.maine.rr.com>
|
|
Message-ID: <O4CY2.928$9L5.341454@news.shore.net>
|
|
Content-Length: 2375
|
|
X-UID: 1801
|
|
|
|
David Miller <dmillerNO at MAPSmote.rsn.com> wrote:
|
|
: The application I'm developing in python/Tkinter needs to have
|
|
: a parent frame start some number of child browser frames. When the
|
|
: user double clicks on a file listed in a child listbox I want to
|
|
: insert the selection in a different listbox on the parent.
|
|
|
|
: Specifically, the parent is a master scheduling window. The child
|
|
: browsers drill down N directories deep, and there may be and number
|
|
: of child browsers. This is to let someone program video for playback
|
|
: at a TV station - pick a video from this category (sports tip, child1)
|
|
: a video from another category (athlete profile, child 2), then an ad
|
|
: from child 3.
|
|
|
|
: Is this easily doable? Doable without the security problems of send()?
|
|
|
|
Are the child frames seperate processes? Just toplevel windows within
|
|
the same process? If so, then there is no need to communicate over a
|
|
socket. Below assumes that the child frames are not seperate
|
|
processes.
|
|
|
|
I'm not sure how you would want to proceed, but my best suggestion
|
|
would be to take a more object oriented approach and less of a GUI
|
|
approach.
|
|
|
|
class Scheduler:
|
|
# no locking in this schedule, very simple
|
|
def __init__(self, master_frame):
|
|
self.queue = []
|
|
self.frame = Frame(master_frame)
|
|
self.create_widgets()
|
|
self.child_browser = Browser(self, self.frame)
|
|
self.frame.after_idle(self.do_work)
|
|
def add_workitem(self, item):
|
|
self.queue.append(item)
|
|
def do_work(self):
|
|
self.process_queue()
|
|
|
|
class Browser(Toplevel):
|
|
def __init__(self, scheduler, master):
|
|
Toplevel.__init__(self, master, bd=2)
|
|
self.scheduler = scheduler
|
|
self.listbox = Listbox(self, setgrid=1, relief=SUNKEN)
|
|
scroll = Scrollbar(self, command=self.listbox.yview, relief=SUNKEN)
|
|
self.listbox['yscrollcommand'] = scroll.set
|
|
self.bind('<Double-Button-1>', self.select)
|
|
scroll.pack(side=RIGHT, fill=Y, expand=YES)
|
|
self.listbox.pack(side=LEFT, fill=BOTH, expand=YES)
|
|
def select(self, event):
|
|
items = self.listbox.curselection()
|
|
# some versions of Tkinter do not convert to Python integers
|
|
try: items = map(string.atoi, items)
|
|
except ValueError: pass
|
|
itempos = items[0]
|
|
self.scheduler.add_workitem(self.listbox.get(itempos))
|
|
|
|
This lets you use the parent as a workhouse instead of as just a
|
|
widget, which may be more appropriate.
|
|
|
|
-Arcege
|
|
|
|
|
|
|
|
|
|
|