moses-palmer / pystray

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

is there a way to handle double clicks? #71

Closed kevin-fesselier closed 3 years ago

kevin-fesselier commented 3 years ago

I could not find anything in the doc Thanks!

moses-palmer commented 3 years ago

Unfortunately no.

The API surface is intentionally kept simple to accommodate all supported platforms.

PySimpleGUI commented 3 years ago

You can add double-click support yourself by timing the single clicks. This is the code I used for the function that's called when the icon is clicked:

DOUBLE_CLICK_THRESHOLD = 500        # time in milliseconds to determine double clicks

def default_action_callback(icon):
    delta = (time.time() - SystemTray.double_click_timer)*1000
    if delta < DOUBLE_CLICK_THRESHOLD:  # if last click was recent, then this click is a double-click
        # A DOUBLE CLICK HAPPED - add your code here
        SystemTray.double_click_timer = 0
    else:
        SystemTray.double_click_timer = time.time()

The variable SystemTray.double_click_timer is nothing special. It's just a class variable. You could use a global or something else to store the timer value used to figure out if a double-click happened.