call event close handler, when shutdown windows and linux

31 views
Skip to first unread message

franz steinhaeusler

unread,
Apr 17, 2017, 3:13:13 PM4/17/17
to wxPython-users
Hello group, 

how can i achieve that the event close amd the corresponding event handler in the Frame is called (or what other signals can be used), to exit my application in normal way, when my pc is to shutdowm or restarting the os.

Now that is not the case:
First, settings are only stored, when my app will be closed and second, I have an single instance checker, an when next reboot, the delete stale or so messagebox appears.

I need it for both, MS Windows and Ubuntu Linux.

Thank you in advance!

Tim Roberts

unread,
Apr 18, 2017, 12:32:52 PM4/18/17
to wxpytho...@googlegroups.com
franz steinhaeusler wrote:
>
> how can i achieve that the event close amd the corresponding event
> handler in the Frame is called (or what other signals can be used), to
> exit my application in normal way, when my pc is to shutdowm or
> restarting the os.
>
> Now that is not the case:
> First, settings are only stored, when my app will be closed and
> second, I have an single instance checker, an when next reboot, the
> delete stale or so messagebox appears.

I'm going to answer the question you asked, but I'm also going to make
an editorial comment.

Your current strategy is not the correct one. There are ALWAYS going to
be system termination events that you can't catch (power failure, or
forced app termination, for example). If you have settings that need to
be saved, then the RIGHT answer is to have an idle timer, and write out
any changed settings when the user has been idle for a few seconds.
That way, you know that your persisted settings are always correct, no
matter what happens.

The answer to your question is wx.EVT_END_SESSION, but your app would be
much more reliable if you changed the design so you didn't require that.

--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.

franz steinhaeusler

unread,
Apr 19, 2017, 3:11:14 PM4/19/17
to wxPython-users
Hallo Tim, thanks for your response,

I agree, it is no good design to save the changed data only at the end of the program.
I have anyway a timer for watching the clipboard data and this I use for save the data, if they have changed.

But nevertheless: I have my program in background, and when the pc shuts down, the program will be quit.
An interruption of the power supply is so seldom (and my data are not so important), so that is no problem.

Anyway, the events EVT_QUERY_END_SESSION and also no EVT_END_SESSION are fired, at least in ubuntu.

There comes the messagebox then:

Python Information

Deleted stale lock file '/home/franz/SingleApp-wxPythonMultiClipboardFrame'.
Reply all
Reply to author
Forward
0 new messages