[PythonCE] PPYGUI - parent window and closing it

Alexandre Delattre alexandre.delattre at enst-bretagne.fr
Thu Jul 10 15:04:03 CEST 2008


> Hello, Alexandre.

> I have begun testing some ideas using the PPYGUI and find it very easy to
> work with. However, I would like to ask if there is a way to know when the
> user has pressed the 'X' button in the top right of the window to close the
> app? The reason I ask, is that when I run some ppygui code a blank Python
> window opens, then the ppygui app window opens on top of it. When I close
> the app using the top right 'X' I am returned to the blank Python window.
> This is very similar to the situation on the desktop version of Python,
> where a terminal window opens unless your Python file is run with the .pyw
> extension.

> I can implement a 'close' button that executes the sys.exit() command, and
> this successfully closes the app and the blank Python terminal window
> together. Nevertheless that top right 'X' is still there, and I would prefer
> the users of my app to have something consistent and which behaves as
> expected (i.e when you press 'X' the app exits or at least is hidden fully).

> How do it detect this 'close' event for the main app?

> Adam

Currently the best option is to install the tMan task manager <http://pda.jasnapaka.com/tman/> or others,
which allow to close program when clicking 'X' instead of the default minimize behaviour which is problematic
with PythonCE (other PythonCE gui toolkits have the same problem regarding this).

PPygui has already some inner logic, which makes the 'app.run()'
line returns when the main frame is closed (with tMan), so it'll work well with it.

Unfortunately the .pyw extension is buggy on PythonCE due to a mis-written registry key,
You can fix it with a registry editor of your choice, by setting the key:
HKEY_CLASSES_ROOT/Python.File.NoShell/Shell/Open/Command/Default = 
 "\Program Files\Python25\python.exe" /nopcceshell "%1"


You can also intercept the 'close' event at application level (but still need tMan to work)

import ppygui as gui
class MainFrame(gui.CeFrame):
  def __init__(self):
    gui.CeFrame.__init__(self, title='Hello')
    self.bind(close=self.on_close)

  def on_close(self, ev):
    if gui.Message.yesno('Confirmation', 
                         'Do you want to quit', 
                         'question', self) == 'yes':
      ev.skip() # If user say yes, let the close event be further processed by the default implementation which will close the window for good


Hope this helps,
Alexandre



More information about the PythonCE mailing list