Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import wx
  2.  
  3. TRAY_TOOLTIP = 'System Tray Demo'
  4. TRAY_ICON = 'icon.png'
  5.  
  6.  
  7. def create_menu_item(menu, label, func):
  8.     item = wx.MenuItem(menu, -1, label)
  9.     menu.Bind(wx.EVT_MENU, func, id=item.GetId())
  10.     menu.AppendItem(item)
  11.     return item
  12.  
  13.  
  14. class TaskBarIcon(wx.TaskBarIcon):
  15.     def __init__(self):
  16.         super(TaskBarIcon, self).__init__()
  17.         self.set_icon(TRAY_ICON)
  18.         self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
  19.  
  20.     def CreatePopupMenu(self):
  21.         menu = wx.Menu()
  22.         create_menu_item(menu, 'Say Hello', self.on_hello)
  23.         menu.AppendSeparator()
  24.         create_menu_item(menu, 'Exit', self.on_exit)
  25.         return menu
  26.  
  27.     def set_icon(self, path):
  28.         icon = wx.IconFromBitmap(wx.Bitmap(path))
  29.         self.SetIcon(icon, TRAY_TOOLTIP)
  30.  
  31.     def on_left_down(self, event):
  32.         print 'Tray icon was left-clicked.'
  33.  
  34.     def on_hello(self, event):
  35.         print 'Hello, world!'
  36.  
  37.     def on_exit(self, event):
  38.         wx.CallAfter(self.Destroy)
  39.  
  40.  
  41. def main():
  42.     app = wx.PySimpleApp()
  43.     TaskBarIcon()
  44.     app.MainLoop()
  45.  
  46.  
  47. if __name__ == '__main__':
  48.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement