How to use the pystray._darwin.Icon function in pystray

To help you get started, we’ve selected a few pystray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ralphwetzel / theonionbox / theonionbox / tob / system / darwin / systray.py View on Github external
import AppKit
import PyObjCTools.MachSignals
import signal

from pystray._darwin import Icon as pystray_Icon, IconDelegate


class Icon(pystray_Icon):

    def _run(self):
        # Make sure there is an NSApplication instance
        self._app = AppKit.NSApplication.sharedApplication()

        # Make sure we have a delegate to handle the acttion events
        self._delegate = IconDelegate.alloc().init()
        self._delegate.icon = self

        self._status_bar = AppKit.NSStatusBar.systemStatusBar()
        self._status_item = self._status_bar.statusItemWithLength_(
            AppKit.NSVariableStatusItemLength)

        self._status_item.button().setTarget_(self._delegate)
        self._status_item.button().setAction_(self._ACTION_SELECTOR)