[Tutor] os.path.walk
Hi All, I was wondering if anyone had used os.path.walk within a class or not, and what are the pitfalls... What has got me worried is that the function called by os.path.walk must be a method of the class. Now this means it will have something like this as a def: def func_called_by_walk(self, arg, directory, names): Will this work with os.path.walk with that definition? Thanks, Matt ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] tkinter events:
Luke Paireepinart wrote: > Zsiros Levente wrote: > >> [snip code] >> *def* handler(event): >> *if* buttonpressed == 1 : >> /#if the mousebutton is pressed and moved, circles should >> appear, but they do not/ >> can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, >> fill="orange") >> lab.config(text='buttonpressed=' + str(buttonpressed) ) >> >> *def* press(event): >> buttonpressed=1 >> lab2.config(text=buttonpressed) >> >> *def* release(event): >> buttonpressed=0 >> lab2.config(text=buttonpressed) >> [snip code] >> /#global buttonpressed/ >> buttonpressed=0 > > > I think you're misunderstanding what global variables are. > Yes, others already mentioned that. > Take the following example: > > #--- code > a = 0 > def b(): >print a > b() > > #--- output > 0 > #--- > the function 'b' can see the variable 'a'. ok so far. > > now take this example. > > #--- code > a = 0 > def b(): >a = 1 >print a > b() > print a > > #--- output > 1 > 0 > #--- > in this case, 'a' is assigned to, but it's a local variable called 'a' > and not the one I think you expect it to assign to. > so after 'b' is done the value of the 'a' outside of the scope of the > function is still 0. > in your press and release events you assign values to 'buttonpressed' > before you use them, > and because of this, the same thing happens as in our second example: > a local variable named > 'buttonpressed' is created with the value 0 or 1 assigned to it > (depending on the function you're in.) > that works fine, and it sets the label's text value accordingly. But, > since it's a local variable and the > functions aren't actually modifying the global 'buttonpressed', the > 'buttonpressed' that you're checking for > in your 'handler' function is always going to be 0. That's why your > oval code is never drawn. > > Rather than messing with global variables, which are for the most part > evil creatures, > as we've witnessed so far here, I'd recommend using a class. > I wrote the class I would use for you so you can see it. > It's commented, but if you need any more help than the comments feel > free to write me back. > Just be sure to use the reply-all button so the whole list can see the > response. > -Luke > (note: code attached) > > > >#!/usr/bin/python > ># This program implements . it was originally written by >#Zsiros Levente. all rights of this modified version go to him :) > >from Tkinter import * > >class ButtonHandler(object): >def __init__(self): >#our self.mousedown variable is what we'll use to check the state >#of the button, since we're going to be passing a copy of 'self' >#around, we don't have to deal with scoping of the variables. >#I.E. self.mousedown is global to functions in the class >#that accept a 'self' argument. >self.mousedown = 0 > >#we make the window normally. note all these are 'self' variables >#so we can change them easily elsewhere in the class. >self.root = Tk() >self.root.geometry('600x500+200+200') >self.label = Label(self.root, text=str(self.mousedown)) >self.can = Canvas(self.root, width='500', height='400', bg='white') >#lambda is a way we can add extra arguments to a function. >#since the callback of bound events is only a single argument, >#we use 'lambda x' to get the 'event' instance, and pass it >#along with another string identifying which event it came from. >#this may or may not be necessary, but it's cool and it >#makes the handler function make more sense. >#also, we only need one handler function this way. >self.can.bind("",lambda x:self.handler(x,'motion')) >self.can.bind("",lambda x:self.handler(x,'press')) >self.can.bind("",lambda x:self.handler(x,'release')) >self.label.pack() >self.can.pack() >self.root.mainloop() > >def handler(self,event,x): >#the first two clauses of the if-elif branch implement your >#'press' and 'release' functions. >if x == 'press': >self.mousedown = 1 >elif x == 'release': >self.mousedown = 0 >elif x == 'motion': >if self.mousedown: >#you could do something really cool here, like store the time >#that the button was last pressed, and increase the radius of > the circle >#depending on how long it's been since then. >r = 5 >self.can.create_oval(event.x-r, event.y-r, event.x+r, > event.y+r, fill="orange") > self.label.config(text=str(self.mousedown)) > > >#we create an instance of the class which automatically >#calls the '__init__' method. >x = ButtonHandler() > > ___ Tutor maillist - T
Re: [Tutor] Limiting Characters
On Mon, 21 Aug 2006 13:19:54 -0400 "Marcus Dean Adams" <[EMAIL PROTECTED]> wrote: > I_m fairly new to python, I_ve been dabbling in it for school and I have a > question. I_ve written a few programs using graphical windows with input > boxes such as a stopwatch, temperature converter, etc. I_ve always found a > gui much prettier than command line. Anyway, I have limited the size of the > input boxes to the number of digits I wanted, but you can still put more > digits than that in the box. For example, the temperature converter input > box is only 3 digits wide, however I can enter a 20 digit number if I want, > it just only shows 3 digits at a time. How can I actually limit the number > of characters a user can enter, and not just the size of the input box? > > Hi Marcus, this depends of course on the toolkit you use. If it is Tkinter, you can use the Entry widget's validatecommand, see: http://mail.python.org/pipermail/tkinter-discuss/2006-August/000863.html I hope this helps Michael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] tkinter events:
You're right, that I pressed reply instead of reply-to-all, so the list didn't see my response. But this way you got my mail twice. Isn't that annoying? Other maillist servers used to use the reply-to tag in the message header. Luke Paireepinart wrote: > Zsiros Levente wrote: > >> [snip code] >> *def* handler(event): >> *if* buttonpressed == 1 : >> /#if the mousebutton is pressed and moved, circles should >> appear, but they do not/ >> can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, >> fill="orange") >> lab.config(text='buttonpressed=' + str(buttonpressed) ) >> >> *def* press(event): >> buttonpressed=1 >> lab2.config(text=buttonpressed) >> >> *def* release(event): >> buttonpressed=0 >> lab2.config(text=buttonpressed) >> [snip code] >> /#global buttonpressed/ >> buttonpressed=0 > > > I think you're misunderstanding what global variables are. > > Take the following example: > > #--- code > a = 0 > def b(): >print a > b() > > #--- output > 0 > #--- > the function 'b' can see the variable 'a'. ok so far. > > now take this example. > > #--- code > a = 0 > def b(): >a = 1 >print a > b() > print a > > #--- output > 1 > 0 > #--- > in this case, 'a' is assigned to, but it's a local variable called 'a' > and not the one I think you expect it to assign to. > so after 'b' is done the value of the 'a' outside of the scope of the > function is still 0. > in your press and release events you assign values to 'buttonpressed' > before you use them, > and because of this, the same thing happens as in our second example: > a local variable named > 'buttonpressed' is created with the value 0 or 1 assigned to it > (depending on the function you're in.) > that works fine, and it sets the label's text value accordingly. But, > since it's a local variable and the > functions aren't actually modifying the global 'buttonpressed', the > 'buttonpressed' that you're checking for > in your 'handler' function is always going to be 0. That's why your > oval code is never drawn. > > Rather than messing with global variables, which are for the most part > evil creatures, > as we've witnessed so far here, I'd recommend using a class. > I wrote the class I would use for you so you can see it. > It's commented, but if you need any more help than the comments feel > free to write me back. > Just be sure to use the reply-all button so the whole list can see the > response. > -Luke > (note: code attached) > > > >#!/usr/bin/python > ># This program implements . it was originally written by >#Zsiros Levente. all rights of this modified version go to him :) > >from Tkinter import * > >class ButtonHandler(object): >def __init__(self): >#our self.mousedown variable is what we'll use to check the state >#of the button, since we're going to be passing a copy of 'self' >#around, we don't have to deal with scoping of the variables. >#I.E. self.mousedown is global to functions in the class >#that accept a 'self' argument. >self.mousedown = 0 > >#we make the window normally. note all these are 'self' variables >#so we can change them easily elsewhere in the class. >self.root = Tk() >self.root.geometry('600x500+200+200') >self.label = Label(self.root, text=str(self.mousedown)) >self.can = Canvas(self.root, width='500', height='400', bg='white') >#lambda is a way we can add extra arguments to a function. >#since the callback of bound events is only a single argument, >#we use 'lambda x' to get the 'event' instance, and pass it >#along with another string identifying which event it came from. >#this may or may not be necessary, but it's cool and it >#makes the handler function make more sense. >#also, we only need one handler function this way. >self.can.bind("",lambda x:self.handler(x,'motion')) >self.can.bind("",lambda x:self.handler(x,'press')) >self.can.bind("",lambda x:self.handler(x,'release')) >self.label.pack() >self.can.pack() >self.root.mainloop() > >def handler(self,event,x): >#the first two clauses of the if-elif branch implement your >#'press' and 'release' functions. >if x == 'press': >self.mousedown = 1 >elif x == 'release': >self.mousedown = 0 >elif x == 'motion': >if self.mousedown: >#you could do something really cool here, like store the time >#that the button was last pressed, and increase the radius of > the circle >#depending on how long it's been since then. >r = 5 >self.can.create_oval(event.x-r, event.y-r, event.x+r, > event.y+r, fill="orange") > self.label.config(text=str(self.mousedown)) >
Re: [Tutor] tkinter events:
Zsiros Levente wrote: >Luke Paireepinart wrote: > > > >>Zsiros Levente wrote: >> >> >> >>>[snip code] >>>*def* handler(event): >>>*if* buttonpressed == 1 : >>>/#if the mousebutton is pressed and moved, circles should >>>appear, but they do not/ >>>can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, >>>fill="orange") >>>lab.config(text='buttonpressed=' + str(buttonpressed) ) >>> >>>*def* press(event): >>>buttonpressed=1 >>>lab2.config(text=buttonpressed) >>> >>>*def* release(event): >>>buttonpressed=0 >>>lab2.config(text=buttonpressed) >>>[snip code] >>>/#global buttonpressed/ >>>buttonpressed=0 >>> >>> >>I think you're misunderstanding what global variables are. >> >> >> >Yes, others already mentioned that. > > You didn't notice that, because first I accidentally sent the code to other thread (self-modification; of which I have three already :-X ) > > >>Take the following example: >> >>#--- code >>a = 0 >>def b(): >> print a >>b() >> >>#--- output >>0 >>#--- >>the function 'b' can see the variable 'a'. ok so far. >> >>now take this example. >> >>#--- code >>a = 0 >>def b(): >> a = 1 >> print a >>b() >>print a >> >>#--- output >>1 >>0 >>#--- >>in this case, 'a' is assigned to, but it's a local variable called 'a' >>and not the one I think you expect it to assign to. >>so after 'b' is done the value of the 'a' outside of the scope of the >>function is still 0. >>in your press and release events you assign values to 'buttonpressed' >>before you use them, >>and because of this, the same thing happens as in our second example: >>a local variable named >>'buttonpressed' is created with the value 0 or 1 assigned to it >>(depending on the function you're in.) >>that works fine, and it sets the label's text value accordingly. But, >>since it's a local variable and the >>functions aren't actually modifying the global 'buttonpressed', the >>'buttonpressed' that you're checking for >>in your 'handler' function is always going to be 0. That's why your >>oval code is never drawn. >> >>Rather than messing with global variables, which are for the most part >>evil creatures, >>as we've witnessed so far here, I'd recommend using a class. >>I wrote the class I would use for you so you can see it. >>It's commented, but if you need any more help than the comments feel >>free to write me back. >>Just be sure to use the reply-all button so the whole list can see the >>response. >>-Luke >>(note: code attached) >> >> >> >>#!/usr/bin/python >> >># This program implements . it was originally written by >>#Zsiros Levente. all rights of this modified version go to him :) >> >> >> >>from Tkinter import * > > >>class ButtonHandler(object): >> def __init__(self): >> #our self.mousedown variable is what we'll use to check the state >> #of the button, since we're going to be passing a copy of 'self' >> #around, we don't have to deal with scoping of the variables. >> #I.E. self.mousedown is global to functions in the class >> #that accept a 'self' argument. >> self.mousedown = 0 >> >> #we make the window normally. note all these are 'self' variables >> #so we can change them easily elsewhere in the class. >> self.root = Tk() >> self.root.geometry('600x500+200+200') >> self.label = Label(self.root, text=str(self.mousedown)) >> self.can = Canvas(self.root, width='500', height='400', bg='white') >> #lambda is a way we can add extra arguments to a function. >> #since the callback of bound events is only a single argument, >> #we use 'lambda x' to get the 'event' instance, and pass it >> #along with another string identifying which event it came from. >> #this may or may not be necessary, but it's cool and it >> #makes the handler function make more sense. >> #also, we only need one handler function this way. >> self.can.bind("",lambda x:self.handler(x,'motion')) >> self.can.bind("",lambda x:self.handler(x,'press')) >> self.can.bind("",lambda x:self.handler(x,'release')) >> self.label.pack() >> self.can.pack() >> self.root.mainloop() >> >> def handler(self,event,x): >> #the first two clauses of the if-elif branch implement your >> #'press' and 'release' functions. >> if x == 'press': >> self.mousedown = 1 >> elif x == 'release': >> self.mousedown = 0 >> elif x == 'motion': >> if self.mousedown: >> #you could do something really cool here, like store the time >> #that the button was last pressed, and increase the radius of >> the circle >> #depending on how long it's been since then. >> r = 5 >> self.can.create_oval(event.x-r, event.y-r, event.x+r, >> event.y+r, fill="orange")
Re: [Tutor] [Fwd: [Fwd: self-modification]]
Why does the python shell says this: >>> print exec.__doc__ File "", line 1 print exec.__doc__ ^ SyntaxError: invalid syntax While it works with "eval". Anyway, I'm quite impressed with the resposiveness of this list. Thanks a lot. Zsiros Levente wrote: > > > Sorry, the source was for my tkinter question. I'm a bit disorganized > today. > > The problematic part is the 11. line, where I have to convert the item > selected from the list to an object, or something like that. At the > moment it only applies to a string object, but I want to call the > function for the object, represented by the string. (If you run it, it > will become more obvious what I mean.) > > > Original Message > Subject: [Fwd: self-modification] > Date: Mon, 21 Aug 2006 16:06:52 +0200 > From: Zsiros Levente <[EMAIL PROTECTED]> > To: python tutor > > > > I forgot the most important thing: the attachment. > Original Message > Subject: self-modification > Date: Mon, 21 Aug 2006 16:04:19 +0200 > From: Zsiros Levente <[EMAIL PROTECTED]> > To: python tutor > > > > I'm a newbie to Python. I wanted to write a graphical interface which > would show the built-in documentation (I mean dir() and __doc__ ) of > Python. The code shows how far I got before realizing that I had to > use some self-modification feature (converting a string to a function > or to an object; i'm not sure you would call it self-modification in > an interpreted language). > > I was googling around, and searching in the maillist archives and > found this: > http://mail.python.org/pipermail/tutor/2004-October/032388.html > Unanswered for two years. Not too promising :) > > P.S.: I'm new to this mailing list, so I don't know whether it is > allowed to send code as attachment. (I didn't found anything about > your policy in the subscription site. ) If not, I'm sorry. > > > > > > >#!/usr/bin/python > >from Tkinter import * >from os import * >from string import * >import os >import string >import Tkinter > >def list_click(event): > description.config( text=listbox.get(listbox.curselection()[0]).__doc__ > ) > >list = dir(Tkinter) >#print list > >root=Tk() >root.geometry('+100+100') > >l_frame = Frame(root) >r_frame = Frame(root) > >label = Label(l_frame) >label.config(text='filename') > >description = Label(r_frame) > >listbox = Listbox(l_frame) >listbox.bind('',list_click) > >for item in list : > listbox.insert(0,item) > > >l_frame.pack(side=LEFT,fill=BOTH) >label.pack() >listbox.pack(expand=1,fill=BOTH) > >r_frame.pack(side=RIGHT) >description.pack() > >root.mainloop() > > > > > >___ >Tutor maillist - Tutor@python.org >http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.path.walk
nimrodx wrote: > Hi All, > > I was wondering if anyone had used os.path.walk within a class or not, > and what are the pitfalls... > > What has got me worried is that the function called by os.path.walk > must be a method of the class. > Now this means it will have something like this as a def: > > def func_called_by_walk(self, arg, directory, names): > > Will this work with os.path.walk with that definition? Yes, that is the right way to do it and it will work fine. Something like class Walker(object): def walk(self, base): os.path.walk(base, self.callback, None) def callback(self, arg, dir, names): pass What happens is, when Python looks up self.callback it converts the method to a "bound method". The bound method is a a callable that takes (in this case) only three arguments; the value of self is held by the bound method and passed to the original function object (which does take four arguments). But, if you are using a recent version of Python (2.3 or greater) you should look at os.walk(), it is easier to use than os.path.walk(). Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: [Fwd: self-modification]]
Zsiros Levente wrote: > Why does the python shell says this: > > print exec.__doc__ > File "", line 1 > print exec.__doc__ > ^ > SyntaxError: invalid syntax > > > While it works with "eval". exec is a statement that is interpreted by the compiler and compiled to byte code. There is no 'exec' object. OTOH eval is a function in the built-in namespace, so there is an 'eval' object and you can look at its attributes, including its doc string. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Larger GUI design ?
I have managed to write a small GUI app, it had a frm_app.py from eric3s QT designer & a dlg_app.py which defined a class that inherited the frm_app.py class ... all AOK I am now on a more ambitious project. There will be a main app screen, some dialogue screens for more info etc and a backend script analysing a database which will take some time to run. The backend script is almost there, just tons of auditing rules to write for it but the backend 'engine' is working. How to fit the GUI around it ? If I have my dlg_app.py inhereting frm_app.py all is well until I need a poppup dialogue. Would I define another module say dlg_info.py with its frm_info.py which I would import and call when needed generating its own QT object and window. And in that module code something like the following would make the window on the fly ? app = QApplication(sys.argv) win = info() app.setMainWidget(win) win.show() QObject.connect(app, SIGNAL('lastWindowClosed()'),app, SLOT('quit()')) app.exec_loop() Secondly my backend will take a while to run & I would like to display a status bar in the GUI. The only way i can see to do this is to either (1) make my backend a class & inherit dlg_app.py so I can access the QT widget directly or (2) pass info from the backend via a socket (yep know about them now!) to a QT script running in timerEvent() Which is the best method ? Or is there a better way ? Dave ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [whitelist] Re: regular expressions question
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi Nimrodx, In case you haven't found a solution yet, I developed a program to encode/decode stuff similar to this. You may want to take a look at it at http://home.townisp.com/~arobert/python/file_encoder.py nimrodx wrote: > Hi Alan, > > I found a pretty complicated way to do it (Alan's way is way more elegant). > In case someone is searching the archive, maybe they will find something > in it that is useful. > It uses the regular experessions module. > > import re > > def dehexlify_websites(fle): ># get binary data >inpt = open(fle,'rb') >dat = inpt.read() >inpt.close() >#strip out the hex "0"'s >pattern = r"\x00" >res = re.sub(pattern, "", dat) >#- >#it seemed easier to do it in two passes >#create the pattern regular expression for the stuff we want to keep >web = re.compile( > r"(?P[/a-zA-Z0-9\.\-:\_%\?&=]+)" > ) >#grab them all and put them in temp variable >res = re.findall(web,res) >tmp = "" >#oops need some new lines at the end of each one to mark end of > #web address, >#and need it all as one string >for i in res: >tmp = tmp + i+'\n' >#compile reg expr for everything between :// and the newline >web2 = re.compile(r":/(?P[^\n]+)") >#find the websites >#make them into an object we can pass >res2 = re.findall(web2,tmp) >#return 'em >return res2 > > > Thanks Alan, > > Matt > > > Alan Gauld wrote: >>> if you look carefully at the string below, you see >>> that in amongst the "\x" stuff you have the text I want: >>> z tfile://home/alpha >> OK, those characters are obviously string data and it looks >> like its using 16 bit characters, so yes some kind of >> unicode string. In between and at the end ;lies the binary >> data in whatever format it is. >> > Here is the first section of the file: > '\x00\x00\x00\x02\xb8,\x08\x9f\x00\x00z\xa8\x00\x00\x01\xf4\x00\x00\x01\xf4\x00\x00\x00t\x00f\x00i\x00l\x00e\x00:\x00/\x00h\x00o\x00m\x00e\x00/\x00a\x00l' > > >> >>> In a hex editor it turns out to be readable and sensible url's with >>> spaces between each digit, and a bit of crud at the end of url's, >>> just as above. >> Here's a fairly drastic approach: >> > s = > '\x00\x00\x00\x02\xb8,\x08\x9f\x00\x00z\xa8\x00\x00\x01\xf4\x00\x00\x01 > >> \xf4\x00\x00\x00t\x00f\x00i\x00l\x00e\x00:\x00/\x00h\x00o\x00m\x00e\x00/\x00a\x >> >> >> 00l' > ''.join([c for c in s if c.isalnum() or c in '/: ']) >> 'ztfile:/home/al' >> But it gets close... >> >> Alan g. >> > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.1 (MingW32) Comment: GnuPT 2.7.2 iD8DBQFE6ySXDvn/4H0LjDwRApntAJ0Wd0ecE/KFUSbbKQSRmrV72yyvfwCeOwAQ Gjg5IK0WG0YT6keGlDw0q94= =7QB2 -END PGP SIGNATURE- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.path.walk
> What has got me worried is that the function called by os.path.walk > must be a method of the class. > Now this means it will have something like this as a def: > > def func_called_by_walk(self, arg, directory, names): > > Will this work with os.path.walk with that definition? No, but you can wrap it in a lambda that calls the method: lambda x,y,z: self.func_called_by_walk(x,y,z) But have you looked at os.walk? It is a little easier to use for most things IMHO. No need to pass a function in for a start. Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] os.path.walk
> Yes, that is the right way to do it and it will work fine. Something > like > > class Walker(object): > def walk(self, base): >os.path.walk(base, self.callback, None) > > What happens is, when Python looks up self.callback it converts the > method to a "bound method". Aargh! I should have remembered that. No need for lambdas here. Apologies... > But, if you are using a recent version of Python (2.3 or greater) > you should look at os.walk(), it is easier to use than > os.path.walk(). But I did suggest that too :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: [Fwd: self-modification]]
> Why does the python shell says this: > print exec.__doc__ > File "", line 1 >print exec.__doc__ > ^ > SyntaxError: invalid syntax exec, like print, is a statement, or command, not a function. You get the same response if you try >>> print print.__doc__ or >>> help(print) > While it works with "eval". eval is a function so has a doc string attached. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Larger GUI design ?
> I am now on a more ambitious project. There will be a main app > screen, some > dialogue screens for more info etc and a backend script analysing a > database > which will take some time to run. > > How to fit the GUI around it ? > > If I have my dlg_app.py inhereting frm_app.py all is well until I > need a > poppup dialogue. Its usually better to make popups inherit directly from TopLevel rather than the parent form. > Would I define another module say dlg_info.py with its frm_info.py Its usually best to put each significant window/dialog in its own form. It makes them easier to reuse in other projects for one thing! > would import and call when needed generating its own QT > object and window. Not sure how QT works so can't comment on that. > app = QApplication(sys.argv) Are you sure there isn't a QDialog base class somewhere in QT? Thats usually been the case in other GUI toolkits I've used. > Secondly my backend will take a while to run & I would like to > display a > status bar in the GUI. The only way i can see to do this is to > either Sounds like a job for a thread... > (2) pass info from the backend via a socket (yep know about them > now!) to a QT > script running in timerEvent() You can do this but threads are less resource greedy. HTH, Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Larger GUI design ?
On Tuesday 22 August 2006 17:15, Alan Gauld wrote: > > I am now on a more ambitious project. There will be a main app > > screen, some > > dialogue screens for more info etc and a backend script analysing a > > database > > which will take some time to run. > > > > How to fit the GUI around it ? > > > > If I have my dlg_app.py inhereting frm_app.py all is well until I > > need a > > poppup dialogue. > > Its usually better to make popups inherit directly from TopLevel > rather > than the parent form OK I will look into that > > > Would I define another module say dlg_info.py with its frm_info.py > > Its usually best to put each significant window/dialog in its own > form. > It makes them easier to reuse in other projects for one thing! > Code reuse is good > > would import and call when needed generating its own QT > > object and window. > > Not sure how QT works so can't comment on that. > > > app = QApplication(sys.argv) > > Are you sure there isn't a QDialog base class somewhere in QT? > Thats usually been the case in other GUI toolkits I've used. Base class ? OK you lost me - I will dig into the docs > > > Secondly my backend will take a while to run & I would like to > > display a > > status bar in the GUI. The only way i can see to do this is to > > either > > Sounds like a job for a thread... > > > (2) pass info from the backend via a socket (yep know about them > > now!) to a QT > > script running in timerEvent() > > You can do this but threads are less resource greedy. I had not thought of a thread - thats a cool solution Thanks for your suggestions, Its probably obvious for you old hands but its a whole new world for us beginners :) You have given me enough info to run with - I will give it a go & see what happens Dave > > HTH, > > Alan Gauld > Author of the Learn to Program web site > http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] tkinter events:
> def handler(event): > if buttonpressed == 1 : > /#if the mousebutton is pressed and moved, circles should > appear, but they do not/ > can.create_oval(event.x-r, event.y-r, event.x+r, event.y+r, > fill="orange") > lab.config(text='buttonpressed=' + str(buttonpressed) ) The variables of functions are normally independent of each other. That is, if I have a function square(): ## def square(x): y = x * x return y ## and if I have a function that uses square that itself has a 'y' variable, I should not see interference: ## def test(): y = 17 print "square of y is", square(y) print "y itself is", y ## This black-boxing is what allows us to write and reuse functions with reckless abandon: their innards are meant not to interact with one another. This is a feature that you usually want to have. But for your purposes, you want some controlled form of leakage. Use 'global' for this purpose by declaring the shared variable at the head of your functions. Compare the results above to the ones below: # def square(x): global y y = x * x return y def test(): global y y = 17 print "square of y is", square(y) print "y itself is", y # There's terse reference material here about global: http://www.python.org/doc/ref/global.html#l2h-558 It's idiomatic programming practice to limit the use of 'global' to situations where it's necessary; using it in an uncontrolled way leads to code that's difficult to read or reason with. There are more sophsticated ways to share variables between functions. That being said, though, the 'global' mechanism will probably be simplest for your purposes. Good luck to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] how to get an email attachment
On 8/21/06, shawn bright <[EMAIL PROTECTED]> wrote: > Yes, indeed. I found in the essential reference book. It looks like it works > in the email module also. I will try a few things out here and let you know > how it goes. > thanks. > > shawn > > > On 8/21/06, Alan Gauld <[EMAIL PROTECTED]> wrote: > > I'm no expert here, but isn't there a Mime module for > > handling mail attachments? Might be worth a look. > > > > - Original Message - > > From: "shawn bright" < [EMAIL PROTECTED]> > > Sent: Monday, August 21, 2006 9:50 PM > > > > What i need to do is get an attachment. That > > > attachment > > > is going to be encoded in base 64. > > > so, i am looking and i can't find how to get the attachment. shawn, in particular, check out the email.Message submodule, esp. get_payload(). good luck! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Low level socket and threading code in python in HUGEwebsites -
On 8/18/06, anil maran <[EMAIL PROTECTED]> wrote: > thanks alan it is very enlightening > can one of you guys who have experience building sites > such as yahoo mail and stuff, explain what parts of a > webserver needs to be multithreaded > > > > Because of the low-level socket and threading code > > we had to write, > > > > > > I would imagine that they aren't just using a > > database. > > > most of the "low level socket stuff" I've seen is > > about setting > > > timeouts and doing Async IO. even way back then, yahoo!mail was created on a similar platform as most web-based applications are now: apache (w/appropriate modules) and a pool of child threads that captured incoming HTTP requests and serviced them in an async manner. we had std socket communication but no database access at all; none of the code was threaded either... just apache. it sounds relatively simple, and in our case, it was from this architectural point-of-view. the complexity was all in the infrastructure, i.e., managing all of the servers on all of the networks, load-balancing, arranging the outgoing and incoming SMTP, refreshing DNS MX records, all of the users (old and new), user registration, and of course, the hard disks where everyone's mail is stored. again, these things aren't special... save for the mail-only stuff. it's just a web app! :-) HTH, -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] [OT] Re: Limiting Characters
Luke Paireepinart said unto the world upon 21/08/06 03:48 PM: > Sort of how my last name is 12 characters long, but on some apps that > only have a 12 character array (with the actual length being 11 because > of the null terminator) the last letter of my name gets truncated. > This doesn't happen anymore, but I used to have everyone calling me > 'paireepinar' because that's what was in the computer so they believed > it. Stupid old programs :) Hi all, I've noticed fewer programs stymied by length, though paper forms with their boxes for each letter still suck. There are, however, quite a few programs in the wild that, suffused with Anglo-Saxon assumptions, refuse to admit that a surname might just possibly commence with a lower case letter or contain spaces (the horror!) Indeed, my current email address was auto assigned by software that gives you your last name as your user name, except when it doesn't ;-) Brian van den Broek ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to teach Python
Thanks to everyone for your helpful answers! -Elaine __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to use
How to use this program? Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1ยข/min.___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to wrap this line of code?
I have this long print statement in a script: print "Initial integer of first sequence with number of terms of %d or more was %s (%d)" % (length, intCommas(n_for_max_c), n_for_max_c) It's one line of code, and too long. How can I wrap it so that it is written in the code as 2 lines? (I hope I've phrased the question correctly..) Thanks, Dick Moores [EMAIL PROTECTED] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to wrap this line of code?
Dick Moores wrote: > I have this long print statement in a script: > > print "Initial integer of first sequence with number of terms of %d > or more was %s (%d)" % (length, intCommas(n_for_max_c), n_for_max_c) > > It's one line of code, and too long. How can I wrap it so that it is > written in the code as 2 lines? > At least either of the following: print "Initial integer of first sequence with number of terms of %d \ or more was %s (%d)" % (length, intCommas(n_for_max_c), n_for_max_c) print "Initial integer of first sequence with number of terms of %d", print "or more was %s (%d)" % (length, intCommas(n_for_max_c), n_for_max_c) -- Bob Gailer 510-978-4454 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to wrap this line of code?
At 11:10 PM 8/22/2006, Bob Gailer wrote: >Dick Moores wrote: >>I have this long print statement in a script: >> >>print "Initial integer of first sequence with number of terms of %d >>or more was %s (%d)" % (length, intCommas(n_for_max_c), n_for_max_c) >> >>It's one line of code, and too long. How can I wrap it so that it >>is written in the code as 2 lines? >> >At least either of the following: > >print "Initial integer of first sequence with number of terms of %d \ >or more was %s (%d)" % (length, intCommas(n_for_max_c), n_for_max_c) Thanks! That's the one I was trying to remember. >print "Initial integer of first sequence with number of terms of %d", >print "or more was %s (%d)" % (length, intCommas(n_for_max_c), n_for_max_c) That first line produces the error, "TypeError: int argument required". Maybe this is what you meant?: print "Initial integer of first sequence with number of terms of", print "%d or more was %s (%d)" % (length, intCommas(n_for_max_c), n_for_max_c) Thanks very much, Dick Moores ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor