Skip to content

Commit

Permalink
feat(tray): enhance context menu behavior with focus out handling
Browse files Browse the repository at this point in the history
Added a custom MenuExt class that overrides the focusOutEvent method to ensure the context menu closes when it loses focus.
  • Loading branch information
amnweb committed Nov 23, 2024
1 parent 5501f37 commit 118facf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/core/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@
SHORTCUT_FILENAME = "yasb.lnk"
AUTOSTART_FILE = EXE_PATH if os.path.exists(EXE_PATH) else VBS_PATH
WORKING_DIRECTORY = INSTALLATION_PATH if os.path.exists(EXE_PATH) else SCRIPT_PATH


class MenuExt(QMenu):
def focusOutEvent(self, event):
self.close()
super().focusOutEvent(event)

class TrayIcon(QSystemTrayIcon):
def __init__(self, bar_manager: BarManager):
super().__init__()
Expand Down Expand Up @@ -59,7 +64,7 @@ def _load_favicon(self):


def _load_context_menu(self):
menu = QMenu()
menu = MenuExt()
menu.setWindowModality(Qt.WindowModality.WindowModal)
style_sheet = """
QMenu {
Expand Down

0 comments on commit 118facf

Please sign in to comment.