moses-palmer / pystray

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

PYSTRAY_BACKEND and the dummy backend #118

Closed simonrob closed 2 years ago

simonrob commented 2 years ago

I use pystray in a multi-platform application where there may or may not be a GUI present. On platforms that have no GUI toolkit available, pystray throws an ImportError when it is imported. This is fine, but means that it is harder to use the same code on multiple platforms without detecting GUI support before importing pystray.

Commit 5176d26 added the option to use an environment variable PYSTRAY_BACKEND to explicitly set the backend, which was very helpful to allow the same code to work across multiple platforms. Although it was not explicitly documented, using a value of dummy meant that it was much easier to use the same code whether a GUI was present or not. With this variable set, the pystray import succeeds, and I just don't load the icon if there is no GUI toolkit present.

Handling of this environment variable was updated in 2ca3445 to explicitly enumerate valid backend options. In the process, this broke the usage of dummy. Could this be updated so that the dummy backend is again supported (on all platforms) to allow importing of pystray even if there is no GUI toolkit present?

moses-palmer commented 2 years ago

Thank you for your report.

This is a clear oversight. I have updated the master branch to allow selecting the dummy backend.