How to use the pystray.Menu 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 simonlindholm / decomp-permuter / src / server_main.py View on Github external
def run_with_systray(
    server: Server,
    output_queue: "queue.Queue[IoActivity]",
    loop: Callable[[SystrayState], None],
) -> None:
    menu_items: List[pystray.MenuItem] = []

    icon = pystray.Icon(
        name="permuter@home",
        title="permuter@home",
        icon=Image.open(os.path.join(os.path.dirname(__file__), "..", "icon.png")),
        menu=pystray.Menu(lambda: menu_items),
    )

    def update_menu(items: List[pystray.MenuItem], flush: bool) -> None:
        nonlocal menu_items
        menu_items = items
        if flush:
            icon.update_menu()

    systray = RealSystrayState(server, output_queue, update_menu)
    systray.initial_update()

    def inner(icon: pystray.Icon) -> None:
        icon.visible = True
        loop(systray)
        icon.stop()
github moses-palmer / virtual-touchpad / lib / virtualtouchpad / trayicon.py View on Github external
def access_token_toggle(*args):
        configuration.ACCESS_TOKEN = (
            None if configuration.ACCESS_TOKEN is not None
            else generate_access_token())

    return pystray.Icon(
        __name__,
        title='Virtual Touchpad - {}'.format(
            configuration.SERVER_URL),
        icon=PIL.Image.open(
            resource.open_stream(
                {
                    'darwin': 'icon-dark.png',
                    'linux': 'icon-light.png',
                    'win32': 'icon-light.png'}[sys.platform])),
        menu=menu(
            item(
                _('Connect mobile device...'),
                href('qr')),
            item(
                _('Require access code to connect'),
                access_token_toggle,
                checked=lambda i: bool(configuration.ACCESS_TOKEN)),
            menu.SEPARATOR,
            item(
                _('Help'),
                href('help')),
            menu.SEPARATOR,
            item(
                _('Exit'),
                lambda icon: icon.server.stop())))
github simonlindholm / decomp-permuter / src / server_main.py View on Github external
def _update(self, flush: bool = True) -> None:
        title = "Currently permuting:" if self._clients else ""
        items: List[pystray.MenuItem] = [
            pystray.MenuItem(title, None, enabled=False),
        ]

        for handle, client in self._clients.items():
            fn_names = ", ".join(client.fn_names)
            items.append(
                pystray.MenuItem(
                    f"{fn_names} ({client.nickname})",
                    pystray.Menu(
                        pystray.MenuItem(
                            f"Iterations: {client.iterations}", None, enabled=False
                        ),
                        pystray.MenuItem(
                            f"Improvements found: {client.improvements}",
                            None,
                            enabled=False,
                        ),
                        pystray.MenuItem("Stop", partial(self._remove_client, handle)),
                    ),
                ),
            )

        items.append(pystray.MenuItem("Quit", self._quit))

        self._update_menu(items, flush)
github ralphwetzel / theonionbox / theonionbox / tob / system / darwin / __init__.py View on Github external
def run_with_icon(self, launch, shutdown):

        from . import Icon
        import pystray
        from functools import partial
        import os

        def on_openBox(icon, item, self):
            os.system(f"open /Applications/Safari.app {self.url}")

        menu = pystray.Menu(
            pystray.MenuItem('Show TheOnionBox...', partial(on_openBox, self=self))
        )

        icon = Icon('The Onion Box', menu=menu)
        from PIL import Image, ImageDraw

        def create_image():
            # Generate an image and draw a pattern
            width = 41
            height = 41
            color1 = 0x000000
            color2 = 0xffffff

            image = Image.new('RGB', (width, height), color1)
            dc = ImageDraw.Draw(image)
            dc.rectangle(
github TCB13 / LoFloccus / LoFloccus.py View on Github external
def hide_tray():
    global window
    print("tray hide")
    # hide window
    window.withdraw()
    window.overrideredirect(True)

    # Create tray icon
    icon = pystray.Icon("Floccus Local XBEL")
    icon.icon = Image.open("logo.png")
    icon.visible = True
    icon.menu = Menu(
        MenuItem("Open", lambda: restore_tray(icon, False)),
        MenuItem("Exit", lambda: restore_tray(icon, True)),
    )
    icon.title = "tooltip"
    icon.run(setup_tray)