How to use the pystray._darwin.IconDelegate 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
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)

        # Notify the setup callback
        self._mark_ready()

        def sigint(*args):
            self.stop()
            if previous_sigint:
                previous_sigint(*args)