dchen327 / pingmote

Cross-platform Python global emote picker to quickly insert custom images/gifs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

System Tray Icon or other "running" indicator

PySimpleGUI opened this issue · comments

I'm still working on a TRUE System Tray Icon for the tkinter port. For now, it looks like an icon on the desktop.

I will be using your program for SURE (I'm already using it). I would like some indicator that it's running. I guess I could add something to my launcher that I'll use to start it up to indicate that it's running, but the system tray would be the best place. Then it can be used to manage the program too.,

Suggestion - SystemTray Icon

I changed your event loop to be like this:

    def create_window_gui(self):
        """ Run the event loop for the GUI, listening for clicks """
        # Event loop
        while True:
            event, _ = self.window.read(timeout=100)
            tevent = self.system_tray.read(timeout=10)
            # Process events common in Window and Tray
            if 'Exit' in (event, tevent) or event == sg.WINDOW_CLOSED:
                break
            elif 'Hide' in (event, tevent):
                self.hide_gui()
            elif 'Edit Me' in (event, tevent):
                sg.execute_editor(__file__)

            # Process events found only in Window or Tray
            if tevent == 'Show':
                self.on_activate()
            if event in self.filename_to_link:
                print(f'selection event = {event}')
                self.on_select(event)
            # A tray double-click toggles visibility
            if tevent == sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED:
                self.on_activate() if self.hidden else self.hide_gui()

        self.system_tray.close()
        self.window.close()

In the layout method where you create the window, I created a system tray

        self.system_tray = sg.SystemTray(menu=['_', ['Show', 'Hide', 'Edit Me', 'Settings', 'Exit']], data_base64=sg.DEFAULT_BASE64_ICON)

At the moment, the system tray for tkinter displays like an icon on the desktop instead of the system tray. I'm working on using another library with PySimpleGUI so they will be in the actual system tray like the feature is in PySimpleGUIQt and PySimpleGUIWx.

This screencapture shows the kinds of things is does with the icon. You can double click it to show/hide your window. The operation you see at the end of the video is where I'm double-clicking the system tray icon. The ControlQ key is quite problematic since it's a heavily used key in PyCharm, so I'm adding the ability to set it using the settings (not quite done but it's all I had time for this morning). It eats up a fair amount of CPU time because of the polling, so I'll look into doing something about that down the road maybe.

PingMote with  System Tray

Thank you for providing a fun distraction and something new for me to learn from. It's nice to run across programs like this that I can use every day, all day, that are PySimpleGUI based, and are fun to tinker with for a few minutes here and there.


Right click enhancement added

I made a change, BTW, based on your program. Buttons don't normally have the opportunity to show a right click menu. But for programs like yours that are almost all buttons, it leaves very few places to right click. So, I added right click menu to buttons. :-)

Now I can see the menu when right clicking a button. This change will be released to PyPI today

image

It's programs like this that push the envelope of PySimpleGUI's capabilities. Or in the very least push it in ways that haven't been done before. This is how PySimpleGUI has grown over the years. I utilize real-world problems to grow features. Your program had a real-world problem of it mostly having buttons and also a right click menu would benefit it. That's a trigger for me that here's an area where PySimpleGUI can grow a little. There is an immediate need and it will benefit a lot of people in the future perhaps.

I'm working on the Button lesson on the Udemy course, so I'm really looking hard at Buttons. I fixed the Realtime Button for example because it kinda needs to work in order to teach it. And I wanted to get this change in before I finish recording the Button lessons.

I should have added 1 line of code to replace the print after I created the system tray:

        self.system_tray = sg.SystemTray(menu=['_', ['Show', 'Hide', 'Edit Me', 'Settings', 'Exit']], data_base64=sg.DEFAULT_BASE64_ICON)
        self.system_tray.show_message('Ready', 'window created and hidden', messageicon=sg.SYSTEM_TRAY_MESSAGE_ICON_INFORMATION)

image