Quick and easy: trayicon with python?

For Windows & Gnome Here ya go! wxPython is the bomb. Adapted from the source of my Feed Notifier application. import wx TRAY_TOOLTIP = ‘System Tray Demo’ TRAY_ICON = ‘icon.png’ 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.set_icon(TRAY_ICON) self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down) def … Read more

How to stop a looping thread in Python?

Threaded stoppable function Instead of subclassing threading.Thread, one can modify the function to allow stopping by a flag. We need an object, accessible to running function, to which we set the flag to stop running. We can use threading.currentThread() object. import threading import time def doit(arg): t = threading.currentThread() while getattr(t, “do_run”, True): print (“working … Read more

Embedding a matplotlib figure inside a WxPython panel

This is a minimal example for a Panel with a matplotlib canvas: from numpy import arange, sin, pi import matplotlib matplotlib.use(‘WXAgg’) from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas from matplotlib.backends.backend_wx import NavigationToolbar2Wx from matplotlib.figure import Figure import wx class CanvasPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) … Read more