From jepler at unpythonic.net Tue Jan 8 14:36:03 2013 From: jepler at unpythonic.net (Jeff Epler) Date: Tue, 8 Jan 2013 07:36:03 -0600 Subject: [Tkinter-discuss] tkinter wiki (temporarily) offline Message-ID: <20130108133603.GA8291@unpythonic.net> I read today that the python.org wiki (running an unspecified version of moinmoin) was compromised in December http://pyfound.blogspot.com/2013/01/wikipythonorg-compromised.html As a result, I am disabling the tkinter wiki temporarily while I investigate how to obtain a fixed version for Ubuntu 10.04 LTS. I apologize for the inconvenience. Jeff From francois.laforgia at hds.com Thu Jan 10 11:04:15 2013 From: francois.laforgia at hds.com (=?iso-8859-1?Q?Fran=E7ois_laforgia?=) Date: Thu, 10 Jan 2013 10:04:15 +0000 Subject: [Tkinter-discuss] No menu displayed. Message-ID: Hi all, I'm a beginner in Tkinter development and I have a problem w/ the menus under Mac OS. I would like to build a GUI w/ menus but when I run the program on MAC OS Lion everything is ok but no menus are displayed in my window. I tried to run the same program w/ the same Python version on a Ubuntu 12.04 and this time the menus are correctly displayed. I also noticed that IDLE doesn't display the menus either. I'm not stuck as I can continue to code on my Linux but at the end this program will have to run mainly on Mac OS and at this time I can't provide it as it is. I had a look at the known issue on the Python website but nothing seems related to this problem. It is also possible I do something wrong but I can't find what. Please can you help me to troubleshoot this issue ? My configuration is the following: Mac Book Pro 2.4GHz Core i5 / 4GB RAM Mac OS X 10.7.5 Python 2.7.3 (the one provided w/ Mac OS) I believe TK is ver. 8.5 but I don't know how to verify it. I attached to this email the test case I used to confirm the issue. Best regards, Francois. -------------- next part -------------- A non-text attachment was scrubbed... Name: Menutk2.py Type: text/x-python-script Size: 1842 bytes Desc: Menutk2.py URL: From kw at codebykevin.com Thu Jan 10 12:57:59 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Thu, 10 Jan 2013 06:57:59 -0500 Subject: [Tkinter-discuss] No menu displayed. In-Reply-To: References: Message-ID: <50EEACC7.3090703@codebykevin.com> On 1/10/13 5:04 AM, Fran?ois laforgia wrote: > Hi all, > > I'm a beginner in Tkinter development and I have a problem w/ the menus > under Mac OS. > I would like to build a GUI w/ menus but when I run the program on MAC OS > Lion everything is ok but no menus are displayed in my window. I tried to > run the same program w/ the same Python version on a Ubuntu 12.04 and this > time the menus are correctly displayed. > I also noticed that IDLE doesn't display the menus either. > I'm not stuck as I can continue to code on my Linux but at the end this > program will have to run mainly on Mac OS and at this time I can't provide > it as it is. > I had a look at the known issue on the Python website but nothing seems > related to this problem. It is also possible I do something wrong but I > can't find what. Please can you help me to troubleshoot this issue ? > On MacOS, the menubar is at the top of the screen, not attached to a window. I see the menu fine on my system in your code sample. -- Kevin Walzer Code by Kevin http://www.codebykevin.com From jepler at unpythonic.net Thu Jan 10 14:41:50 2013 From: jepler at unpythonic.net (Jeff Epler) Date: Thu, 10 Jan 2013 07:41:50 -0600 Subject: [Tkinter-discuss] tkinter wiki back online In-Reply-To: <20130108133603.GA8291@unpythonic.net> References: <20130108133603.GA8291@unpythonic.net> Message-ID: <20130110134149.GA11854@unpythonic.net> Canonical has pushed out an update for moinmoin that appears to address the security bugs recently disclosed. I also found no evidence in logs of exploitation of the bugs on the tkinter wiki. Accordingly, the wiki is back online: http://tkinter.unpythonic.net/wiki/ Jeff From francois.laforgia at hds.com Thu Jan 10 14:53:51 2013 From: francois.laforgia at hds.com (=?iso-8859-1?Q?Fran=E7ois_laforgia?=) Date: Thu, 10 Jan 2013 13:53:51 +0000 Subject: [Tkinter-discuss] No menu displayed. In-Reply-To: <50EEACC7.3090703@codebykevin.com> Message-ID: Hi Kevin, Thanks. I was so sure that the menus will be displayed in the window that I forgot to look at the screen bar. Shame on me ! Best regards, Francois. >On 1/10/13 5:04 AM, Fran?ois laforgia wrote: >> Hi all, >> >> I'm a beginner in Tkinter development and I have a problem w/ the menus >> under Mac OS. >> I would like to build a GUI w/ menus but when I run the program on MAC >>OS >> Lion everything is ok but no menus are displayed in my window. I tried >>to >> run the same program w/ the same Python version on a Ubuntu 12.04 and >>this >> time the menus are correctly displayed. >> I also noticed that IDLE doesn't display the menus either. >> I'm not stuck as I can continue to code on my Linux but at the end this >> program will have to run mainly on Mac OS and at this time I can't >>provide >> it as it is. >> I had a look at the known issue on the Python website but nothing seems >> related to this problem. It is also possible I do something wrong but I >> can't find what. Please can you help me to troubleshoot this issue ? >> >On MacOS, the menubar is at the top of the screen, not attached to a >window. I see the menu fine on my system in your code sample. > > >-- >Kevin Walzer >Code by Kevin >http://www.codebykevin.com >_______________________________________________ >Tkinter-discuss mailing list >Tkinter-discuss at python.org >http://mail.python.org/mailman/listinfo/tkinter-discuss From leon.maurer at gmail.com Sat Jan 12 16:46:51 2013 From: leon.maurer at gmail.com (Leon Maurer) Date: Sat, 12 Jan 2013 09:46:51 -0600 Subject: [Tkinter-discuss] TkInter won't update display on OS X if delay is too small Message-ID: Howdy, I'm running in to a problem where TkInter won't update the interface on OS X. I've filed a bug (http://bugs.python.org/issue16941), but it was suggested that I also send the message here, in case you have some thoughts about what to do -- either a fix or a workaround. Here's a small piece of code which has the problem: https://mywebspace.wisc.edu/lnmaurer/web/updatebug/bugtest.py The program is simple -- basically a big canvas with a some text in the middle that counts up. Here's a short quick-time movie showing the problem with that code: https://mywebspace.wisc.edu/lnmaurer/web/updatebug/updatebug.mov The screen-cast has three parts. First, it shows the program working as it should. Then, I add a simple background image to the canvas (a black rectangle), and the interface refuses to refresh at all; I get a spinning beach ball wheel (although the cursor appears as the usual black arrow in the screen-cast). Finally I increase the delay between updates, and the interface again refreshes as it should. The middle case, where the interface becomes totally unresponsive, is a bug. I haven't been able to reproduce this problem under Linux or Windows; I've only run in to it on OS X. Also, the size of the canvas and image matters; if I make them small enough, the interface won't freeze up. I first ran in to this problem on a more complicated program with a more complex interface http://lnmaurer.github.com/Interference-Inference-Interface/ so -- if you can't reproduce the problem with the simple code -- you may be able to reproduce it with that more complex code. Computer and software information: OS X 10.6.8 Python 2.7.3 ActiveTcl 8.5.13 PIL 1.1.7 MacBookPro5,5 w/ 2.26GHz Core 2 Duo (So it's a machine that's kind of slow by today's standards. Maybe faster machines won't run in to this problem, but this machine doesn't have the problem when running Windows or Linux.) Thanks. -Leon -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Sat Jan 12 16:58:27 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 12 Jan 2013 10:58:27 -0500 Subject: [Tkinter-discuss] TkInter won't update display on OS X if delay is too small In-Reply-To: References: Message-ID: <50F18823.5090801@codebykevin.com> On 1/12/13 10:46 AM, Leon Maurer wrote: > Howdy, > > I'm running in to a problem where TkInter won't update the interface on > OS X. I've filed a bug (http://bugs.python.org/issue16941), but it was > suggested that I also send the message here, in case you have some > thoughts about what to do -- either a fix or a workaround. > > Here's a small piece of code which has the problem: > > https://mywebspace.wisc.edu/lnmaurer/web/updatebug/bugtest.py > > The program is simple -- basically a big canvas with a some text in the > middle that counts up. > > Here's a short quick-time movie showing the problem with that code: > > https://mywebspace.wisc.edu/lnmaurer/web/updatebug/updatebug.mov > > The screen-cast has three parts. First, it shows the program working as > it should. Then, I add a simple background image to the canvas (a black > rectangle), and the interface refuses to refresh at all; I get a > spinning beach ball wheel (although the cursor appears as the usual > black arrow in the screen-cast).? Finally? I increase the delay between > updates, and the interface again refreshes as it should. > You're running into a well-known and essentially unsolvable bug with Tk on OS X, essentially integration between the event loop of Tk and Cocoa's event loop. This is not a Tkinter issue, it's a Tk issue, and it's essentially impossible to fix: the event loops of Tk and Cocoa are very different and their integration is a fragile, leading at times to the kinds of screen freeze/lockups you see. Increasing the delay between events a bit, as you've done, is a recommended best practice, as it gives the event loop time to spin and process the event queue; so you've essentially already found the best solution for your problem. I'm speaking here at the maintainer of Tk on the Mac; we've discussed these issues on the Tcl-Mac mailing list, the MacPython list, and here, and a lot of talented developers besides myself have looked at it. No one has been able to solve the issue, it's simply an inherent artifact that can only be worked around. Thanks, Kevin ---- Kevin Walzer Code by Kevin http://www.codebykevin.com From leon.maurer at gmail.com Sat Jan 12 17:25:33 2013 From: leon.maurer at gmail.com (Leon Maurer) Date: Sat, 12 Jan 2013 10:25:33 -0600 Subject: [Tkinter-discuss] TkInter won't update display on OS X if delay is too small In-Reply-To: <50F18823.5090801@codebykevin.com> References: <50F18823.5090801@codebykevin.com> Message-ID: Oh well, thanks for the answer. Is there much data on how much of a delay is needed, and does it vary much from computer to computer? I'm trying to produce a smooth animation with the more complicated code, so adding a big delay isn't acceptable. -Leon On Sat, Jan 12, 2013 at 9:58 AM, Kevin Walzer wrote: > > You're running into a well-known and essentially unsolvable bug with Tk on > OS X, essentially integration between the event loop of Tk and Cocoa's > event loop. This is not a Tkinter issue, it's a Tk issue, and it's > essentially impossible to fix: the event loops of Tk and Cocoa are very > different and their integration is a fragile, leading at times to the kinds > of screen freeze/lockups you see. Increasing the delay between events a > bit, as you've done, is a recommended best practice, as it gives the event > loop time to spin and process the event queue; so you've essentially > already found the best solution for your problem. > > I'm speaking here at the maintainer of Tk on the Mac; we've discussed > these issues on the Tcl-Mac mailing list, the MacPython list, and here, and > a lot of talented developers besides myself have looked at it. No one has > been able to solve the issue, it's simply an inherent artifact that can > only be worked around. > > Thanks, > Kevin > -------------- next part -------------- An HTML attachment was scrubbed... URL: From leon.maurer at gmail.com Sat Jan 12 18:33:15 2013 From: leon.maurer at gmail.com (Leon Maurer) Date: Sat, 12 Jan 2013 11:33:15 -0600 Subject: [Tkinter-discuss] TkInter won't update display on OS X if delay is too small In-Reply-To: References: <50F18823.5090801@codebykevin.com> Message-ID: It seems like putting a "root.update" before the "root.after" makes things work well, even if I keep the small delay in the "root.after". Is this a reasonable thing to do? Otherwise, I have to use a large enough delay that it pushes an already slow animation in to slide show territory. -Leon On Sat, Jan 12, 2013 at 10:25 AM, Leon Maurer wrote: > Oh well, thanks for the answer. > > Is there much data on how much of a delay is needed, and does it vary much > from computer to computer? I'm trying to produce a smooth animation with > the more complicated code, so adding a big delay isn't acceptable. > -Leon > > > On Sat, Jan 12, 2013 at 9:58 AM, Kevin Walzer wrote: >> >> You're running into a well-known and essentially unsolvable bug with Tk >> on OS X, essentially integration between the event loop of Tk and Cocoa's >> event loop. This is not a Tkinter issue, it's a Tk issue, and it's >> essentially impossible to fix: the event loops of Tk and Cocoa are very >> different and their integration is a fragile, leading at times to the kinds >> of screen freeze/lockups you see. Increasing the delay between events a >> bit, as you've done, is a recommended best practice, as it gives the event >> loop time to spin and process the event queue; so you've essentially >> already found the best solution for your problem. >> >> I'm speaking here at the maintainer of Tk on the Mac; we've discussed >> these issues on the Tcl-Mac mailing list, the MacPython list, and here, and >> a lot of talented developers besides myself have looked at it. No one has >> been able to solve the issue, it's simply an inherent artifact that can >> only be worked around. >> >> Thanks, >> Kevin >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: From kw at codebykevin.com Sat Jan 12 18:40:26 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Sat, 12 Jan 2013 12:40:26 -0500 Subject: [Tkinter-discuss] TkInter won't update display on OS X if delay is too small In-Reply-To: References: <50F18823.5090801@codebykevin.com> Message-ID: <50F1A00A.7080308@codebykevin.com> On 1/12/13 12:33 PM, Leon Maurer wrote: > It seems like putting a "root.update" before the "root.after" makes > things work well, even if I keep the small delay in the "root.after". Is > this a reasonable thing to do? Otherwise, I have to use a large enough > delay that it pushes an already slow animation in to slide show territory. > -Leon root.update() should be used sparingly, because it causes all events to be processed and can have unpredictable results, but in a case like this it can be helpful. --Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com From kalman_g at verizon.net Sun Jan 13 20:06:39 2013 From: kalman_g at verizon.net (GKalman) Date: Sun, 13 Jan 2013 11:06:39 -0800 (PST) Subject: [Tkinter-discuss] itemcget question Message-ID: <1358103999414-5002250.post@n6.nabble.com> In the short sample code below I have two print statements, each of which contains *"itemcget()" * The first print statement works OK. It accesses the "fill" option and returns "red" The second print statements generates an error-message. My intent is to print (or in general access) one of the coordinates of the oval (in this example, designated as x1). *In general my question is:* How to access the coordinates in a *canvas. create_oval(x1,y1,x2,y2, options...*) statement? #==================== SAMPLE CODE ==================================== from Tkinter import * class Appr: def __init__(self,root): self.c = Canvas(root, width=500, height=500) self.c.pack(fill=BOTH, expand=YES) x1=10 self.oval=self.c.create_oval(x1,10,20,20,fill="red",tags='red') self.c.tag_bind('red', '', self.startDoIt) def startDoIt(self,event): widget = event.widget self.startx, self.starty = widget.winfo_pointerxy() print widget.itemcget(self.oval,"fill") print widget.itemcget(self.oval, x1) raw_input() #=========== MAIN ==== root=Tk() app=Ap(root) root.mainloop() -- View this message in context: http://python.6.n6.nabble.com/itemcget-question-tp5002250.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From kalman_g at verizon.net Sun Jan 13 21:40:23 2013 From: kalman_g at verizon.net (GKalman) Date: Sun, 13 Jan 2013 12:40:23 -0800 (PST) Subject: [Tkinter-discuss] itemcget question In-Reply-To: <1358103999414-5002250.post@n6.nabble.com> References: <1358103999414-5002250.post@n6.nabble.com> Message-ID: <1358109623797-5002257.post@n6.nabble.com> Thanks to an earlier post by Michael Lange on 18 Dec 2011 at 17:30 the issue is resolved by the following statement: print "x1= ",(widget.coords(self.ovalt)[0]) -- View this message in context: http://python.6.n6.nabble.com/itemcget-question-tp5002250p5002257.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From RLAdams at AdamsInfoServ.Com Thu Jan 17 00:11:52 2013 From: RLAdams at AdamsInfoServ.Com (Russell Adams) Date: Wed, 16 Jan 2013 17:11:52 -0600 Subject: [Tkinter-discuss] StringVar fails to honor None Message-ID: <20130116231152.GR13770@cardamom.adamsinfoserv.com> Found this while reverting a data entry form to database values (ie: Undo), all my fields became "None". Set changes None to a string, creating with value= doesn't. Seems inconsistent, is this intentional or to be expected? -- #!/usr/bin/env python3 from tkinter import * from tkinter import ttk import tkinter.font as tkFont root = Tk() print("Creating a stringvar") derp=StringVar(value=None) print("Derp was created with value of None, it's value is '{}'.".format(derp.get())) print("Now setting derp to None again") derp.set(None) print("Derp was set to None, it's value is '{}'.".format(derp.get())) assert derp.get() == '' ------------------------------------------------------------------ Russell Adams RLAdams at AdamsInfoServ.com PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3 From klappnase at web.de Thu Jan 17 11:59:00 2013 From: klappnase at web.de (Michael Lange) Date: Thu, 17 Jan 2013 11:59:00 +0100 Subject: [Tkinter-discuss] StringVar fails to honor None In-Reply-To: <20130116231152.GR13770@cardamom.adamsinfoserv.com> References: <20130116231152.GR13770@cardamom.adamsinfoserv.com> Message-ID: <20130117115900.3810d80f.klappnase@web.de> Hi Russell, On Wed, 16 Jan 2013 17:11:52 -0600 Russell Adams wrote: > Found this while reverting a data entry form to database values (ie: > Undo), all my fields became "None". Set changes None to a string, > creating with value= doesn't. > > Seems inconsistent, is this intentional or to be expected? this seems like a feature or a bug in tkapp.globalsetvar(). When we look at Variable.__init_(), we find: class Variable: def __init__(self, master=None, value=None, name=None): (...) if value is not None: self.set(value) so if value == None, value actually won't be applied. Now in set() it is simply: def set(self, value): """Set the variable to VALUE.""" return self._tk.globalsetvar(self._name, value) apparently globalsetvar() tries its best to convert anything it gets into a string. This is probably useful in most cases (for example when we pas an integer or a float to set()), but shows odd results sometimes. Setting the StringVar to boolean True or False e.g. actually sets its value to "1" or "0" ;) If I pass an empty dict or list to set(), I get the strings "{}" or "[]", which seems at least to be consistent with the behavior of set (None). I guess this is one of the tkinter oddities we have to live with, at least I don't see how this should be fixed without breaking existing code. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Violence in reality is quite different from theory. -- Spock, "The Cloud Minders", stardate 5818.4 From RLAdams at AdamsInfoServ.Com Thu Jan 17 19:52:36 2013 From: RLAdams at AdamsInfoServ.Com (Russell Adams) Date: Thu, 17 Jan 2013 12:52:36 -0600 Subject: [Tkinter-discuss] StringVar fails to honor None In-Reply-To: <20130117115900.3810d80f.klappnase@web.de> References: <20130116231152.GR13770@cardamom.adamsinfoserv.com> <20130117115900.3810d80f.klappnase@web.de> Message-ID: <20130117185236.GU13770@cardamom.adamsinfoserv.com> On Thu, Jan 17, 2013 at 11:59:00AM +0100, Michael Lange wrote: > Hi Russell, > > On Wed, 16 Jan 2013 17:11:52 -0600 > Russell Adams wrote: > > > Found this while reverting a data entry form to database values (ie: > > Undo), all my fields became "None". Set changes None to a string, > > creating with value= doesn't. > > > > Seems inconsistent, is this intentional or to be expected? > > this seems like a feature or a bug in tkapp.globalsetvar(). > > When we look at Variable.__init_(), we find: > > class Variable: > def __init__(self, master=None, value=None, name=None): > (...) > if value is not None: > self.set(value) > > so if value == None, value actually won't be applied. > Now in set() it is simply: > > def set(self, value): > """Set the variable to VALUE.""" > return self._tk.globalsetvar(self._name, value) > > apparently globalsetvar() tries its best to convert anything it gets into > a string. > This is probably useful in most cases (for example when we pas > an integer or a float to set()), but shows odd results sometimes. Setting > the StringVar to boolean True or False e.g. actually sets its value to > "1" or "0" ;) > If I pass an empty dict or list to set(), I get the strings > "{}" or "[]", which seems at least to be consistent with the behavior of > set (None). > I can appreciate that. Is there a "proper" way to reset a Variable to it's original state? Thanks. > I guess this is one of the tkinter oddities we have to live with, at > least I don't see how this should be fixed without breaking existing > code. > > Regards > > Michael > > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Violence in reality is quite different from theory. > -- Spock, "The Cloud Minders", stardate 5818.4 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > ------------------------------------------------------------------ Russell Adams RLAdams at AdamsInfoServ.com PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3 From klappnase at web.de Thu Jan 17 20:20:46 2013 From: klappnase at web.de (Michael Lange) Date: Thu, 17 Jan 2013 20:20:46 +0100 Subject: [Tkinter-discuss] StringVar fails to honor None In-Reply-To: <20130117185236.GU13770@cardamom.adamsinfoserv.com> References: <20130116231152.GR13770@cardamom.adamsinfoserv.com> <20130117115900.3810d80f.klappnase@web.de> <20130117185236.GU13770@cardamom.adamsinfoserv.com> Message-ID: <20130117202046.4f75d0ec.klappnase@web.de> On Thu, 17 Jan 2013 12:52:36 -0600 Russell Adams wrote: > > I can appreciate that. Is there a "proper" way to reset a Variable to > it's original state? There is the Variable's _default attribute, but I don't think that it helps much, and since it is a "hidden" attribute, I don't think using it could be considered "proper" In your case maybe creating a custom StringVar class with a modified set() might be the most handy approach, like: class MyStringVar(StringVar): def __init__(self, *args, **kw): StringVar.__init__(self, *args, **kw) def set(self, value): if value is None: value = '' return StringVar.set(self, value) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. You can't evaluate a man by logic alone. -- McCoy, "I, Mudd", stardate 4513.3 From RLAdams at AdamsInfoServ.Com Thu Jan 17 20:35:47 2013 From: RLAdams at AdamsInfoServ.Com (Russell Adams) Date: Thu, 17 Jan 2013 13:35:47 -0600 Subject: [Tkinter-discuss] StringVar fails to honor None In-Reply-To: <20130117202046.4f75d0ec.klappnase@web.de> References: <20130116231152.GR13770@cardamom.adamsinfoserv.com> <20130117115900.3810d80f.klappnase@web.de> <20130117185236.GU13770@cardamom.adamsinfoserv.com> <20130117202046.4f75d0ec.klappnase@web.de> Message-ID: <20130117193547.GW13770@cardamom.adamsinfoserv.com> On Thu, Jan 17, 2013 at 08:20:46PM +0100, Michael Lange wrote: > On Thu, 17 Jan 2013 12:52:36 -0600 > In your case maybe creating a custom StringVar class with a modified > set() might be the most handy approach, like: That's exactly what I've done. Thanks. ------------------------------------------------------------------ Russell Adams RLAdams at AdamsInfoServ.com PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3 From greg.ewing at canterbury.ac.nz Fri Jan 18 08:49:40 2013 From: greg.ewing at canterbury.ac.nz (Greg Ewing) Date: Fri, 18 Jan 2013 20:49:40 +1300 Subject: [Tkinter-discuss] StringVar fails to honor None In-Reply-To: <20130117185236.GU13770@cardamom.adamsinfoserv.com> References: <20130116231152.GR13770@cardamom.adamsinfoserv.com> <20130117115900.3810d80f.klappnase@web.de> <20130117185236.GU13770@cardamom.adamsinfoserv.com> Message-ID: <50F8FE94.1000600@canterbury.ac.nz> > On Thu, Jan 17, 2013 at 11:59:00AM +0100, Michael Lange wrote: >>apparently globalsetvar() tries its best to convert anything it gets into >>a string. Since strings are the only thing a tcl variable can hold, it doesn't have much choice, really. If you want to store an arbitrary Python value without it getting munged, a tcl variable is probably the wrong thing to use. -- Greg From RLAdams at AdamsInfoServ.Com Fri Jan 18 09:19:35 2013 From: RLAdams at AdamsInfoServ.Com (Russell Adams) Date: Fri, 18 Jan 2013 02:19:35 -0600 Subject: [Tkinter-discuss] StringVar fails to honor None In-Reply-To: <50F8FE94.1000600@canterbury.ac.nz> References: <20130116231152.GR13770@cardamom.adamsinfoserv.com> <20130117115900.3810d80f.klappnase@web.de> <20130117185236.GU13770@cardamom.adamsinfoserv.com> <50F8FE94.1000600@canterbury.ac.nz> Message-ID: <20130118081935.GE13770@cardamom.adamsinfoserv.com> On Fri, Jan 18, 2013 at 08:49:40PM +1300, Greg Ewing wrote: > >On Thu, Jan 17, 2013 at 11:59:00AM +0100, Michael Lange wrote: > > >>apparently globalsetvar() tries its best to convert anything it gets into > >>a string. > > Since strings are the only thing a tcl variable can hold, > it doesn't have much choice, really. > > If you want to store an arbitrary Python value without it > getting munged, a tcl variable is probably the wrong thing > to use. I found this making a form with SQL-Alchemy. I used the object returned for my row from SQL-A to set the initial values on my Tkinter form. I created a "Revert" button to essentially undo any data entry and go back to that SQL-A data. Revert revealed the behavior, which made no sense at the time because I had passed a None unwittingly as an initial value (from a NULL SQL row converted to None), and I set it back to the same SQL-A object's value. I thought I'd made a mistake somewhere and converted to string, obviously I hadn't. Now I've just added some code to convert None to '', and let it be. Thanks. ------------------------------------------------------------------ Russell Adams RLAdams at AdamsInfoServ.com PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3 From RLAdams at AdamsInfoServ.Com Sat Jan 26 01:50:56 2013 From: RLAdams at AdamsInfoServ.Com (Russell Adams) Date: Fri, 25 Jan 2013 18:50:56 -0600 Subject: [Tkinter-discuss] Tkinter (python 3) and Sql-Alchemy Message-ID: <20130126005056.GB5299@cardamom.adamsinfoserv.com> I've hit a wall trying to make a fairly simple tkinter form oriented application using SQL-Alchemy in keeping the tkinter widgets and the sql-alchemy objects in synchronization. Google searches haven't provided any benefit, so I turn to the mailing list. Does anyone have any code samples, best practices, or could recommend other open source programs that use tkinter and sql-alchemy that correctly demonstrate how to work with the pair? The issues I've been having are typically due to implicit string conversions, input validation, converting strings back to the sql data type (date, datetime, boolean, integer, decimal.decimal), and synchronizing updates to the screen vs updates to the sql-a object. I've tried a few methods now, including using Variables (ie: IntVar, StringVar, etc), tracing those variables, and now I'm working through creating a class which would inherit from Variable but perform the type conversions. Oddly enough session management has been a breeze. Code is at: https://code.launchpad.net/~rladams/+junk/TERT Thanks. ------------------------------------------------------------------ Russell Adams RLAdams at AdamsInfoServ.com PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3 From klappnase at web.de Sat Jan 26 18:37:11 2013 From: klappnase at web.de (Michael Lange) Date: Sat, 26 Jan 2013 18:37:11 +0100 Subject: [Tkinter-discuss] Tkinter (python 3) and Sql-Alchemy In-Reply-To: <20130126005056.GB5299@cardamom.adamsinfoserv.com> References: <20130126005056.GB5299@cardamom.adamsinfoserv.com> Message-ID: <20130126183711.12feb25c.klappnase@web.de> Hi, On Fri, 25 Jan 2013 18:50:56 -0600 Russell Adams wrote: > Does anyone have any code samples, best practices, or could recommend > other open source programs that use tkinter and sql-alchemy that > correctly demonstrate how to work with the pair? (...) > I've tried a few methods now, including using Variables (ie: IntVar, > StringVar, etc), tracing those variables, and now I'm working through > creating a class which would inherit from Variable but perform the > type conversions. I don't know anything about sql-alchemy, from what you write my first idea too was to subclass StringVar and add a datatype attribute to the new SqlVariable class and let get() and set() handle the conversions according to self.datatype. If you have only the five mentioned datatypes I think this shouldn't be too hard and might prove quite handy then. For the date and time datatypes maybe you could borrow some code from the Pmw.EntryField validation mechanisms. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Vulcans worship peace above all. -- McCoy, "Return to Tomorrow", stardate 4768.3 From RLAdams at AdamsInfoServ.Com Tue Jan 29 00:22:14 2013 From: RLAdams at AdamsInfoServ.Com (Russell Adams) Date: Mon, 28 Jan 2013 17:22:14 -0600 Subject: [Tkinter-discuss] Tkinter (python 3) and Sql-Alchemy In-Reply-To: <20130126183711.12feb25c.klappnase@web.de> References: <20130126005056.GB5299@cardamom.adamsinfoserv.com> <20130126183711.12feb25c.klappnase@web.de> Message-ID: <20130128232214.GH15765@cardamom.adamsinfoserv.com> On Sat, Jan 26, 2013 at 06:37:11PM +0100, Michael Lange wrote: > I don't know anything about sql-alchemy, from what you write my first > idea too was to subclass StringVar and add a datatype attribute to the > new SqlVariable class and let get() and set() handle the conversions > according to self.datatype. If you have only the five mentioned datatypes > I think this shouldn't be too hard and might prove quite handy then. So I've just tried this, with verbose logging. I've overridden the set method to also try to set the DB object to the native value with a conversion, and soft failure (ie: if you haven't finished typing a date, it doesn't bomb, it just doesn't update the DB object). Making changes on the screen (ie: typing in a widget) doesn't appear to call set at all, my debugging messages never even pop up. Thus the DB object is never updated. Did I misunderstand something in your suggestion? I'm thinking I may need to add a trace that does the sync, not override set(). Thanks. ------------------------------------------------------------------ Russell Adams RLAdams at AdamsInfoServ.com PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3 From RLAdams at AdamsInfoServ.Com Tue Jan 29 15:26:11 2013 From: RLAdams at AdamsInfoServ.Com (Russell Adams) Date: Tue, 29 Jan 2013 08:26:11 -0600 Subject: [Tkinter-discuss] Tkinter (python 3) and Sql-Alchemy In-Reply-To: <20130128232214.GH15765@cardamom.adamsinfoserv.com> References: <20130126005056.GB5299@cardamom.adamsinfoserv.com> <20130126183711.12feb25c.klappnase@web.de> <20130128232214.GH15765@cardamom.adamsinfoserv.com> Message-ID: <20130129142611.GJ15765@cardamom.adamsinfoserv.com> > I'm thinking I may need to add a trace that does the sync, not > override set(). To answer my own question and put it on the ML for future reference, creating classes for SQL-Alchemy SQL data types that bind a trace callback does indeed synchronize changes that happen to the widget onscreen with the SQL-A object. This is very convenient because my forms are all a single transaction in the DB, and when the changes are synced my save call is merely commit. Thanks. # ---------------------------------------------------------------------- class stringFieldVar(Variable): """Override Tk Variable class to allow sync and validation with SQLA objects""" def __init__(self, datum, field): self.datum = datum self.field = field super().__init__( value = self._tkConvert(getattr(self.datum, self.field, '')) ) self.trace("w", self.synchronizeWithSQL) def _tkConvert(self, value): """Convert to a string for Tk, only used on initial set from DB""" if value == None: result = '' else: result = str(value) return result def _sqlConvert(self, value): """Convert a Tk string back to SQL datatype, happens every widget refresh""" if value == '': result = None elif value: result = str(value) return result def synchronizeWithSQL(self, *args): """Convert data for DB type, the widget calls this repeatedly with changes""" try: # only update the sql object if the value is valid logger.debug("Testing {}, is '{}' valid?".format(self.field, self.get())) sqlValue = self._sqlConvert(self.get()) setattr(self.datum, self.field, sqlValue) logger.debug("Setting {}, converted '{}', to '{}'".format(self.field, self.get(), sqlValue)) except (AttributeError, TypeError): pass class intFieldVar(stringFieldVar): def _sqlConvert(self, value): if value == '': result = None elif value: result = int(value) return result class numericFieldVar(stringFieldVar): def _sqlConvert(self, value): if value == '': result = None elif value: result = D.decimal(value) return result class booleanFieldVar(stringFieldVar): def _tkConvert(self, value): """Convert to a string for Tk, only used on initial set from DB""" if value == None: result = '' elif value == True: result = '1' else: result = '0' return result def _sqlConvert(self, value): if value == '': result = None elif value == '1': result = True else: result = False return result class dateFieldVar(stringFieldVar): def _tkConvert(self, value): return '' if value == None else value.strftime("%Y/%m/%d") def _sqlConvert(self, value): if value == '': result = None elif value == 'now': result = 'now' elif value: result = time.strftime("%Y/%m/%d", value) return result class datetimeFieldVar(stringFieldVar): def _tkConvert(self, value): return '' if value == None else value.strftime("%Y/%m/%d %H:%M:%S") def _sqlConvert(self, value): if value == '': result = None elif value == 'now': result = 'now' elif value: result = time.strftime("%Y/%m/%d %H:%M:%S", value) return result ------------------------------------------------------------------ Russell Adams RLAdams at AdamsInfoServ.com PGP Key ID: 0x1160DCB3 http://www.adamsinfoserv.com/ Fingerprint: 1723 D8CA 4280 1EC9 557F 66E8 1154 E018 1160 DCB3