From mart.franklin at gmail.com Sat Apr 2 17:52:01 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Sat Apr 2 17:52:35 2005 Subject: [Tkinter-discuss] Re: Here's a tough one -- dynamic, multi-line XML syntax highlighting In-Reply-To: <42483A72.2080506@noaa.gov> References: <42483A72.2080506@noaa.gov> Message-ID: Jared Cohen wrote: > Hiya. My current project is an XML editor using the Tkinter.Text widget. > Using the parsing tools from xml.parsers.expat, I've managed to > implement a nice system of syntax highlighting when the document is > first loaded. However, I want the user to be able to edit the text, and > have the highlightling automatically update to conform to whatever is > added or deleted. I can easily do this for single-line tags (those that > start and end on the same line), because then I can just read in that > one line and use the parser to re-highlight it. But for multiple-line > tags, like comments or CDATA sections, it's not so easy. > > The problem is that the exact location where the user inserts/removes > text, will determine how the highlighting changes. For example, a > comment block is delimeted by Now, if the user types new > text BETWEEN those two tags, nothing changes; the new text gets the > existing "comment" highlighting that's already there. If they type new > text on the same line as one of the delimeters, but outside their range, > it gets no tags at all. But if the new text is INSIDE one of the > delimeters themselves (making them no longer syntactically valid), then > the whole comment block needs to get re-highlighted. And I don't know > how to do that without re-highlighting the WHOLE document all over > again. When that happens with every single keystroke, it adds up to a > whole lot of highlighting. There's got to be a better way, but I can't > think of one. Can anyone help? > > And by the way, I already know about the xmltools package from logilab, > and it might be exactly what I need. However, I'm working on this > project at my office, not at home; so I have to rely on the sysadmins to > install new packages. And the xmltools package will require a LOT of > dependancies, so it doesn't look like it'll be done any time in the near > future. :-( > Jared, I've Been away so only just spotted this message have you looked at the ColorDelagator class in idlelib? It is very fast. I am don't know how easy it would be to change it syntax rules, but I'm sure it beats rolling your own colourizer... Martin. From glee at pharsight.com Mon Apr 4 21:29:13 2005 From: glee at pharsight.com (Greg Lee) Date: Mon Apr 4 23:52:46 2005 Subject: [Tkinter-discuss] making tkFileDialog and tkMessageBox modal on Win32 Message-ID: <08AAC77C2656414E91980F8EBB1E7F0102ADB6A3@electra.corp.pharsight.com> Is there a way to make these dialogs modal on Win32? -------------------------------------------- Greg Lee / Pharsight Corporation / Suite 200 800 W El Camino / Mountain View CA 94040 voice: 650-314-3860 / fax: 650-314-3810 This email message (including any attachments) is for the sole use of the intended recipient and may contain confidential and proprietary information. Any disclosure or distribution to third parties that is not specifically authorized by the sender is prohibited. If you are not the intended recipient, please contact the sender (greg@pharsight.com) by reply email and destroy all copies of the original message. Thank you. From fredrik at pythonware.com Tue Apr 5 17:04:35 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Tue Apr 5 17:06:57 2005 Subject: [Tkinter-discuss] Re: making tkFileDialog and tkMessageBox modal onWin32 References: <08AAC77C2656414E91980F8EBB1E7F0102ADB6A3@electra.corp.pharsight.com> Message-ID: Greg Lee wrote: > Is there a way to make these dialogs modal on Win32? well, they sure are modal on my machine. maybe you could post an example, tell us how it behaves on your machine, and tell us how you expected it to behave. From glee at pharsight.com Wed Apr 6 20:04:50 2005 From: glee at pharsight.com (Greg Lee) Date: Wed Apr 6 20:04:55 2005 Subject: [Tkinter-discuss] Re: making tkFileDialog and tkMessageBox modal on Win32 Message-ID: <08AAC77C2656414E91980F8EBB1E7F01037EFB50@electra.corp.pharsight.com> The esteemed Fredrik Lundh responded: > well, they sure are modal on my machine. maybe you could post an example, tell > us how it behaves on your machine, and tell us how you expected it to behave. I, too, have seen the file dialogs behave modally on my machine---but not always. This following has a top-level window with a menu item that launches a child. The child has two browse buttons. On my machine I can use the browse buttons to bring up about eleven simultaneous file dialogs. What I had hoped for was that the first file dialog to appear would be modal, i.e. the browse buttons would be inactive until the file dialog was dismissed. -------------------------------------------- import os import Tkinter import tkMessageBox import tkFileDialog import sys # constants for NewPhx widgets CONFIG_ROW = 0 SOURCEDIR_ROW = 1 ENTRY_WIDTH = 64 LABEL_WIDTH= 21 class NewPhx: def __init__(self, top): self.top = top self.title = "See how many browse dialogs we can launch" self.top.title(self.title) self.frame = Tkinter.Frame(self.top) self.frame.grid() self.count = 0 # Control variables self.configfile = Tkinter.StringVar() # Add the widgets self.browserow('File 1', self.configfile, self.cb_file1, CONFIG_ROW) self.browserow('File 2', self.configfile, self.cb_file2, SOURCEDIR_ROW) def browserow(self, labeltext, entryvar, cb, row): '''Make a row to browse for a file or directory.''' Tkinter.Label(self.frame, text=labeltext + ":", anchor=Tkinter.W, width=LABEL_WIDTH).grid(row=row, column=0) Tkinter.Entry(self.frame, textvariable=entryvar, width=ENTRY_WIDTH).grid(row=row, column=1, columnspan=3) self.spacer(row, 4) Tkinter.Button(self.frame, text='Browse...', command=cb).grid(row=row, sticky=Tkinter.W, column=5) def spacer(self, row, column=0, text=' '): Tkinter.Label(self.frame, text=text).grid(row=row, column=column) def cb_file1(self): self.cb_configfile('file1') def cb_file2(self): self.cb_configfile('file2') def cb_configfile(self, which): '''Callback for configuration-file button''' self.count += 1 kw = {'title': '%s %d' % (which, self.count)} retval = tkFileDialog.askopenfilename(**kw) if retval: self.configfile.set(os.path.normpath(retval)) class App: def __init__(self, root): self.root = root menubar = Tkinter.Menu(self.root) self.root.config(menu=menubar) taskmenu = Tkinter.Menu(menubar, tearoff=0) taskmenu.add_command(label='Launch child', command=self.menu_new) menubar.add_cascade(label='Pick task', menu=taskmenu) def menu_new(self): NewPhx(Tkinter.Toplevel(self.root)) def main(argv): root = Tkinter.Tk() App(root) root.mainloop() if __name__ == '__main__': main(sys.argv) -------------------------------------------- Greg Lee / Pharsight Corporation / Suite 200 800 W El Camino / Mountain View CA 94040 voice: 650-314-3860 / fax: 650-314-3810 From klappnase at web.de Wed Apr 6 21:33:03 2005 From: klappnase at web.de (Michael Lange) Date: Wed Apr 6 21:29:40 2005 Subject: [Tkinter-discuss] Re: making tkFileDialog and tkMessageBox modal on Win32 In-Reply-To: <08AAC77C2656414E91980F8EBB1E7F01037EFB50@electra.corp.pharsight.com> References: <08AAC77C2656414E91980F8EBB1E7F01037EFB50@electra.corp.pharsight.com> Message-ID: <20050406213303.6317e661.klappnase@web.de> On Wed, 6 Apr 2005 11:04:50 -0700 "Greg Lee" wrote: > The esteemed Fredrik Lundh responded: > > > well, they sure are modal on my machine. maybe you could post an example, tell > > us how it behaves on your machine, and tell us how you expected it to behave. > > I, too, have seen the file dialogs behave modally on my machine---but not always. > > This following has a top-level window with a menu item that launches a child. The child has two browse buttons. On my machine I can use the browse buttons to bring up about eleven simultaneous file dialogs. What I had hoped for was that the first file dialog to appear would be modal, i.e. the browse buttons would be inactive until the file dialog was dismissed. > -------------------------------------------- > > import os > import Tkinter > import tkMessageBox > import tkFileDialog > import sys > > # constants for NewPhx widgets > CONFIG_ROW = 0 > SOURCEDIR_ROW = 1 > ENTRY_WIDTH = 64 > LABEL_WIDTH= 21 > > class NewPhx: ...... On my box (linux) the file dialog is modal, however because you didn't specify a parent to the file dialog it's modal to the root window and not to the child-toplevel, so I can lift the toplevel over the file dialog, but as expected the toplevel's buttons do not respond. Maybe it's a system/Tk-version problem that the grab doesn't work for you? Anyway, you could try to pass "parent=self.top" to askopenfilename() and see what happens. I hope this helps Michael From stewart.midwinter at gmail.com Wed Apr 6 23:31:57 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed Apr 6 23:31:59 2005 Subject: [Tkinter-discuss] Re: making tkFileDialog and tkMessageBox modal on Win32 In-Reply-To: <20050406213303.6317e661.klappnase@web.de> References: <08AAC77C2656414E91980F8EBB1E7F01037EFB50@electra.corp.pharsight.com> <20050406213303.6317e661.klappnase@web.de> Message-ID: Good observation, Michael! That was the ticket, at least for me when I run Greg's sample app on WinXP with Python 2.4.1 cheers S On Apr 6, 2005 1:33 PM, Michael Lange wrote: > On my box (linux) the file dialog is modal, however because you didn't specify a parent to the file dialog > it's modal to the root window and not to the child-toplevel, so I can lift the toplevel over the file dialog, > but as expected the toplevel's buttons do not respond. Maybe it's a system/Tk-version problem that the grab > doesn't work for you? Anyway, you could try to pass "parent=self.top" to askopenfilename() and see what happens. -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad From glee at pharsight.com Thu Apr 7 01:16:51 2005 From: glee at pharsight.com (Greg Lee) Date: Thu Apr 7 01:16:55 2005 Subject: [Tkinter-discuss] RE: Re: making tkFileDialog and tkMessageBox modal on Win32 Message-ID: <08AAC77C2656414E91980F8EBB1E7F01037EFB52@electra.corp.pharsight.com> On Apr 6, 2005 1:33 PM, Michael Lange wrote: > On my box (linux) the file dialog is modal, however because you didn't specify a parent to the file dialog > it's modal to the root window and not to the child-toplevel, so I can lift the toplevel over the file dialog, > but as expected the toplevel's buttons do not respond. Maybe it's a system/Tk-version problem that the grab > doesn't work for you? Anyway, you could try to pass "parent=self.top" to askopenfilename() and see what happens. This change makes the dialog modal with respect to the child-toplevel, but not to the root window. (This isn't good enough because my real application has some other tasks, I can launch them while the file dialog is up, but their rendering is fubar.) I experimented a bit and discovered that tkFileDialog and tkMessageBox share this behavior. In contrast, tkSimpleDialog does not: it appears to be application modal. If memory serves, the former use the native Win32 dialogs, but the latter does not. From jepler at unpythonic.net Thu Apr 7 03:50:44 2005 From: jepler at unpythonic.net (jepler@unpythonic.net) Date: Thu Apr 7 03:50:47 2005 Subject: [Tkinter-discuss] RE: Re: making tkFileDialog and tkMessageBox modal on Win32 In-Reply-To: <08AAC77C2656414E91980F8EBB1E7F01037EFB52@electra.corp.pharsight.com> References: <08AAC77C2656414E91980F8EBB1E7F01037EFB52@electra.corp.pharsight.com> Message-ID: <20050407015044.GA19863@unpythonic.net> I just took a look at what we do in the linux/windows/tcl/tk app I work with. It looks like when we create dialogs with tk_getOpenFile and friends, they are created with the proper parent *and that parent has the Tk application-level grab*. The result on Windows seems to be that Tk prohibits interaction with the other toplevel windows of the application, and Windows prohibits interaction with the parent window of the file dialog. Maybe this general arrangement will work for you. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050406/531e06a5/attachment.pgp From glee at pharsight.com Fri Apr 8 02:52:57 2005 From: glee at pharsight.com (Greg Lee) Date: Fri Apr 8 02:53:09 2005 Subject: [Tkinter-discuss] Re: making tkFileDialog and tkMessageBox modal on Win32 Message-ID: <08AAC77C2656414E91980F8EBB1E7F01037EFB56@electra.corp.pharsight.com> jepler's suggestion seems to solve the problem: # Wrap a dialog in a grab pair. # Use to make tkFileDialog and tkMessageBox application-modal. # Not needed for tkSimpleDialog. # tk - grab target # f - tkFileDialog.askopenfilename, tkMessageBox.showinfo, etc. # kw - dictionary of key-word arguments to f def wrapgrab(tk, f, kw): kw['parent'] = tk tk.grab_set() retval = f(**kw) tk.grab_release() return retval thanks, greg ps: is the need to use the grab function a bug or something I should have expected? From jepler at unpythonic.net Fri Apr 8 03:04:10 2005 From: jepler at unpythonic.net (jepler@unpythonic.net) Date: Fri Apr 8 03:04:15 2005 Subject: [Tkinter-discuss] Re: making tkFileDialog and tkMessageBox modal on Win32 In-Reply-To: <08AAC77C2656414E91980F8EBB1E7F01037EFB56@electra.corp.pharsight.com> References: <08AAC77C2656414E91980F8EBB1E7F01037EFB56@electra.corp.pharsight.com> Message-ID: <20050408010410.GA4146@unpythonic.net> On Thu, Apr 07, 2005 at 05:52:57PM -0700, Greg Lee wrote: > ps: is the need to use the grab function a bug or something > I should have expected? Good question. The behavior has been this way in Tk since the introduction of the Windows-native dialogs. If it hasn't been fixed in that time, the Tk folks must not consider it a bug. If window B is not modal, (you can still work with window A while it's displayed) then why do you want the dialog which is conceptually the child of B to block interaction with A? Maybe the behavior you saw on Windows is correct for this reason. On the other hand, it's still a cross-platform difference between Unix and Windows. That's not a very good answer, but it's the best I have. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050407/87c53f08/attachment.pgp From jepler at unpythonic.net Tue Apr 12 17:44:24 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Tue Apr 12 17:44:35 2005 Subject: [Tkinter-discuss] Tkinter clipboard_get method... In-Reply-To: References: Message-ID: <20050412154424.GE2419@unpythonic.net> I know this message was written a long time ago, but I finally got around to investigating this. I added my comments to the SF tracker item and recommended that the patch be applied as-is. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050412/ee34e63b/attachment.pgp From marvboyes at gmail.com Tue Apr 12 22:18:43 2005 From: marvboyes at gmail.com (Marv Boyes) Date: Tue Apr 12 22:20:16 2005 Subject: [Tkinter-discuss] Font control in tkMessageBox? Message-ID: <425C2D23.4080209@gmail.com> Hello, all. Sorry if this is so elementary that I should have been able to find it on my own; if it's out there, I must have missed it. I'm wondering if it's possible to specify font type and size in a tkMessageBox under Python 2.3 in Linux. Nothing I've tried has worked, and my messagebox text is simply coming out too big for what I want to do. Any guidance would be greatly appreicated; thanks very much in advance. Marv Boyes From mart.franklin at gmail.com Tue Apr 12 22:48:53 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Tue Apr 12 22:52:01 2005 Subject: [Tkinter-discuss] Re: Tkinter clipboard_get method... In-Reply-To: <20050412154424.GE2419@unpythonic.net> References: <20050412154424.GE2419@unpythonic.net> Message-ID: Jeff Epler wrote: > I know this message was written a long time ago, but I finally got > around to investigating this. I added my comments to the SF tracker > item and recommended that the patch be applied as-is. > Thanks Jeff, I had forgotten about that. From glee at pharsight.com Wed Apr 13 01:10:26 2005 From: glee at pharsight.com (Greg Lee) Date: Wed Apr 13 01:10:33 2005 Subject: [Tkinter-discuss] Re: making tkFileDialog and tkMessageBox modal on Win32 Message-ID: <08AAC77C2656414E91980F8EBB1E7F01037EFB5E@electra.corp.pharsight.com> On Fri Apr 8 03:04:10 CEST 2005, jepeler wrote: >If window B is not modal, (you can still work with window A while it's >displayed) then why do you want the dialog which is conceptually the child of B >to block interaction with A? Maybe the behavior you saw on Windows is >correct for this reason. If a file-dialog child of B is active and I launch A, the rendering of A is messed up. Application modality prevents this. Absent this rendering problem, I probably wouldn't care (although it would still be odd that tkSimpleDialog is application-modal but tkFileDialog and tkMessageBox are not). -------------------------------------------- Greg Lee / Pharsight Corporation / Suite 200 800 W El Camino / Mountain View CA 94040 voice: 650-314-3860 / fax: 650-314-3810 This email message (including any attachments) is for the sole use of the intended recipient and may contain confidential and proprietary information. Any disclosure or distribution to third parties that is not specifically authorized by the sender is prohibited. If you are not the intended recipient, please contact the sender (greg@pharsight.com) by reply email and destroy all copies of the original message. Thank you. From klappnase at web.de Wed Apr 13 11:18:46 2005 From: klappnase at web.de (Michael Lange) Date: Wed Apr 13 11:15:11 2005 Subject: [Tkinter-discuss] Font control in tkMessageBox? In-Reply-To: <425C2D23.4080209@gmail.com> References: <425C2D23.4080209@gmail.com> Message-ID: <20050413111846.1bbf234b.klappnase@web.de> On Tue, 12 Apr 2005 16:18:43 -0400 Marv Boyes wrote: > Hello, all. Sorry if this is so elementary that I should have been able > to find it on my own; if it's out there, I must have missed it. > > I'm wondering if it's possible to specify font type and size in a > tkMessageBox under Python 2.3 in Linux. Nothing I've tried has worked, > and my messagebox text is simply coming out too big for what I want to do. > > Any guidance would be greatly appreicated; thanks very much in advance. > > > Marv Boyes Hi Marv, you can specify an application-wide default font which will be used by tkMessageBox , too. >>> from Tkinter import * >>> import tkMessageBox >>> r = Tk() >>> r.option_add('*font', 'Helvetica -12') >>> tkMessageBox.showinfo(message='Hello') I hope this helps Michael From stewart.midwinter at gmail.com Wed Apr 13 17:37:36 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed Apr 13 17:37:38 2005 Subject: [Tkinter-discuss] Font control in tkMessageBox? In-Reply-To: <20050413111846.1bbf234b.klappnase@web.de> References: <425C2D23.4080209@gmail.com> <20050413111846.1bbf234b.klappnase@web.de> Message-ID: On 4/13/05, Michael Lange wrote: > you can specify an application-wide default font which will be used by tkMessageBox , too. > > >>> from Tkinter import * > >>> import tkMessageBox > >>> r = Tk() > >>> r.option_add('*font', 'Helvetica -12') > >>> tkMessageBox.showinfo(message='Hello') This seems to have no effect under WindowsXP. If I use a different widget, I do get the font to be set, but only if I add the following line before instantiating my widget: r.option_readfile('optionDB') also, you have to explicitly create your file optionDB before you run your app. The following example does show colours and fonts set: from Tkinter import * import tkMessageBox, os optionFile = 'optionDB' if not os.path.exists(optionFile): f1 = open(optionFile,'r') f1.close() r = Tk() r.option_add('*font', ('Courier 6 italic')) r.option_readfile('optionDB') tkMessageBox.showinfo(message='Hello, World!') l = Label(r, text = "What colour am I?") b = Button(r, text = "Quit Now!", command= sys.exit) l.pack() b.pack() r.mainloop() -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad From stewart.midwinter at gmail.com Wed Apr 13 17:38:43 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed Apr 13 17:38:45 2005 Subject: [Tkinter-discuss] Font control in tkMessageBox? In-Reply-To: References: <425C2D23.4080209@gmail.com> <20050413111846.1bbf234b.klappnase@web.de> Message-ID: I forgot to include the contents of my optionsDB: *font: Verdana 28 *Label*font: Verdana 28 bold *background: yellow *Entry*background: white *Label*background: yellow *foreground: blue *tkMessageBox*background: yellow *Button*background: orange Setting options using option_add appears to have no effect for me. -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad From klappnase at web.de Wed Apr 13 20:25:28 2005 From: klappnase at web.de (Michael Lange) Date: Wed Apr 13 20:21:54 2005 Subject: [Tkinter-discuss] Font control in tkMessageBox? In-Reply-To: References: <425C2D23.4080209@gmail.com> <20050413111846.1bbf234b.klappnase@web.de> Message-ID: <20050413202528.107e4e94.klappnase@web.de> On Wed, 13 Apr 2005 09:38:43 -0600 Stewart Midwinter wrote: > On 4/13/05, Michael Lange wrote: > > you can specify an application-wide default font which will be used by tkMessageBox , too. > > > > >>> from Tkinter import * > > >>> import tkMessageBox > > >>> r = Tk() > > >>> r.option_add('*font', 'Helvetica -12') > > >>> tkMessageBox.showinfo(message='Hello') > > This seems to have no effect under WindowsXP. I think under windows Tk uses native OS message boxes, the original poster asked about linux. > I forgot to include the contents of my optionsDB: > > *font: Verdana 28 > *Label*font: Verdana 28 bold > *background: yellow > *Entry*background: white > *Label*background: yellow > *foreground: blue > *tkMessageBox*background: yellow > *Button*background: orange > > Setting options using option_add appears to have no effect for me. > > I think option_add() *should* work, I don't have windows installed though, so I cannnot try it here. I know you can use option_readfile() as well, but if you just want to change the default font it seemed nicer to me if you don't need an extra file. BTW, does this: *tkMessageBox*background: yellow work under windows (under linux it surely does not)? Best regards Michael From stewart.midwinter at gmail.com Wed Apr 13 22:17:14 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed Apr 13 22:17:17 2005 Subject: [Tkinter-discuss] Font control in tkMessageBox? In-Reply-To: <20050413202528.107e4e94.klappnase@web.de> References: <425C2D23.4080209@gmail.com> <20050413111846.1bbf234b.klappnase@web.de> <20050413202528.107e4e94.klappnase@web.de> Message-ID: On 4/13/05, Michael Lange wrote: > BTW, does this: > *tkMessageBox*background: yellow > work under windows (under linux it surely does not)? No, that didn't work. I tried it just to see, but nothing seems to change the default background of a tkMessageBox widget under Windows. s -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad From Jared.Cohen at noaa.gov Wed Apr 13 22:24:51 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Wed Apr 13 22:24:55 2005 Subject: [Tkinter-discuss] Okay, this one really has me baffled -- KeyboardInterrupt signal not working! Message-ID: <425D8013.4070702@noaa.gov> Thanks a bunch for everybody's help with the syntax highlighting problem, but I finally got fed up with trying, so now I'm looking for a good XML parser to do the work for me ;-) Anyway, now there's a new problem. Part of my application executes a system command, captures the standard input/output/error pipes using "(stdin, stdout_err) = os.popen4(...)", and displays them to a Pmw TextDialog. Now then, this system command may take a long time to execute, so I want the user to be able to abort the process if they decide it's taking too long or if they realize they made a mistake. In essence, the output dialog should function like a shell window, which means the user can press Ctrl-C to send an interrupt signal. I *THOUGHT* I could do that by adding an Abort button, which raises a KeyboardException. Here's the full code snippet: ######################################################################################## def SetupOutputDialog(self): self.outputDialog = Pmw.TextDialog(self.root, title="Output", text_state='disabled', buttons=('OK', 'Abort'), command=self.OutputButtonPress) ...... def OutputButtonPress(self, button): if button == 'OK': self.outputDialog.withdraw() elif button == 'Abort': raise KeyboardInterrupt ..... (stdin, stdout_err) = os.popen4(compileString + " &") s = stdout_err.readline() while s != "": self.outputDialog.appendtext(s) self.outputDialog.update() s = stdout_err.readline() ######################################################################################## Seems perfectly sound, right? But for some reason, the Abort button doesn't seem to work right. When I press it, I get the following exception: KeyboardInterrupt Exception in Tk callback Function: at 0x40ac9bc4> (type: ) Args: () Traceback (innermost last): File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwBase.py", line 1747, in __call__ return apply(self.func, args) File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwDialog.py", line 153, in command=lambda self=self, name=name: self._doCommand(name)) File "/usr/lib/python2.3/site-packages/Pmw/Pmw_1_2/lib/PmwDialog.py", line 132, in _doCommand return command(name) File "/home/jmc/projects/tkfre/src/freMainGui.py", line 361, in OutputButtonPress raise KeyboardInterrupt KeyboardInterrupt: That seems like the exception I was supposed to get.......but the process didn't stop!!! It detected the interrupt signal, but it didn't interrupt anything! The wierd thing is, if I Alt-Tab back into the shell from which I started this application, and actually type Ctrl-C there, THEN it works. But I don't understand why raising the KeyboardInterrupt signal doesn't seem to do anything! Can anyone help please? From jepler at unpythonic.net Wed Apr 13 23:05:03 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Wed Apr 13 23:05:25 2005 Subject: [Tkinter-discuss] Font control in tkMessageBox? In-Reply-To: References: <425C2D23.4080209@gmail.com> <20050413111846.1bbf234b.klappnase@web.de> <20050413202528.107e4e94.klappnase@web.de> Message-ID: <20050413210503.GA26058@unpythonic.net> You can force Tk to use the non-native dialogs on Windows, but in a Tk-version-dependent fashion. The following code is snipped from tk.tcl on my 8.3 installation: #---------------------------------------------------------------------- # Define common dialogs on platforms where they are not implemented # using compiled code. #---------------------------------------------------------------------- if {[string equal [info commands tk_chooseColor] ""]} { proc tk_chooseColor {args} { return [eval tkColorDialog $args] } } # [and likewise for tk_getOpenFile, tk_getSaveFile, tk_messageBox, # tk_chooseDirectory] If you know the version-specific code you can just remove the check for the native version and directly evaluate something like this just after creating your interpreter: catch { rename tk_chooseColor {} } proc tk_chooseColor {args} { return [eval tkColorDialog $args] } I discourage actually doing this for a number of reasons. Besides being an implementation detail (one that changed between 8.3 and 8.4, iirc) and not a public interface, there's the fact that you create the best experience for your users by having an application that looks like the others that run on the same system. Except for pure turn-key systems, this means looking like the other programs on the same platform. You should think twice before throwing away the fact that these native dialogs are, well, native. Lastly, the non-native file and directory dialogs probably doesn't support drive letters so it's going to be pretty useless on Windows machines. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050413/a18a81d6/attachment.pgp From klappnase at web.de Thu Apr 14 11:29:10 2005 From: klappnase at web.de (Michael Lange) Date: Thu Apr 14 11:25:36 2005 Subject: [Tkinter-discuss] Okay, this one really has me baffled -- KeyboardInterrupt signal not working! In-Reply-To: <425D8013.4070702@noaa.gov> References: <425D8013.4070702@noaa.gov> Message-ID: <20050414112910.6d99fd53.klappnase@web.de> On Wed, 13 Apr 2005 16:24:51 -0400 Jared Cohen wrote: > Thanks a bunch for everybody's help with the syntax highlighting > problem, but I finally got fed up with trying, so now I'm looking for a > good XML parser to do the work for me ;-) > > Anyway, now there's a new problem. Part of my application executes a > system command, captures the standard input/output/error pipes using > "(stdin, stdout_err) = os.popen4(...)", and displays them to a Pmw > TextDialog. > > Now then, this system command may take a long time to execute, so I want > the user to be able to abort the process if they decide it's taking too > long or if they realize they made a mistake. In essence, the output > dialog should function like a shell window, which means the user can > press Ctrl-C to send an interrupt signal. I *THOUGHT* I could do that by > adding an Abort button, which raises a KeyboardException. Here's the > full code snippet: > > ######################################################################################## > > def SetupOutputDialog(self): > self.outputDialog = Pmw.TextDialog(self.root, > title="Output", > text_state='disabled', > buttons=('OK', 'Abort'), > command=self.OutputButtonPress) > ...... > > def OutputButtonPress(self, button): > if button == 'OK': > self.outputDialog.withdraw() > elif button == 'Abort': > raise KeyboardInterrupt > > ..... > > (stdin, stdout_err) = os.popen4(compileString + " &") > s = stdout_err.readline() > while s != "": > self.outputDialog.appendtext(s) > self.outputDialog.update() > s = stdout_err.readline() > > ######################################################################################## > > > Seems perfectly sound, right? But for some reason, the Abort button > doesn't seem to work right. When I press it, I get the following exception: > I guess you would have to send the keyboard interrupt signal to the compileString process with os.kill(pid, 2) where pid is of course the process id of the compileString process. Best regards Michael From camfarnell at cogeco.ca Thu Apr 14 19:16:11 2005 From: camfarnell at cogeco.ca (Cam) Date: Thu Apr 14 19:16:18 2005 Subject: [Tkinter-discuss] Unwanted Text widget bindings Message-ID: <425EA55B.1020909@cogeco.ca> Hello list, I'm running on a Debian/Gnome Linux box. The "Text" widget comes with a bunch of free bindings to various control codes, for "home", for "cursor left" and so on, none of which I want for my application. Most of these I can get rid of by doing w.unbind_class('Text',''), but the bindings for Control-x (cut), Control-c (copy) and Control-v (paste) are different; they persist even after unbind, unbind_class and unbind_all. I know you CAN get rid of them because Guido manages it just fine in Idle. However, several hours of pouring over the Idle source has not left me any closer to figuring out just how Idle manages to defeat these bindings. If any of you list members know what the secret is or can point me to some documentation that covers this issue I would *very* much appreciate it. Thanks Cam Farnell From klappnase at web.de Thu Apr 14 21:47:00 2005 From: klappnase at web.de (Michael Lange) Date: Thu Apr 14 21:43:24 2005 Subject: [Tkinter-discuss] Unwanted Text widget bindings In-Reply-To: <425EA55B.1020909@cogeco.ca> References: <425EA55B.1020909@cogeco.ca> Message-ID: <20050414214700.609e79dd.klappnase@web.de> On Thu, 14 Apr 2005 13:16:11 -0400 Cam wrote: > Hello list, > > I'm running on a Debian/Gnome Linux box. > > The "Text" widget comes with a bunch of free bindings to various control > codes, for "home", for "cursor left" and so on, > none of which I want for my application. Most of these I can get rid of > by doing w.unbind_class('Text',''), but the bindings > for Control-x (cut), Control-c (copy) and Control-v (paste) are > different; they persist even after unbind, unbind_class and unbind_all. > > I know you CAN get rid of them because Guido manages it just fine in > Idle. However, several hours of pouring over the Idle source has not > left me any closer to figuring out just how Idle manages to defeat these > bindings. > > If any of you list members know what the secret is or can point me to > some documentation that covers this issue I would *very* much appreciate it. > > Thanks > > Cam Farnell You can get rid of the default bindings if you replace them with a "dummy" callback that prevents the event from being propagated to the widget: >>> r=Tk() >>> t=Text(r) >>> t.pack() >>> t.bind('', lambda event : 'break') I hope this helps Michael From dimitri.pater at gmail.com Fri Apr 15 23:38:26 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Fri Apr 15 23:38:39 2005 Subject: [Tkinter-discuss] scrolledframepage and multilistbox Message-ID: Hello! I recently included this very nice recipe for the multilistbox in my application: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52266 however I can't seem to get it to fit into a scrolledframe, this is what I do: /snip self.frame1 = Pmw.ScrolledFrame(page, labelpos = 'n', label_text = 'Database', vertflex="elastic") self.frame1.pack(fill="both", expand=1) /snip /snip columns = tuple([x[0:1] for x in fg.fields]) columns2 = tuple([x+(15,) for x in columns]) self.mlb = MultiLB.MultiListbox(self.frame1.interior(), columns2) for i in range(len(fg.data)): self.mlb.insert("end", fg.data[i]) self.mlb.pack(expand=1, fill="both") /snip the horizontal scrollbar is displayed correctly, but the vertical scrollbar is only visible when you scroll to the far right side of the screen. So, apparently it is added to the last listbox in stead of to the scrolledframe itself. Any suggestions, anyone? Thanks, Dimitri -- -- Please visit dimitri's website: www.serpia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050415/f8a149ed/attachment.htm From Jared.Cohen at noaa.gov Mon Apr 18 21:04:54 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Mon Apr 18 21:04:58 2005 Subject: [Tkinter-discuss] Okay, this one really has me baffled --KeyboardInterrupt signal not working! Message-ID: <426404D6.5070105@noaa.gov> Well, I tried your suggestion, but no dice. The problem is that the system command I'm calling, immediately forks several other processes which actually do the work; the initial process seems to be just a dummy. But I can't get the PIDs of those child processes, so I can't kill them from inside the program. In fact, the os.kill() method doesn't even seem to work on the initial, dummy process. I don't think this route is going to pan out. Thanks anyway, though. However, as I said previously, if I physically go into the terminal window and hit Ctrl-C, the interrupt signal works. What I need is some way to do that from inside my program; that is, to send the interrupt signal directly to the controlling terminal. Any ideas? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050418/3c3a6ff7/attachment.html From smr at essemer.com.au Tue Apr 19 02:24:40 2005 From: smr at essemer.com.au (Steven Reddie) Date: Tue Apr 19 02:24:51 2005 Subject: [Tkinter-discuss] Tix failures:: _tkinter.TclError: invalid command name "tixNoteBook" Message-ID: <200504190024.j3J0Oj3d024811@mail08.syd.optusnet.com.au> Hi, I'm having trouble getting Tix to work (appologies if the Tkinter list isn't the correct place for Tix issues). I'm guessing that it's a configuration problem, however I get the exact same failures with Cygwin's Python and the python.org Windows Python, on multiple machines. Here is a session using the python.org Windows Python 2.4: Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import Tkinter >>> import Tix >>> Tix.Grid() >>> Tix.NoteBook() Traceback (most recent call last): File "", line 1, in ? File "C:\Program Files\Python24\lib\lib-tk\Tix.py", line 1138, in __init__ TixWidget.__init__(self,master,'tixNoteBook', ['options'], cnf, kw) File "C:\Program Files\Python24\lib\lib-tk\Tix.py", line 307, in __init__ self.tk.call(widgetName, self._w, *extra) _tkinter.TclError: invalid command name "tixNoteBook" The path includes "C:\Program Files\Python24" and "C:\Program Files\Python24\DLLs" so I'm assuming the issue isn't that tix8184.dll couldn't be found, and since Tkinter is working elsewhere I'm assuming that the issue isn't that tcl isn't configured properly, but maybe it hasn't been configured for tix? When using Cygwin's Python the results are identical (except for the instance address and path to Tix.py); this is for Python 2.4 on the same machine and 2.3 on another machine. I've found various posts (about: _tkinter.TclError: invalid command name "???????") but none have helped. Any help would be much appreciated. Regards, Steven From mart.franklin at gmail.com Tue Apr 19 15:22:42 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Tue Apr 19 15:26:27 2005 Subject: [Tkinter-discuss] Re: Tix failures:: _tkinter.TclError: invalid command name "tixNoteBook" In-Reply-To: <200504190024.j3J0Oj3d024811@mail08.syd.optusnet.com.au> References: <200504190024.j3J0Oj3d024811@mail08.syd.optusnet.com.au> Message-ID: Steven Reddie wrote: > Hi, > > I'm having trouble getting Tix to work (appologies if the Tkinter list isn't > the correct place for Tix issues). I'm guessing that it's a configuration > problem, however I get the exact same failures with Cygwin's Python and the > python.org Windows Python, on multiple machines. > > Here is a session using the python.org Windows Python 2.4: > > Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] > on win32 > Type "help", "copyright", "credits" or "license" for more > information. > >>> import Tkinter > >>> import Tix > >>> Tix.Grid() > > >>> Tix.NoteBook() > Traceback (most recent call last): > File "", line 1, in ? > File "C:\Program Files\Python24\lib\lib-tk\Tix.py", line 1138, in > __init__ > TixWidget.__init__(self,master,'tixNoteBook', ['options'], cnf, > kw) > File "C:\Program Files\Python24\lib\lib-tk\Tix.py", line 307, in > __init__ > self.tk.call(widgetName, self._w, *extra) > _tkinter.TclError: invalid command name "tixNoteBook" Steven, I know nothing about Tix but the above error suggests that there is no tixNoteBook in the Tix dll C:\Python23\DLLs\tix8184.dll Perhaps someone with more Tix knowledge will be able to provide more help... Martin From mart.franklin at gmail.com Tue Apr 19 15:31:07 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Tue Apr 19 15:32:12 2005 Subject: [Tkinter-discuss] Re: Okay, this one really has me baffled --KeyboardInterrupt signal not working! In-Reply-To: <426404D6.5070105@noaa.gov> References: <426404D6.5070105@noaa.gov> Message-ID: Jared Cohen wrote: > Well, I tried your suggestion, but no dice. The problem is that the > system command I'm calling, immediately forks several other processes > which actually do the work; the initial process seems to be just a > dummy. But I can't get the PIDs of those child processes, so I can't > kill them from inside the program. In fact, the os.kill() method doesn't > even seem to work on the initial, dummy process. I don't think this > route is going to pan out. Thanks anyway, though. > > However, as I said previously, if I physically go into the terminal > window and hit Ctrl-C, the interrupt signal works. What I need is some > way to do that from inside my program; that is, to send the interrupt > signal directly to the controlling terminal. Any ideas? > Jared, You may get more control of the sub-process if you use pexpect (*nix* only no windows)... http://pexpect.sourceforge.net/ I have not tried to send an interupt signal to a pexpect child but it may work ;-) Martin. From bbaxter at wadsworth.org Tue Apr 19 22:34:46 2005 From: bbaxter at wadsworth.org (William Baxter) Date: Tue Apr 19 22:38:05 2005 Subject: [Tkinter-discuss] busy cursor stores up events Message-ID: <42656B66.3116AC61@wadsworth.org> Is there a way to prevent widgets from servicing events accumulated during the busy period? I've been looking at the 2nd example at http://effbot.org/zone/tkinter-busy.htm Although the widgets do not respond to user events while the system is 'busy', they seem to register user events. When the system returns to the 'not busy' state, all the events are then processed. For instance, if I try to click the button repeatedly while 'busy', the gui doesn't respond (that's good). But when it's no longer busy, the button command prints out a whole column of 'hello's from the stored up events. Thanks, Bill Baxter From jepler at unpythonic.net Wed Apr 20 04:16:32 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Wed Apr 20 04:16:35 2005 Subject: [Tkinter-discuss] busy cursor stores up events In-Reply-To: <42656B66.3116AC61@wadsworth.org> References: <42656B66.3116AC61@wadsworth.org> Message-ID: <20050420021629.GB26325@unpythonic.net> Those examples don't seem to do anything besides change the cursor displayed when the mouse is over the affected widgets. They don't do any true "busy" handling. Apparently PMW provides an interface to the Blt "busy" command, which does a little better. With "busy", I think you set an entire toplevel (or maybe just a widget tree) busy, and any mouse actions taken in the meantime have no effect. I think the two gotchas are in BLT's implementation of busy are that * Keyboard input is not handled by busy, only mouse input * An "update" is needed so that the widget created by Blt to consume mouse events actually gets to consume them. If the busy ends before events are handled, they end up being handled by the real widget clicked instead. I've used BLT's "busy" only once, and at the Tk level, not with the interface PWM provides. Here's the code I came up with, with most of the app-specific bits removed and a few comments added. Overall, I felt like it was very fiddly and I'm still not sure it's right. def open_file_guts(f): old_focus = root_window.tk.call("focus", "-lastfor", ".") root_window.tk.call("blt::busy", "hold", ".") # blt::busy adds a fake window that keeps mouse events from reaching # widgets. It does nothing about keys. To hide key events, I must # first provide a widget that will be given keyboard focus. It must # break on events, because most keybindings are on . which # means they are automatically applied to all widgets in the # top-level window. In order to focus the window, it must be # visible. I place it in a location that should be offscreen. root_window.tk.call("label", "._busy") root_window.tk.call("bind", "._busy", "", "break") root_window.tk.call("place", "._busy", "-x", "9999", "-y", "9999") root_window.tk.call("focus", "-force", "._busy") root_window.update() try: # app-specific stuff here which might take awhile. # It is best if the code in here calls "update" from time to # time finally: # Before unbusying, I update again, so that any keystroke events # that reached the program while it was busy are sent to the # label, not to another window in the application. If this # update call is removed, the events are only handled after that # widget is destroyed and focus has passed to some other widget, # which will handle the keystrokes instead, leading to the # R-while-loading bug. root_window.update() root_window.tk.call("blt::busy", "release", ".") root_window.tk.call("destroy", "._busy") root_window.tk.call("focus", old_focus) Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050419/0c008070/attachment.pgp From PPNTWIMBXFFC at spammotel.com Wed Apr 20 09:59:43 2005 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Wed Apr 20 10:55:21 2005 Subject: [Tkinter-discuss] realtime resizing Message-ID: Hi I am laying out widgets on a canvas. I would like to be able to resize this widget on runtime as follows: 1. The cursor changes close to the edges of the widget (or when exiting) into an appropiate "resizing"-cursor. 2. When the user clicks now on the widget he may resize the widget (). How would I do that? Here are my thoughts: The only way I can think of cheating around: 1. Place the the widget XYZ into a frame. 2. Pad widget XYZ with 1-2 pixels within the frame. 3. When entering the surrounding frame, the "resizing"-cursor is set depending on the exit/entry point. 4. When the user clicks now it will resize the widget XYZ. The extra frame and the extra padding space disturbs me. I would like to define all "events" on the widget. Any suggestions? I found none so far. Thanks for any hints, Cheers, Marco From dimitri.pater at gmail.com Wed Apr 20 12:40:38 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Wed Apr 20 12:40:40 2005 Subject: [Tkinter-discuss] tkinter pmw notebook Message-ID: Hello, does anybody knows how to automatically refresh the content of a page of a notebook? I have been trying several things, no success. Pseudo code: class Notebook: def __init__(self, parent): page = notebook.add('Project') page = notebook.add('Database') b = Tkinter.Button(self.frame2, text='Refresh', width=25, underline=0, command=self.refreshDB) b.pack(side="left", padx=2, pady=2) def refreshDB(self): Now, I use a button on the second page of the notebook, but what I really want is to automatically refresh the page when the user clicks the "Database" tab. Thanks in advance! Dimitri -- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050420/ac64a858/attachment.html From mfranklin1 at gatwick.westerngeco.slb.com Wed Apr 20 16:54:10 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed Apr 20 16:57:21 2005 Subject: [Tkinter-discuss] Re: tkinter pmw notebook In-Reply-To: References: Message-ID: dimitri pater wrote: > Hello, > does anybody knows how to automatically refresh the content of a page of > a notebook? I have been trying several things, no success. > > Pseudo code: > > class Notebook: > def __init__(self, parent): > > page = notebook.add('Project') > > page = notebook.add('Database') > b = Tkinter.Button(self.frame2, text='Refresh', width=25, > underline=0, command=self.refreshDB) > b.pack(side="left", padx=2, pady=2) > > def refreshDB(self): > > Now, I use a button on the second page of the notebook, but what I > really want is to automatically refresh the page when the user clicks > the "Database" tab. > If I remember correctly there is an onraise or onclick option in the Pmw.NoteBook.__init__ check the source code for the exact spelling note it will be called for all pages (tabs) when any one of them is brought to the front. Martin From klappnase at web.de Wed Apr 20 17:08:34 2005 From: klappnase at web.de (Michael Lange) Date: Wed Apr 20 17:04:45 2005 Subject: [Tkinter-discuss] tkinter pmw notebook In-Reply-To: References: Message-ID: <20050420170834.38a5c010.klappnase@web.de> On Wed, 20 Apr 2005 12:40:38 +0200 dimitri pater wrote: > Hello, > does anybody knows how to automatically refresh the content of a page of a > notebook? I have been trying several things, no success. > > Pseudo code: > > class Notebook: > def __init__(self, parent): > > page = notebook.add('Project') > > page = notebook.add('Database') > b = Tkinter.Button(self.frame2, text='Refresh', width=25, underline=0, > command=self.refreshDB) > b.pack(side="left", padx=2, pady=2) > > def refreshDB(self): > > Now, I use a button on the second page of the notebook, but what I really > want is to automatically refresh the page when the user clicks the > "Database" tab. > Have you tried the NoteBook's raisecommand option? Best regards Michael From stewart.midwinter at gmail.com Wed Apr 20 17:32:17 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed Apr 20 17:32:19 2005 Subject: [Tkinter-discuss] Re: tkinter pmw notebook In-Reply-To: References: Message-ID: Grayson's book 'Python & Tkinter Programming' says that there is a raisecommand option for Notebook: "Specifies a function to call when a new page is selected. the function is called with a single argument, which is the name of the selected page. cheers, S On 4/20/05, Martin Franklin wrote: > dimitri pater wrote: > > Hello, > > does anybody knows how to automatically refresh the content of a page of > > a notebook? I have been trying several things, no success. -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad From stewart.midwinter at gmail.com Wed Apr 20 18:26:51 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed Apr 20 18:26:53 2005 Subject: [Tkinter-discuss] realtime resizing In-Reply-To: References: Message-ID: Marco: I see one problem with what you are trying to accomplish. You want to resize the widget when the mouse passes over the widget and the user clicks. Normally you might want to do several things when clicking on an object, not just resize it. Perhaps you need to consider a different mouse event, such as detecting click and drag (mouse-down, mouse-move) instead. As to how to specifically accomplish that, my suggestion is to search around for Tkinter drawing programs. I've seen a couple of examples that, IIRC, allow resizing or movement of widgets on the canvas. Matt Conway wrote a bunch of canvas demos. The one attached shows how to move a widget by dragging it; others may show sizing. Find them all at: http://unununium.org/darcs/prebuilt-python/Demo/tkinter/ I hope this helps. #---------------------- #canvas-moving-with-mouse.py from Tkinter import * # this file demonstrates the movement of a single canvas item under mouse control class Test(Frame): ################################################################### ###### Event callbacks for THE CANVAS (not the stuff drawn on it) ################################################################### def mouseDown(self, event): # remember where the mouse went down self.lastx = event.x self.lasty = event.y def mouseMove(self, event): # whatever the mouse is over gets tagged as CURRENT for free by tk. self.draw.move(CURRENT, event.x - self.lastx, event.y - self.lasty) self.lastx = event.x self.lasty = event.y ################################################################### ###### Event callbacks for canvas ITEMS (stuff drawn on the canvas) ################################################################### def mouseEnter(self, event): # the CURRENT tag is applied to the object the cursor is over. # this happens automatically. self.draw.itemconfig(CURRENT, fill="red") def mouseLeave(self, event): # the CURRENT tag is applied to the object the cursor is over. # this happens automatically. self.draw.itemconfig(CURRENT, fill="blue") def createWidgets(self): self.QUIT = Button(self, text='QUIT', foreground='red', command=self.quit) self.QUIT.pack(side=LEFT, fill=BOTH) self.draw = Canvas(self, width="5i", height="5i") self.draw.pack(side=LEFT) fred = self.draw.create_oval(0, 0, 20, 20, fill="green", tags="selected") self.draw.tag_bind(fred, "", self.mouseEnter) self.draw.tag_bind(fred, "", self.mouseLeave) Widget.bind(self.draw, "<1>", self.mouseDown) Widget.bind(self.draw, "", self.mouseMove) def __init__(self, master=None): Frame.__init__(self, master) Pack.config(self) self.createWidgets() test = Test() test.mainloop() On 4/20/05, Marco Aschwanden wrote: > Hi > > I am laying out widgets on a canvas. I would like to be able to resize > this widget on runtime as follows: > > 1. The cursor changes close to the edges of the widget (or when exiting) > into an appropiate "resizing"-cursor. > 2. When the user clicks now on the widget he may resize the widget > (). > > How would I do that? > > Here are my thoughts: > > The only way I can think of cheating around: > > 1. Place the the widget XYZ into a frame. > 2. Pad widget XYZ with 1-2 pixels within the frame. > 3. When entering the surrounding frame, the "resizing"-cursor is set > depending on the exit/entry point. > 4. When the user clicks now it will resize the widget XYZ. > > The extra frame and the extra padding space disturbs me. I would like to > define all "events" on the widget. > > Any suggestions? I found none so far. > Thanks for any hints, > Cheers, > Marco > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss@python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad From dimitri.pater at gmail.com Wed Apr 20 20:30:46 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Wed Apr 20 20:30:48 2005 Subject: [Tkinter-discuss] Re: tkinter pmw notebook In-Reply-To: References: Message-ID: Hello, yes thanks, I have tried the raisecommand, but it doesn't seem to work and I can't find any clear examples. I am not sure what "the function is called with a single argument, which is the name of the selected page." means exactly... This is what I do (wrong): class Notebook: def __init__(self, parent): notebook = Pmw.NoteBook(parent, raisecommand=self.refreshDB()) notebook.pack(fill = 'both', expand = 1, padx = 10, pady = 10) page = notebook.add('Project') page = notebook.add('Database') b = Tkinter.Button(self.frame2, text='Refresh', width=25, underline=0, command=self.refreshDB) b.pack(side="left", padx=2, pady=2) def refreshDB(self): Thanks for you help! Dimitri On 4/20/05, Stewart Midwinter wrote: > > Grayson's book 'Python & Tkinter Programming' says that there is a > raisecommand option for Notebook: > > "Specifies a function to call when a new page is selected. the > function is called with a single argument, which is the name of the > selected page. > > cheers, > S > > On 4/20/05, Martin Franklin > wrote: > > dimitri pater wrote: > > > Hello, > > > does anybody knows how to automatically refresh the content of a page > of > > > a notebook? I have been trying several things, no success. > > -- > Stewart Midwinter > stewart@midwinter.ca > stewart.midwinter@gmail.com > Skype: midtoad > -- -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050420/5f121c81/attachment.htm From stewart.midwinter at gmail.com Wed Apr 20 21:55:39 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed Apr 20 21:55:42 2005 Subject: [Tkinter-discuss] Re: Tix failures:: _tkinter.TclError: invalid command name "tixNoteBook" In-Reply-To: References: <200504190024.j3J0Oj3d024811@mail08.syd.optusnet.com.au> Message-ID: Let's see... 1996-07-25 13:31 3,608 ipasdatabase.py 1996-07-25 13:31 4,719 ipasextract.py 1996-07-29 17:16 10,982 ipasfieldtransfer.py 1996-07-29 17:16 8,028 ipaslessons.py 1996-07-25 13:31 15,689 ipaspoints.py 1996-07-02 17:28 870 ipasporttable.py 1996-08-13 13:58 393 ipasprint.py 1996-07-25 13:31 11,649 ipasretrievedata.py 1996-05-23 14:59 870 ipassqm.py 1996-08-12 10:04 30,397 ipastime.py 2003-05-09 10:33 1,162 ipastypes.py 2005-04-19 17:35 isl 2003-11-24 11:32 4,638 ISLError.py 2001-03-29 18:14 861 leakwarnparams.py 2005-04-19 17:35 lwi 2003-12-11 15:59 7,395 makediagram.py 2005-04-19 17:35 nist12 2005-04-19 17:35 odb 2004-10-15 13:34 11,168 odbcreatedomain.py 2001-09-20 16:23 8,248 options.py 2005-04-19 17:35 pcm 2005-04-19 17:35 pha 2005-04-19 17:35 port 2002-03-18 17:04 4,334 process.py 2005-04-19 17:35 pso 2005-04-19 17:35 ptr 2003-09-05 12:27 994 pw_factory_project.py 1999-06-02 11:26 806 pw_project.py 2005-04-19 17:35 rap 1998-01-06 11:52 10,219 RemoteCall.py 1996-11-04 17:33 801 RemoteCalldefs.py 1997-08-16 12:53 11,888 RemoteCallServer.py 1997-02-19 08:31 3,425 RemoteCallServerExtensions.py 2005-04-19 17:35 rtm 2005-04-19 17:35 scm 2005-04-19 17:35 spam 2005-04-19 17:36 tbe 2005-04-19 17:36 test 1996-03-27 15:31 24,894 testtime.py 2005-04-19 17:36 thm 2005-04-19 17:36 trk 2005-04-19 18:17 uom 2005-04-19 17:36 util 2005-04-19 18:23 51 __init__.py 44 File(s) 335,750 bytes 29 Dir(s) 5,816,524,800 bytes free C:\Programs\Pipeworks-Source\lib\python>python uom/unitlibrary.py C:\Programs\Pipeworks-Source\lib\python>python uom/unitlibrary.py Traceback (most recent call last): File "uom/unitlibrary.py", line 270, in ? print u.list() TypeError: unbound method list() must be called with UnitLibrary instance as first argument (got noth ing instead) C:\Programs\Pipeworks-Source\lib\python>python uom/unitlibrary.py [] C:\Programs\Pipeworks-Source\lib\python>python uom/unitlibrary.py ['lb/ft3', 'kJ/kg/K', 'lb/ft3/s', 'MMbbl/day', 'mm2/s', 'Mbbl/hr/min', 'kg/m3/s', 'm3/hr', 'ton/hr/s' , 'bbl/hr/s', 'K', 'cm3', 'cm2', 'ton/d', 'ft/s', 'psi', 'rev/s/s', 'm3/s2', 'rev/h', 'yd', 'rev/s', 'psi (elasticity)', 'ton/hr', 'yr', 'Mg/hr/s', 'rev/s/min', 'rpm/s', 'bbl/day', 'bar', 'd', '(nodim)' , 'psi (delta)', 'm3/day', '%/s', 'rad/s/min', 'BTU/lb/F', 'C/s', 'g/cm3', 'bbl/hr (compensated)', 'm m2', 'Pa', 'm3/hr2', 'Mbbl', 'yd2', 'F/min', 'Hz', 'rev/h/s', 'm2/s', 'spec grav/s', '% (concentratio n)', 'rad/s/s', 'm3/s', 'kW/s', 'Mg/day', 'bbl/hr/min', 'kg/min', 'Mg', 'Mbbl/hr/s', 'MPa', 'MW/s', ' s', 'kg/hr', 'Pa (elasticity)', 'm3/hr/s', 'Mbbl/hr', 'W/s', 'W', 'K/s', 'BTU', 'ft2', 'g', 'kPa', 'C ', 'kg/m3 (delta)', 'MW', 'kW', 'psi/s', 'cm', 'm/s', 'kPa (delta)', 'J/kg/K', 'ppm', 'api', 'Mg/hr', 'ft2/s', 'rpm', 'spec grav (delta)', 'mi/hr', 'bbl', 'lb/hr/s', 'tonne/day/s', 'ton', 'm3', 'm2', 's pec grav', 'kg/s', 'F', 'hr', 'L/min', 'hp', 'J', 'ton/hr/min', 'Pa/s', 'V', 'kg/m3', 'kgf/cm2', 'BTU /ft/hr/F', 'BTU/lb', 'rpm/min', 'mm', 'mi', 'Hz (rotational)', 'K (delta)', 'm3/hr (compensated)', 'C entistokes', 'kPag', 'USG', 'tonne', 'atm', 'lb/hr', 'J/kg', 'W/m/K', 'Pa (delta)', '(nodim)/s', 'in' , 'kg/s2', 'lbm', 'tonne/day', '%', 'Mg/day/s', 'min', 'C (delta)', 'Mbbl/day', 'rad/s', 'hp/min', 'F (delta)', 'kPa/s', 'A', 'USGPM', 'ft', 'USGPH', 'F/s', 'in2', 'L', 'lb/ft3/min', 'hp/s', 'psig', 'm3 /s (compensated)', 'psi/min', 'bbl/hr', 'kg', 'm', 'km', 'tonne/hr'] C:\Programs\Pipeworks-Source\lib\python>set 6=C:\Programs\Simone5\Logs\6.log; ALLUSERSPROFILE=C:\Documents and Settings\All Users APPDATA=C:\Documents and Settings\smidwint\Application Data CLIENTNAME=Console CommonProgramFiles=C:\Program Files\Common Files COMPUTERNAME=MULATA ComSpec=C:\WINDOWS\system32\cmd.exe CVSROOT=:server:@sunfs:/cmt/repository EXPLORER_IPASDBHOME=d:\database\explorer EXPLORER_PIPEWORKSHOME=C:\Programs\Pipeworks FP_NO_HOST_CHECK=NO HOMEDRIVE=C: HOMEPATH=\Documents and Settings\smidwint INCLUDE=C:\PROGRAMS\ODI\OSTORE\INCLUDE; LIB=C:\PROGRAMS\ODI\OSTORE\LIB; LOGONSERVER=\\11WFS01 NOVACHEM_IPASDBHOME=D:\DATABASE\NOVACHEM2 NOVACHEM_PIPEWORKSHOME=C:\PROGRAMS\PIPEWORKS NUMBER_OF_PROCESSORS=1 OS=Windows_NT OS_ROOTDIR=C:\PROGRAMS\ODI\OSTORE OS_TMPDIR=C:\WINDOWS\TEMP Path=d:\WebServ\php;d:\WebServ\perl\bin;C:\Programs\Simone5\exe;C:\Program Files\Corel\Corel SVG View er\;c:\programs\tcl\bin;C:\PROGRAMS\ODI\OSTORE\BIN;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32 \Wbem;C:\PROGRA~1\GNU\WINCVS~1.3\CVSNT;C:\Program Files\Common Files\GTK\2.0\bin;C:\Program Files\Mic rosoft USB Flash Drive Manager\;C:\PROGRAMS\PYTHON24;C:\PROGRAMS\WIN32APP\SALFORD;C:\cygwin\bin;C:\Pr ogram Files\Microsoft USB Flash Drive Manager\;C:\Program Files\CVSNT\ PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH PERL_EXEC_DIR=C:\Programs\Simone5\Pscript; PHP_PEAR_BIN_DIR=d:\WebServ\php PHP_PEAR_DATA_DIR=d:\WebServ\php\pear\data PHP_PEAR_DOC_DIR=d:\WebServ\php\pear\docs PHP_PEAR_INSTALL_DIR=d:\WebServ\php\pear PHP_PEAR_PHP_BIN=d:\WebServ\php\cli\php.exe PHP_PEAR_SYSCONF_DIR=d:\WebServ\php PHP_PEAR_TEST_DIR=d:\WebServ\php\pear\tests PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 1, GenuineIntel PROCESSOR_LEVEL=15 PROCESSOR_REVISION=0401 ProgramFiles=C:\Program Files PROMPT=$P$G PWPROJECTHOME_B=D:\User\PipeWorksB QMAKESPEC=win32-msvc.net QTDIR=C:\Program Files\qt-win-free-msvc.net SESSIONNAME=Console SystemDrive=C: SystemRoot=C:\WINDOWS TEMP=C:\DOCUME~1\smidwint\LOCALS~1\Temp TMP=C:\DOCUME~1\smidwint\LOCALS~1\Temp USERDNSDOMAIN=ES.INT USERDOMAIN=ES USERNAME=smidwint USERPROFILE=C:\Documents and Settings\smidwint windir=C:\WINDOWS C:\Programs\Pipeworks-Source\lib\python> C:\Programs\Pipeworks-Source\lib\python>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import types >>> a = 'me' >>> b = 3 >>> dir(types) ['BooleanType', 'BufferType', 'BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', 'CodeType', 'C omplexType', 'DictProxyType', 'DictType', 'DictionaryType', 'EllipsisType', 'FileType', 'FloatType', 'FrameType', 'FunctionType', 'GeneratorType', 'InstanceType', 'IntType', 'LambdaType', 'ListType', 'L ongType', 'MethodType', 'ModuleType', 'NoneType', 'NotImplementedType', 'ObjectType', 'SliceType', 'S tringType', 'StringTypes', 'TracebackType', 'TupleType', 'TypeType', 'UnboundMethodType', 'UnicodeTyp e', 'XRangeType', '__builtins__', '__doc__', '__file__', '__name__'] >>> a==types.StringTypes False >>> dir(types.StringTypes) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribut e__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr __', '__rmul__', '__setattr__', '__str__'] >>> dir(types.StringType) ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__ge__', '__getattribut e__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '_ _len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr_ _', '__rmod__', '__rmul__', '__setattr__', '__str__', 'capitalize', 'center', 'count', 'decode', 'enc ode', 'endswith', 'expandtabs', 'find', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace ', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'replace', 'rfind', 'rindex', 'rjust', ' rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'u pper', 'zfill'] >>> a==types.StringType False >>> b==types.IntType False >>> type(a)==types.StringType True >>> type(b)==types.IntType True >>> a = 'me' >>> b = 3 >>> type(a)==types.StringType True >>> type(b)==types.IntType True >>> exit 'Use Ctrl-Z plus Return to exit.' >>> >>> C:\Programs\Pipeworks-Source\lib\python>set 6=C:\Programs\Simone5\Logs\6.log; ALLUSERSPROFILE=C:\Documents and Settings\All Users APPDATA=C:\Documents and Settings\smidwint\Application Data CLIENTNAME=Console CommonProgramFiles=C:\Program Files\Common Files COMPUTERNAME=MULATA ComSpec=C:\WINDOWS\system32\cmd.exe CVSROOT=:server:@sunfs:/cmt/repository EXPLORER_IPASDBHOME=d:\database\explorer EXPLORER_PIPEWORKSHOME=C:\Programs\Pipeworks FP_NO_HOST_CHECK=NO HOMEDRIVE=C: HOMEPATH=\Documents and Settings\smidwint INCLUDE=C:\PROGRAMS\ODI\OSTORE\INCLUDE; LIB=C:\PROGRAMS\ODI\OSTORE\LIB; LOGONSERVER=\\11WFS01 NOVACHEM_IPASDBHOME=D:\DATABASE\NOVACHEM2 NOVACHEM_PIPEWORKSHOME=C:\PROGRAMS\PIPEWORKS NUMBER_OF_PROCESSORS=1 OS=Windows_NT OS_ROOTDIR=C:\PROGRAMS\ODI\OSTORE OS_TMPDIR=C:\WINDOWS\TEMP Path=d:\WebServ\php;d:\WebServ\perl\bin;C:\Programs\Simone5\exe;C:\Program Files\Corel\Corel SVG View er\;c:\programs\tcl\bin;C:\PROGRAMS\ODI\OSTORE\BIN;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32 \Wbem;C:\PROGRA~1\GNU\WINCVS~1.3\CVSNT;C:\Program Files\Common Files\GTK\2.0\bin;C:\Program Files\Mic rosoft USB Flash Drive Manager\;C:\PROGRAMS\PYTHON24;C:\PROGRAMS\WIN32APP\SALFORD;C:\cygwin\bin;C:\Pr ogram Files\Microsoft USB Flash Drive Manager\;C:\Program Files\CVSNT\ PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH PERL_EXEC_DIR=C:\Programs\Simone5\Pscript; PHP_PEAR_BIN_DIR=d:\WebServ\php PHP_PEAR_DATA_DIR=d:\WebServ\php\pear\data PHP_PEAR_DOC_DIR=d:\WebServ\php\pear\docs PHP_PEAR_INSTALL_DIR=d:\WebServ\php\pear PHP_PEAR_PHP_BIN=d:\WebServ\php\cli\php.exe PHP_PEAR_SYSCONF_DIR=d:\WebServ\php PHP_PEAR_TEST_DIR=d:\WebServ\php\pear\tests PROCESSOR_ARCHITECTURE=x86 PROCESSOR_IDENTIFIER=x86 Family 15 Model 4 Stepping 1, GenuineIntel PROCESSOR_LEVEL=15 PROCESSOR_REVISION=0401 ProgramFiles=C:\Program Files PROMPT=$P$G PWPROJECTHOME_B=D:\User\PipeWorksB QMAKESPEC=win32-msvc.net QTDIR=C:\Program Files\qt-win-free-msvc.net SESSIONNAME=Console SystemDrive=C: SystemRoot=C:\WINDOWS TEMP=C:\DOCUME~1\smidwint\LOCALS~1\Temp TMP=C:\DOCUME~1\smidwint\LOCALS~1\Temp USERDNSDOMAIN=ES.INT USERDOMAIN=ES USERNAME=smidwint USERPROFILE=C:\Documents and Settings\smidwint windir=C:\WINDOWS C:\Programs\Pipeworks-Source\lib\python>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter Traceback (most recent call last): File "", line 1, in ? ImportError: No module named tkinter >>> import Tkinter >>> import Tix >>> Tix.Grid() >>> Tix.Notebook() Traceback (most recent call last): File "", line 1, in ? AttributeError: 'module' object has no attribute 'Notebook' >>> dir(Tix) ['ACROSSTOP', 'ACTIVE', 'ALL', 'ANCHOR', 'ARC', 'AUTO', 'At', 'AtEnd', 'AtInsert', 'AtSelFirst', 'AtSelLast', 'BALLOON', 'BASELINE', 'BEVEL', 'BOTH', 'BOTTOM', 'BROWSE', 'BUTT', 'Balloon', 'BaseWidget', 'BitmapImage', 'BooleanType', 'BooleanVar', 'BufferType', 'BuiltinFunctionType', 'BuiltinMethodType', 'Button', 'ButtonBox', 'CASCADE', 'CENTER', 'CHAR', 'CHECKBUTTON', 'CHORD', 'COMMAND', 'CObjView','CURRENT', 'CallWrapper', 'Canvas', 'CheckList', 'Checkbutton', 'ClassType', 'CodeType', 'ComboBox','ComplexType', 'Control', 'DISABLED', 'DOTBOX', 'DialogShell', 'DictProxyType', 'DictType', 'DictionaryType', 'DirList', 'DirSelectBox', 'DirSelectDialog', 'DirTree', 'DisplayStyle', 'DoubleVar', 'E', 'END', 'EW', 'EXCEPTION', 'EXTENDED', 'EllipsisType', 'Entry', 'Event', 'ExFileSelectBox', 'ExFileSelectDialog', 'FALSE', 'FIRST', 'FLAT', 'FileEntry', 'FileSelectBox', 'FileSelectDialog', 'FileType', 'FileTypeList', 'FixTk', 'FloatType', 'Form', 'Frame', 'FrameType', 'FunctionType', 'GROOVE', 'GeneratorType', 'Grid', 'HIDDEN', 'HList', 'HORIZONTAL', 'IMAGE', 'IMAGETEXT', 'IMMEDIATE', 'INSERT', 'INSIDE', 'Image', 'InputOnly', 'InstanceType', 'IntType', 'IntVar', 'LAST', 'LEFT', 'Label', 'LabelEntry','LabelFrame', 'LambdaType', 'ListNoteBook', 'ListType', 'Listbox', 'LongType', 'MITER', 'MOVETO', 'MULTIPLE', 'Menu', 'Menubutton', 'Message', 'Meter', 'MethodType', 'Misc', 'ModuleType', 'N', 'NE', 'NO', 'NONE', 'NORMAL', 'NS', 'NSEW', 'NUMERIC', 'NW', 'NoDefaultRoot', 'NoneType', 'NotImplementedType', 'NoteBook', 'NoteBookFrame', 'OFF', 'ON', 'OUTSIDE', 'ObjectType', 'OptionMenu', 'OptionName', 'PAGES', 'PIESLICE', 'PROJECTING', 'Pack', 'PanedWindow', 'PhotoImage', 'Place', 'PopupMenu', 'RADIOBUTTON', 'RAISED', 'READABLE', 'RIDGE', 'RIGHT', 'ROUND', 'Radiobutton', 'ResizeHandle', 'S', 'SCROLL', 'SE', 'SEL', 'SEL_FIRST', 'SEL_LAST', 'SEPARATOR', 'SINGLE', 'SOLID', 'STATUS', 'SUNKEN', 'SW', 'Scale' , 'Scrollbar', 'ScrolledGrid', 'ScrolledHList', 'ScrolledListBox', 'ScrolledTList', 'ScrolledText', ' ScrolledWindow', 'Select', 'Shell', 'SliceType', 'Spinbox', 'StdButtonBox', 'StringType', 'StringTypes', 'StringVar', 'Studbutton', 'TCL_ALL_EVENTS', 'TCL_DONT_WAIT', 'TCL_FILE_EVENTS', 'TCL_IDLE_EVENTS', 'TCL_TIMER_EVENTS', 'TCL_WINDOW_EVENTS', 'TEXT', 'TList', 'TOP', 'TRUE', 'Tcl', 'TclError', 'TclVe rsion', 'Text', 'TixSubWidget', 'TixWidget', 'Tk', 'TkVersion', 'Tkinter', 'Toplevel', 'TracebackType', 'Tree', 'Tributton', 'TupleType', 'TypeType', 'UNDERLINE', 'UNITS', 'UnboundMethodType', 'UnicodeType', 'VERTICAL', 'Variable', 'W', 'WINDOW', 'WORD', 'WRITABLE', 'Widget', 'Wm', 'X', 'XRangeType', 'Y', 'YES', '__builtins__', '__doc__', '__file__', '__name__', '_cnfmerge', '_default_root', '_dummyButton', '_dummyCheckbutton', '_dummyComboBox', '_dummyDirList', '_dummyDirSelectBox', '_dummyEntry', ' _dummyExFileSelectBox', '_dummyFileComboBox', '_dummyFileSelectBox', '_dummyFrame', '_dummyHList', '_dummyLabel', '_dummyListbox', '_dummyMenu', '_dummyMenubutton', '_dummyNoteBookFrame', '_dummyPanedWindow', '_dummyScrollbar', '_dummyScrolledHList', '_dummyScrolledListBox', '_dummyStdButtonBox', '_dummyTList', '_dummyText', '_flatten', '_lst2dict', '_tkinter', 'getboolean', 'getdouble', 'getint', 'image_names', 'image_types', 'mainloop', 'os', 'sys', 'tixCommand', 'tkinter', 'wantobjects'] >>> dirlist = dir(Tix) >>> for dir in dirlist: ... if 'book' in dir: ... print dir ... >>> for dir in dirlist: ... if 'Grid' in dir: ... print dir ... Grid ScrolledGrid >>> for dir in dirlist: ... if 'Book' in dir: ... print dir ... ListNoteBook NoteBook NoteBookFrame _dummyNoteBookFrame >>> Conclusion: the widget is called NoteBook, not tixNoteBook. -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad From stewart.midwinter at gmail.com Wed Apr 20 22:06:35 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Wed Apr 20 22:06:38 2005 Subject: [Tkinter-discuss] Okay, this one really has me baffled --KeyboardInterrupt signal not working! In-Reply-To: <426404D6.5070105@noaa.gov> References: <426404D6.5070105@noaa.gov> Message-ID: Jared, maybe I've missed part of the conversation, but instead of running an os.system command to start your process, how about using a call to win32file's process creation? That way you can get a process handle that will continue to exist only so long as the process is alive. you can monitor for its continued existence. If you need to kill the process, first check the handle, then kill using the PID. you said you had problems getting access to the child process, but I wonder if that's due to the fact that you are using an os.system command to start the initial process. Just a thought. Anyway, here's some code that starts a process: def createProcess(self, file, args, env, name, logFilename, currentDirectory, hide): '''Start up a process to run some task, so that control is returned to Scenario Manager immediately. "file" is the name of the batch file to be run in the process (e.g. "diagram" > diagram.bat) "args" is a string containing any command-line arguments to be passed to the batch file "env" is an optional environment variable "name" is an optional name for the process "logFilename" is an optional log file name "currentDirectory" is an optional specification of the directory to be run in ''' fname = self.createProcess.__name__ self.__lock = threading.Lock() self.__terminationEvent = threading.Event() file = os.path.normpath(file) if not os.path.splitext(file)[1]: file = file + '.exe' if not os.path.isabs(file): # Windows NT seems to want a full path paths = string.split(self.getFromEnv('PATH', env, []),os.pathsep) for path in paths: fullPath = os.path.join(path, file) if os.path.isfile(fullPath): file = fullPath break args = file+' '+args if self.debug: print 'args ',args self._hideWindow = 0 # was 1 self.__fileSecurity = pywintypes.SECURITY_ATTRIBUTES() self.__fileSecurity.bInheritHandle = pywintypes.TRUE self.__inputFile = win32file.CreateFile( _nullFilename, win32file.GENERIC_READ, win32file.FILE_SHARE_READ , self.__fileSecurity, win32file.OPEN_EXISTING, win32file.FILE_ATTRIBUTE_NORMAL, 0) startupInfo = win32process.STARTUPINFO() #print 'log ',logFilename if logFilename: logfile = win32file.CreateFile( logFilename, win32file.GENERIC_WRITE | win32file.GENERIC_READ, win32file.FILE_SHARE_READ | win32file.FILE_SHARE_WRITE, self.__fileSecurity, win32file.CREATE_ALWAYS, 0, 0) startupInfo.hStdInput = self.__inputFile startupInfo.hStdOutput = int(logfile) startupInfo.hStdError = int(logfile) startupInfo.dwFlags = win32process.STARTF_USESTDHANDLES if self._hideWindow: startupInfo.dwFlags = (startupInfo.dwFlags | win32process.STARTF_USESHOWWINDOW) else: logfile = None if currentDirectory: directoryMessage = ' in %s' % currentDirectory else: directoryMessage = '' try: try: flags = 0 # Session Cancel will kill the required processes. if hide == 0: flags = flags | win32process.DETACHED_PROCESS msg = 'now starting process with file %s & args %s & env %s & directory %s' % (str(file), str(args), str(env), str(currentDirectory)) if self.debug: self.write_debug(fname, msg) self.__processInfo = win32process.CreateProcess( file, args , None, None, pywintypes.TRUE, flags, env, currentDirectory, startupInfo) except win32process.error, value: raise win32process.error( value.args + (file, currentDirectory)) finally: if logfile is not None: logfile.Close() # Close the thread handle, we don't need it self.__processInfo[1].Close() # createProcess() must return the new process id print 'process %s has the following info:\n - handle %s, thread %s, pid %s, threadID %s ' % \ (name, str(self.__processInfo[0]), str(self.__processInfo[1]), str(self.__processInfo[2]), str(self.__processInfo[3]) ) return self.__processInfo And here's an excerpt from a method that calls that method to start a process. In this case, we are running an executable called tui.exe: ... info = self.createProcess('tui', msg, env=None, name = 'status-%s' % (self.scenario_name), logFilename=None, currentDirectory=os.path.join(pwPythonHome,'sm'), hide=0) #we care about the handle, the pid and maybe the threadID self.statusHandle, statusThread, self.statusPid, self.statusThreadID = info self.handles.append(self.statusHandle) msg = 'Status pid is %i' % self.statusPid And here's how I cancel a process: def cancel(self): '''Cancel the execution of a process''' fname = self.cancel.__name__ self.__paused = 'false' self.run_state = 'false' msg = 'trying to stop a process with self.__paused state= ' msg = '%s %s and self.run_state= %s and process PID %s' % (msg, self.__paused, self.run_state, str(self.statusPid)) if self.debug: self.write_debug(fname, msg) self.executeLogging("Stop RUNNING") if self.statusPid is not None: #someone might have already closed the status window cmd = 'kill %s' % str(self.statusPid) end1 = os.path.join(pwPipeworksHome, 'bin', cmd) if self.debug: print 'kill status window,', cmd os.system(end1) hope this helps. -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad From mart.franklin at gmail.com Thu Apr 21 00:11:50 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Thu Apr 21 00:13:42 2005 Subject: [Tkinter-discuss] Re: tkinter pmw notebook In-Reply-To: References: Message-ID: dimitri pater wrote: > Hello, > yes thanks, I have tried the raisecommand, but it doesn't seem to work > and I can't find any clear examples. > I am not sure what "the function is called with a single argument, which > is the name of the selected page." means exactly... > The function name you bind to the raisecommand will be called when you raise a page of the notebook and at the same time the name of the page will be sent to it > This is what I do (wrong): > class Notebook: > def __init__(self, parent): > > notebook = Pmw.NoteBook(parent, raisecommand=self.refreshDB()) Here is one problem, you are calling self.refreshDB() remove the () and it will bind the name of that method to the raisecommand > notebook.pack(fill = 'both', expand = 1, padx = 10, pady = 10) > > page = notebook.add('Project') > > page = notebook.add('Database') > b = Tkinter.Button(self.frame2, text='Refresh', width=25, > underline=0, command=self.refreshDB) > b.pack(side="left", padx=2, pady=2) > > def refreshDB(self): > Change this to : def refreshDB(self, pageName): if pageName=="My Interesting Page": ## do somthng interesting > Thanks for you help! > Dimitri > > On 4/20/05, *Stewart Midwinter* > wrote: > > Grayson's book 'Python & Tkinter Programming' says that there is a > raisecommand option for Notebook: > > "Specifies a function to call when a new page is selected. the > function is called with a single argument, which is the name of the > selected page. > Thanks Stuart I was away from a python'ised machine when I wrote my original reply Cheers Martin From klappnase at web.de Thu Apr 21 00:23:51 2005 From: klappnase at web.de (Michael Lange) Date: Thu Apr 21 00:20:04 2005 Subject: [Tkinter-discuss] Re: tkinter pmw notebook In-Reply-To: References: Message-ID: <20050421002351.063e25fb.klappnase@web.de> On Wed, 20 Apr 2005 20:30:46 +0200 dimitri pater wrote: Hello Dimitri, > Hello, > yes thanks, I have tried the raisecommand, but it doesn't seem to work and I > can't find any clear examples. > I am not sure what "the function is called with a single argument, which is > the name of the selected page." means exactly... > > This is what I do (wrong): > class Notebook: > def __init__(self, parent): > > notebook = Pmw.NoteBook(parent, raisecommand=self.refreshDB()) ^^ The above line has an error - remove the parentheses. The name of the selected page, which will be passed as argument to the raisecommand callback is the name of the page as you defined in the NoteBook.add() method, i.e. in your example 'Project' or 'Database' . If I understood you correctly, you might do something like this: def refreshDB(self, pagename): if pagename == 'Database': # stuff to refresh the database contents here I hope this helps Michael From dimitri.pater at gmail.com Thu Apr 21 00:25:44 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Thu Apr 21 00:25:50 2005 Subject: [Tkinter-discuss] Re: tkinter pmw notebook In-Reply-To: <20050421002351.063e25fb.klappnase@web.de> References: <20050421002351.063e25fb.klappnase@web.de> Message-ID: Hello! Thank you all very much for your help. Everything works fine now, I just needed that extra little "push". Thanks again, I am new to this list and I am glad I joined it! Dimitri On 4/21/05, Michael Lange wrote: > > On Wed, 20 Apr 2005 20:30:46 +0200 > dimitri pater wrote: > > Hello Dimitri, > > > Hello, > > yes thanks, I have tried the raisecommand, but it doesn't seem to work > and I > > can't find any clear examples. > > I am not sure what "the function is called with a single argument, which > is > > the name of the selected page." means exactly... > > > > This is what I do (wrong): > > class Notebook: > > def __init__(self, parent): > > > > notebook = Pmw.NoteBook(parent, raisecommand=self.refreshDB()) > ^^ > The above line has an error - remove the parentheses. > The name of the selected page, which will be passed as argument to the > raisecommand callback > is the name of the page as you defined in the NoteBook.add() method, i.e. > in your example > 'Project' or 'Database' . > If I understood you correctly, you might do something like this: > > def refreshDB(self, pagename): > if pagename == 'Database': > # stuff to refresh the database contents here > > I hope this helps > > Michael > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss@python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -- Please visit dimitri's website: www.serpia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050421/38ef73ec/attachment.htm From dimitri.pater at gmail.com Thu Apr 21 00:57:29 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Thu Apr 21 00:57:32 2005 Subject: [Tkinter-discuss] wckgraph double y-axis Message-ID: Hello again, inspired by your great help (and eager to help if I can in posts to come), I have another question that concerns the (very nice) wckgraph package by Fredrik Lundh. I want to "merge" to graphs, they share the x-axis so I need y-axis1 and y-axis2 in one graph. Is this possible? This is how I create the two graphs: self.barCanvas2 = Tkinter.Canvas(self.outputFr2) self.barCanvas2.pack(fill="both", expand=1) bar1 = wckgraph.GraphWidget(self.barCanvas2) bar1.pack(fill="both", expand=1) ydata = [] for i in range(len(fg.data)): x = int(fg.data[i][1]) ydata.append(x) xdata = range(len(fg.data)) data = xdata, ydata bar1.add(wckgraph.Axes(data)) bar1.add(wckgraph.BarGraph(data, barwidth=0.3)) # ShoeSize bar self.barCanvas3 = Tkinter.Canvas(self.outputFr3) self.barCanvas3.pack(fill="both", expand=1) bar2 = wckgraph.GraphWidget(self.barCanvas3) bar2.pack(fill="both", expand=1) ydata2 = [] for i in range(len(fg.data)): x = int(fg.data[i][2]) ydata2.append(x) #xdata2 = range(len(fg.data)) data2 = xdata, ydata2 bar2.add(wckgraph.Axes(data2)) bar2.add(wckgraph.ScatterGraph(data2)) Looks very nice, but how can I merge them into one graph? I have read something about add(layer) but I am not sure if this is the way to do this. Thanks, Dimitri -- Please visit dimitri's website: www.serpia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050421/c7273fe7/attachment.htm From PPNTWIMBXFFC at spammotel.com Thu Apr 21 09:08:51 2005 From: PPNTWIMBXFFC at spammotel.com (Marco Aschwanden) Date: Thu Apr 21 09:08:01 2005 Subject: [Tkinter-discuss] Thanks Message-ID: Thanks for the link. I will further investigate on it. I found no solution for it that is why I proceeded with my sketched idea... and it works smoother than I thought. Anyhow, thanks for your input. Marco -- Using Opera's revolutionary e-mail client: http://www.opera.com/m2/ From dimitri.pater at gmail.com Thu Apr 21 14:38:29 2005 From: dimitri.pater at gmail.com (dimitri pater) Date: Thu Apr 21 14:38:34 2005 Subject: [Tkinter-discuss] Re: tkinter pmw notebook In-Reply-To: References: <20050421002351.063e25fb.klappnase@web.de> Message-ID: Hello, here is a little test app for the "lowercommand" of the notebook: # test app auto refresh pages of a notebook import Tkinter import Pmw import time class Notebook: def __init__(self, parent): # Create and pack the NoteBook. notebook = Pmw.NoteBook(parent, lowercommand=self.timePlease) notebook.pack(fill = 'both', expand = 1, padx = 10, pady = 10) # Add the "Hello" page to the notebook. page = notebook.add('Appearance') notebook.tab('Appearance').focus_set() # Add the "Now" page to the notebook. page = notebook.add('Now') self.timeframe = Tkinter.Frame(page) self.timeframe.pack(side="bottom", fill="x", anchor="nw", pady=5, padx=5) notebook.setnaturalsize() def timePlease(self, Now): while True: try: self.nowtime.destroy() break except AttributeError: break t = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time())) self.nowtime = Tkinter.Label(self.timeframe, text=t, pady=15, padx=15) self.nowtime.pack() if __name__ == '__main__': root = Tkinter.Tk() geometry = '400x400+0+0' root.geometry(geometry) root.title('Demo notebook refresh') root.deiconify() Pmw.initialise(root) GUI = Notebook(root) root.mainloop() -- Please visit dimitri's website: www.serpia.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050421/0dcc44e5/attachment.htm From vedanta.barooah at gmail.com Fri Apr 22 21:35:16 2005 From: vedanta.barooah at gmail.com (Vedanta Barooah) Date: Fri Apr 22 21:35:18 2005 Subject: [Tkinter-discuss] Test mail please ignore Message-ID: -- *~:~*~:~*~:~*~:~*~:~*~:~*~:~*~:~*~:~*~:~* Vedanta Barooah YM! - vedanta2006 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050423/47b3544c/attachment.htm From dking at nrao.edu Wed Apr 27 18:35:18 2005 From: dking at nrao.edu (David King) Date: Wed Apr 27 18:35:30 2005 Subject: [Tkinter-discuss] Hooking into custom Tcl/Tk Widgets Message-ID: <426FBF46.7040708@nrao.edu> Hi Folks: I am looking to make a custom Tcl/Tk widget available in Tkinter. It is written in C/C++ and does graphics rendering of some custom astronomical data formats. It has previously been driven stand-alone from a C++ program, without benefit of python (i.e., the Tcl/Tk interpreter and its event loop are currently created / run from the top level of a C++ program). I now want to do most of the fancier control GUI creation from python/Tkinter, and embed the widget within that. I will need somehow to send the widget various custom commands to control it from python. Probably even harder, I will need to hook callbacks into various custom 'events' generated by the widget, and process them in python. Guidance / doc pointers covering any of these issues will be welcome. Direct replies preferred (in addition group postings if useful to the general group). Regrard, dk From fredrik at pythonware.com Wed Apr 27 18:54:27 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed Apr 27 18:56:19 2005 Subject: [Tkinter-discuss] Re: Hooking into custom Tcl/Tk Widgets References: <426FBF46.7040708@nrao.edu> Message-ID: David King wrote: > I am looking to make a custom Tcl/Tk widget available in Tkinter. It is > written in C/C++ and does graphics rendering of some custom astronomical > data formats. It has previously been driven stand-alone from a C++ program, > without benefit of python (i.e., the Tcl/Tk interpreter and its event loop > are currently created / run from the top level of a C++ program). are you migrating from C++ to Python, and have full control over the code base (including the widget)? if so, the approach outlined here might be less work: http://effbot.org/zone/tkinter3000-embed.htm for configuration and custom events, use standard Python extension techniques: http://docs.python.org/ext/simpleExample.html http://docs.python.org/ext/callingPython.html From rowen at cesmail.net Wed Apr 27 20:33:49 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Wed Apr 27 20:37:17 2005 Subject: [Tkinter-discuss] more control over truncating long strings in Labels? Message-ID: I'd was wondering if there was some fairly easy way to display text in a Label such that it is is anchored on the west (short strings are against the left edge), but too-long strings are truncated on the left. This would be useful for displaying very long path names. It might be even nicer to truncate the text in the middle, replacing the excess text with ..., but truncating on the left would be fine. I fear the only way is to use font metrics (using a tkFont object from the tkFont module) and iteratively try to figure out what length of string will fit. If so, it sounds messy. Hope I'm missing something. -- Russell From klappnase at web.de Wed Apr 27 22:37:02 2005 From: klappnase at web.de (Michael Lange) Date: Wed Apr 27 22:33:02 2005 Subject: [Tkinter-discuss] more control over truncating long strings in Labels? In-Reply-To: References: Message-ID: <20050427223702.02b7cd84.klappnase@web.de> On Wed, 27 Apr 2005 11:33:49 -0700 "Russell E. Owen" wrote: > I'd was wondering if there was some fairly easy way to display text in a > Label such that it is is anchored on the west (short strings are against > the left edge), but too-long strings are truncated on the left. This > would be useful for displaying very long path names. It might be even > nicer to truncate the text in the middle, replacing the excess text with > ..., but truncating on the left would be fine. > > I fear the only way is to use font metrics (using a tkFont object from > the tkFont module) and iteratively try to figure out what length of > string will fit. If so, it sounds messy. Hope I'm missing something. > > -- Russell > I've done something like that by simply checking the length of the string, like this: label = Label(parent, width=40, anchor='w') if len(labeltext) > 36: labeltext = '...%s' % labeltext[-33:] label.configure(text=labeltext) Maybe it's not perfect, but for me it worked fine. Best regards Michael From jepler at unpythonic.net Wed Apr 27 23:05:31 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Wed Apr 27 23:05:41 2005 Subject: [Tkinter-discuss] more control over truncating long strings in Labels? In-Reply-To: References: Message-ID: <20050427210530.GB25406@unpythonic.net> This code is not well tested, but I'll share it anyway. You must create the label widget, and a variable to hold the string. Then you call make_ellip with the widget, the variable, and the side---"left", "right", or "center". "left" gives abbreviated text like "And no...", and so forth. On at least some platform/fonts combinations, you can replace the "..."s in the tcl_code with \N{HORIZONTAL ELLIPSIS} to get a true ellipsis character. #------------------------------------------------------------------------ # This code is in the public domain tcl_code = u""" proc ellip {text font avail {side l}} { set m [font measure $font $text] if {$m <= $avail} { return $text } for {set i [string length $text]} {$i >= 0} {incr i -1} { switch $side { l - le - lef - left { set s [string range $text 0 $i]... } r - ri - rig - righ - right { set j [expr [string length $text]-$i] set s ...[string range $text $j end] } c - ce - cen - cent - cente - center { set p [expr $i/2] set q [expr [string length $text]-$i+$p] set s [string range $text 0 $p]...[string range $text $q end] } } if {[font measure $font $s] <= $avail} { break } } set s } proc do_ellip { w args } { if {![winfo exists $w]} { return } upvar \#0 [bind $w <>] var set side [bind $w <>] $w configure -text [ellip $var [$w cget -font] [winfo width $w] $side] } proc make_ellip {w v {side l}} { upvar \#0 $v var trace variable var w [list do_ellip $w] bind $w <> $v bind $w <> $side bind $w {+do_ellip %W } bind $w [list +trace vdelete $v] } """ def make_ellip(widget, variable, side="l"): call = widget.tk.call if not call("info", "commands", "make_ellip"): call("eval", tcl_code) return call("make_ellip", widget, variable, side) def test(): import Tkinter t = Tkinter.Tk() s = Tkinter.StringVar(t) s.set("And now for something completely different!") for side in "lcr": l = Tkinter.Label(t, width=5) make_ellip(l, s, side) l.pack(side="top", fill="x") t.mainloop() if __name__ == '__main__': test() #------------------------------------------------------------------------ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050427/9c06372e/attachment.pgp From jepler at unpythonic.net Fri Apr 29 14:22:00 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Fri Apr 29 14:22:07 2005 Subject: [Tkinter-discuss] more control over truncating long strings in Labels? In-Reply-To: <20050427210530.GB25406@unpythonic.net> References: <20050427210530.GB25406@unpythonic.net> Message-ID: <20050429122157.GA13675@unpythonic.net> On Wed, Apr 27, 2005 at 04:05:31PM -0500, Jeff Epler wrote: > This code is not well tested, but I'll share it anyway. [snipped] Someone asked me off-list if there was a reason I wrote this code in tcl, not Python. No, there was no efficiency reason. I wrote this code first for a tcl/tk app, then wrapped it for use from Python. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050429/bf41dc79/attachment.pgp From dking at nrao.edu Fri Apr 29 19:01:15 2005 From: dking at nrao.edu (David King) Date: Fri Apr 29 19:01:32 2005 Subject: [Tkinter-discuss] Re: Hooking into custom Tcl/Tk Widgets from Tkinter (vis) In-Reply-To: References: <426FBF46.7040708@nrao.edu> Message-ID: <4272685B.6090606@nrao.edu> > David King wrote: > >> I am looking to make a custom Tcl/Tk widget available in Tkinter. It >> is written in C/C++ and does graphics rendering of some custom >> astronomical data formats. It has previously been driven stand-alone >> from a C++ program, without benefit of python (i.e., the Tcl/Tk >> interpreter and its event loop are currently created / run from the >> top level of a C++ program). Fredrik Lundh wrote: > are you migrating from C++ to Python, and have full control over the code > base (including the widget)? if so, the approach outlined here might be > less > work: > > http://effbot.org/zone/tkinter3000-embed.htm > > for configuration and custom events, use standard Python extension > techniques: > > http://docs.python.org/ext/simpleExample.html > http://docs.python.org/ext/callingPython.html Thank you, Mr. Lundh, for your helpful pointers. I was especially gratified to see that the standard python C API had routines for calling back to python code from C[++]. We are fairly new to the python world here, but several of us are investigating the various 'binding systems' (boost, esp.; also swig, sip) that purport to make python-C++ communication simpler than python's standard (PyObject*) offerings; any comments you have on these will be welcome, including whether the callbacks to python that you mention have any shortcuts in, say, boost. The 'Tkinter 3000 Widget Construction Kit' looks interesting, although to first appearance it appears designed mainly for implementing new widgets purely in python. Our 'display library' primarily draws fancy graphics straight to the X window underlying its incarnation as a Tk widget. Although we control all this code, we definitely don't plan to reimplement the graphics part of the library entirely in python (just the GUIs surrounding the core graphics widget). If, however there are ways in which WCK can create the 'widget' itself, but pass out to the C++ code the handles it needs to do its drawing (X window, gc, display, etc.), perhaps this approach may be workable. Any advice in that regard is welcome. But let's leave WCK aside and just talk about plain Tkinter for the moment. I'd like to understand how my custom C++/Tk widget could make itself known in the usual Tkinter world. On the C++ side, essentially all my Tcl/Tk API calls interact with a tcl interpreter handle ('Tcl_Interp*'). Presumably I need to get the one Tkinter uses, instead of creating an interpreter myself (and also to let Tkinter handle the event loop, rather than doing _that_ myself). I'm wondering how I get this handle from Tkinter. Once I've got that handle, the way a custom Tk widget is created in C++ is to register my widget 'constructor' and other widget operations with the interpreter as new Tcl/Tk commands. E.g., after such registration calls (to 'Tcl_CreateCommand' etc.), the arbitrarily-chosen new name 'pixelcanvas' could now be given as a new Tcl/Tk command that will construct an instance of my custom widget. I'm wondering how this new 'pixelcanvas' command (and any others I register to operate the widget) are made available to be invoked from python/Tkinter. Any further insights you have in this regard will be welcome. Thanks again, David King From jepler at unpythonic.net Fri Apr 29 20:25:23 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Fri Apr 29 20:25:34 2005 Subject: [Tkinter-discuss] Re: Hooking into custom Tcl/Tk Widgets from Tkinter (vis) In-Reply-To: <4272685B.6090606@nrao.edu> References: <426FBF46.7040708@nrao.edu> <4272685B.6090606@nrao.edu> Message-ID: <20050429182522.GC6636@unpythonic.net> On Fri, Apr 29, 2005 at 11:01:15AM -0600, David King wrote: > But let's leave WCK aside and just talk about plain Tkinter for the moment. > I'd like to understand how my custom C++/Tk widget could make itself known > in the usual Tkinter world. On the C++ side, essentially all my Tcl/Tk API > calls interact with a tcl interpreter handle ('Tcl_Interp*'). Presumably I > need to get the one Tkinter uses, instead of creating an interpreter myself > (and also to let Tkinter handle the event loop, rather than doing _that_ > myself). I'm wondering how I get this handle from Tkinter. Here is some "C" code that I have used for this purpose. // this code is in the public domain static Tcl_Interp *get_interpreter(PyObject *tkapp) { long interpaddr; PyObject *interpaddrobj = PyObject_CallMethod(tkapp, "interpaddr", NULL); if(interpaddrobj == NULL) { return NULL; } interpaddr = PyInt_AsLong(interpaddrobj); Py_DECREF(interpaddrobj); if(interpaddr == -1) { return NULL; } return (Tcl_Interp*)interpaddr; } 'PyObject *tkapp' is the thing returned by _tkinter.create(), and available as the 'tk' attribute on all Tkinter widgets. This is not foolproof, because passing in an object like class K: interpaddr = 0 will soon lead to a crash. But if you can trust the calling code to only pass in "real" interpreters, it should work just fine. Jeff -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050429/5df5a7ad/attachment.pgp