From stewart.midwinter at gmail.com Tue Mar 1 15:08:47 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Tue Mar 1 15:08:50 2005 Subject: [Tkinter-discuss] using list elements in menu construction? Message-ID: Hi all: I want to use a list to contain variables in a series of option-menu toggles. I've got 15 options to set, so I would like to use a single for loop to draw the 15 menu items and use a list containing Tkinter IntVar instances to keep track of the value of these options. But, Tkinter doesn't seem to like me using a list member as the variable in the menu. Is there a way to do what I want? Here's a sample app with the offending behaviour: #test-opts.py import sys, thread, string, os, time class rsyncApp: def __init__(self, parent): '''define rsync defaults; get from settings file if it exists''' self.font = ('Helvetica', 10) #default font os.chdir(folder) def drawGUI(self, parent): '''Create and pack the MenuBar.''' menuBar = Pmw.MenuBar(parent, hull_relief = 'raised', hull_borderwidth = 1) menuBar.pack(fill = 'x') self.menuBar = menuBar # Add some buttons to the MenuBar. menuBar.addmenu('File', 'Connect or quit') # File menu item 0 menuBar.addmenuitem('File', 'command', 'Exit the application', command = self.quit, font = self.font, label = 'Exit') menuBar.addmenu('Edit', 'Edit Options') self.names = ["Quiet","Recursive", "Relative path names","Update only", "Preserve times","Dry run", "only update Existing","Delete missing source", "Delete excluded on dest", "Delete excluded from source","ignore times", "Use size only", "CVS-exclude", "print version (ignore other options)","help (ignore other options)",] self.opts = [] for i in range(0,15): self.opts.append(None) for i in range(0,15): # Create a checkbutton menu item. self.opts[i] = Tkinter.IntVar() # Initialise the checkbutton to 1: self.opts[i].set(0) print "Options:", self.opts for i in range(0,15): print '%s: %i ' % (self.names[i], self.opts[i].get()) menuBar.addmenuitem('Options', 'checkbutton', self.names[i], label = self.names[i], font = self.font, command = self._toggleMe, variable = self.opts[i]) self._toggleMe() def _toggleMe(self): '''get the option settings''' for i in range(0,15): print '%s value:' %self.names[i], self.opts[i].get() def quit(self): '''clean up nicely when we quit''' root.destroy() root.quit() if __name__ == '__main__': OS = os.name.lower() if OS == 'ce': import osce import pythonrc #contains the sys.path.append() commands folder = '\\My Documents\\Python' else: # we are on the desktop sys.path.append('c:\\programs') folder = os.getcwd() import Tkinter, Pmw from tkMessageBox import * root = Tkinter.Tk() #initialise global vars global sizex, sizey, startx, starty if OS == 'ce': sizex, sizey = root.wm_maxsize() startx = 0; starty = 0 sizex = sizex - startx -6 sizey = sizey - starty -6 else: xmax, ymax = root.wm_maxsize() sizex, sizey = (240, 400) startx = xmax/4; starty = ymax/4 Pmw.initialise(root) root.title('rsync') global geometry geometry = "%dx%d+%d+%d"%(sizex,sizey,startx,starty) root.wm_geometry(geometry) root.update() app = rsyncApp(root) app.drawGUI(root) root.mainloop() thanks, -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From jepler at unpythonic.net Tue Mar 1 15:55:42 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Tue Mar 1 15:55:55 2005 Subject: [Tkinter-discuss] using list elements in menu construction? In-Reply-To: References: Message-ID: <20050301145539.GA19996@unpythonic.net> I don't see what's wrong with your program, but a simple Tkinter program not using pmw seems to work just as expected on my system. It seems like it would be hard for Python/PMW/Tkinter to even know that a particular option for varible= was computed by a list indexing operation, as opposed to any other way. Whatever problem is in your code, I think you may not have identified it correctly. Jeff #------------------------------------------------------------------------ import Tkinter # Create widgets t = Tkinter.Tk() m = Tkinter.Menu(t); t.configure(menu=m) menu = Tkinter.Menu(m); m.add_cascade(menu=menu, label="Radiobuttons") opts = [Tkinter.IntVar() for i in range(15)] # Callback when checkbutton clicked def print_opts(): for i in range(15): print "Checkbutton %d: %d" % (i, opts[i].get()) print # Populate the checkbutton menu for i in range(15): menu.add_checkbutton(variable=opts[i], label="Checkbutton %d" % i, command=print_opts) # Run the application t.mainloop() #------------------------------------------------------------------------ -------------- 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/20050301/b1601f8c/attachment.pgp From stewart.midwinter at gmail.com Tue Mar 1 17:07:30 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Tue Mar 1 17:07:33 2005 Subject: [Tkinter-discuss] using list elements in menu construction? In-Reply-To: <20050301145539.GA19996@unpythonic.net> References: <20050301145539.GA19996@unpythonic.net> Message-ID: Jeff: you're right, there seems to be no problem with using list elements to construct menus IF you use basic Tkinter menus, and not Pmw menus (thanks for the example, BTW). I prefer using Pmw menus, so I'd like to get this to work, but OTOH it might be easier to use Tkinter menus, so that the end user doesn't have to have Pmw installed. BTW, I'm building a GUI front end for Vivian deSmedt's rsync.py, so my menu structure will be fairly simple. cheers, -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From klappnase at web.de Tue Mar 1 20:42:58 2005 From: klappnase at web.de (Michael Lange) Date: Tue Mar 1 20:39:55 2005 Subject: [Tkinter-discuss] using list elements in menu construction? In-Reply-To: References: Message-ID: <20050301204258.6ef5066e.klappnase@web.de> On Tue, 1 Mar 2005 07:08:47 -0700 Stewart Midwinter wrote: Hi Stewart, there's a typo in your drawGui() method: > for i in range(0,15): > print '%s: %i ' % (self.names[i], self.opts[i].get()) > menuBar.addmenuitem('Options', 'checkbutton', self.names[i], > ^^^^^^^ I guess you meant 'Edit', at least you have defined an 'Edit' menu and no 'Options' menu before. Best regards Michael From stewart.midwinter at gmail.com Tue Mar 1 23:33:22 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Tue Mar 1 23:33:26 2005 Subject: [Tkinter-discuss] using list elements in menu construction? In-Reply-To: <20050301204258.6ef5066e.klappnase@web.de> References: <20050301204258.6ef5066e.klappnase@web.de> Message-ID: Doh! I guess it's true what they say, that you can't proof-read your own work.! thanks Michael. cheers S On Tue, 1 Mar 2005 20:42:58 +0100, Michael Lange wrote: > there's a typo in your drawGui() method: -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From rowen at cesmail.net Wed Mar 2 00:19:58 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Wed Mar 2 00:21:15 2005 Subject: [Tkinter-discuss] Re: Custom cursor? References: <20050224220021.GB27663@unpythonic.net> <20050225115427.04d8ede0.klappnase@web.de> Message-ID: In article <20050225115427.04d8ede0.klappnase@web.de>, Michael Lange wrote: > You have to use a tuple instead of a string (at least if you want to use a > two-colored cursor), like this: > > mycursor = ('@/usr/X11R6/include/X11/bitmaps/cntr_ptr', > '/usr/X11R6/include/X11/bitmaps/cntr_ptrmsk', 'black', white') > t.configure(cursor=mycursor) Thanks everybody for all the help. In summary: - unix, MacOS X and Windows each have a different required file format (the standard format for cursors on that platform). This makes cross-platform cursors in Tkinter a lot of work -- more than I'm ready to do right now. - Unix requirements: - specify an xbm format file path plus at least a foreground color (a fancier form allows a mask and background color as well); - the xbm file must include hotspot info - the multiple args must be in a tuple It is conceivable that if one wrote a C interface to Tk_GetCursorFromData, then one form of data might be acceptable to all platforms. I'm not ready to try that yet. Regards, -- Russell From Jared.Cohen at noaa.gov Wed Mar 2 18:39:32 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Wed Mar 2 18:39:41 2005 Subject: [Tkinter-discuss] Re: Another problem -- deselecting individualentries in Tix HList Message-ID: <4225FA54.8040909@noaa.gov> Thanks, but that didn't work. I tried the format: self.tree.hlist.selection_clear(from_=path) And I got this error message: File "/usr/lib/python2.3/lib-tk/Tix.py", line 1015, in selection_clear self.tk.call(self._w, 'selection', 'clear', *self._options(cnf, kw)) TclError: Entry "-from" not found Using the leading underscore resulted in the same error. Any other ideas? From fredrik at pythonware.com Wed Mar 2 20:14:22 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Wed Mar 2 20:23:55 2005 Subject: [Tkinter-discuss] Re: Another problem -- deselecting individual entriesin Tix HList References: <42236CE0.5010303@noaa.gov> Message-ID: Jared Cohen wrote: > According to the documentation for the Tcl version of Tix, it's possible to use selection_clear() > to deselect individual entries, as opposed to the entire selection. The documentation says the > following: > > pathName selection clear ?from? ?to? > > When no extra arguments are given, deselects all of the list entrie(s) in this HList widget. When > only from is given, only the list entry identified by from is deselected. When both from and to > are given, deselects all of the list entrie(s) between between from and to, inclusive, without > affecting the selection state of entries outside that range. > > However, I can't for the life of me figure out how to get this functionality in Python. You'd > think that you could just pass in "from" and "to" as individual arguments, but you'd be wrong -- > the Python version of selection_clear() has the form: selection_clear(self, cnf={}, **kw) . It > expects a dictionary and/or a keyword list. And I can't figure out the right syntax for that > "from-to" thing. Can anyone help please? might be a bug in the Python binding. does the following "direct" call work as expected? widget.tk.call(widget, "selection", "clear", fromvalue, tovalue) From Jared.Cohen at noaa.gov Wed Mar 2 21:10:33 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Wed Mar 2 21:10:36 2005 Subject: [Tkinter-discuss] Re: Another problem -- deselecting individualentriesin Tix HList Message-ID: <42261DB9.2010401@noaa.gov> That works perfectly! Many thanx!! :-) >might be a bug in the Python binding. does the following "direct" call >work as expected? > > widget.tk.call(widget, "selection", "clear", fromvalue, tovalue) > From jstevens1984 at hotmail.com Sat Mar 5 19:36:14 2005 From: jstevens1984 at hotmail.com (Jonathan Stevens) Date: Sat Mar 5 19:36:18 2005 Subject: [Tkinter-discuss] creating a conformation window that does multiple commands Message-ID: Hello, I'm new to tkinter, so this might be a stupid question, but please bear with me. I have a gui made and when the user goes to file->quit a conformation window will pop up asking if they are sure that they want to quit, if "yes" then the program will quit. What I can not get it how to get the conformation window to be destroyed and the main program will quit with one command? Plus can this be done where, for another command instead of qiuting the program, i say go to another function but the pop up window does close? Any advice will be much appreciated and I thank you all for helping me out From stewart.midwinter at gmail.com Sun Mar 6 07:25:06 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Sun Mar 6 07:25:09 2005 Subject: [Tkinter-discuss] creating a conformation window that does multiple commands In-Reply-To: References: Message-ID: Jonathan: I'm struggling a little bit to understand your note, but it seems you want to do the following: 1. get confirmation from the user before quitting the app. That's easy. 2. in the confirmation, if the user chooses to not quit the app, you want to run some other command. That's also easy. My attached example accomplishes both of these objectives; maybe it'll give you some ideas. cheers S #quit-confirm.py from Tkinter import * from tkMessageBox import askyesno root=Tk() def editOptions(): top=Toplevel() lab=Label(top, text="Do some stuff here") lab.pack(side='top') but1=Button(top, text="Close", command=top.destroy) but1.pack(side='top') def confirm(): ans=askyesno(title='Quit',message='Do you really want to quit?') if ans: sys.exit() #or we can also do the following: #if ans: root.destroy() else: editOptions() mb=Menu(root) root.configure(menu=mb) mb.insert_cascade("end", label="File", underline=0) mb.insert_cascade("end", label="Edit", underline=0, command=editOptions) mb.insert_cascade("end", label="Quit", underline=0, command=confirm) root.mainloop() On Sat, 05 Mar 2005 18:36:14 +0000, Jonathan Stevens wrote: > Hello, > I'm new to tkinter, so this might be a stupid question, but please bear with > me. I have a gui made and when the user goes to file->quit a conformation > window will pop up asking if they are sure that they want to quit, if "yes" > then the program will quit. What I can not get it how to get the > conformation window to be destroyed and the main program will quit with one > command? Plus can this be done where, for another command instead of qiuting > the program, i say go to another function but the pop up window does close? > > Any advice will be much appreciated and I thank you all for helping me out > > _______________________________________________ > 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 From jstevens1984 at hotmail.com Mon Mar 7 05:34:01 2005 From: jstevens1984 at hotmail.com (Jonathan Stevens) Date: Mon Mar 7 05:34:04 2005 Subject: [Tkinter-discuss] creating a conformation window that does multiplecommands In-Reply-To: Message-ID: An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050307/a8b0ce88/attachment.html From mfranklin1 at gatwick.westerngeco.slb.com Wed Mar 16 16:56:34 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed Mar 16 17:15:47 2005 Subject: [Tkinter-discuss] Tile Message-ID: Hi All, I've made a start on wrapping Tile (see previous post + thread on c.l.python) a *very* rough first stab is here:- http://mfranklin.is-a-geek.org/docs/Tile/index.html lots of stubs and NO documentation... plus I can't find the progress bar in the tile package, that said it works for me Martin. From mart.franklin at gmail.com Sun Mar 20 00:24:42 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Sun Mar 20 00:24:49 2005 Subject: [Tkinter-discuss] Re: Tile In-Reply-To: References: Message-ID: Martin Franklin wrote: > > > Hi All, > > > I've made a start on wrapping Tile (see previous post + thread on > c.l.python) > > a *very* rough first stab is here:- > > http://mfranklin.is-a-geek.org/docs/Tile/index.html > > > lots of stubs and NO documentation... plus I can't find the progress > bar in the tile package, that said it works for me > > > Martin. just a quick update I have downloaded the CVS version of tile - built it and now have progress bar working, along with other things... Martin From klappnase at web.de Tue Mar 22 21:22:31 2005 From: klappnase at web.de (Michael Lange) Date: Tue Mar 22 21:19:07 2005 Subject: [Tkinter-discuss] Modal dialog behavior Message-ID: <20050322212231.0220ac98.klappnase@web.de> Hello list, I encoutered a strange behavior of modal dialog windows on linux, which depends on the window manager I use. I use a message box to notify the user that a process that takes a while has finished. Now when I switch to another workspace while this process is running, the dialog box should ideally pop up on the current workspace; this worked as expected with tk-8.3.3, now with tk-8.4.5 I get the following: XFCE: it still works as expected GNOME: the dialog pops up for a split second on the current workspace and then disppears, when I switch back to the main window's workspace the dialog is there. KDE: dito IceWM: here it is worst; the dialog pops up for a split second and then disappears again, but as soon as I try to switch to the main window's workspace IceWM "automagically" switches back to the workspace where the dialog *should* be. There's no way to get back to the application, except of opening the window list and move the main window to the current workspace (that's most annoying, because Icewm is usually my preferred wm :-( I don't think that it is a IceWm bug, because it worked correctly with tk-8.3.3) Has anyone else encountered similar problems, and is there a way to fix it? Thanks in advance Michael From mart.franklin at gmail.com Tue Mar 22 21:58:58 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Tue Mar 22 22:11:01 2005 Subject: [Tkinter-discuss] Re: Modal dialog behavior In-Reply-To: <20050322212231.0220ac98.klappnase@web.de> References: <20050322212231.0220ac98.klappnase@web.de> Message-ID: Michael Lange wrote: > Hello list, > > I encoutered a strange behavior of modal dialog windows on linux, which depends on > the window manager I use. > I use a message box to notify the user that a process that takes a while has finished. > Now when I switch to another workspace while this process is running, the dialog box > should ideally pop up on the current workspace; this worked as expected with tk-8.3.3, > now with tk-8.4.5 I get the following: > > XFCE: it still works as expected > Michael, Could you share a small snippet of code that exhibits this behavior? I use XFCE4 by default but can test with at least GNOME (I think I still have KDE on an older machine somewhere...) I also have a couple of version of Tk installed so we can at least narrow it down Martin. From jepler at unpythonic.net Tue Mar 22 22:20:49 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Tue Mar 22 22:20:53 2005 Subject: [Tkinter-discuss] Modal dialog behavior In-Reply-To: <20050322212231.0220ac98.klappnase@web.de> References: <20050322212231.0220ac98.klappnase@web.de> Message-ID: <20050322212049.GE31828@unpythonic.net> I took a look at the source and CVS history of some related files in Tk (dialog.tcl and tkUnixWm.c). It could be due to the addition of 'WmWaitMapProc': http://cvs.sourceforge.net/viewcvs.py/tktoolkit/tk/unix/tkUnixWm.c#rev1.21 http://cvs.sourceforge.net/viewcvs.py/tktoolkit/tk/unix/tkUnixWm.c?r1=1.20&r2=1.21 If this is the case, you can't really do anything about it in Python/Tkinter, because this is low-level stuff whose details are all internal to Tk. You can write your own code that steers clear of 'wm transient', but this is really the only way to enforce the stacking order between your application and its pop-up, too. Having looked at this code, re-read the section on 'wm transient' in the wm manpage, and the ICCCM text on WM_TRANSIENT_FOR[1], I'm not sure what to think. On the one hand, the window manager is supposed to build whatever behavior it likes on WM_TRANSIENT_FOR. The Tk documentation, on the other hand, has a muddled explanation about how this is for "e.g. pull-down menu" which is not at all what WM_TRANSIENT_FOR is about---a common misconception explicitly mentioned in ICCCM The Tk documentation says 'A transient window will mirror state changes in the master and inherit the state of the master when initially mapped.' (which I would have said is something the window manager is supposed to manage, as far as X is concerned---and something that icewm+tk8.3 seems do just fine!). So when your window manager implements desktops by withdrawing windows not on that desktop, you can get behavior like you saw in icewm: 0. Master on desktop 1, desktop 2 is visible. New window is mapped, transient for master 1. Master is not mapped, so transient is unmapped by WmWaitMapProc 2. User switches to desktop 1, so WM maps master. Tk maps transient 3. Wm switches to desktop 2 to show transient, unmapping master 4. Tk unmaps transient because master was unmapped This sure looks like an unintended consequence/interaction of Tk's 'wm transient' and your window manager's implementation of desktops/workspaces. You may want to pursue this on a Tk newsgroup/mailing list, armed with a simple Tk-only program that shows the problem with the various window managers. Jeff [1] http://tronche.com/gui/x/icccm/sec-4.html#s-4.1.2.6 -------------- 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/20050322/28f2e98a/attachment.pgp From rowen at cesmail.net Tue Mar 22 22:42:07 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Tue Mar 22 22:57:02 2005 Subject: [Tkinter-discuss] Re: Modal dialog behavior References: <20050322212231.0220ac98.klappnase@web.de> Message-ID: In article <20050322212231.0220ac98.klappnase@web.de>, Michael Lange wrote: > I encoutered a strange behavior of modal dialog windows on linux, which > depends on the window manager I use. > I use a message box to notify the user that a process that takes a while has > finished. > Now when I switch to another workspace while this process is running, the > dialog box > should ideally pop up on the current workspace; this worked as expected with > tk-8.3.3, > now with tk-8.4.5 I get the following: I don't have a direct answer for you. Barring anybody else having one... Several things you can try: - Update to the current Tk (8.4.9). (You could search the tk bug database first.) - Roll your own dialog box. How are you creating it anyway? tkMessageBox? There are some "interesting" differences between Tkinter's dialog boxes and the code suggested in Welch's "Practical Programming in Tcl and Tk". I don't remember the details at the moment, but after running into nasty problems with tkSimpleDialog.askfloat I ended up writing my own dialog boxes*, mostly following Welch but with a few changes that proved desirable for MacOS X aqua. -- Russell *RO.Wdg.InputDialog in the RO package . You would probably need to make a few changes for a message-only dialog box. From klappnase at web.de Wed Mar 23 11:33:56 2005 From: klappnase at web.de (Michael Lange) Date: Wed Mar 23 11:30:30 2005 Subject: [Tkinter-discuss] Re: Modal dialog behavior In-Reply-To: References: <20050322212231.0220ac98.klappnase@web.de> Message-ID: <20050323113356.7c2ef646.klappnase@web.de> Martin, Jeff, Russell, thanks for the replies, > Could you share a small snippet of code that exhibits this behavior? I > use XFCE4 by default but can test with at least GNOME (I think I still > have KDE on an older machine somewhere...) I also have a couple of > version of Tk installed so we can at least narrow it down A minimal code example that shows this behavior: ############################### #!/usr/bin/env python from Tkinter import * class ModalDialog(Toplevel): def __init__(self, master=None, **kw): Toplevel.__init__(self, master, **kw) self.withdraw() def show(self): self.deiconify() self.transient(self.master) self.grab_set() def main(): root = Tk() top = ModalDialog(root) b = Button(root, text='Show', command=lambda:root.after(3000, top.show)) b.pack() root.mainloop() if __name__ == '__main__': main() ################################# > Several things you can try: > - Update to the current Tk (8.4.9). (You could search the tk bug > database first.) > - Roll your own dialog box. How are you creating it anyway? > tkMessageBox? There are some "interesting" differences between Tkinter's > dialog boxes and the code suggested in Welch's "Practical Programming in > Tcl and Tk". I don't remember the details at the moment, but after > running into nasty problems with tkSimpleDialog.askfloat I ended up > writing my own dialog boxes*, mostly following Welch but with a few > changes that proved desirable for MacOS X aqua. > I use Pmw.Dialog.activate() for modal dialogs. Unfortunately updating Tk is not much of an option, because I want it to work with any Tk >= 8.3.3 . Maybe the quick workaround to make the one dialog in my program where this is likely to happen non-modal will be the best for now. Thanks and best regards Michael From klappnase at web.de Wed Mar 23 13:54:33 2005 From: klappnase at web.de (Michael Lange) Date: Wed Mar 23 13:51:06 2005 Subject: [Tkinter-discuss] Re: Modal dialog behavior In-Reply-To: References: <20050322212231.0220ac98.klappnase@web.de> Message-ID: <20050323135433.3c100b0b.klappnase@web.de> Ok, I did some further investigation and found that the problem doesn't occur with tkMessageBox. The reason can apparently be found in msgbox.tcl: # Message boxes should be transient with respect to their parent so that # they always stay on top of the parent window. But some window managers # will simply create the child window as withdrawn if the parent is not # viewable (because it is withdrawn or iconified). This is not good for # "grab"bed windows. So only make the message box transient if the parent # is viewable. # if {[winfo viewable [winfo toplevel $data(-parent)]] } { wm transient $w $data(-parent) } Unfortunately neither the Pmw.Dialog nor the Dialog classes in the standard library seem to check this, so I guess I'll have to override Pmw.Dialog.activate() . Best regards Michael From Jared.Cohen at noaa.gov Mon Mar 28 19:10:10 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Mon Mar 28 19:10:13 2005 Subject: [Tkinter-discuss] Here's a tough one -- dynamic, multi-line XML syntax highlighting Message-ID: <42483A72.2080506@noaa.gov> 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. :-( P.S. On a totally unrelated note, how do I reply to messages on this board and get them to appear in "nested thread" format? Every time I reply, it always appears as a new top-level thread! From tjmac at tolisgroup.com Mon Mar 28 19:35:12 2005 From: tjmac at tolisgroup.com (Tim Jones) Date: Mon Mar 28 20:25:24 2005 Subject: [Tkinter-discuss] Here's a tough one -- dynamic, multi-line XML syntax highlighting In-Reply-To: <42483D36.5080409@noaa.gov> References: <42483A72.2080506@noaa.gov> <208ed7d22256c56e068c59cd4565cb8a@tolisgroup.com> <42483D36.5080409@noaa.gov> Message-ID: <23d7b8f29e3c7985c2925a4205bdb9f7@tolisgroup.com> On Mar 28, 2005, at 10:21 AM, Jared Cohen wrote: > Not a bad idea, but real syntax highlighting doesn't work that way. If > I'm programming C++ and I type the word "int", the word gets > highlighted as a keyword the instant I type the "t", not when there's > a pause in my typing. If that were the case, then I could type an > entire paragraph and the highlighting wouldn't change until I was > done. > > Thanks anyway though. Any other ideas? :-) How about a maintained list of keywords as part of your syntax dictionary that effect from the current insertion point forward ( for example)? This way you're not always parsing the entire text on an insertion. And, you might consider only updating the text that is visible at the moment of updating. As another thought, how about auto-completion of the block for the user: i.e.: They type '' on the next line or on a new line at the end of a selected section. I can't think of anything else at the moment. Have you also considered examining what is done in VIM's syntax highlighting? Tim -- Tim Jones tjmac [at] tolisgroup [dot] com > > Tim Jones wrote: > On Mar 28, 2005, at 10:10 AM, Jared Cohen wrote: > > > > ?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? > > > How about using a timer to monitor the delay between keystrokes?? > This way, you only update the highlight if the user pauses in their > typing rather than after each keyup. > > Tim > -- > Tim Jones???????????????????????????????????????????????? tjmac [at] > tolisgroup [dot] com > > -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: text/enriched Size: 1816 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050328/4fbc7539/attachment.bin From tjmac at tolisgroup.com Mon Mar 28 20:08:12 2005 From: tjmac at tolisgroup.com (Tim Jones) Date: Mon Mar 28 20:25:25 2005 Subject: [Tkinter-discuss] GCC Error when building under Irix 6.5 Message-ID: <756583622af52ec1a5c8019a24aa0222@tolisgroup.com> HI Folks, I'm working on a port of a Python/Tkinter project to Irix 6.5, but attempts to compile results in a GCC error of a type I've not seen before. Python 2.3.3 by itself builds properly. This turns out to be an issue with the optimization flag. If any of you run into this, start by checking the -O flag in your Python Makefile. If this is a FAQ, sorry but I couldn't find it via Google. Tim -- Tim Jones tjmac [at] tolisgroup [dot] com Example of the GCC error: gcc -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -c ./Modules/timemodule.c -o Modules/timemodule.o ./Modules/timemodule.c: In function `floattime': ./Modules/timemodule.c:941: Internal compiler error in `gen_tagged_type_instantiation_die', at dwarf2out.c:9308 Please submit a full bug report. See for instructions. make: *** [Modules/timemodule.o] Error 1 Command returned 2 From Jared.Cohen at noaa.gov Mon Mar 28 20:45:56 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Mon Mar 28 20:46:00 2005 Subject: [Tkinter-discuss] Here's a tough one -- dynamic, multi-line XML syntax highlighting In-Reply-To: <23d7b8f29e3c7985c2925a4205bdb9f7@tolisgroup.com> References: <42483A72.2080506@noaa.gov> <208ed7d22256c56e068c59cd4565cb8a@tolisgroup.com> <42483D36.5080409@noaa.gov> <23d7b8f29e3c7985c2925a4205bdb9f7@tolisgroup.com> Message-ID: <424850E4.7000606@noaa.gov> Actually, I seem to have hit on a solution. It seems that the two instances of multi-line highlighting that I mentioned (comments and CDATA) are the ONLY two instances there are. And in each of these two cases, there are five subcases: when the user inserts/removes a new start-delimeter, inserts/removes a new end-delimeter, or makes some change between 2 delimeters (changing a delimeter to make it invalid counts as "removing" it). With this in mind, I was able to manually test for these cases and change the highlighting myself, without having to go back to expat and re-parse the file. For all OTHER cases, I use expat to just re-parse that one line. So far, it seems to be working perfectly, and it's certainly much more efficient than before! Thanks anyway for the suggestions :-) Tim Jones wrote: > On Mar 28, 2005, at 10:21 AM, Jared Cohen wrote: > > Not a bad idea, but real syntax highlighting doesn't work that > way. If I'm programming C++ and I type the word "int", the word > gets highlighted as a keyword the instant I type the "t", not when > there's a pause in my typing. If that were the case, then I could > type an entire paragraph and the highlighting wouldn't change > until I was done. > > Thanks anyway though. Any other ideas? :-) > > > How about a maintained list of keywords as part of your syntax > dictionary that effect from the current insertion point forward ( for > example)? This way you're not always parsing the entire text on an > insertion. And, you might consider only updating the text that is > visible at the moment of updating. > > As another thought, how about auto-completion of the block for the > user: i.e.: They type '' on the next line or on a new line at the end of a selected section. > > I can't think of anything else at the moment. Have you also considered > examining what is done in VIM's syntax highlighting? > > Tim > -- > Tim Jones tjmac [at] tolisgroup [dot] com > > > Tim Jones wrote: > On Mar 28, 2005, at 10:10 AM, Jared Cohen wrote: > > > > 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? > > > How about using a timer to monitor the delay between keystrokes? > This way, you only update the highlight if the user pauses in > their typing rather than after each keyup. > > Tim > -- > Tim Jones tjmac > [at] tolisgroup [dot] com > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050328/4e9ceca2/attachment.html From stewart.midwinter at gmail.com Mon Mar 28 23:02:44 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Mon Mar 28 23:02:45 2005 Subject: [Tkinter-discuss] Here's a tough one -- dynamic, multi-line XML syntax highlighting In-Reply-To: <42486E87.9000407@noaa.gov> References: <42483A72.2080506@noaa.gov> <208ed7d22256c56e068c59cd4565cb8a@tolisgroup.com> <42483D36.5080409@noaa.gov> <23d7b8f29e3c7985c2925a4205bdb9f7@tolisgroup.com> <42486E87.9000407@noaa.gov> Message-ID: you can get ElementTree from http://effbot.org, Fredrik Lundh's site. He has a full page of documentation on how it works here: http://effbot.org/zone/element.htm He also has a cElementTree module, which is the same thing implemented in C for speed. If you are parsing very large files, that would be worth using instead. I use ElementTree to process configuration information for an app, and display it in a pick-list. S On Mon, 28 Mar 2005 15:52:23 -0500, Jared Cohen wrote: > Where can I find elementTree? > > -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com Skype: midtoad