Get Event by leaving or get to the app again

Hello,

I want to trigger two functions:
one, when the app loses the focus
and another, when the app gains the focus.

I tried in the wxframe derived class:
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)

but I didn't get any event.

So I found finally wx.EVT_ACTIVATE.
This event is unfortunatly generated also, if some
dialog is called from within wx.Frame.
Also if another wx.frame derived class is called
from wxApp. This make a new entry in the Windows XP Tasklist.
example:drFindReplaceInFilesDialog(wx.Frame)

Is there another way, to only get any event,
or some other hint, if really the task is changed
(from the current wxapp to another task and back)?

many thank in advance!

···

--
Franz Steinhaeusler

EVT_ACTIVATE_APP isn't working at all.
Aside from, I saw, that EVT_ACTIVATE is only working for Windows.
I want to find a solution for Linux also.

Again thanks in advance.

···

On Mon, 30 Aug 2004 17:06:02 +0200, Franz Steinhäusler <franz.steinhaeusler@gmx.at> wrote:

[...]

--
Franz Steinhaeusler

Franz Steinh�sler writes:

EVT_ACTIVATE_APP isn't working at all.

I just checked, and it works for me on Linux / wxPython 2.5.2.7u
/ GTK2.

Aside from, I saw, that EVT_ACTIVATE is only working for
Windows. I want to find a solution for Linux also.

EVT_ACTIVATE works for me on Linux...

···

--
Paul McNett
Independent Software Consultant
http://www.paulmcnett.com

Franz Steinh?sler writes:

EVT_ACTIVATE_APP isn't working at all.

I just checked, and it works for me on Linux / wxPython 2.5.2.7u
/ GTK2.

in the wxwidgets doc, there is written:
"""
An application is activated or deactivated when one of its frames
becomes activated, or a frame becomes inactivate resulting in all
application frames being inactive. (Windows only)
"""
Maybe a misunderstanding.

Aside from, I saw, that EVT_ACTIVATE is only working for
Windows. I want to find a solution for Linux also.

EVT_ACTIVATE works for me on Linux...

Someone knows a solution for getting an event, only
if i switch to another task and back to it.

The background is:
for an editor:
If the app loses the focus, it should save all open files.
If it gains the focus, it should automatically reload changed files.

···

On Mon, 30 Aug 2004 08:44:43 -0700, Paul McNett <p@ulmcnett.com> wrote:

--
Franz Steinhaeusler

Franz Steinh�sler writes:

in the wxwidgets doc, there is written:
"""
An application is activated or deactivated when one of its
frames becomes activated, or a frame becomes inactivate
resulting in all application frames being inactive. (Windows
only)
"""
Maybe a misunderstanding.

Probably a documentation bug. EVT_ACTIVATE_APP is definitely
working in Linux. Not sure about OS X, though.

Someone knows a solution for getting an event, only
if i switch to another task and back to it.

The background is:
for an editor:
If the app loses the focus, it should save all open files.
If it gains the focus, it should automatically reload changed
files.

I think that EVT_ACTIVATE_APP is what you want. Something like:

import wx

class MyApp(wx.App):

  def __init__(self, *args):
    wx.App.__init__(self, 0, args)
    self.Bind(wx.EVT_ACTIVATE_APP, self._onActivate)

  def OnInit(self):
    return True

  def _onActivate(self, event):
    """ Call the proper callback, onActivate or onDeactivate.
    """
    if bool(event.GetActive()):
      self.onActivate()
    else:
      self.onDeactivate()
    event.Skip()
      
  def onActivate(self):
    print "MyApp:Activate"

  def onDeactivate(self):
    print "MyApp:Deactivate"
  
if __name__ == "__main__":
  app = MyApp()
  frame = wx.Frame(None)
  frame.Show()
  app.MainLoop()

-- when I run this on Linux, I see the deactivate and activate
messages when I switch from/to the application to some other
application.

I hope this helps.

···

--
Paul McNett
Independent Software Consultant
http://www.paulmcnett.com

Paul, many thanks.

I tried wx.EVT_ACTIVATE_APP before in wx.Frame and not in wx.App.

that was the error.

Now it is working as expected.

regards.

···

On Tue, 31 Aug 2004 06:22:48 -0700, Paul McNett <p@ulmcnett.com> wrote:

Franz Steinh?sler writes:

[...]
I think that EVT_ACTIVATE_APP is what you want. Something like:

import wx

class MyApp(wx.App):

def __init__(self, *args):
  wx.App.__init__(self, 0, args)
  self.Bind(wx.EVT_ACTIVATE_APP, self._onActivate)

def OnInit(self):
  return True

def _onActivate(self, event):
  """ Call the proper callback, onActivate or onDeactivate.
  """
  if bool(event.GetActive()):
    self.onActivate()
  else:
    self.onDeactivate()
  event.Skip()
    
def onActivate(self):
  print "MyApp:Activate"

def onDeactivate(self):
  print "MyApp:Deactivate"

if __name__ == "__main__":
app = MyApp()
frame = wx.Frame(None)
frame.Show()
app.MainLoop()

-- when I run this on Linux, I see the deactivate and activate
messages when I switch from/to the application to some other
application.

I hope this helps.

--
Franz Steinhaeusler