moses-palmer / pystray

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

Is it possible to run a function on left click #110

Closed crnkyunicorn closed 2 years ago

crnkyunicorn commented 2 years ago

I’d like to run a function on left click of the tray icon, so essentially bypassing creating a menu. Is this possible?

moses-palmer commented 2 years ago

This is unfortunately not possible since not all supported platforms allow for intercepting clicks at all.

ReenigneArcher commented 2 years ago

This is unfortunately not possible since not all supported platforms allow for intercepting clicks at all.

I am not sure of the behavior on all OSes yet (having a lot of trouble getting an icon working on Linux to be honest)... but on Windows, I get a traceback when I left click the icon. Seems to register the click anyway. Not really sure what it's trying to call.

An error occurred when calling message handler
Traceback (most recent call last):
  File "C:\Users\ReenigneArcher\Documents\GitHub\RetroArcher\RetroArcher\venv\lib\site-packages\pystray\_win32.py", line 401, in _dispatcher
    return int(icon._message_handlers.get(
  File "C:\Users\ReenigneArcher\Documents\GitHub\RetroArcher\RetroArcher\venv\lib\site-packages\pystray\_win32.py", line 190, in _on_notify
    self()
  File "C:\Users\ReenigneArcher\Documents\GitHub\RetroArcher\RetroArcher\venv\lib\site-packages\pystray\_base.py", line 110, in __call__
    self._menu(self)
TypeError: 'tuple' object is not callable

Would be a nice addition to have a left click command where it is supported!