Catching events at shutdown/logout in windows

Hi,

I have a problem with close/shutdown events not being caught when i
shutdown or log off in windows. I've bound all close-related events i
know of both to my App and Frame objects. The events are caught
properly when i manually close the application, but when i shutdown
windows or log off, nothing happens at all.

I've tested this in the following environments:
* 2 diffent VPC machines running windows XP
* 1 VPC running Vista SP1
* 1 real pc running Vista
* 1 real pc running Windows 7

The *only* events i caught were the EVT_QUERY_END_SESSION &
EVT_END_SESSION events on Windows 7. In ALL the other situation,
nothing is caught at all.

I'm working with wxPython 2.8.7.1 and Python 2.5.2.

I know for sure that the EVT_CLOSE event was being caught in earlier
versions of either python or wxPython, but i dont know since when this
problem started.

I need to catch the close events in my main application to close it in
a proper way, as it is now crashing when the user logs out while its
running. The code below is what i've used to isolate the problem.
Please ignore the ugly parts, it has been subject to hours of
tinkering/hacking :slight_smile:

Thanks in advance for your help.

···

------------------------------------------

import wx
import time

def log(text):
  logFile = open("log.txt", "a")

  now = time.localtime()
  timeString = "%04d/%02d/%02d %02d:%02d:%02d" % (now[0], now[1],
now[2], now[3], now[4], now[5])

  print timeString + " " + text
  logFile.write(timeString + " " + text + "\n")

  logFile.close()

class Frame(wx.Frame):

  def __init__(self, parent, ID, title,
pos=wx.DefaultPosition,size=wx.DefaultSize,
style=wx.DEFAULT_FRAME_STYLE):
    wx.Frame.__init__(self, parent, ID, title, pos, size, style)
    panel = wx.Panel(self, -1)

    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    #self.Bind(wx.EVT_QUERY_END_SESSION, self.OnCloseAppQuery)
    #self.Bind(wx.EVT_END_SESSION, self.OnCloseApp)

  def OnCloseAppQuery(self, event):
    log("OnCloseAppQuery(): received close QUERY event!")

  def OnCloseApp(self, event):
    log("OnCloseApp(): received close event!")

  def OnCloseWindow(self, event):
    log("OnCloseWindow(): -FRAME- received close event!")
    event.Skip()

class App(wx.App):

  def OnInit(self):
    self.frame = Frame(None, -1, "Test afsluiten")
    self.frame.Show(True)
    self.SetTopWindow(self.frame)

    self.Bind(wx.EVT_QUERY_END_SESSION, self.frame.OnCloseAppQuery)
    self.Bind(wx.EVT_END_SESSION, self.frame.OnCloseApp)

    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    return True

  #def OnCloseAppQuery(self, event):
  # log("OnCloseAppQuery(): received close QUERY event!")
  #
  #def OnCloseApp(self, event):
  # log("OnCloseApp(): received close event!")

  def OnExit(self):
    log("OnExit(): called")

  def OnCloseWindow(self, event):
    log("OnCloseWindow(): -APP- received close event!")

app = App(0)
app.MainLoop()

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

The end_session events bound to the app object should be working. Please create a ticket about this.

···

On 5/4/10 5:02 AM, Rappie wrote:

Hi,

I have a problem with close/shutdown events not being caught when i
shutdown or log off in windows. I've bound all close-related events i
know of both to my App and Frame objects. The events are caught
properly when i manually close the application, but when i shutdown
windows or log off, nothing happens at all.

I've tested this in the following environments:
  * 2 diffent VPC machines running windows XP
  * 1 VPC running Vista SP1
  * 1 real pc running Vista
  * 1 real pc running Windows 7

The *only* events i caught were the EVT_QUERY_END_SESSION&
EVT_END_SESSION events on Windows 7. In ALL the other situation,
nothing is caught at all.

I'm working with wxPython 2.8.7.1 and Python 2.5.2.

I know for sure that the EVT_CLOSE event was being caught in earlier
versions of either python or wxPython, but i dont know since when this
problem started.

I need to catch the close events in my main application to close it in
a proper way, as it is now crashing when the user logs out while its
running. The code below is what i've used to isolate the problem.
Please ignore the ugly parts, it has been subject to hours of
tinkering/hacking :slight_smile:

Thanks in advance for your help.

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

The end_session events bound to the app object should be working.
Please create a ticket about this.

Thanks for your reply Robin, i've created a ticket:
http://trac.wxwidgets.org/ticket/12032

Apart from the END_SESSION events, shouldn't the EVT_CLOSE event also
be generated at shutdown?

I'm certain it was the case a couple of years ago, I've actually had
to make a fix in my code back then because the EVT_CLOSE event kept
firing over and over while Windows was shutting down (crashing the
app). Is there a known reason why this isnt working anymore?

I've tried to go back to the older versions (wxPython 2.4.2.4 and
Python 2.3.5) to see if it still works in those versions, but i got no
results. I tested that on a VPC running Windows XP with SP3, maybe MS
changed something in one of their service packs? I'm still trying to
get my hands on an XP install without them.

Also, at the moment the application keeps crashing every time one of
our customers shuts down Windows while our app is still running. Any
quick-and-dirty workarounds are very welcome :slight_smile:

Thanks in advance.

···

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

The docs say:
"""
The handler function for EVT_CLOSE is called when the user has tried to close a frame or dialog box using the window manager (X) or system menu (Windows). It can also be invoked by the application itself programmatically, for example by calling the wxWindow::Close function.
"""

So my guess is that it isn't supposed to. Whether it (incorrectly?) did so in earlier versions is a separate issue.

···

On 5/10/10 5:52 AM, Rappie wrote:

The end_session events bound to the app object should be working.
Please create a ticket about this.

Thanks for your reply Robin, i've created a ticket:
wxTrac has been migrated to GitHub Issues - wxWidgets

Apart from the END_SESSION events, shouldn't the EVT_CLOSE event also
be generated at shutdown?

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en