What happens when WinXP shuts down while wxPython app is still running?

Good day!

What is the behaviour of pythonw running a wxPython app when Windows XP
tries to log off or shutdown?

Would pythonw calls wx.App destory method or will there be an event send
to the wx.App?

The reason is that I have a hidden frame as the top window and the frame
has a task bar icon, but I can't log off or shutdown windows XP if the
program is still running. Any idea what is going on?

Regards,
Hatim

You probably have an wxEVT_CLOSE routine which doesn't call event.Skip()

Hatim Khan wrote:

···

Good day!

What is the behaviour of pythonw running a wxPython app when Windows XP
tries to log off or shutdown?

Would pythonw calls wx.App destory method or will there be an event send
to the wx.App?

The reason is that I have a hidden frame as the top window and the frame
has a task bar icon, but I can't log off or shutdown windows XP if the
program is still running. Any idea what is going on?

Regards,
Hatim

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hatim Khan wrote:

Good day!

What is the behaviour of pythonw running a wxPython app when Windows XP
tries to log off or shutdown?

Would pythonw calls wx.App destory method or will there be an event send
to the wx.App?

The reason is that I have a hidden frame as the top window and the frame
has a task bar icon, but I can't log off or shutdown windows XP if the
program is still running. Any idea what is going on?

I've never tried using it but your App object should be getting a couple events. First is EVT_QUERY_END_SESSION which is sent to all apps to determine if it is okay to end the session and logout/shutdown. The default handler for this calls Close on all top-level windows in your app and vetos the end_session if any of the Closes returns False (i.e., their EVT_CLOSE vetoed the close.) The other event is EVT_END_SESSION which is called when all apps have okayed the shutdown/logout and it is about to be done.

···

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

Thanks Joe,

I do catch the event and then destroy the frame but I don't call
event.Skip(). I am assuming that it is acceptable and it will not lead
to unpleasnt bugs.

It turns out that the problem might not be related to Python at all. In
fact, if I try to log off and login more than once, windows XP does not
allow me to log off the second time.

-H

···

-----Original Message-----
From: Joe Brown [mailto:joebrown@rclooke.com]
Sent: Sunday, May 16, 2004 12:11 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] What happens when WinXP shuts down while
wxPython app is still running?

You probably have an wxEVT_CLOSE routine which doesn't call event.Skip()

Hatim Khan wrote:

Good day!

What is the behaviour of pythonw running a wxPython app when Windows XP

tries to log off or shutdown?

Would pythonw calls wx.App destory method or will there be an event
send to the wx.App?

The reason is that I have a hidden frame as the top window and the
frame has a task bar icon, but I can't log off or shutdown windows XP
if the program is still running. Any idea what is going on?

Regards,
Hatim

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Very good to know. Thanks Robin

-H

···

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Monday, May 17, 2004 3:00 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] What happens when WinXP shuts down while
wxPython app is still running?

Hatim Khan wrote:

Good day!

What is the behaviour of pythonw running a wxPython app when Windows
XP tries to log off or shutdown?

Would pythonw calls wx.App destory method or will there be an event
send to the wx.App?

The reason is that I have a hidden frame as the top window and the
frame has a task bar icon, but I can't log off or shutdown windows XP
if the program is still running. Any idea what is going on?

I've never tried using it but your App object should be getting a couple

events. First is EVT_QUERY_END_SESSION which is sent to all apps to
determine if it is okay to end the session and logout/shutdown. The
default handler for this calls Close on all top-level windows in your
app and vetos the end_session if any of the Closes returns False (i.e.,
their EVT_CLOSE vetoed the close.) The other event is EVT_END_SESSION
which is called when all apps have okayed the shutdown/logout and it is
about to be done.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

I got a few questions about event handling:

1- If a hidden frame is using wx.Timer for call back, the wx.Timer would
use the postEvent method to send the events. Correct? So this way it
does not matter if wx.Timer is running on an non UI thread.

2- What is the difference between using Connect, Bind,
EventManager.register, and all the EVT_* helper functions? What are the
best practices.

Thanks,
-H

Hatim Khan wrote:

I got a few questions about event handling:

1- If a hidden frame is using wx.Timer for call back, the wx.Timer would
use the postEvent method to send the events. Correct?

No. Hidden frames can recieve events exactly the same way as shown frames.

So this way it
does not matter if wx.Timer is running on an non UI thread.

It does matter. Timers should only be used on the UI thread.

2- What is the difference between using Connect, Bind,
EventManager.register, and all the EVT_* helper functions?

The EVT_* helper (used to be) functions are just simple wrappers around Connect that were meant to make binding events similar to using the EVT_* macros in an event table in C++. Bind is a recent addition that abstracts the same thing to a little higher more OO level.

EventManager is a completely different animal, sorta. It allows you to subscribe listeners to receive messages published in response to events, following a Publish/Subscribe or Observer design pattern. It makes it easy to have more loosly coupled applications as the subscriber doesn't have to be the object that receives the wxEvent, and there can be many subscribers to a single event if you need it.

What are the
best practices.

A lot of people are shifting to using Bind for normal event handling, although the EVT_* funciton interface will probably still be valid for the forseeable future. (The EVT_* objects are now instances of a class that has a __call__ method, so they can still be used as functions.)

···

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

Thanks Robin,

How the wx.Timer works is a bit mysterious to me. I am definitely
missing an important concept here, I greatly appreciate any help in that
direction.

Here is an example of a mini frame that registers itself for a call back
from the timer. Now, when the timer calls the OnTimer() method object,
what assumptions can we make about the thread? Can I draw to the screen
from inside the OnTimer() method?

class TimerAgent(wx.MiniFrame):

···

#---------------------------------------------
    def __init__(self, parent, interval):
        wx.MiniFrame.__init__(self, parent, -1, ' ', pos=(200, 200),
size=(100, 100), style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ)
        self.Show(False)
        self.interval = interval
        self.timerId = wx.NewId()
    #---------------------------------------------
    def StartWork(self):
        self.timer = wx.Timer(self, self.timerId)
        wx.EVT_TIMER(self, self.timerId, self.OnTimer)
        self.timer.Start(self.interval)
    #---------------------------------------------
    def OnTimer(self, event):
        self.DoScheduledWork()
    #---------------------------------------------
    def DoScheduledWork(self):
        # do some work here. But can I draw to the screen?

Thanks,
-H

-----Original Message-----
From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Tuesday, May 18, 2004 2:15 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] EventManager, wx.Timer and the UI thread

Hatim Khan wrote:

I got a few questions about event handling:

1- If a hidden frame is using wx.Timer for call back, the wx.Timer
would use the postEvent method to send the events. Correct?

No. Hidden frames can recieve events exactly the same way as shown
frames.

So this way it
does not matter if wx.Timer is running on an non UI thread.

It does matter. Timers should only be used on the UI thread.

2- What is the difference between using Connect, Bind,
EventManager.register, and all the EVT_* helper functions?

The EVT_* helper (used to be) functions are just simple wrappers around
Connect that were meant to make binding events similar to using the
EVT_* macros in an event table in C++. Bind is a recent addition that
abstracts the same thing to a little higher more OO level.

EventManager is a completely different animal, sorta. It allows you to
subscribe listeners to receive messages published in response to events,

following a Publish/Subscribe or Observer design pattern. It makes it
easy to have more loosly coupled applications as the subscriber doesn't
have to be the object that receives the wxEvent, and there can be many
subscribers to a single event if you need it.

What are the
best practices.

A lot of people are shifting to using Bind for normal event handling,
although the EVT_* funciton interface will probably still be valid for
the forseeable future. (The EVT_* objects are now instances of a class
that has a __call__ method, so they can still be used as functions.)

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

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hatim Khan wrote:

Here is an example of a mini frame that registers itself for a call back
from the timer. Now, when the timer calls the OnTimer() method object,
what assumptions can we make about the thread?

It is the same as any other event handler. You are in the main thread and have been called from the MainLoop. You can do whatever you need to and then return in order to allow the next event (if any) to be dispatched.

Can I draw to the screen
from inside the OnTimer() method?

Yes. Just create a wx.ClientDC for the window and draw from there. Or you could update whatever internal structures you need to and then call Refresh and let the painting take place in the EVT_PAINT event that will be sent as a result.

···

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