tetsuya24 / pyscripter

Automatically exported from code.google.com/p/pyscripter
0 stars 0 forks source link

Pyscripter 2.5.3 denies the exit() request of Tkinter programs generated with SpecTCL, on Windows #772

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Install Python 2.7.6 on Windows
2. Install Pyscripter 2.5.3
3. Install SpecTCL ( http://www.sourceforge.net/projects/spectcl )
4. Call SpecTCL. A minimal GUI is created. Save this GUI as 
"spectcl_helloworld.ui". It does not matter if you add contents, so a button 
with manually added "exit()" callback code does not work too. 
5. SpecTCL creates the files "spectcl_helloworld.py" ( may be executed ) and 
"spectcl_helloworld" ( is not intended for execution ).
6. Load and execute a Pyton script "spectcl_helloworld.py", with Pyscripter on 
Windows
7. Press on the [x] button of the window frame

What is the expected output? What do you see instead?
Expected: 
- The Python program closes, the TCL GUI interface disappears - as it is true 
if I do it by Command.com shell
Instead: 
- The python program is closed ( so the Pyscripter is active again, especially 
the Python interpreter window ), but the TCL GUI interface stays on the desktop 
screen.
- To make the TCL GUI interface disappear, I must quit Pyscripter.
- If I try to call and exit a classical, more simple TCL application 
"hellotcl.py", Pyscripter works properly and deletes the TCL GUI interface. So 
there is something wrong with the generated code of SpecTCL, what Pyscripter 
does not like...

What version of the product are you using? On what operating system?
OS: Windows 8.1
Python: 2.7.6
Product: Pyscripter 2.5.3

Please provide any additional information below.

*** spectcl_helloworld.ui ***

# GUIBUILDER FILE Build 146
# Created: 2014-06-08 09:35:37 by GUI Builder Build 146
language tkinter 8.4
widget {Tk frame} f {
    geometry min_column {40 40}
    geometry min_row {40 40}
    geometry pad_column {0 0}
    geometry pad_row {0 0}
    geometry resize_column {0 0}
    geometry resize_row {0 0}
    geometry weight_column {0 0}
    geometry weight_row {0 0}
    data GROUP Tk
    data ID {}
    data MASTER {}
    data TYPE {Tk frame}
    data level 0
}

Automatically generated code:
*** spectcl_helloworld.py ***

""" spectcl_helloworld.py --

 UI generated by GUI Builder Build 146 on 2014-06-08 09:35:37 from:
    C:/Users/Public/projects/python_testing_pybehave/codebreaker_v9_spectcl/spectcl_helloworld.ui
 This file is auto-generated.  Only the code within
    '# BEGIN USER CODE (global|class)'
    '# END USER CODE (global|class)'
 and code inside the callback subroutines will be round-tripped.
 The 'main' function is reserved.
"""

from Tkinter import *
from spectcl_helloworld_ui import Spectcl_helloworld

# BEGIN USER CODE global

# END USER CODE global

class CustomSpectcl_helloworld(Spectcl_helloworld):
    pass

    # BEGIN CALLBACK CODE
    # ONLY EDIT CODE INSIDE THE def FUNCTIONS.

    # END CALLBACK CODE

    # BEGIN USER CODE class

    # END USER CODE class

def main():
    # Standalone Code Initialization
    # DO NOT EDIT
    try: userinit()
    except NameError: pass
    root = Tk()
    demo = CustomSpectcl_helloworld(root)
    root.title('spectcl_helloworld')
    try: run()
    except NameError: pass
    root.protocol('WM_DELETE_WINDOW', root.quit)
    root.mainloop()

if __name__ == '__main__': main()

*** spectcl_helloworld_ui.py ***

""" spectcl_helloworld_ui.py --

 UI generated by GUI Builder Build 146 on 2014-06-08 09:35:37 from:
    C:/Users/Public/projects/python_testing_pybehave/codebreaker_v9_spectcl/spectcl_helloworld.ui
THIS IS AN AUTOGENERATED FILE AND SHOULD NOT BE EDITED.
The associated callback file should be modified instead.
"""

import Tkinter
import os # needed for relative image paths

# Using new-style classes: create empty base class object
# for compatibility with older python interps
#if sys.version_info < (2, 2):
#    class object:
#        pass

class Spectcl_helloworld(object):
    _images = [] # Holds image refs to prevent GC
    def __init__(self, root):

        # Widget Initialization

        # Geometry Management

        # Resize Behavior
        root.grid_rowconfigure(1, weight = 0, minsize = 40, pad = 0)
        root.grid_rowconfigure(2, weight = 0, minsize = 40, pad = 0)
        root.grid_columnconfigure(1, weight = 0, minsize = 40, pad = 0)
        root.grid_columnconfigure(2, weight = 0, minsize = 40, pad = 0)

*** This helloworld.py is terminated properly with Pyscripter, for comparison 
***

from Tkinter import *

root = Tk()
w = Label(root, text="Hello World")
w.pack()
root.mainloop()

Original issue reported on code.google.com by rolf.hem...@gmail.com on 8 Jun 2014 at 7:54

GoogleCodeExporter commented 9 years ago
One obvious workaround is
to replace

    root.protocol('WM_DELETE_WINDOW', root.quit)

by

    root.protocol('WM_DELETE_WINDOW', root.destroy)

but this would be a change in a section of code which is named

    # Standalone Code Initialization
    # DO NOT EDIT

and of course it does not explain why root.quit() does not work when called 
from Pyscripter.

Sincerly
Rolf

Original comment by rolf.hem...@gmail.com on 8 Jun 2014 at 12:00

GoogleCodeExporter commented 9 years ago
Please use the standard remote Python engine and reinitialize before each run 
(this is done by default).  Then it will behave as expected

See also https://code.google.com/p/pyscripter/wiki/RemoteEngines (contenet is 
in the help file as well)

Remote Tk
This remote Python engine is specifically created to run and debug Tkinter 
applications including pylab using the Tkagg backend. It also supports running 
pylab in interactive mode. The engine activates a Tkinter mainloop and replaces 
the mainloop with a dummy function so that the Tkinter scripts you are running 
or debugging do not block the engine. You may even develop and test Tkinter 
widgets using the interactive console.

Debugging Wx and Tkinter scirpts using the remote Wx and Tk engines
As mentioned above the Wx and Tk engines activate a main loop and replace the 
MainLoop? with a dummy function. Therefore, when debugging Gui scripts using 
these engines, as soon as you reach the MainLoop? statement debugging ends and 
you can then test the running application but without further debugging 
support. This means two things:

Breakpoints and debugging would work up to the point the script enters the 
MainLoop? routine
You will not be able to debug event triggered code using these two engines.
To debug event code of Wx and Tkinter scripts use **the standard remote 
engine**. 

You may wonder why should you ever use the Wx and Tk specific remote engines. 
Here is a few reasons:

-  These engine allow you to interactively develop and test frames and widgets. 
(possible because they run their own main loop.
-  They support running pylab in interactive mode like IPython does, which was 
a request from many Pyscripter users.
-  There is no need to reinitialize the engines after running Gui scripts.
Pyscripter does not stay in running mode while the Gui Windows are showing but 
instead it returns in ready mode allowing further work and runs.

Original comment by pyscripter on 28 Mar 2015 at 10:13

GoogleCodeExporter commented 9 years ago

Original comment by pyscripter on 28 Mar 2015 at 10:15