Skip to content

Instantly share code, notes, and snippets.

@Tehnix
Created January 13, 2013 23:56
Show Gist options
  • Save Tehnix/4526922 to your computer and use it in GitHub Desktop.
Save Tehnix/4526922 to your computer and use it in GitHub Desktop.
Toying with getting an icon in the system tray on OS X
import sys
import wx
TRAY_TOOLTIP = 'System Tray Demo'
TRAY_ICON = 'dropboxstatus-idle.ico'
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__()
icon = wx.Icon(TRAY_ICON, wx.BITMAP_TYPE_ICO)
self.SetIcon(icon, "I am the icon")
self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Say Hello', self.on_hello)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def set_icon(self, path):
icon = wx.IconFromBitmap(wx.Bitmap(path))
self.SetIcon(icon, TRAY_TOOLTIP)
def on_left_down(self, event):
print('Tray icon was left-clicked.')
def on_hello(self, event):
print('Hello, world!')
def on_exit(self, event):
wx.CallAfter(self.Destroy)
sys.exit(0)
class App(wx.App):
def OnInit(self):
self.SetTopWindow(wx.Frame(None, -1))
TaskBarIcon()
return True
def main():
app = App()
app.MainLoop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment