绑定wx.TaskBarIcon派生类中的事件处理程序

时间:2011-06-15 22:02:59

标签: python wxpython bind

我正在尝试将EVT_TASKBAR_RIGHT_UP事件附加到使用self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnTaskBarRight)从wx.TaskBarIcon派生的自定义类中的函数。这是在类的 init 函数中。然而,当翻译遇到它时,它给了我这个:

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-gtk2-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 *'

据我所知,这就是说wx.EVT_TASKBAR_RIGHT_UP不是一个事件处理程序类型,我认为它是。这与我正在使用它的类有关吗? 这是相关的一点:

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()

谢谢!

1 个答案:

答案 0 :(得分:2)

如果覆盖窗口小部件的__init__方法,则需要调用父类的__init__方法。添加

super(tbicon, self).__init__()

__init__