这是我的脚本。由于某种原因,它不再起作用了。它以前做过。有人可以追踪任何潜在的错误吗?
#! /usr/bin/env python
import wx
import os
TRAY_TOOLTIP = 'jmtpfs mounter'
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.AppendItem(item)
return item
class TaskBarIcon(wx.TaskBarIcon):
def __init__(self):
super(TaskBarIcon, self).__init__()
self.off=wx.IconFromBitmap(wx.Bitmap("android_off.png"))
self.SetIcon(self.off)
self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Mount', self.mount)
create_menu_item(menu, 'UnMount', self.unmount)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def on_left_down(self, event):
print 'Tray icon was left-clicked.'
def mount(self, event):
retvalue = os.system("jmtpfs ~/Nexus")
print retvalue
self.on=wx.IconFromBitmap(wx.Bitmap("android_on.png"))
self.SetIcon(self.on)
def unmount(self, event):
retvalue = os.system("fusermount -u ~/Nexus")
print retvalue
self.off=wx.IconFromBitmap(wx.Bitmap("android_off.png"))
self.SetIcon(self.off)
def on_exit(self, event):
wx.CallAfter(self.Destroy)
def main():
app = wx.PySimpleApp()
TaskBarIcon()
app.MainLoop()
if __name__ == '__main__':
main()
运行跟踪给出了这个:
mounter.py(17): self.SetIcon(self.off) --- modulename: _windows, funcname: SetIcon _windows.py(2174): return windows .TaskBarIcon_SetIcon(*args, **kwargs) mounter.py(18) :self.Bind(wx.EVT_TASKBAR_LEFT_DOWN,self.on_left_down)---模块名称:_core,funcname:绑定_core.py(3916):断言isinstance(事件,wx.PyEventBinder)_core.py(3917):断言处理程序是无或 callable(handler) _core.py(3918): assert source is None or hasattr(source, 'GetId') _core.py(3919): if source is not None: _core.py(3921): event.Bind(self , id, id2, 处理程序)
--- 模块名:_core,funcname:绑定 _core.py(3994):for et in self.evtType:_core.py(3995):target.Connect(id1, id2, et, function) --- 模块名:_core, funcname: Connect _core.py(3875): return core .EvtHandler_Connect(*args, **kwargs) _core.py(3994): for et in self.evtType: mounter.py(44): app.MainLoop() -- - 模块名称:_core,函数名称:MainLoop _core.py(8010):wx.PyApp.MainLoop(self) --- 模块名称:_core,函数名称:MainLoop _core.py(7306):返回核心.PyApp_MainLoop(*args, **夸格斯)