Re: Can a Tkinter GUI check for abort script:
Michael Yanowitz top posted (again): >No. test3.py (for example) is just plain Python code that sends and receives socket data >from another machine. It does (or could) contain loops that last a long time, repeating >the read or write operations to and from the socket. This grabs the CPU. > What I am hoping for is a function call I can make, without knowing any of the >GUI objects, I can call from test3.py (or while test3.py is running) which will >refresh the GUI and check for activity such as button presses on the GUI itself. > For example, if I just call sleep(), will it do this? ok here is the rub - the tkinter gui and the sockets stuff both want to be the main thread. You are going to have to run separate processes, and communicate via pipes. Its a hard nut to chew, but there you have it - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
RE: Can a Tkinter GUI check for abort script:
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of hg Sent: Tuesday, December 19, 2006 9:44 AM To: python-list@python.org Subject: Re: Can a Tkinter GUI check for abort script: Michael Yanowitz wrote: > Hello: > >I have successfully implemented a Tkinter GUI which has > this (simplified here for explanation): > +-+ > | filename: [./test3.py] | > | | > | [Run Script] | > +-+ > >But, now what I would like to do while the script is > running, is replace the "Run Script" with "Abort Script". > > +-+ > | filename: [./test3.py] | > | | > | [Abort Script] | > +-+ > >So, every tenth of a seconds or ??? better time, I > would like to 'return' to the GUI and check if the > "Abort Script" button has been pressed. >How do I do this? Or is there a better way to > implement this? > > Thanks in advance: > Michael Yanowitz It depends: As you cannot "kill" a thread in Python, you need some mechanism to stop your script another way (is that a python script or a .sh / .bat ? ... from what you're writing, it seems you're calling some external entity which just might launch a bunch of processes) So do you or not control the inner workings of that external script ? If you don't, then "killing" might be the way as posted / clearly the methord will change from environment to environment. hg -- Yeah, it is a Python script, which I preprocess and then load using __import__(script_filename) So when I preprocess it, I can add/remove codelines and possibly add control of the GUI - the original Python scripts will not know anything about the GUI. Thanks: Michael Yanowitz -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a Tkinter GUI check for abort script:
Michael Yanowitz wrote: > Hello: > >I have successfully implemented a Tkinter GUI which has > this (simplified here for explanation): > +-+ > | filename: [./test3.py] | > | | > | [Run Script] | > +-+ > >But, now what I would like to do while the script is > running, is replace the "Run Script" with "Abort Script". > > +-+ > | filename: [./test3.py] | > | | > | [Abort Script] | > +-+ > >So, every tenth of a seconds or ??? better time, I > would like to 'return' to the GUI and check if the > "Abort Script" button has been pressed. >How do I do this? Or is there a better way to > implement this? > > Thanks in advance: > Michael Yanowitz It depends: As you cannot "kill" a thread in Python, you need some mechanism to stop your script another way (is that a python script or a .sh / .bat ? ... from what you're writing, it seems you're calling some external entity which just might launch a bunch of processes) So do you or not control the inner workings of that external script ? If you don't, then "killing" might be the way as posted / clearly the methord will change from environment to environment. hg -- http://mail.python.org/mailman/listinfo/python-list
RE: Can a Tkinter GUI check for abort script:
Michael Yanowitz <[EMAIL PROTECTED]> wrote: > What I am hoping for is a function call I can make, without knowing any > of the GUI objects, I can call from test3.py (or while test3.py is running) > which will refresh the GUI and check for activity such as button presses > on the GUI itself. call w.update_idletasks(). see http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html#update_idletasks > For example, if I just call sleep(), will it do this? No, it won't > Thanks in advance: > Michael Yanowitz You're welcome __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Can a Tkinter GUI check for abort script:
No. test3.py (for example) is just plain Python code that sends and receives socket data from another machine. It does (or could) contain loops that last a long time, repeating the read or write operations to and from the socket. This grabs the CPU. What I am hoping for is a function call I can make, without knowing any of the GUI objects, I can call from test3.py (or while test3.py is running) which will refresh the GUI and check for activity such as button presses on the GUI itself. For example, if I just call sleep(), will it do this? Thanks in advance: Michael Yanowitz -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Mohammad Tayseer Sent: Monday, December 18, 2006 11:28 AM To: python-list@python.org Subject: RE: Can a Tkinter GUI check for abort script: I don't know why this happen. do you call mainloop() inside the test3.py?? you shouldn't Michael Yanowitz <[EMAIL PROTECTED]> wrote: > Presently what happens is that the script takes over and all the buttons on > the GUI disappear > as the GUI is not given any cpu time to refresh or check if any activity in > the dialog. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Can a Tkinter GUI check for abort script:
I don't know why this happen. do you call mainloop() inside the test3.py?? you shouldn't Michael Yanowitz <[EMAIL PROTECTED]> wrote:> Presently what happens is that the script takes over and all the buttons on > the GUI disappear > as the GUI is not given any cpu time to refresh or check if any activity in > the dialog. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a Tkinter GUI check for abort script:
Michael Yanowitz top posted: > Presently what happens is that the script takes over and all the buttons on the GUI disappear >as the GUI is not given any cpu time to refresh or check if any activity in the dialog. Yuk! you may have to run the script in a thread then, to preserve the GUI mainloop. Check out the Threading and Thread modules - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
RE: Can a Tkinter GUI check for abort script:
Thank you (and Thanks to Hendrik). Both good ideas. I will need to do those or something similar too. But what I really want to know is what I need to do when pressing the "Run Script" button, so that I 'return' to the GUI every once in a while, like every 100 milliseconds to check if the "Abort Script" button is pressed. Presently what happens is that the script takes over and all the buttons on the GUI disappear as the GUI is not given any cpu time to refresh or check if any activity in the dialog. Thanks in advance: Michael Yanowitz -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Mohammad Tayseer Sent: Monday, December 18, 2006 10:40 AM To: python-list@python.org Subject: Re: Can a Tkinter GUI check for abort script: To view a button & hide the other, call .pack_forget() on the button you want to hide & pack() on the button you want to show test3.py should contains a main() function that returns the new window. if you press 'Abort script' button you should call new_window.destroy(), pack_forget() the current button & pack() the 'run script' button __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a Tkinter GUI check for abort script:
To view a button & hide the other, call .pack_forget() on the button you want to hide & pack() on the button you want to show test3.py should contains a main() function that returns the new window. if you press 'Abort script' button you should call new_window.destroy(), pack_forget() the current button & pack() the 'run script' button __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a Tkinter GUI check for abort script:
"Michael Yanowitz" <[EMAIL PROTECTED]> Wrote: > Hello: > >I have successfully implemented a Tkinter GUI which has > this (simplified here for explanation): > +-+ > | filename: [./test3.py] | > | | > | [Run Script] | > +-+ > >But, now what I would like to do while the script is > running, is replace the "Run Script" with "Abort Script". > > +-+ > | filename: [./test3.py] | > | | > | [Abort Script] | > +-+ > >So, every tenth of a seconds or ??? better time, I > would like to 'return' to the GUI and check if the > "Abort Script" button has been pressed. >How do I do this? Or is there a better way to > implement this? Use the configure method to change the command of the button, to point away from "run" to "abort", as the first thing done in "run". You can change the text too to read correctly, at the same time, as well as the background colour to red... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list