From ht at inf.ed.ac.uk Fri Feb 4 09:50:24 2005 From: ht at inf.ed.ac.uk (Henry S. Thompson) Date: Fri Feb 4 09:50:29 2005 Subject: [Tkinter-discuss] Problem with 'cascade' and state=disabled (maybe) Message-ID: Python2.3, Tk 8.3, RedHat Linux. I spent most of yesterday chasing a _very_ obscure menu problem. Core symptom: after some incremental menu building followed by cascaded entry enabling/disabling, menu entry 0, although claiming (correctly, as I built it) to be of type 'cascade', returns as the value of entrycget(0,'menu'), instead of .xyzzy.foobar.... I _cannot_ find anything in my code which is doing this, I can't even localise it very well, it seems to be asynchronous, but adding debugging printouts in Tkinter.Misc._configure confirms that I'm not changing the entry explicitly. Does this ring _any_ bells with anyone? I've installed a workaround to cache the correct value of 'menu' and re-install it whenever it gets trashed, but that leaves a very bad taste in my mouth. Thanks ht (new to this list, but long-time Python/XML/Tkinter developer) -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh Half-time member of W3C Team 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440 Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk URL: http://www.ltg.ed.ac.uk/~ht/ [mail really from me _always_ has this .sig -- mail without it is forged spam] From stewart.midwinter at gmail.com Fri Feb 4 09:57:20 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Fri Feb 4 09:57:24 2005 Subject: [Tkinter-discuss] Problem with 'cascade' and state=disabled (maybe) In-Reply-To: References: Message-ID: Henry, I did some work on enabling and disabling menus. I even posted some stuff on this to the list a while back, so you can search for it. I was able to enable or disable main menu items, but never cascaded items individually. Are you able to address them individually? cheers S -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From ht at inf.ed.ac.uk Fri Feb 4 10:16:47 2005 From: ht at inf.ed.ac.uk (Henry S. Thompson) Date: Fri Feb 4 10:16:51 2005 Subject: [Tkinter-discuss] Problem with 'cascade' and state=disabled (maybe) In-Reply-To: (Stewart Midwinter's message of "Fri, 4 Feb 2005 01:57:20 -0700") References: Message-ID: Stewart Midwinter writes: > Henry, I did some work on enabling and disabling menus. I even posted > some stuff on this to the list a while back, so you can search for it. I indeed saw your posts, thanks. > I was able to enable or disable main menu items, but never cascaded > items individually. Are you able to address them individually? This code has been shipping for years (in XED [1]), and I've used deeply nested cascades and enabling/disabling of individual items without trouble up until recently. I can't be sure, but I _think_ the problem only arose with Python2.3. A good starting point would simply be to find out where the cmdName object is getting created -- I can't immediately determine even whether it's a Tcl/Tk object or a Python/(_)Tkinter object. . . ht [1] http://www.ltg.ed.ac.uk/~ht/xed.html -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh Half-time member of W3C Team 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440 Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk URL: http://www.ltg.ed.ac.uk/~ht/ [mail really from me _always_ has this .sig -- mail without it is forged spam] From dblank at brynmawr.edu Sat Feb 5 00:43:07 2005 From: dblank at brynmawr.edu (Douglas S. Blank) Date: Sat Feb 5 00:43:12 2005 Subject: [Tkinter-discuss] Tkinter and Threads Message-ID: <4204088B.3020201@brynmawr.edu> Hi, I'm running some Tkinter code that works fine on some machines, but doesn't on others. The error I get is: ... File "/usr/lib/python2.3/lib-tk/Tkinter.py", line 2066, in create_oval return self._create('oval', args, kw) File "/usr/lib/python2.3/lib-tk/Tkinter.py", line 2049, in _create return getint(self.tk.call( RuntimeError: main thread is not in main loop This code works under Fedora Core 2, Python 2.3.3 with Tkinter 1.177, but doesn't under Debian, Python 2.3.4, with Tkinter 1.177. I see that the error is raised in _tkinter.c because the Tk interpreter is in a different thread from where I am attempting to run this code. The questions: is this error dependent on whether Tkinter was compiled with or without threads? If so, is there a way I can, via Python, find out the method Tkinter was compiled? Is there a workaround for this problem (short of rewriting my code)? Will going to Python 2.4 alter this behavior? The situation is that I create a canvas in a thread, and have another thread running that calls a callback that updates the canvas. Thanks for any hints! -Doug -- Douglas S. Blank, Assistant Professor dblank@brynmawr.edu, (610)526-6501 Bryn Mawr College, Computer Science Program 101 North Merion Ave, Park Science Bld. Bryn Mawr, PA 19010 dangermouse.brynmawr.edu From stewart.midwinter at gmail.com Sat Feb 5 02:54:47 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Sat Feb 5 02:54:50 2005 Subject: [Tkinter-discuss] Tkinter and Threads In-Reply-To: <4204088B.3020201@brynmawr.edu> References: <4204088B.3020201@brynmawr.edu> Message-ID: Douglas: After reading your post I'm reminded of a scene early in Ghostbusters I where Venkmann says "whatever you do, don't cross the rays (threads) ! That would be very, very, bad! " Russell Owen's page of 'common Tkinter pitfalls and how to avoid them', at the following URL: http://www.astro.washington.edu/rowen/TkinterSummary.html, says that "all Tkinter access must be from the main thread (or more precisely, from the thread that calls the mainloop). Violating this is likely to cause nasty and mysterious symptoms such as freezes and core dumps. Yes, this makes combining multi-threading and Tkinter very difficult. The only fully safe technique I have found it polling (e.g. use 'freeze' from the main loop to poll a threading Queue that your thread writes). since you have two separate threads both working on the same widgets, the surprising thing may not be that you are having difficulties, but rather that it worked at all! HTH Stewart -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From ht at inf.ed.ac.uk Sat Feb 5 12:54:09 2005 From: ht at inf.ed.ac.uk (Henry S. Thompson) Date: Sat Feb 5 12:54:12 2005 Subject: [Tkinter-discuss] Problem with 'cascade' and state=disabled (maybe) In-Reply-To: (Henry S. Thompson's message of "Fri, 04 Feb 2005 08:50:24 +0000") References: Message-ID: I should have added that this problem does _not_ occur with Python2.3 and Tcl/Tk 8.3 on Windows . . . ht -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh Half-time member of W3C Team 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440 Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk URL: http://www.ltg.ed.ac.uk/~ht/ [mail really from me _always_ has this .sig -- mail without it is forged spam] From stewart.midwinter at gmail.com Sat Feb 5 16:59:56 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Sat Feb 5 16:59:59 2005 Subject: [Tkinter-discuss] Tkinter and Threads In-Reply-To: References: <4204088B.3020201@brynmawr.edu> Message-ID: Douglas, here's a small app showing threading to update a canvas. Pretty simple little app but it may be of use. I found it on a website that Ed Blake discovered with lots of good example. S On Fri, 4 Feb 2005 18:54:47 -0700, Stewart Midwinter wrote: > Douglas: > > After reading your post I'm reminded of a scene early in Ghostbusters > I where Venkmann says "whatever you do, don't cross the rays (threads) > ! That would be very, very, bad! " > > Russell Owen's page of 'common Tkinter pitfalls and how to avoid > them', at the following URL: > http://www.astro.washington.edu/rowen/TkinterSummary.html, says that > "all Tkinter access must be from the main thread (or more precisely, > from the thread that calls the mainloop). Violating this is likely to > cause nasty and mysterious symptoms such as freezes and core dumps. > Yes, this makes combining multi-threading and Tkinter very difficult. > The only fully safe technique I have found it polling (e.g. use > 'freeze' from the main loop to poll a threading Queue that your thread > writes). > > since you have two separate threads both working on the same widgets, > the surprising thing may not be that you are having difficulties, but > rather that it worked at all! > > HTH > Stewart > > > -- > Stewart Midwinter > stewart@midwinter.ca > stewart.midwinter@gmail.com > -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com -------------- next part -------------- # Brownian motion -- an example of a multi-threaded Tkinter program. from Tkinter import * import random import threading import time import sys WIDTH = 400 HEIGHT = 300 SIGMA = 10 BUZZ = 2 RADIUS = 2 LAMBDA = 10 FILL = 'red' stop = 0 # Set when main loop exits def particle(canvas): r = RADIUS x = random.gauss(WIDTH/2.0, SIGMA) y = random.gauss(HEIGHT/2.0, SIGMA) p = canvas.create_oval(x-r, y-r, x+r, y+r, fill=FILL) while not stop: dx = random.gauss(0, BUZZ) dy = random.gauss(0, BUZZ) dt = random.expovariate(LAMBDA) try: canvas.move(p, dx, dy) except TclError: break time.sleep(dt) def main(): global stop root = Tk() canvas = Canvas(root, width=WIDTH, height=HEIGHT) canvas.pack(fill='both', expand=1) np = 30 if sys.argv[1:]: np = int(sys.argv[1]) for i in range(np): t = threading.Thread(target=particle, args=(canvas,)) t.start() try: root.mainloop() finally: stop = 1 main() From jepler at unpythonic.net Sun Feb 6 17:50:03 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Sun Feb 6 17:50:13 2005 Subject: [Tkinter-discuss] Problem with 'cascade' and state=disabled (maybe) In-Reply-To: References: Message-ID: <20050206165001.GA16104@unpythonic.net> Do you have a full program that demonstrates the problem? It's *likely* that str(w.entrycget(0, 'menu')) will return the menu's path as a string, in all cases. It's also possible that import Tkinter Tkinter.wantobjects = 0 before creating any interpeter will get you a string instead. Tcl started as a typeless language: everything is a string, but some strings can be interpreted as lists, as numbers, or as commands. In later versions, Tcl gained an "object" representation, with a C type called TclObj* which could hold just a string, an efficient representation of numbers or lists, a pointer directly to a command, etc. With 'wantobjects = 1' (the default), a wrapper of a TclObject* can be returned from Tkinter calls, rather than a string. In this case, you're getting the command object that corresponds to the menu widget, rather than the string naming the menu widget, or the Python object that wraps that particular menu widget. 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/20050206/2e752ef3/attachment.pgp From ht at inf.ed.ac.uk Mon Feb 7 22:35:15 2005 From: ht at inf.ed.ac.uk (Henry S. Thompson) Date: Mon Feb 7 22:35:17 2005 Subject: [Tkinter-discuss] Problem with 'cascade' and state=disabled (maybe) In-Reply-To: <20050206165001.GA16104@unpythonic.net> (Jeff Epler's message of "Sun, 6 Feb 2005 10:50:03 -0600") References: <20050206165001.GA16104@unpythonic.net> Message-ID: Jeff Epler writes: > Do you have a full program that demonstrates the problem? > > It's *likely* that str(w.entrycget(0, 'menu')) will return the menu's path > as a string, in all cases. Nope, that's precisely the bug. > It's also possible that > import Tkinter > Tkinter.wantobjects = 0 > before creating any interpeter will get you a string instead. Yes, that 'fixed' the problem. But of course it had the side-effect of causing other uses of entryget to _stop_ returning numbers and go back to their old behaviour of returning strings. > Tcl started as a typeless language: everything is a string, but some > strings can be interpreted as lists, as numbers, or as commands. In > later versions, Tcl gained an "object" representation, with a C type > called TclObj* which could hold just a string, an efficient > representation of numbers or lists, a pointer directly to a command, > etc. > > With 'wantobjects = 1' (the default), a wrapper of a TclObject* can be > returned from Tkinter calls, rather than a string. In this case, you're > getting the command object that corresponds to the menu widget, rather > than the string naming the menu widget, or the Python object that wraps > that particular menu widget. So that seems like a bug, and whatever magic (in _tkinter.c ?) negotiates return types should surely never let a raw cmdObject surface into Python. . . I will _try_ to produce a small test case, it may be difficult. . . ht -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh Half-time member of W3C Team 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440 Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk URL: http://www.ltg.ed.ac.uk/~ht/ [mail really from me _always_ has this .sig -- mail without it is forged spam] From ht at inf.ed.ac.uk Mon Feb 7 22:55:34 2005 From: ht at inf.ed.ac.uk (Henry S. Thompson) Date: Mon Feb 7 22:55:36 2005 Subject: [Tkinter-discuss] Problem with 'cascade' and state=disabled (maybe) In-Reply-To: <20050206165001.GA16104@unpythonic.net> (Jeff Epler's message of "Sun, 6 Feb 2005 10:50:03 -0600") References: <20050206165001.GA16104@unpythonic.net> Message-ID: Yes, so following up my own message, I find if (value->typePtr == app->ProcBodyType) { /* fall through: return tcl object. */ } in _tkinter:FromObj, which is what does the Tcl->Python conversion if wantobjects=1 I understand that this is sometimes pbly the right thing, but certainly _not_ for entrycget(n,'menu'). Or at least, if it _is_ right, then nametowidget should do the right thing with the result. . . ht -- Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh Half-time member of W3C Team 2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440 Fax: (44) 131 650-4587, e-mail: ht@inf.ed.ac.uk URL: http://www.ltg.ed.ac.uk/~ht/ [mail really from me _always_ has this .sig -- mail without it is forged spam] From stewart.midwinter at gmail.com Thu Feb 10 07:19:06 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Thu Feb 10 07:19:09 2005 Subject: [Tkinter-discuss] Re: Yet Another Table widget... In-Reply-To: References: Message-ID: Martin: How's it going with the Python wrapper for that interesting tablelist widget you found? Are you making any headway? cheers S -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From mfranklin1 at gatwick.westerngeco.slb.com Thu Feb 10 11:41:42 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu Feb 10 11:43:31 2005 Subject: [Tkinter-discuss] Re: Yet Another Table widget... In-Reply-To: References: Message-ID: Stewart Midwinter wrote: > Martin: > > How's it going with the Python wrapper for that interesting tablelist > widget you found? Are you making any headway? > > cheers > S > > > Stewart, I updated the Wiki with a link to my code.. http://tkinter.unpythonic.net/wiki/Widgets http://mfranklin.is-a-geek.org/docs/TableList/index.html The wrapper is complete (all methods are wrapped) but relatively untested.. I have started using it in a new project at work but I am only using it as a multi column list box - no cell editing... my TO DO list for TableList would look something like ;-) 1) edit all doc-strings (to make them more pythonic) 2) TEST I have added a few extra convenience methods (getcurselection, clear, setlist) that make it feel a bit like a Pmw widget - I also added a ScrolledTableList widget ala ScrolledText in the standard library It's far from complete but seems very usable. Cheers Martin From stewart.midwinter at gmail.com Thu Feb 10 15:00:41 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Thu Feb 10 15:00:50 2005 Subject: [Tkinter-discuss] Re: Yet Another Table widget... In-Reply-To: References: Message-ID: Nice work, Martin! I especially liked the way you provided a web page with detailed instructions on how you did the conversion so that others can use it as a guide for their own requirements if they discover other Tcl widgets that would be useful to use under Python. In addition, you provided a simple test for the widget so someone can get an immediate example of the widget in use. Fredrik Lundh could take a page from your book! I see you did your work under Linux. Have you tested it at all under Windows? For me under Win2k, when I try to run the example, I get the following error complaining about the tablelist::tablelist that you spent so much time on. Same error with both standard and scroll-bar version of the tablelist: Traceback (most recent call last): File "TableList.py", line 1049, in ? selectmode="extended") File "TableList.py", line 999, in __init__ self.tablelist = TableList(self, **kw) File "TableList.py", line 55, in __init__ Widget.__init__(self, master, 'tablelist::tablelist', cnf, kw) File "c:\python24\lib\lib-tk\Tkinter.py", line 1861, in __init__ self.tk.call( _tkinter.TclError: invalid command name "tablelist::tablelist" -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From mfranklin1 at gatwick.westerngeco.slb.com Thu Feb 10 16:40:02 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Thu Feb 10 16:40:15 2005 Subject: [Tkinter-discuss] Re: Yet Another Table widget... In-Reply-To: References: Message-ID: <420B8052.9020302@gatwick.westerngeco.slb.com> Stewart Midwinter wrote: > Nice work, Martin! I especially liked the way you provided a web page > with detailed instructions on how you did the conversion so that > others can use it as a guide for their own requirements if they > discover other Tcl widgets that would be useful to use under Python. > > In addition, you provided a simple test for the widget so someone can > get an immediate example of the widget in use. Fredrik Lundh could > take a page from your book! > > I see you did your work under Linux. Have you tested it at all under > Windows? For me under Win2k, when I try to run the example, I get the > following error complaining about the tablelist::tablelist that you > spent so much time on. Same error with both standard and scroll-bar > version of the tablelist: > > > Traceback (most recent call last): > File "TableList.py", line 1049, in ? > selectmode="extended") > File "TableList.py", line 999, in __init__ > self.tablelist = TableList(self, **kw) > File "TableList.py", line 55, in __init__ > Widget.__init__(self, master, 'tablelist::tablelist', cnf, kw) > File "c:\python24\lib\lib-tk\Tkinter.py", line 1861, in __init__ > self.tk.call( > _tkinter.TclError: invalid command name "tablelist::tablelist" > > > Stewart, Sorry for the quick reply but I am just leaving work.... I just downloaded my tar ball and unwrapped it on my Win2K laptop, I edited the TableList.py file and pressed F5 (SciTE run buffer) and sorry to say it just worked! can you give me some more info (python version, command used to test etc) I'll take a look when I get home (2+ hours from now!) Cheers Martin From stewart.midwinter at gmail.com Thu Feb 10 19:19:52 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Thu Feb 10 19:57:31 2005 Subject: [Tkinter-discuss] Re: Yet Another Table widget... In-Reply-To: <420B8052.9020302@gatwick.westerngeco.slb.com> References: <420B8052.9020302@gatwick.westerngeco.slb.com> Message-ID: hi Martin: I'm using SciTE as well - great editor! anyway, I installed it under Python 2.4, then opened tablelist.py under SciTE and ran it from there. I can't remember if I ran the file from the folder where I downloaded it, or from its installed folder. I'm now at work (GMT-7), so I'll try installing it here and see what happens... let's see, open the .tar.gz file, copy the contents to ..python24\lib\site-packages, browse to that folder, open tablelist.py with SciTE, press F5 for Run - bingo! I notice that the button on the side of the list seems to be fixed in that location. Is there a way to have it display underneath the table list? (no biggie if not). Very easy to get back the selection: just click on a row and then click on the button (to which I added text="select"). The show method could be modified as needed by the user. Just yesterday, I used a multiListBox to display some information (see attached graphic); but it looks like TableList could be more powerful in the future if it supports cell by cell editing. It could then support data entry as well as its current display capabilities. Thanks for you work so far on this! cheers, S -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: SM_fluids-list.jpg Type: image/jpeg Size: 36120 bytes Desc: not available Url : http://mail.python.org/pipermail/tkinter-discuss/attachments/20050210/17ed29c0/SM_fluids-list-0001.jpg From mfranklin1 at gatwick.westerngeco.slb.com Fri Feb 11 09:34:59 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Fri Feb 11 09:43:51 2005 Subject: [Tkinter-discuss] Re: Yet Another Table widget... In-Reply-To: References: <420B8052.9020302@gatwick.westerngeco.slb.com> Message-ID: <420C6E33.1060100@gatwick.westerngeco.slb.com> Stewart Midwinter wrote: > hi Martin: > > I'm using SciTE as well - great editor! > > anyway, I installed it under Python 2.4, then opened tablelist.py > under SciTE and ran it from there. I can't remember if I ran the file > from the folder where I downloaded it, or from its installed folder. > > I'm now at work (GMT-7), so I'll try installing it here and see what > happens... let's see, open the .tar.gz file, copy the contents to > ..python24\lib\site-packages, browse to that folder, open tablelist.py > with SciTE, press F5 for Run - bingo! > Great, it would be nice to find out what happened on your other machine... > I notice that the button on the side of the list seems to be fixed in > that location. Is there a way to have it display underneath the table > list? (no biggie if not). Very easy to get back the selection: just > click on a row and then click on the button (to which I added > text="select"). The show method could be modified as needed by the > user. > Yes that demo/test code at the end of the module could be cleaned up a bit! > Just yesterday, I used a multiListBox to display some information (see > attached graphic); but it looks like TableList could be more powerful > in the future if it supports cell by cell editing. It could then > support data entry as well as its current display capabilities. > I was using a multi-column list box (part of the Pmw Contrib I think) but a new project at work required a column with images in. This is why I started this whole thing. I would like to get the cell editing tested - I have not even switched it on yet! Only trouble is I don't have a good enough reason (not project that requires it!) > Thanks for you work so far on this! > No problem Cheers, Martin. > cheers, > S > > From stewart.midwinter at gmail.com Sat Feb 12 09:41:12 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Sat Feb 12 09:41:14 2005 Subject: [Tkinter-discuss] poor-man's table widget Message-ID: well, I managed to implement a poor-man's table widget - I used the multiListbox widget! Luckily for me, I was interested in editing all of a record, handily displayed as a row in the widget. Using the show() method, I am able to get the index of the selected row. A gotcha: that index is actually returned as a tuple! e.g. the 18th row will yield a return value of (17,). Having the index of the desired row, it's a simple matter to create a dialog widget that displays the fields of the desired record, then simply replace those elements in the lists that have been created for each column's data. Finally, after completing an edit of a record, I delete the multiListbox widget and redraw with the edited lists' contents. Easier than figuring out how to implement live updating on a cell-by-cell basis! Hope this helps someone. If I get a chance, I'll post an example in the next week or two. cheers S Stewart Midwinter Stewart@Midwinter.ca sent from my Toshiba e830 -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From Jared.Cohen at noaa.gov Mon Feb 14 19:02:44 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Mon Feb 14 19:02:53 2005 Subject: [Tkinter-discuss] Problem with Text widget's "see" method Message-ID: <4210E7C4.2070805@noaa.gov> I'm building a text editor that has an Undo/Redo feature. To do this, I basically invoke a callback every time the user presses a key; the callback copies the entire contents of the Text widget to a history list. Later, if the user presses Ctrl-Z, the widget steps back through the history list, and if the user presses Ctrl-Y, it steps forward. Now, I not only want the widget to recall its previous contents when the user does an Undo, but I also want it to remember the position of the insertion cursor and automatically set the cursor to that position. I did this by saving the index (i.e. "1.0") of the cursor each time a new history item is added; then, when that item is recalled, I can set the cursor back to that index. Of course, the Text widget doesn't actually HAVE a method to explicitly set the position of the cursor; so I simulated that behavior by using event_generate to pretend the user had actually clicked at the desired position. Now, here's the problem. The "pretend clicking" method will only work if it can get the on-screen coordinates of the index, which means the index needs to actually be on screen. To ensure that it is, I used the Text widget's "see" method, which is supposed to scroll the widget so the desired index is visible, IF it isn't already visible. But the "see" method doesn't work correctly. If the user enters text on the first "screen" (i.e. when the scroll bar is at the top) and then hits Ctrl-Z, no scrolling occurs -- the index is still on screen. But if the added text is on a later "screen", then the widget scrolls so the index is in the center of the screen, even if it's already visible! I tried explicitly using the "bbox" method, which is supposed to return None if the index is off-screen; but that didn't work either! I think the problem is that when I perform an Undo, I completely erase the Text widget and refill it with the previous history item -- this seems to mess up the indices somehow. Any thoughts as to how I can fix this? Here's some sample code. Be warned, it's pretty long. To test it, first scroll down a few pages; type some characters into the text widget; scroll down a little more, but make sure the new text is still visible; and then hit Ctrl-Z. The added text is still visible, so the widget SHOULDN'T scroll, but it does anyway. ---------------------------------------------------------------------------------------- #!/usr/bin/env python import sys, os, Tkinter, types, tkFont, Pmw def makeResizable(widget): for i in range(0, widget.grid_size()[0]): widget.columnconfigure(i, weight=1) for i in range(0, widget.grid_size()[1]): widget.rowconfigure(i, weight=1) class seeTest: def __init__(self, root): self.root = root self.tableText = Pmw.ScrolledText(self.root, text_bg='white', text_wrap='none') self.tableText.grid(row=0, rowspan=20, column=0, columnspan=20, sticky='nsew') fileName = "/home/textfile.txt" #this can be any text file file = open(fileName, "r") lines = file.readlines() file.close() for l in lines: self.tableText.component('text').insert("end", l) self.tableText.component('text').see("1.0") self.root.update_idletasks() self.history = [(self.tableText.getvalue(), "1.0"), ] self.curHist = 0 self.tableText.component('text').bind("", self.AddHistory) self.tableText.component('text').bind("", self.AddHistory) self.tableText.component('text').bind("", self.AddHistory) self.tableText.component('text').bind("", self.AddHistory) self.tableText.component('text').bind("", self.Dummy) self.tableText.component('text').bind("", self.Dummy) self.tableText.component('text').bind("", self.Dummy) self.tableText.component('text').bind("", self.Dummy) self.tableText.component('text').bind("", self.Undo) self.tableText.component('text').bind("", self.Undo) self.tableText.component('text').bind("", self.Dummy) self.tableText.component('text').bind("", self.Dummy) self.root.update() makeResizable(self.root) def AddHistory(self, *args): self.tableText.update_idletasks() text = self.tableText.getvalue() if text != (self.history[self.curHist])[0]: while self.curHist < len(self.history)-1: self.history.pop() self.root.update_idletasks() index = str(self.tableText.component('text').index(Tkinter.INSERT)) self.history.append( (text, index) ) self.curHist += 1 def Undo(self, *args): if self.curHist == 0: self.root.bell() else: self.curHist -= 1 text = (self.history[self.curHist])[0] if text[-1] == '\n': text = text[:-1] if self.curHist == 0: index = (self.history[1])[1] else: index = (self.history[self.curHist])[1] self.tableText.component('text').delete("1.0", "end") self.tableText.component('text').insert("end", text) self.tableText.component('text').update_idletasks() self.tableText.component('text').see(index) return "break" def Dummy(self, *args): return "break" def main(): root = Tkinter.Tk() root.geometry("1000x600+0+0") Pmw.initialise(root) test = seeTest(root) root.mainloop() if __name__=='__main__': main() From fredrik at pythonware.com Mon Feb 14 19:31:52 2005 From: fredrik at pythonware.com (Fredrik Lundh) Date: Mon Feb 14 19:42:16 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method References: <4210E7C4.2070805@noaa.gov> Message-ID: Jared Cohen wrote: > I'm building a text editor that has an Undo/Redo feature. To do this, I basically invoke a > callback every time the user presses a key; the callback copies the entire contents of the Text > widget to a history list. that's a bit more brute-force than it has to be; a better (but less obvious) way is to "override" the insert and delete commands at the widget implementation level. see Lib/idlelib/Percolator.py for a helper class, and sample code (the actual overriding is done in the WidgetRedirector.py module in the same directory) > Of course, the Text widget doesn't actually HAVE a method to explicitly > set the position of the cursor the cursor is represented by the INSERT mark, so text.mark_set(INSERT, position) possibly followed by text.see(INSERT) should do the trick. From klappnase at web.de Mon Feb 14 19:50:26 2005 From: klappnase at web.de (Michael Lange) Date: Mon Feb 14 19:47:49 2005 Subject: [Tkinter-discuss] Problem with Text widget's "see" method In-Reply-To: <4210E7C4.2070805@noaa.gov> References: <4210E7C4.2070805@noaa.gov> Message-ID: <20050214195026.25a84a5f.klappnase@web.de> On Mon, 14 Feb 2005 13:02:44 -0500 "Jared Cohen" wrote: > cursor back to that index. Of course, the Text widget doesn't actually > HAVE a method to explicitly set the position of the cursor; so I > simulated that behavior by using event_generate to pretend the user had > actually clicked at the desired position. > You can use the mark_set() method to set the cursor position: text.mark_set('insert', '1.0') I am not sure if I understood you correctly, but maybe this helps to fix some of your problems. Regards Michael From Jared.Cohen at noaa.gov Mon Feb 14 22:11:52 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Mon Feb 14 22:11:55 2005 Subject: [Tkinter-discuss] Problem with Text widget's "see" method Message-ID: <42111418.2010701@noaa.gov> Thanks guys. The mark_set() method is definitely a better way of moving the insertion point than the one I was using. But that still doesn't solve the problem with the see() method. Any ideas? From Jared.Cohen at noaa.gov Mon Feb 14 22:16:04 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Mon Feb 14 22:16:07 2005 Subject: [Tkinter-discuss] Problem with Text widget's "see" method Message-ID: <42111514.50907@noaa.gov> Also, thanks Fredrik for that Percolator example, I'll look into that as soon as I get a chance. From mfranklin1 at gatwick.westerngeco.slb.com Tue Feb 15 11:00:02 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Feb 15 11:00:16 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method In-Reply-To: <4210E7C4.2070805@noaa.gov> References: <4210E7C4.2070805@noaa.gov> Message-ID: Jared Cohen wrote: > I'm building a text editor that has an Undo/Redo feature. To do this, I > basically invoke a callback every time the user presses a key; the > callback copies the entire contents of the Text widget to a history > list. Later, if the user presses Ctrl-Z, the widget steps back through > the history list, and if the user presses Ctrl-Y, it steps forward. > Jared, I see you got lots of help on the 'see' problem I just wanted to point out the Text widget comes with it's own undo/redo methods as of Tk 8.4 so if you have an up to date Python & Tk you should be able to use them Cheers, Martin. From mfranklin1 at gatwick.westerngeco.slb.com Tue Feb 15 11:04:15 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Tue Feb 15 11:06:21 2005 Subject: [Tkinter-discuss] Re: Yet Another Table widget... In-Reply-To: References: Message-ID: Martin Franklin wrote: > > All, > > I stumbled across a pure tcl table widget here:- > > http://www.nemethi.de/ > > and thought it may be of interest. > > I have started writing the python bindings for it > (I couldn't find any with google) and will add a link > to the wiki when i'm done... > > I have played with it on Windows (Python 2.4, Win2K) > and Linux (Python 2.3.4, Fedora Core 3 and Python > 2.2.?, RedHat 9) > > Cheers, > Martin. Just FYI. I've added a few examples to my website including two editable examples (entry and checkbutton) I will try to add an interesting 'other' widget soon (after I've finished basking in the glory of my new found fame ;-) http://mfranklin.is-a-geek.org/docs/TableList/index.html Cheers, Martin. From gabriel.barros at gmail.com Wed Feb 16 12:25:53 2005 From: gabriel.barros at gmail.com (Gabriel B.) Date: Wed Feb 16 12:25:55 2005 Subject: [Tkinter-discuss] Tk resource file for layout manager Message-ID: <5175a81c050216032573339858@mail.gmail.com> i'm using almost every widget property from my pyTk programs in the form of resources, like: self.tk.option_add ( "*InputClass*background", "White" ) In the widget creation i have only the Class and the Command attribute, but i'm having to add some tk options to the geometry method, in the case, pack. Is there any way to overcome this? For example, every single Frame i pack i use, at least: self.pack(fill='both', expand=1) I'd love to have something like: self.tk.option_add ( "*Frame*fill", 'both' ) self.tk.option_add ( "*Frame*expand", 'yes' ) Is there anything like it? Thanks, From mfranklin1 at gatwick.westerngeco.slb.com Wed Feb 16 13:23:09 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Wed Feb 16 13:23:29 2005 Subject: [Tkinter-discuss] Re: Tk resource file for layout manager In-Reply-To: <5175a81c050216032573339858@mail.gmail.com> References: <5175a81c050216032573339858@mail.gmail.com> Message-ID: Gabriel B. wrote: > i'm using almost every widget property from my pyTk programs in the > form of resources, like: > self.tk.option_add ( "*InputClass*background", "White" ) > > In the widget creation i have only the Class and the Command > attribute, but i'm having to add some tk options to the geometry > method, in the case, pack. Is there any way to overcome this? > > For example, every single Frame i pack i use, at least: > self.pack(fill='both', expand=1) > I'd love to have something like: > self.tk.option_add ( "*Frame*fill", 'both' ) > self.tk.option_add ( "*Frame*expand", 'yes' ) > > Is there anything like it? > > Thanks, I don't think you can use the option 'database' for geometry (packing or otherwise) options. You could try using sub-classing: class BothFrame(Frame): def __init__(self, parent, *args, **kw): Frame.__init__(self, parent, *args, **kw) def pack(self, fill="both", **kw): Frame.pack(self, fill=fill, **kw) Cheers, Martin. From Jared.Cohen at noaa.gov Wed Feb 16 19:10:30 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Wed Feb 16 19:10:38 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method Message-ID: <42138C96.4040908@noaa.gov> > > >I see you got lots of help on the 'see' problem I just wanted to point >out the Text widget comes with it's own undo/redo methods as of Tk 8.4 >so if you have an up to date Python & Tk you should be able to use them > Thanks anyway, but the undo doesn't seem to work. It's weird, because there IS an edit_undo() method in Tkinter.py (the Python wrapper), but apparently, the underlying Tk doesn't understand the command. Oh well. Anyway, I still need some help with this "see" problem. Come on guys, isn't there a way to fix this? -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050216/e096f0b0/attachment.html From mfranklin1 at gatwick.westerngeco.slb.com Fri Feb 18 12:05:15 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Fri Feb 18 12:07:06 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method In-Reply-To: <42138C96.4040908@noaa.gov> References: <42138C96.4040908@noaa.gov> Message-ID: Jared Cohen wrote: >> >> >>I see you got lots of help on the 'see' problem I just wanted to point >>out the Text widget comes with it's own undo/redo methods as of Tk 8.4 >>so if you have an up to date Python & Tk you should be able to use them >> > > Thanks anyway, but the undo doesn't seem to work. It's weird, because > there IS an edit_undo() method in Tkinter.py (the Python wrapper), but > apparently, the underlying Tk doesn't understand the command. Oh well. I guess your Tk version is not >= 8.4 thats too bad. > > Anyway, I still need some help with this "see" problem. Come on guys, > isn't there a way to fix this? > > I have tried a couple of things but it boils down to the fact you are replacing all the text in the widget, it just has to move (without the see call it moves the viewpoint to the top of the text widget) If I were you I would investigate the IDLE undo / redo stuff Fredrik pointed you to, it undoes / redoes just the small changes (not the entire document) I must admit *I* looked into that code when I needed undo / redo in a small project, I couldn't quite grok the code, eventually the need went away, but it would be nice if we could use the undo/redo from idlelib on *any* Tkinter Text widget - I seem to remember when I was looking at it it had a lot of idle dependencies... you couldn't just, for example: undoer = idlelib.Undoer(myTextWidget) # or whatever it's called and have it look after the undo and redo 'ing of your text widget would be nice if we could though;-) Cheers, Martin. From mfranklin1 at gatwick.westerngeco.slb.com Fri Feb 18 12:27:45 2005 From: mfranklin1 at gatwick.westerngeco.slb.com (Martin Franklin) Date: Fri Feb 18 12:28:18 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method In-Reply-To: References: <42138C96.4040908@noaa.gov> Message-ID: Martin Franklin wrote: > Jared Cohen wrote: > >>> >>> >>> I see you got lots of help on the 'see' problem I just wanted to >>> point out the Text widget comes with it's own undo/redo methods as of >>> Tk 8.4 >>> so if you have an up to date Python & Tk you should be able to use them >>> >> >> Thanks anyway, but the undo doesn't seem to work. It's weird, because >> there IS an edit_undo() method in Tkinter.py (the Python wrapper), but >> apparently, the underlying Tk doesn't understand the command. Oh well. > > > I guess your Tk version is not >= 8.4 thats too bad. > >> >> Anyway, I still need some help with this "see" problem. Come on guys, >> isn't there a way to fix this? >> >> > > I have tried a couple of things but it boils down to the fact you are > replacing all the text in the widget, it just has to move (without the > see call it moves the viewpoint to the top of the text widget) If I > were you I would investigate the IDLE undo / redo stuff Fredrik pointed > you to, it undoes / redoes just the small changes (not the entire > document) I must admit *I* looked into that code when I needed undo / > redo in a small project, I couldn't quite grok the code, eventually the > need went away, but it would be nice if we could use the undo/redo from > idlelib on *any* Tkinter Text widget - I seem to remember when I was > looking at it it had a lot of idle dependencies... you couldn't just, > for example: > > undoer = idlelib.Undoer(myTextWidget) # or whatever it's called > > and have it look after the undo and redo 'ing of your text widget > would be nice if we could though;-) And it seems (after a little more investigation) we can... from Tkinter import Tk, Text from idlelib.Percolator import Percolator from idlelib.UndoDelegator import UndoDelegator root= Tk() text = Text(root) text.pack() per = Percolator(text) undo = UndoDelegator() per.insertfilter(undo) text.bind("", undo.undo_event) text.bind("", undo.redo_event) root.mainloop() *Seems to work* but has only been tested for 1 minute.... Cheers, Martin. From mart.franklin at gmail.com Tue Feb 22 11:43:17 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Tue Feb 22 11:54:17 2005 Subject: [Tkinter-discuss] Shrinking and Expanding a Frame widget Message-ID: Hi all, I just wanted to ask if anyone has been able to programatically shrink or expand a Frame widget by setting it's height. I have this.... self.height = self.frame.winfo_reqheight() for a in range(self.height, 0, -1): self.frame.configure(height=str(a)) self.update_idletasks() time.sleep(0.1) But it doesn't work! If I set the time.sleep to 1 second the widget flashes (every second) but doesn't shrink. The frame widget is packed (with fill and expand set) perhaps this is interfering (I have tried changing the packing options to no avail! I googled for shrinking Tk Frame widget - and got a few hits but mostly links for other widget sets (Tix, etc) *I* am restricted to pure Tkinter widgets Martin From mart.franklin at gmail.com Tue Feb 22 12:48:28 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Tue Feb 22 12:48:43 2005 Subject: [Tkinter-discuss] Re: Shrinking and Expanding a Frame widget In-Reply-To: References: Message-ID: Martin Franklin wrote: > > > Hi all, > > > I just wanted to ask if anyone has been able to programatically shrink > or expand a Frame widget by setting it's height. I have this.... > > self.height = self.frame.winfo_reqheight() > for a in range(self.height, 0, -1): > self.frame.configure(height=str(a)) > self.update_idletasks() > time.sleep(0.1) > > But it doesn't work! If I set the time.sleep to 1 second the widget > flashes (every second) but doesn't shrink. > > The frame widget is packed (with fill and expand set) perhaps this is > interfering (I have tried changing the packing options to no avail! > > I googled for shrinking Tk Frame widget - and got a few hits but mostly > links for other widget sets (Tix, etc) *I* am restricted to pure Tkinter > widgets > > > Martin After more goog'ling pack_propagate(0) ... From Jared.Cohen at noaa.gov Wed Feb 23 18:48:32 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Wed Feb 23 18:48:40 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method Message-ID: <421CC1F0.5030707@noaa.gov> Well son of a gun! It works!! Many thanx guys, this will do quite nicely!! :-) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050223/f91a4ef0/attachment.htm From mart.franklin at gmail.com Wed Feb 23 22:02:05 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Wed Feb 23 22:03:08 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method In-Reply-To: <421CC1F0.5030707@noaa.gov> References: <421CC1F0.5030707@noaa.gov> Message-ID: Jared Cohen wrote: > Well son of a gun! It works!! Many thanx guys, this will do quite > nicely!! :-) Jared, Just out of interest (and for others who may have the same problem) what worked? Cheers, Martin. From Jared.Cohen at noaa.gov Wed Feb 23 23:03:51 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Wed Feb 23 23:03:54 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method Message-ID: <421CFDC7.607@noaa.gov> Sorry, I forgot to include the previous message text: >Martin Franklin wrote: >> Jared Cohen wrote: >> >>>> >>>> >>>> I see you got lots of help on the 'see' problem I just wanted to >>>> point out the Text widget comes with it's own undo/redo methods as of >>>> Tk 8.4 >>>> so if you have an up to date Python & Tk you should be able to use them >>>> >>> >>> Thanks anyway, but the undo doesn't seem to work. It's weird, because >>> there IS an edit_undo() method in Tkinter.py (the Python wrapper), but >>> apparently, the underlying Tk doesn't understand the command. Oh well. >> >> >> I guess your Tk version is not >= 8.4 thats too bad. >> >>> >>> Anyway, I still need some help with this "see" problem. Come on guys, >>> isn't there a way to fix this? >>> >>> >> >> I have tried a couple of things but it boils down to the fact you are >> replacing all the text in the widget, it just has to move (without the >> see call it moves the viewpoint to the top of the text widget) If I >> were you I would investigate the IDLE undo / redo stuff Fredrik pointed >> you to, it undoes / redoes just the small changes (not the entire >> document) I must admit *I* looked into that code when I needed undo / >> redo in a small project, I couldn't quite grok the code, eventually the >> need went away, but it would be nice if we could use the undo/redo from >> idlelib on *any* Tkinter Text widget - I seem to remember when I was >> looking at it it had a lot of idle dependencies... you couldn't just, >> for example: >> >> undoer = idlelib.Undoer(myTextWidget) # or whatever it's called >> >> and have it look after the undo and redo 'ing of your text widget >> would be nice if we could though;-) > >And it seems (after a little more investigation) we can... > >from Tkinter import Tk, Text > >from idlelib.Percolator import Percolator >from idlelib.UndoDelegator import UndoDelegator >root= Tk() > > >text = Text(root) >text.pack() > >per = Percolator(text) >undo = UndoDelegator() >per.insertfilter(undo) > >text.bind("", undo.undo_event) >text.bind("", undo.redo_event) > >root.mainloop() > >*Seems to work* but has only been tested for 1 minute.... > >Cheers, >Martin. > > > > > > > > ------------------------------------------------------------------------ > Previous message: -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20050223/c0f90162/attachment.html From Jared.Cohen at noaa.gov Wed Feb 23 23:18:06 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Wed Feb 23 23:18:13 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method In-Reply-To: References: <421CC1F0.5030707@noaa.gov> Message-ID: <421D011E.3000706@noaa.gov> Sorry, but it's for a very specific purpose; I doubt you'd get much use out of it. :-) Stewart Midwinter wrote: >Jared: >And whiile you're explaing to Martin what worked, can you say anything >about the editor you are working on? Is it a gerneral - purpose >editor for public consumption, or something different? > >cheers >S > > > > From stewart.midwinter at gmail.com Wed Feb 23 23:15:37 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Thu Feb 24 02:02:52 2005 Subject: [Tkinter-discuss] Re: Problem with Text widget's "see" method In-Reply-To: References: <421CC1F0.5030707@noaa.gov> Message-ID: Jared: And whiile you're explaing to Martin what worked, can you say anything about the editor you are working on? Is it a gerneral - purpose editor for public consumption, or something different? cheers S -- Stewart Midwinter stewart@midwinter.ca stewart.midwinter@gmail.com From rowen at cesmail.net Thu Feb 24 20:08:14 2005 From: rowen at cesmail.net (Russell E. Owen) Date: Thu Feb 24 20:15:01 2005 Subject: [Tkinter-discuss] Custom cursor? Message-ID: I'd like to create a few custom cursors Tkinter (including a magnifying glass). >From reading the documentation I could find, it appears that the only cross-platform way to specify cursors in Tk is using Tk_GetCursorFromData*. Unfortunately, I can't seem to figure out how to run this from Tkinter. root.tk.call("Tk_GetCursorFromData") fails with invalid command name "Tk_GetCursorFromData". Any suggestions? -- Russell *on unix one can allegedly use "@bitmapfile.xbm" as the cursor specifier, but this is not cross-platform and it didn't even work in my one test on unix. From jepler at unpythonic.net Thu Feb 24 23:00:21 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Thu Feb 24 23:00:26 2005 Subject: [Tkinter-discuss] Custom cursor? In-Reply-To: References: Message-ID: <20050224220021.GB27663@unpythonic.net> On my Linux machine, this worked in wish: $ cd /usr/X11R6/include/X11/bitmaps $ wish % . configure -cursor {@cntr_ptr cntr_ptrmsk black white} The Python version would probably read something like import Tkinter t = Tkinter.Tk() t.configure(cursor="@cntr_ptr cntr_ptrmsk black white") t.mainloop() I suspect the 1-arg format "@example.cur" should work just as well on Windows. Tk_GetCursorFromData is a C API, while Tkinter mostly exposes the Tcl API. Reading the Tk_GetCursorFromData manual page, it looks like it doesn't expose any capabilities that the @-form of the cursor property doesn't (instance, the X and Y hotspots are named in the "cntr_ptr" file), but maybe I'm missing something. 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/20050224/85fd803e/attachment.pgp From stewart.midwinter at gmail.com Fri Feb 25 00:08:24 2005 From: stewart.midwinter at gmail.com (Stewart Midwinter) Date: Fri Feb 25 00:08:32 2005 Subject: [Tkinter-discuss] Custom cursor? In-Reply-To: <20050224220021.GB27663@unpythonic.net> References: <20050224220021.GB27663@unpythonic.net> Message-ID: Actually on Windows it gives an exception but you're probably close on the config options. Traceback (most recent call last): File "test-cursor.py", line 3, in ? t.configure(cursor="@cntr_ptr cntr_ptrmsk black white") File "C:\Programs\Python24\Lib\lib-tk\Tkinter.py", line 1139, in configure return self._configure('configure', cnf, kw) File "C:\Programs\Python24\Lib\lib-tk\Tkinter.py", line 1130, in _configure self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) _tkinter.TclError: bad cursor spec "@cntr_ptr cntr_ptrmsk black white" On Thu, 24 Feb 2005 16:00:21 -0600, Jeff Epler wrote: > On my Linux machine, this worked in wish: > $ cd /usr/X11R6/include/X11/bitmaps > $ wish > % . configure -cursor {@cntr_ptr cntr_ptrmsk black white} > > The Python version would probably read something like > import Tkinter > t = Tkinter.Tk() > t.configure(cursor="@cntr_ptr cntr_ptrmsk black white") > t.mainloop() > I suspect the 1-arg format "@example.cur" should work just as well on > Windows. > > Tk_GetCursorFromData is a C API, while Tkinter mostly exposes the Tcl > API. Reading the Tk_GetCursorFromData manual page, it looks like it > doesn't expose any capabilities that the @-form of the cursor property > doesn't (instance, the X and Y hotspots are named in the "cntr_ptr" > file), but maybe I'm missing something. > > Jeff > > > _______________________________________________ > 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 klappnase at web.de Fri Feb 25 11:54:27 2005 From: klappnase at web.de (Michael Lange) Date: Fri Feb 25 11:51:32 2005 Subject: [Tkinter-discuss] Custom cursor? In-Reply-To: References: <20050224220021.GB27663@unpythonic.net> Message-ID: <20050225115427.04d8ede0.klappnase@web.de> On Thu, 24 Feb 2005 16:08:24 -0700 Stewart Midwinter wrote: > Actually on Windows it gives an exception but you're probably close on > the config options. > > Traceback (most recent call last): > File "test-cursor.py", line 3, in ? > t.configure(cursor="@cntr_ptr cntr_ptrmsk black white") > File "C:\Programs\Python24\Lib\lib-tk\Tkinter.py", line 1139, in configure > return self._configure('configure', cnf, kw) > File "C:\Programs\Python24\Lib\lib-tk\Tkinter.py", line 1130, in _configure > self.tk.call(_flatten((self._w, cmd)) + self._options(cnf)) > _tkinter.TclError: bad cursor spec "@cntr_ptr cntr_ptrmsk black white" > > 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) Michael From jepler at unpythonic.net Fri Feb 25 16:15:13 2005 From: jepler at unpythonic.net (Jeff Epler) Date: Fri Feb 25 16:16:09 2005 Subject: [Tkinter-discuss] Custom cursor? In-Reply-To: References: <20050224220021.GB27663@unpythonic.net> Message-ID: <20050225151513.GG21350@unpythonic.net> On Thu, Feb 24, 2005 at 04:08:24PM -0700, Stewart Midwinter wrote: > Actually on Windows it gives an exception but you're probably close on > the config options. The length-4 version is X only. "This form of the command will not work on Macintosh or Windows computers" -- man Tk_GetCursor This is the version that works on Windows: % . configure -cursor @treeview.cur ;# wish, tested or t.configure(cursor="@treeview.cur") # python + tkinter, not tested (treeview.cur is a cursor file that I found in the BLT source directory, but any Windows-format .cur or .ani file is supposed to work) Keep in mind that these filenames are always relative to the working directory, not necessarily to the location of your script or the Python executable. 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/20050225/a20b19ad/attachment.pgp From Jared.Cohen at noaa.gov Mon Feb 28 20:11:28 2005 From: Jared.Cohen at noaa.gov (Jared Cohen) Date: Mon Feb 28 20:11:36 2005 Subject: [Tkinter-discuss] Another problem -- deselecting individual entries in Tix HList Message-ID: <42236CE0.5010303@noaa.gov> 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? From mart.franklin at gmail.com Mon Feb 28 21:28:02 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Mon Feb 28 21:30:36 2005 Subject: [Tkinter-discuss] Re: Another problem -- deselecting individual entries in Tix HList In-Reply-To: <42236CE0.5010303@noaa.gov> 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? Because from is a reserved word in python the Tkinter spelling of it is usually _from (note the leading underscore) this is true of standard Tkinter widgets not sure about Tix (don't use it) For more on keyword arguments see the online docs:- http://docs.python.org/tut/node6.html#SECTION006600000000000000000 http://docs.python.org/tut/node6.html#SECTION006720000000000000000 Cheers, Martin. From mart.franklin at gmail.com Mon Feb 28 21:31:55 2005 From: mart.franklin at gmail.com (Martin Franklin) Date: Mon Feb 28 21:35:28 2005 Subject: [Tkinter-discuss] Re: Another problem -- deselecting individual entries in Tix HList In-Reply-To: <42236CE0.5010303@noaa.gov> 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? whoops I should have checked its from_ (trailing underscore!) sorry for any _confusion_ Martin