r0x0r/pywebview

Pystray Icon

Jetrom17 opened this issue · 2 comments

Linux: ZorinOS.

Following the documentation, that is, installation and dependencies suggested by pywebview. Pywebview is not starting with example code in the documentation itself.

import multiprocessing
import sys

from PIL import Image
from pystray import Icon, Menu, MenuItem

import webview

if sys.platform == 'darwin':
    ctx = multiprocessing.get_context('spawn')
    Process = ctx.Process
    Queue = ctx.Queue
else:
    Process = multiprocessing.Process
    Queue = multiprocessing.Queue

webview_process = None

def run_webview():
    window = webview.create_window('Webview', 'https://pywebview.flowrl.com/hello')
    webview.start()

if __name__ == '__main__':

    def start_webview_process():
        global webview_process
        webview_process = Process(target=run_webview)
        webview_process.start()

    def on_open(icon, item):
        global webview_process
        if not webview_process.is_alive():
            start_webview_process()

    def on_exit(icon, item):
        icon.stop()

    start_webview_process()

    image = Image.open('logo/logo.png')
    menu = Menu(MenuItem('Open', on_open), MenuItem('Exit', on_exit))
    icon = Icon('Pystray', image, menu=menu)
    icon.run()

    webview_process.terminate()

Font: https://pywebview.flowrl.com/examples/pystray_icon.html

Debug:

python3 test.py 
[pywebview] Using GTK

(test.py:45851): GVFS-WARNING **: 11:17:26.823: Error creating proxy: Erro ao chamar StartServiceByName para org.gtk.vfs.Daemon: O tempo limite foi alcançado (g-io-error-quark, 24)

Gdk-Message: 11:17:26.962: Error 22 (Argumento inválido) dispatching to Wayland display.
EGLDisplay Initialization failed: EGL_NOT_INITIALIZED
jeiel@jeiel-pc:~/test/squarecloud$ 
** (test.py:45851): WARNING **: 11:17:27.126: Disabled hardware acceleration because GTK failed to initialize GL: Nenhuma implementação GL está disponível.
Could not determine the accessibility bus address
Gdk-Message: 11:17:57.471: Error 32 (Pipe quebrado) dispatching to Wayland display.

I believe the pystray example has never been tested on Linux. Contributions are welcomed.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.