[wxpython-users] Catching user leaving the window

Robin Dunn robin at alldunn.com
Mon Sep 8 12:34:25 PDT 2008


Werner F. Bruhin wrote:
> Tim,
> 
> ...
>>>
>>>
>>>     Did you try EVT_LEAVE_WINDOW ? I would think that would work no
>>>     matter which widget you're using, unless the OS doesn't support it.
>>>
>>>
>>> Doesn't that track mouse-movement? Wouldn't it be a bit extreme to 
>>> rollback your database-transaction and already-entered data just b/c 
>>> the user moves the mouse? ;-)
> I would obviously put up a dialog or something. ;-)
> 
> With the page changing events this works nicely, I just veto it and tell 
> the user that they should save/commit the data.
> 
> Here is what the app does:
> - user selects a wine from an objectlistview
> - system fills the controls on multiple pages on the flatnotebook
> - user selects e.g. the page with ratings
> - starts to create a new rating
> - user switches to another notebook page
> - page changing event fires, I veto it if there is unsaved data and 
> inform user to save data
> 
> Above is fine, but if user does not change page but goes "outside" the 
> notebook I have not found a way to intercept this action.
> 
> Ideally I like an event which I can veto, then all would be fine.
> 
> If that does not exist I am happy with an event telling me that he went 
> "outside" the notebook, I can then try to save the data if it passes 
> validation, or throw it away (rollback) to prevent a SQLAlchemy 
> exception (it does not like a partially created object - which is fine 
> with me).
> 
> I can not do it on close, as no window/frame is closed.
>>>
>>> You could perhaps try window activate/deactivate events, I think that 
>>> these apply only to the whole wx.Frame; not to individual widgets.
> Will look into this one.

Personally I think your users will hate you if you do something like 
this.  Given the multi-process nature of modern operating systems and 
GUI environments it is *very* common to be doing more than one thing at 
a time, in my case it is usually a dozen or so things at one time.  For 
example, suppose the phone rings while your user is entering data, and 
they have to switch to their calendar application to look something up, 
and then they switch back to your application only to find that their 
data entry work was thrown away and rolled back to the prior state.  It 
would only take one such occurrence for me to uninstall the app and 
never look at it again.

Instead, let them do other things and only worry about rolling back, or 
asking the user to save, or whatever, if they change the state in your 
application such that it would cause the currently "dirty" data entry 
forms to be closed, cleared, or reloaded with new data.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!



More information about the wxpython-users mailing list