moses-palmer / pystray

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

Required libraries for ubuntu #121

Closed ReenigneArcher closed 2 years ago

ReenigneArcher commented 2 years ago

What are the required libraries to run this in ubuntu? Specifically I am attempting to test my application with pytest in a github runner using Ubuntu 20.04; however this is Ubuntu server.

I have attempted installing each of these packages, although not at the same time.

This is the traceback when using ubuntu-desktop although each gave the same error at the end, just slightly different tracebacks.

ImportError while loading conftest '/home/runner/work/RetroArcher/RetroArcher/tests/conftest.py'.
tests/conftest.py:14: in <module>
    from pyra import tray_icon
pyra/tray_icon.py:9: in <module>
    import pystray
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/__init__.py:62: in <module>
    Icon = backend().Icon
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/__init__.py:54: in backend
    return candidate()
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/__init__.py:34: in xorg
    from . import _xorg as backend; return backend
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/_xorg.py:36: in <module>
    display = Xlib.display.Display()
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/Xlib/display.py:89: in __init__
    self.display = _BaseDisplay(display)
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/Xlib/display.py:71: in __init__
    protocol_display.Display.__init__(self, *args, **keys)
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/Xlib/protocol/display.py:84: in __init__
    name, protocol, host, displayno, screenno = connect.get_display(display)
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/Xlib/support/connect.py:73: in get_display
    return mod.get_display(display)
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/Xlib/support/unix_connect.py:76: in get_display
    raise error.DisplayNameError(display)
E   Xlib.error.DisplayNameError: Bad display name ""
Error: Process completed with exit code 4.

The pytest works in both windows and macos runners.

Any guidance would be appreciated. Of course as I'm running this in a github runner I don't actually need to see the icon, I just want to test that the icon is created properly using the pystray.Icon() class.

ReenigneArcher commented 2 years ago

I was able to get past the error above by creating a dummy display server.

However receiving new errors now:

==================================== ERRORS ====================================
_____________________ ERROR at setup of test_tray_disable ______________________
    @pytest.fixture(scope='module')
    def test_tray_icon():
        """Initialize and run a test tray icon"""
        test_tray_icon = tray_icon.tray_initialize()

>       tray_icon.tray_run()
tests/conftest.py:60: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyra/tray_icon.py:99: in tray_run
    icon.run_detached()
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/_base.py:242: in run_detached
    self._run_detached()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <pystray._xorg.Icon object at 0x7f159b353790>
    def _run_detached(self):
        """Runs detached.

        This method must call :meth:`_mark_ready` once ready.

        This is a platform dependent implementation.
        """
>       raise NotImplementedError()
E       NotImplementedError
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/_base.py:384: NotImplementedError
_______________________ ERROR at setup of test_tray_end ________________________
    @pytest.fixture(scope='module')
    def test_tray_icon():
        """Initialize and run a test tray icon"""
        test_tray_icon = tray_icon.tray_initialize()

>       tray_icon.tray_run()
tests/conftest.py:60: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyra/tray_icon.py:99: in tray_run
    icon.run_detached()
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/_base.py:242: in run_detached
    self._run_detached()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <pystray._xorg.Icon object at 0x7f159b353790>
    def _run_detached(self):
        """Runs detached.

        This method must call :meth:`_mark_ready` once ready.

        This is a platform dependent implementation.
        """
>       raise NotImplementedError()
E       NotImplementedError
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/_base.py:384: NotImplementedError
_______________________ ERROR at setup of test_tray_run ________________________
    @pytest.fixture(scope='module')
    def test_tray_icon():
        """Initialize and run a test tray icon"""
        test_tray_icon = tray_icon.tray_initialize()

>       tray_icon.tray_run()
tests/conftest.py:60: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
pyra/tray_icon.py:99: in tray_run
    icon.run_detached()
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/_base.py:242: in run_detached
    self._run_detached()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
self = <pystray._xorg.Icon object at 0x7f159b353790>
    def _run_detached(self):
        """Runs detached.

        This method must call :meth:`_mark_ready` once ready.

        This is a platform dependent implementation.
        """
>       raise NotImplementedError()
E       NotImplementedError
/opt/hostedtoolcache/Python/3.9.10/x64/lib/python3.9/site-packages/pystray/_base.py:384: NotImplementedError
=================================== FAILURES ===================================
_____________________________ test_tray_initialize _____________________________
    def test_tray_initialize():
        """Test tray initialization"""
        tray = tray_icon.tray_initialize()
        assert isinstance(tray, pystray.Icon)

        # these test whether the OS supports the feature, not if the menu has the feature
>       assert tray.HAS_MENU
E       assert False
E        +  where False = <pystray._xorg.Icon object at 0x7f1591c10250>.HAS_MENU
tests/unit/test_tray_icon.py:19: AssertionError
=========================== short test summary info ============================
FAILED tests/unit/test_tray_icon.py::test_tray_initialize - assert False
ERROR tests/unit/test_tray_icon.py::test_tray_disable - NotImplementedError
ERROR tests/unit/test_tray_icon.py::test_tray_end - NotImplementedError
ERROR tests/unit/test_tray_icon.py::test_tray_run - NotImplementedError
==================== 1 failed, 40 passed, 3 errors in 7.57s ====================

I've installed the following packages, and really at a loss as to what I could be missing.

moses-palmer commented 2 years ago

Thank your for your report.

By importing pystray with the appindicator backend and checking from which file the introspection data was loaded (/usr/lib/girepository-1.0/AppIndicator3-0.1.typelib), I managed to determine that the package needed on Ubuntu is gir1.2-appindicator3-0.1. I doubt, however, that you will manage to get it running in a github runner, since the backends on Linux generally will not run headless.

However, your second error has revealed a bug in the Xorg backend implementation introduced in commit 558aa1663dd3e9682c673145ee88d194b00b9b5b, which I will try to fix swiftly.

ReenigneArcher commented 2 years ago

However, your second error has revealed a bug in the Xorg backend implementation introduced in commit 558aa16, which I will try to fix swiftly.

Are you referring to the run_detached method? For now I'm using a try/except on that; however I'm unable to run this in the main thread. It doesn't totally make sense why it needs to run in the main thread in some cases. Perhaps that could be made more clear in the docs.

Either way, thank you for this tool!