moses-palmer / pystray

GNU General Public License v3.0
463 stars 57 forks source link

make gtk & appindicator backends better behaved #67

Closed dschep closed 3 years ago

dschep commented 3 years ago

This change makes the gtk and appindicator backends behave better when the gi module is present but the necessary namespace is not. EG, on Lubuntu, the gtk backend works but without this change, pystray crashes because gi is available but the AppIndicator3 namespace is not.

Traceback (most recent call last):
  File "testapp.py", line 1, in <module>
    import pystray
  File "/home/dschep/code/me/pystray-test/venv/lib/python3.8/site-packages/pystray/__init__.py", line 48, in <module>
    Icon = backend().Icon
  File "/home/dschep/code/me/pystray-test/venv/lib/python3.8/site-packages/pystray/__init__.py", line 40, in backend
    return importlib.import_module(__package__ + '._' + module)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/home/dschep/code/me/pystray-test/venv/lib/python3.8/site-packages/pystray/_appindicator.py", line 27, in <module>
    gi.require_version('AppIndicator3', '0.1')
  File "/usr/lib/python3/dist-packages/gi/__init__.py", line 129, in require_version
    raise ValueError('Namespace %s not available' % namespace)
ValueError: Namespace AppIndicator3 not available

It of course works if you specify PYSTRAY_BACKEND, but the default behaviour should be as user friendly & robust as possible.

dschep commented 3 years ago

Closing bc this is littering my github.com/pulls