Event binder to handle closing of python shell window event

Hi all,

Is there any event binder to bind when the following event occurs :

** " Closing of the python shell window " **

I want to do some processing when I manually close the black window that appears with the GUI application.

Hence I am looking for an event binder to handle this event.

Thanks in advance,

Spondita

Why are you running it so that the black windows appears in the first place? Rename your file so it ends in .pyw instead of .py and that will stop happening. The event you’re looking for is probably EVT_WINDOW_DESTROY or possibly EVT_CLOSE, I think.

  • Mike
···

On Thursday, June 28, 2012 1:05:23 AM UTC-5, Spondita wrote:

Hi all,

Is there any event binder to bind when the following event occurs :

** " Closing of the python shell window " **

I want to do some processing when I manually close the black window that appears with the GUI application.

Hence I am looking for an event binder to handle this event.

Thanks in advance,

Spondita

I was wondering what OS you see that? I know it happens on MS-Windows. But on Mac or linux don’t know. On MSW you’ll want to associate the file extention .pyw with pythonw.exe and the .py with python.exe. You do this in Windows File Explorer. When you run a .py script it calls cmd.exe and then executes python.exe within that console environment, I believe. Therefore if you close that “DOS console Python shell window” you will close any subprocesses the cmd.exe is running, that being python.exe. The pythonw.exe does not run cmd.exe with creating a console window.

That stuff just mentioned is automated for you. There is a manual way too. It allows for doing pre-loading and post-loading stuff. Here is not-very-nice-looking version of what I use sometimes.

groups.google.com\wxpython-users topic: “Event binder to handle closing of python shell window”

Here is a way to hide stuff for nice clean looking namespace

if import used, which is not likely unless your using PySlices;

all = [‘app’, ‘frame’, ]

devplayer

2012-07(jun)-06

license: none

print(‘loading sys…’)
import sys
print(‘loading os…’)
import os
print(‘loading subprocess…’)
import subprocess
print(‘loading wx…’)
import wx

doc = “”"
Here is my hack for when I want to launch a wx module from
the MS-DOS command line instead of constantly clicking an icon,
as I often have at least 25 windows, mostly browsers,
open at any one time. Hitting the “Show deskop” icon slows me down.

Try each of the following…

python relaunch.py

python relaunch.py --run

python relaunch.py --without_console

python relaunch.py --with_console

“”"

if name==‘main’:

print(doc)

if len(sys.argv) > 1 and ‘–run’ in sys.argv:
print(“initializing wx app and frame…”)

app = wx.GetApp()
if not app: app = wx.App(0)

frame = wx.Frame(None, title=‘And you can still use your command line…’)
frame.Show()

print(“entering gui blocking loop…”)
if not app.IsMainLoopRunning(): app.MainLoop()
print(“finished gui blocking loop.”)

raw_input(‘Press ENTER to continue…’)

elif len(sys.argv) == 1 or len(sys.argv) > 1 and ‘–without_console’ in sys.argv:
print(“launching wx app in it’s own seperate subprocess without a console.”)

module_filename = os.path.basename(file)
cmd = ‘pythonw.exe %s --run’ % module_filename
p = subprocess.Popen(cmd)

elif len(sys.argv) > 1 and ‘–with_console’ in sys.argv:
print(“launching wx app in its own seperate subprocess with its own console.”)

console_title = ‘CLI wx launcher’
python_executable = sys.executable
module_filename = os.path.basename(file)
module_arguments = ‘–run’
cmd_format = ‘start “%s” %s %s %s’
cmd_values = (console_title, python_executable, module_filename, module_arguments)
cmd = cmd_format % cmd_values
print(‘cmd string = %s’ % repr(cmd))

open gui form its own DOS console so you can see certain exceptions

    p = subprocess.Popen(cmd, shell=True,
        creationflags = subprocess.CREATE_NEW_CONSOLE,
        stdin = subprocess.PIPE, stdout = subprocess.PIPE)

btw by license: none i mean it is open source.