moses-palmer / pystray

GNU General Public License v3.0
482 stars 59 forks source link

Not Working on Ubuntu when using non-system Python #109

Closed elibroftw closed 2 years ago

elibroftw commented 2 years ago

Currently, if developers want to use a newer version of python on Ubuntu, the gi import will fail. But there is a pgi module. Therefore all import gi should be replaced with

try:
    import gi
except ImportError:
    import pgi as gi
    gi.install_as_gi()
elibroftw commented 2 years ago

Actually pystray doesn't work at all on Ubuntu Gnome

elibroftw commented 2 years ago
import pystray

icon = pystray.Icon('test name')
Traceback (most recent call last):
  File "/home/maste/.local/lib/python3.8/site-packages/pystray/_appindicator.py", line 23, 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

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import pystray
  File "/home/maste/.local/lib/python3.8/site-packages/pystray/__init__.py", line 62, in <module>
    Icon = backend().Icon
  File "/home/maste/.local/lib/python3.8/site-packages/pystray/__init__.py", line 54, in backend
    return candidate()
  File "/home/maste/.local/lib/python3.8/site-packages/pystray/__init__.py", line 26, in appindicator
    from . import _appindicator as backend; return backend
  File "/home/maste/.local/lib/python3.8/site-packages/pystray/_appindicator.py", line 26, in <module>
    gi.require_version('AyatanaAppIndicator3', '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 AyatanaAppIndicator3 not available
elibroftw commented 2 years ago

With the pgi fix,

  File "/home/fortanix/Documents/GitHub/music-caster/src/music_caster.py", line 106, in system_tray
    tray = pystray.Icon('Music Caster SystemTray', unfilled_icon, title='Music Caster [LOADING]')
  File "/home/fortanix/.local/lib/python3.10/site-packages/pystray/_gtk.py", line 36, in __init__
    self._status_icon.connect(
  File "/home/fortanix/.local/lib/python3.10/site-packages/pgi/obj.py", line 156, in connect
    return self.__connect(0, detailed_signal, handler, *args)
  File "/home/fortanix/.local/lib/python3.10/site-packages/pgi/obj.py", line 118, in __connect
    cb = generate_signal_callback(info)(_add_self)
  File "/home/fortanix/.local/lib/python3.10/site-packages/pgi/codegen/siggen.py", line 153, in generate_signal_callback
    cb_func = _generate_signal_callback(backend, info, args, arg_types)
  File "/home/fortanix/.local/lib/python3.10/site-packages/pgi/codegen/siggen.py", line 101, in _generate_signal_callback
    cls = get_cbarg_class(type_)
  File "/home/fortanix/.local/lib/python3.10/site-packages/pgi/codegen/cbargs.py", line 149, in get_cbarg_class
    raise NotImplementedError(
NotImplementedError: 'UINT32' signal argument not implemented
moses-palmer commented 2 years ago

Thank you for your report.

I run the latest version of Ubuntu on my computer, and pystray does work. I may have installed the required libraries manually a long time ago. Do you have any of the packages libappindicator* installed? If not, does installing libappindicator3-1 fix your problem?

elibroftw commented 2 years ago

It works fine if I use the built in Python version but I can't seem to get it to work with Python3.10.

moses-palmer commented 2 years ago

Since GI-support appears to be pretty tied to the system Python installation, and pgi does not appear to be functional yet. When looking at the list of issues for pgi, I notice several similar ones.

I think going forward with this will will have to wait until your issue on pgi is resolved.

elibroftw commented 2 years ago

Yeah it's fine

dmtea commented 2 years ago

It was hard to make it work, but per pip-installation (!) of PyGObject from https://pygobject.readthedocs.io/en/latest/getting_started.html#ubuntu-getting-started help me for non-system python from pyenv (3.9.10)

moses-palmer commented 2 years ago

@dmtea, thank you for the suggestion.

I managed to get pystray using AppIndicator up and running in a virtualenv by installing PyGObject. Unfortunately, no wheels are provided on PyPi and it must thus be built locally when installing, requiring installation of at least libgirepository1.0-dev and libcairo-dev.

I will update the documentation with this information.