Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2f9dee9

Browse files
committed
feat(tray): implement event filter for menu visibility and enhance reload handling
- Added an event filter to manage the visibility of the context menu on mouse button press.- Improved the application reload process to handle exceptions and ensure proper cleanup.
1 parentb1b313f commit2f9dee9

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

‎src/core/tray.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
frompathlibimportPath
88
importsubprocess
99
importwinshell
10-
fromPyQt6.QtWidgetsimportQSystemTrayIcon,QMenu,QMessageBox
10+
fromPyQt6.QtWidgetsimportQSystemTrayIcon,QMenu,QMessageBox,QApplication
1111
fromPyQt6.QtGuiimportQIcon,QGuiApplication
12-
fromPyQt6.QtCoreimportQCoreApplication,QSize,Qt,pyqtSlot,QProcess
12+
fromPyQt6.QtCoreimportQCoreApplication,QSize,Qt,pyqtSlot,QProcess,QEvent
1313
fromcore.bar_managerimportBarManager
1414
fromsettingsimportGITHUB_URL,SCRIPT_PATH,APP_NAME,APP_NAME_FULL,DEFAULT_CONFIG_DIRECTORY,GITHUB_THEME_URL,BUILD_VERSION
1515
fromcore.configimportget_config
@@ -42,6 +42,18 @@ def __init__(self, bar_manager: BarManager):
4242
self.cli_pipi_handler=CliPipeHandler(self.stop_or_reload_application)
4343
self.start_cli_server()
4444

45+
defeventFilter(self,obj,event):
46+
ifevent.type()==QEvent.Type.MouseButtonPress:
47+
ifself.menuandself.menu.isVisible():
48+
global_pos=event.globalPosition().toPoint()
49+
all_menus= [self.menu]
50+
all_menus+= [act.menu()foractinself.menu.actions()ifact.menu()andact.menu().isVisible()]
51+
ifnotany(m.geometry().contains(global_pos)forminall_menus):
52+
self.menu.hide()
53+
self.menu.deleteLater()
54+
returnTrue
55+
returnsuper().eventFilter(obj,event)
56+
4557
def_load_config(self):
4658
try:
4759
config=get_config(show_error_dialog=True)
@@ -160,6 +172,8 @@ def _load_context_menu(self):
160172
exit_action.triggered.connect(self._exit_application)
161173

162174
self.setContextMenu(self.menu)
175+
# Connect the activated signal to show the menu
176+
self.activated.connect(lambdareason:self.menu.activateWindow()ifreason==QSystemTrayIcon.ActivationReason.ContextelseNone)
163177

164178
@pyqtSlot()
165179
defremove_tray_icon(self):
@@ -236,10 +250,15 @@ def run_komorebi_reload():
236250
threading.Thread(target=run_komorebi_reload).start()
237251

238252
def_reload_application(self):
239-
self.remove_tray_icon()
240-
logging.info("Reloading Application...")
241-
QProcess.startDetached(sys.executable,sys.argv)
242-
sys.exit()
253+
try:
254+
self.remove_tray_icon()
255+
QApplication.processEvents()
256+
logging.info("Reloading Application...")
257+
QProcess.startDetached(sys.executable,sys.argv)
258+
QCoreApplication.exit(0)
259+
exceptExceptionase:
260+
logging.error(f"Error during reload:{e}")
261+
os._exit(0)
243262

244263
def_exit_application(self):
245264
self.remove_tray_icon()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp