开发者

Binding event handlers in a wx.TaskBarIcon derived class

I'm trying to attach the EVT_TASKBAR_RIGHT_UP event to a function in a custom class derived from wx.TaskBarIcon using self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRight). This is in the init function of the class. However, when the interpreter encounters it, it gives me this:

Traceback (most recent call last):
File "serverindicator.py", line 145, in <module>
    tbicon = tbicon()
File "serverindicator.py", line 125, in __init__
    self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRight)
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3918, in Bind
    event.Bind(self, id, id2, handler)              
File "/usr/lib/python2.7/dist-packages/wx-2.8-gt开发者_StackOverflowk2-unicode/wx/_core.py", line 3992, in Bind
    target.Connect(id1, id2, et, function)
File "/usr/lib/python2.7/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 3875, in Connect
    return _core_.EvtHandler_Connect(*args, **kwargs)
TypeError: in method 'EvtHandler_Connect', expected argument 1 of type 'wxEvtHandler *'

As far as I can tell, that's saying that wx.EVT_TASKBAR_RIGHT_UP is not an event handler type, which I thought it was. Is it something to do with the class I'm using it in? Here's the relevant bit:

class tbicon(wx.TaskBarIcon):
    def __init__(self):
        icon = wx.Icon("red-circle.png", wx.BITMAP_TYPE_PNG)
        self.SetIcon(icon, "")
        self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRight)

    def OnTaskBarRight(self, event):
        ID_SETTINGS = wx.NewId()
        ID_EXIT = wx.NewId()
        self.rightmenu = wx.Menu(self, wx.ID_ANY)
        settingsMenuItem = rightmenu.Append(ID_SETTINGS, "Settings")
        exitMenuItem = rightmenu.Append(ID_EXIT, "Exit")
        wx.EVT_MENU(self, ID_SETTINGS, settingswindow.Show(True))
        wx.EVT_MENU(self, ID_EXIT, self.OnExitClicked)
        self.PopupMenu(self.rightmenu, event.GetPoint())
        self.rightmenu.Destroy()

    def OnExitClicked(self, event):
        serverindicator.Destroy()

Thanks!


If you override the __init__ method of a widget, you need to call the __init__ method of the parent class. Add

super(tbicon, self).__init__()

to your __init__.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜