@ -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 ( )