Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add a proper context menu to the tray icon

  • Loading branch information...
commit 9422213e58157e4a039e731fa6e629e644db7a7f 1 parent f00e988
@BurntBrunch authored
Showing with 14 additions and 8 deletions.
  1. +14 −8 src/main.py
View
22 src/main.py
@@ -15,9 +15,6 @@ def __init__(self):
self.initApp()
self.initUi()
- # TEST
- self.tray_activated(QSystemTrayIcon.DoubleClick)
-
sys.exit(self.app.exec_())
def initApp(self):
@@ -27,6 +24,7 @@ def initApp(self):
self.dev_manager = DeviceManager()
self.udisks_manager = UDisksManager(self.dev_manager)
+ self.window = None
def initUi(self):
self.tray_icon = QSystemTrayIcon(self.app)
@@ -35,12 +33,20 @@ def initUi(self):
self.tray_icon.activated.connect(self.tray_activated)
self.tray_icon.setVisible(True)
+ self.tray_menu = QMenu()
+ self.tray_menu.addAction("&Show manager").triggered.connect(lambda:
+ self.tray_activated(QSystemTrayIcon.DoubleClick))
+
+ self.tray_menu.addAction("&Quit").triggered.connect(self.app.quit)
+ self.tray_icon.setContextMenu(self.tray_menu)
+
def tray_activated(self, reason):
- if reason == QSystemTrayIcon.Context:
- self.app.quit()
- elif reason == QSystemTrayIcon.DoubleClick:
- self.window = MainWindow(self.dev_manager)
- self.window.show()
+ if reason == QSystemTrayIcon.Trigger:
+ if self.window is not None and self.window.isVisible():
+ self.window.hide()
+ else:
+ self.window = MainWindow(self.dev_manager)
+ self.window.show()
if __name__ == "__main__":
app = Application()
Please sign in to comment.
Something went wrong with that request. Please try again.