views:

21

answers:

2

Using wxPython (I am completely new to it), I have created a taskbar icon based on the wxPython demo code. The icon's menu opens upon rightclick of the taskbar icon. However I would want it to do something specific on left click as well.

I've tried implementing this by listening for the EVT_TASKBAR_CLICK event, as in the 3rd Bind line in the following code:

class TrayIcon(wx.TaskBarIcon):
    ...
    def __init__(self, frame):
        ...
        self.Bind(wx.EVT_MENU, self.OnLoanUpdate, id=self.TBMENU_UPDATE)
        self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.TBMENU_CLOSE)
        self.Bind(wx.EVT_TASKBAR_CLICK, self.DoSomething())
        ...
    def DoSomething(self):
        print "do it"

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(200, 100))
        ...
        self.tbicon = TrayIcon(self)
        self.Show(True)
    ...

However, the DoSomething() method is executed upon initialization of my taskbar icon. And it doesn't get fired upon a left (or right) click as I would expect. Actually, even if I use other events (like EVT_CLOSE or EVT_MENU_HIGHLIGHT) the behavior is exactly the same.

I am testing this under Windows 7. What am I doing wrong?

Edit: When I tried this code, and implemented the event in MainWindow class, the double click worked, but I am still puzzled when it doesn't in my case.

A: 

Looking here: http://docs.wxwidgets.org/stable/wx_wxtaskbaricon.html

Have you tried LEFT_UP and LEFT_DOWN instead of CLICK?

davbo
Yes, I've tried those as well.
Rabarberski
+1  A: 

Try removing the () in self.DoSomething(). With the parens, you're binding wx.EVT_TASKBAR_CLICK to whatever DoSomething() returns, which in this case is None.

tom10
Yes, that worked, had indeed overlooked the absence of parens in the other two Bind() methods ! (To completely fix it, I had to add an extra evt parameter to my DoSomething method as well)
Rabarberski