event loop, timer and evt handler question

Hi all,

I try to make a class that will put an icon in the windows tray.
I do the following :

---8<-----------------------------------------
from wxPython.wx import *

ID_ICON_TIMER = 2000

class TestTray :

    def __init__ (self) :
  self.trayIcon = wxTaskBarIcon ()
  icon = wxIcon ("BTDTrayIcon.ico", wxBITMAP_TYPE_ICO)
  self.trayIcon.SetIcon (icon, "lalala")

    # connect the eventhandlers for the tray popup menu
  EVT_TASKBAR_LEFT_DCLICK (self.trayIcon, self.OnClick)

    def OnClick (self, evt) :
  self.iconTimer = wxTimer (self, ID_ICON_TIMER)
  EVT_TIMER (self, ID_ICON_TIMER, self.BlinkIcon)
  self.iconTimer.Start (1000)

    def BlinkIcon (self, evt) :
  print " -->> BLINK <<-- "

class MyApp (wxApp) :
    def OnInit (self) :
  test = TestTray ()
  return true

def main () :
    app = MyApp ()
    app.MainLoop ()

if __name__ == '__main__' :
    main ()
---8<-----------------------------------------

And the problem I have is that the icon appear on second and diseppear because
the program ends... Then I think I'm not in the eventloop
But if I try to derive my class from wxEvtHandler, that I guess would maybe
solve the problem, it make an error that I don't have time to read because the
stdout/stderr windows on windows is only displayed when the programs run (And
I don't succeed on redirecting it in a file). But I think the error text is
somewhere similare to the one I have when trying to use wxTimer :

Traceback (most recent call last):
  File "TrayTest.py", line 22, in OnClick
    self.iconTimer = wxTimer (self, self.ID_ICON_TIMER)
  File "C:\Python22\Lib\site-packages\wxPython\wx.py", line 1557, in __init__
    self.SetOwner(evtHandler, id)
  File "C:\Python22\Lib\site-packages\wxPython\misc2.py", line 353, in
SetOwner
    val = apply(misc2c.wxPyTimer_SetOwner,(self,) + _args, _kwargs)
TypeError: Type error in argument 2 of wxPyTimer_SetOwner. Expected
_wxEvtHandler_p.

Could someone help me with some hints about which parent class to use or
anything else...

Thanks,
-philippe

Philippe Ney wrote:

Hi all,

I try to make a class that will put an icon in the windows tray.
I do the following :

[...]

And the problem I have is that the icon appear on second and diseppear because
the program ends... Then I think I'm not in the eventloop

By default MainLoop will exit when there are no more top level windows (frames or dialogs) so since you don't create a frame before calling MainLoop it will exit right away.

One way to fix this is to create a frame but don't Show it until you need it. Be sure that if you want to exit the app from the trask bar icon that you Close the frame.

Another way to fix it is to call app.SetExitOnFrameDelete(False)

···

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

[...]

By default MainLoop will exit when there are no more top level windows
(frames or dialogs) so since you don't create a frame before calling
MainLoop it will exit right away.

Mmm.. yes. Thanks.