Browse Source

Submenu in tray icon to toggle visibility of individual clients (if supported)

master
Nils 1 year ago
parent
commit
da93e3e7e0
  1. 1
      CHANGELOG
  2. 7
      qtgui/opensessioncontroller.py
  3. 27
      qtgui/systemtray.py

1
CHANGELOG

@ -2,6 +2,7 @@
Remove "Quick" mode. As it turns out "Full" mode is quick enough. Port convenience features to full mode.
Add button in session chooser for alternative access to context menu options
Add normal "Save" to tray icon.
Submenu in tray icon to toggle visibility of individual clients (if supported)
Double click on a crashed clients opens it again. This was intentional so far, because a crash is special. But it will be fine...
2021-01-15 Version 0.2.1

7
qtgui/opensessioncontroller.py

@ -197,6 +197,9 @@ class ClientTable(object):
ClientItem.allItems.clear()
self.clientsTreeWidget.clear()
def allItems(self):
return ClientItem.allItems
def clientsContextMenu(self, qpoint):
"""Reuses the menubar menus"""
pos = QtGui.QCursor.pos()
@ -516,6 +519,10 @@ class OpenSessionController(object):
api.callbacks.sessionOpenReady.append(self._reactCallback_sessionOpen)
logger.info("Full View Open Session Controller ready")
def allSessionItems(self):
"""Can be used by external parts, like the tray icon"""
return self.clientTabe.allItems().values() #dict clientId:SessionItem
def _reactCallback_sessionOpen(self, nsmSessionExportDict:dict):
"""Open does not mean we come from the session chooser. Switching does not close a session"""
#self.description.clear() #Deletes the placesholder and text!

27
qtgui/systemtray.py

@ -48,6 +48,26 @@ class SystemTray(QtWidgets.QSystemTrayIcon):
api.callbacks.sessionClosed.append(self.buildContextMenu)
api.callbacks.sessionOpenReady.append(self.buildContextMenu)
api.callbacks.sessionsChanged.append(self.buildContextMenu)
#api.callbacks.clientStatusChanged.append(self.buildContextMenu) #too much. We deal with the client list separately.
self.toggleVisMenu = None
def updateToggleVisMenu(self):
if not self.toggleVisMenu or not api.currentSession(): return #program start or not in a session
for a in self.toggleVisMenu.findChildren(QtWidgets.QAction):
if not a.menu():
self.toggleVisMenu.removeAction(a)
del a
for clientItem in self.mainWindow.sessionController.openSessionController.allSessionItems():
if clientItem.clientDict["hasOptionalGUI"]:
a = QtWidgets.QAction(clientItem.clientDict["reportedName"], self.toggleVisMenu)
self.toggleVisMenu.addAction(a)
def createToggleLambda(clientId):
return lambda: api.clientToggleVisible(clientId)
command = createToggleLambda(clientItem.clientDict["clientId"])
a.triggered.connect(command)
def buildContextMenu(self, *args):
"""In a function for readability.
@ -63,7 +83,6 @@ class SystemTray(QtWidgets.QSystemTrayIcon):
_add(QtCore.QCoreApplication.translate("TrayIcon", "Hide/Show Agordejo"), lambda: self.mainWindow.toggleVisible(force=None)) #explicit force=None because the qt signal is sending a bool
menu.addSeparator()
#Add other pre-defined actions
if nsmSessionName: #We are in a loaded session
menu.addAction(self.mainWindow.ui.actionShow_All_Clients)
@ -71,6 +90,11 @@ class SystemTray(QtWidgets.QSystemTrayIcon):
menu.addSeparator()
menu.addAction(self.mainWindow.ui.actionShow_All_Clients)
menu.addAction(self.mainWindow.ui.actionHide_All_Clients)
#Create a submenu to toggle visibility for all supported clients.
self.toggleVisMenu = menu.addMenu(QtCore.QCoreApplication.translate("TrayIcon", "Toggle Client Visibility"))
#Updated on each trayIcon show event with updateToggleVisMenu
menu.addSeparator()
_add(QtCore.QCoreApplication.translate("TrayIcon", "Save {}".format(nsmSessionName)), api.sessionSave)
_add(QtCore.QCoreApplication.translate("TrayIcon", "Save && Close {}".format(nsmSessionName)), api.sessionClose)
@ -96,6 +120,7 @@ class SystemTray(QtWidgets.QSystemTrayIcon):
QtWidgets.QSystemTrayIcon.MiddleClick
"""
logger.info(f"System tray activated with reason {qActivationReason}")
self.updateToggleVisMenu()
if qActivationReason == QtWidgets.QSystemTrayIcon.Trigger:
self.mainWindow.toggleVisible()

Loading…
Cancel
Save