moses-palmer / pystray

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

Icon not displayed in LXQt #95

Closed papoteur-mga closed 3 years ago

papoteur-mga commented 3 years ago

I have tried pystray in LXQt in Mageia 7 and Mageia 8. The icon is not displayed, but instead, I get a gear wheel in one case, or an exclamation mark in square box in other case. Tooltip displays the name of the Python program, not the name I have assigned. I don't know from where the problem is (pystray or LXQt). I have tried with env variable PYSTRAY_BACKEND=xorg, I get a place for the icon, but no icon and no action. I have tried with env variable PYSTRAY_BACKEND=gtk I get the icon, I get the menu, with the default action as set ad the commands work fine. But the single left click give an error.

Traceback (most recent call last):
  File "/home/yves/.local/lib/python3.7/site-packages/pystray/_gtk.py", line 63, in _on_status_icon_activate
    self()
  File "/home/yves/.local/lib/python3.7/site-packages/pystray/_base.py", line 88, in __call__
    self._menu(self)
TypeError: 'tuple' object is not callable
moses-palmer commented 3 years ago

Thank you for your report.

As for the error included above, please see the documentation; the meny argument must be an instance of pynput.Menu.

The backends supported on Linux are plain XOrg---with a very limited feature-set!---GTK and AppIndicator. I am not familiar with LXQt, but from the name it appears to be Qt-based; perhaps the GTK->Qt bridge is lacking?

I will close this issue, since I do not think it is an issue with this library, as I have not seen this issue elsewhere. If you have other indications, please reopen.

papoteur-mga commented 3 years ago

As for the error included above, please see the documentation; the meny argument must be an instance of pynput.Menu.

Hello, Thanks for your reply. Do you mean pystray.Menu? This is what i use. Here the complete code.

# -*- coding: utf-8 -*-
"""
Created on Mon Jun 14 19:47:06 2021

@author: yves
"""

import pystray
from pystray import MenuItem
from PIL import Image

import subprocess
def dictate(icon):
    subprocess.Popen(['nerd-dictation',
                    'begin',
                    '--vosk-model-dir=/home/yves/dev/vosk-api/python/example/model',
                    '--full-sentence',
                    '--punctuate-from-previous-timeout=10',
                    '--simulate-input-method=pynput'])
    new_image = Image.open("icons/micro.png")
    icon.icon = new_image

def stop_dictate():
    subprocess.Popen(['nerd-dictation','end',])
    icon.icon = image

def quit_app(icon):
    icon.visible = False
    icon.stop()

def svg_to_Image(svg_string):
    '''
    gets svg content and returns a PIL.Image object
    '''
    import cairosvg
    import io
    in_mem_file = io.BytesIO()
    cairosvg.svg2png(bytestring=svg_string, write_to=in_mem_file)
    return Image.open(io.BytesIO(in_mem_file.getvalue()))

menu = (MenuItem('Dictate', dictate, default=True), MenuItem('Stop dictate', stop_dictate),  MenuItem('Exit', quit_app))

def setup(icon):
    icon.visible = True
with open("icons/no-micro.svg", 'rb') as svg:
    image= svg_to_Image(svg.read())
icon = pystray.Icon('Dictation', image, "Dictation", menu)
icon.icon = image
icon.run(setup)
exit(0)