elig
elig

Reputation: 3078

How to add pywin32 tray icon menu separator / divider?

Based on this pywin32 based script how can I add a separator/divider to the tray menu menu_options ?

Can I also make the menu pop on left click and not just right click ?

Upvotes: 1

Views: 430

Answers (1)

CristiFati
CristiFati

Reputation: 41147

Change the notify function (starting at line #135 in your URL) from:

def notify(self, hwnd, msg, wparam, lparam):
    if lparam==win32con.WM_LBUTTONDBLCLK:
        self.execute_menu_option(self.default_menu_index + self.FIRST_ID)
    elif lparam==win32con.WM_RBUTTONUP:
        self.show_menu()
    elif lparam==win32con.WM_LBUTTONUP:
        pass
    return True

to:

def notify(self, hwnd, msg, wparam, lparam):
    if lparam == win32con.WM_LBUTTONDBLCLK:
        self.execute_menu_option(self.default_menu_index + self.FIRST_ID)
    elif lparam in (win32con.WM_RBUTTONUP, win32con.WM_LBUTTONUP):
        self.show_menu()
    return True

Explanation:

  • notify is a callback function that gets executed automatically when a message is sent to the tray control, and instead of doing nothing when receiving a WM_LBUTTONUP (mouse left button released) message, we simply show the menu as when receiving WM_RBUTTONUP (mouse right button released)

Upvotes: 1

Related Questions