moses-palmer / pystray

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

Title/name not working #45

Closed corus87 closed 2 weeks ago

corus87 commented 4 years ago

Hi, first thanks for this easy to use tray icon! I'm not sure if this is a bug or I didn't understand the parameter for name and title. But if I hover over the icon, it only shows the name of the file not the title or name I assigned in the icon function.

I'm running KDE 5 and I forced to import Icon from _gtk (When using ._appindicator the default click won't work).

Thanks.

moses-palmer commented 4 years ago

Thank you for your report and sorry for the late reply.

I personally run GNOME under Wayland, and on my system the GTK backend does not work at all, so I will need a little help with this. I think the problem is a missing call to set the title here. Would you mind applying the following patch to the current master and verifying that it works?

diff --git a/lib/pystray/_gtk.py b/lib/pystray/_gtk.py
index 66d1eb2..1079f59 100644
--- a/lib/pystray/_gtk.py
+++ b/lib/pystray/_gtk.py
@@ -46,6 +46,7 @@ class Icon(GtkIcon):
         self._remove_fs_icon()
         self._update_fs_icon()
         self._status_icon.set_from_file(self._icon_path)
+        self._status_icon.set_title(self.title)

     @mainloop
     def _update_title(self):
corus87 commented 4 years ago

No problem to help out. But with the current master branch I'm not coming far enough to check it out.

  File "videofeedviewer.py", line 51, in run
    self.icon.run()
  File "/usr/local/lib/python3.6/dist-packages/pystray/_base.py", line 192, in run
    self._run()
  File "/usr/local/lib/python3.6/dist-packages/pystray/_util/gtk.py", line 78, in _run
    self._finalize()
  File "/usr/local/lib/python3.6/dist-packages/pystray/_util/gtk.py", line 139, in _finalize
    self._notifier.hide()
  File "/usr/local/lib/python3.6/dist-packages/pystray/_util/notify_dbus.py", line 83, in hide
    if self._icon is not None:
AttributeError: 'Notifier' object has no attribute '_icon'

Btw, I'm not using KDE anymore, I went back to cinnamon on mint.

moses-palmer commented 4 years ago

This error has been fixed in commit 7d110fd; would you mind testing again?

corus87 commented 4 years ago

I just test it with GTK there is no title at all, not even the filename anymore. But to be honest, I'm not quite sure if I ever saw the filename on cinnamon, its possible it was only shown in KDE. I also tried appindicator, but there I see the icon only once at start and get this warnings:

/home/corus/scripts/on_motion_stream/pystray/_appindicator.py:79: Warning: invalid (NULL) pointer instance
  del self._appindicator
/home/corus/scripts/on_motion_stream/pystray/_appindicator.py:79: Warning: g_signal_handlers_disconnect_matched: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
  del self._appindicator

Edit: I had made a mistake, there was an old installation in of pystray in dist-packages. I installed pystray the proper way by git clone and running setup.py. Now when I want to start pystray I get the following error:

Traceback (most recent call last):
  File "videofeedviewer.py", line 15, in <module>
    from pystray import MenuItem as item, Icon as icon, Menu as menu
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 656, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 626, in _load_backward_compatible
  File "/usr/local/lib/python3.6/dist-packages/pystray-0.16.0-py3.6.egg/pystray/__init__.py", line 48, in <module>
  File "/usr/local/lib/python3.6/dist-packages/pystray-0.16.0-py3.6.egg/pystray/__init__.py", line 40, in backend
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
rschyboll commented 3 years ago

I can confirm that in KDE they are some problems with the title of the icon. I dug around in the code of pystray, and found out that the method "_update_title", in the _appindicator.py file, is not beeing called at all. Calling that method in the "_update_icon" method, fixed the problem.

sinrimin commented 3 years ago

Following code works well self._status_icon.set_tooltip_text(self._title)

SpookedByRoaches commented 2 years ago

For me what worked was changing _appindicator file

+++/lib/_appindicator.py
@@ +57 @@
@mainloop
    def _show(self):
        self._appindicator = AppIndicator.Indicator.new(
            self.name,
            '',
            AppIndicator.IndicatorCategory.APPLICATION_STATUS)

        self._appindicator.set_status(AppIndicator.IndicatorStatus.ACTIVE)
        self._appindicator.set_icon(self._icon_path)
        self._appindicator.set_menu(
            self._menu_handle or self._create_default_menu())
+      self._appindicator.set_title(self.title)

@mainloop
    def _hide(self):
        self._appindicator = None
moses-palmer commented 2 years ago

@SpookedByRoaches, thank you very much! That was an obvious oversight.

I have incorporated your fix into the master branch.

SpookedByRoaches commented 2 years ago

@SpookedByRoaches, thank you very much! That was an obvious oversight.

I have incorporated your fix into the master branch.

No problem, glad to help!