Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Tray icon support #82

Closed
ashishpatel1992 opened this issue Oct 29, 2020 · 12 comments
Closed

[Feature] Tray icon support #82

ashishpatel1992 opened this issue Oct 29, 2020 · 12 comments
Assignees

Comments

@ashishpatel1992
Copy link
Contributor

Support for the Tray icon can be added so that the user is not always required to relaunch the application.

@dynobo
Copy link
Owner

dynobo commented Oct 30, 2020

I personally prefer software to not run in the background constantly, especially if I don't need it very often.

But considering the startup time, which is especially slow for the exe-release on windows, I can understand if some people prefer to run it as a service.

Therefore I'll take a look on this, but can't promise anything here, because I have no idea how difficult it is to implement this platform independently (which is one of the major goals for this project).

Thanks for your suggestion!

@dynobo dynobo self-assigned this Oct 30, 2020
@ashishpatel1992
Copy link
Contributor Author

Well, we don't need to run as a service during startup. But a good suggestion is if it's executed once, it can stay at tray icon. The reason is that if a user has selected text recently. There is a high chance that he will again use the tool within a few minutes.

We can consider it a design enhancement. Although as I said it will only go to tray icon when EXE file is executed manually.
(This could be my personal opinion, for now, I have found an alternative way by dragging the executable file to my taskbar and pinned it, so I don't need to go and run the program again and again)

image

@dynobo
Copy link
Owner

dynobo commented Nov 1, 2020

I like your suggestion! As a first step, we could:

  1. add a command line switch like --keep-in-tray to activate the tray icon
  2. If the tray icon is active and you click on it, a simple menu will show up:
    97741698-24bdb480-1b09-11eb-8319-390251f2cf13
    (the scribble doesn't show a system tray, I know... ;-)

What do you think?

@dynobo dynobo added the backlog This issue is on the roadmap label Nov 1, 2020
@ashishpatel1992
Copy link
Contributor Author

Yeah looks good to me. We can use PyQt5 for that. A demonstrated example is available here
This is a cross-platform library for Windows and macOS

@dynobo
Copy link
Owner

dynobo commented Nov 2, 2020

Hey @ashishpatel1992, while PyQt5 definitely could do that, I'll try to stay away from it. It's a too powerful (and bloated) framework, for such a tiny feature. For the same reason I'm currently using Tkinter as UI-Framework, which is less bloated and a default lib in Python.

However, Tkinter (as far as I can tell) doesn't support tray icons. I'm currently experimenting if pystray can do the job :-)

@dynobo
Copy link
Owner

dynobo commented Nov 3, 2020

pystray conflicts with pyperclip (module for clipboard handling). I filed a simple PR which could help: asweigart/pyperclip#182

Waiting till it arrives upstream...

@ashishpatel1992
Copy link
Contributor Author

Hi @dynobo ,
I have been trying to test pystray but looks like I am stuck at this point. I have followed the documentation Creating a system tray icon.
My Sample code

from pystray import Icon as icon, Menu as menu, MenuItem as item
from PIL import Image

state = False
im = Image.new(mode = "RGB", size = (200, 200), color = (153, 153, 255))

def on_clicked(icon, item):
    global state
    state = not item.checked

icon('test', im, menu=menu(item('Checkable',on_clicked,checked=lambda item: state))).run()

and getting the following error

(base) ashish@pixels:~/Desktop/sa/test$ python test.py 
Failed to dock icon
Traceback (most recent call last):
  File "/home/ashish/anaconda3/lib/python3.7/site-packages/pystray/_xorg.py", line 162, in _update_icon
    self._assert_docked()
  File "/home/ashish/anaconda3/lib/python3.7/site-packages/pystray/_xorg.py", line 389, in _assert_docked
    assert self._systray_manager
AssertionError
Failed to dock icon
Traceback (most recent call last):
  File "/home/ashish/anaconda3/lib/python3.7/site-packages/pystray/_xorg.py", line 143, in _show
    self._assert_docked()
  File "/home/ashish/anaconda3/lib/python3.7/site-packages/pystray/_xorg.py", line 389, in _assert_docked
    assert self._systray_manager
AssertionError

Do you have any idea about this error? I am testing it on Ubuntu 20.04.1 LTS

@dynobo
Copy link
Owner

dynobo commented Nov 3, 2020

@ashishpatel1992 : Your code-example works on my machine, I see the "icon" and don't get an error. My best guess is that you are missing a dependency. You could try to install the following stuff:

sudo apt install libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0
pip install PyGObject

@ashishpatel1992
Copy link
Contributor Author

Hi @dynobo ,
Well, the packages didn't help, but I noticed one thing it wasn't working on Python 3.7.6 but was working fine on python 3.8.
Also tested on windows and working fine under python 3.8

@dynobo
Copy link
Owner

dynobo commented May 29, 2021

Tray Icon Support arrived in the latest beta release 0.2.0-b1!

Please help by testing and providing feedback.

@dynobo dynobo added in progress and removed backlog This issue is on the roadmap labels May 29, 2021
@ashishpatel1992
Copy link
Contributor Author

Hi @dynobo ,
Sure I will test this and let you know the feedback.

@dynobo
Copy link
Owner

dynobo commented Jun 23, 2021

Considered as solved with #116

@dynobo dynobo closed this as completed Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants