def __init__(self, parent=None): QtWidgets.QSystemTrayIcon.__init__(self, parent) self.parent = parent # Menu: self.menu = dict() self.menu['menu'] = QtWidgets.QMenu() # Load menu: menu_path = os.path.join( os.path.join(cgruconfig.VARS['CGRU_LOCATION'], 'start') ) # TODO: why to use os.path.join() two times here, to add '/' at the end ??? menu_paths = cgruconfig.VARS['menu_path'] if menu_paths is None: menu_paths = menu_path if menu_paths.find(';') != -1: menu_paths = menu_paths.split(';') elif sys.platform.find('win') == -1: menu_paths = menu_paths.split(':') else: menu_paths = [menu_paths] if not menu_path in menu_paths: menu_paths.append(menu_path) for menu_path in menu_paths: if not os.path.isdir(menu_path): continue for dirpath, dirnames, filenames in os.walk( menu_path, True, None, True): if dirpath.find('/.') != -1: continue if dirpath.find('\\.') != -1: continue menuname = os.path.basename(dirpath) if menuname == os.path.basename(menu_path): menuname = 'menu' else: self.addMenu(self.menu['menu'], menuname) filenames.sort() was_separator = True for filename in filenames: if filename[0] == '.' or filename[0] == '_': continue if sys.platform[:3] == 'win': if filename[-4:] != '.cmd': continue itemname = filename[:-4] else: if filename[-3:] != '.sh': continue itemname = filename[:-3] filename = os.path.join(dirpath, filename) with open(filename, 'r') as f: lines = f.readlines() iconpath = None separator = False for line in lines: if line.find('Name=') != -1: itemname = line.split('Name=')[-1].strip() if line.find('Icon=') != -1: iconpath = line.split('Icon=')[-1].strip() if line.find('Separator') != -1: separator = True if separator: if not was_separator: self.menu[menuname].addSeparator() was_separator = True else: was_separator = False action = ActionCommand(self, itemname, filename, iconpath) self.menu[menuname].addAction(action) action.triggered.connect(action.runCommand) if separator: self.menu[menuname].addSeparator() # Add permanent items to 'Afanasy': if not self.addMenu(self.menu['menu'], 'AFANASY'): self.menu['AFANASY'].addSeparator() action = QtWidgets.QAction('Web GUI', self) action.triggered.connect(cmd.afwebgui) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() self.action_user = QtWidgets.QAction('Set User...', self) self.action_user.triggered.connect(render.setUserDialog) self.action_user.setToolTip('Change local render user name.') self.menu['AFANASY'].addAction(self.action_user) action = QtWidgets.QAction('Set nimby', self) action.triggered.connect(nimby.setnimby) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Set NIMBY', self) action.triggered.connect(nimby.setNIMBY) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Set Free', self) action.triggered.connect(nimby.setFree) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Eject Tasks', self) action.triggered.connect(nimby.ejectTasks) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Eject And NIMBY', self) action.triggered.connect(nimby.ejectAndNIMBY) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Eject Not My Tasks', self) action.triggered.connect(nimby.ejectNotMyTasks) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Render Info', self) action.triggered.connect(self.renderInfo) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() action = QtWidgets.QAction('Nimby Schedule...', self) action.triggered.connect(self.editNimby) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() action = QtWidgets.QAction('Set Server...', self) action.triggered.connect(cmd.setAFANASYServer) self.menu['AFANASY'].addAction(action) self.menu['menu'].addSeparator() # Add Software menu if it was not created by custom files: if not 'Software' in self.menu: self.addMenu(self.menu['menu'], 'Software') self.menu['menu'].addSeparator() for soft in software.Names: icon = software.getIcon(soft) if icon is None: action = QtWidgets.QAction(soft, self) else: action = QtWidgets.QAction(icon, soft, self) eval("action.triggered.connect(software.start%s)" % soft) self.menu['Software'].addAction(action) # Software setup: self.menu['Setup Soft'] = QtWidgets.QMenu('Setup Soft') self.menu['Software'].addMenu(self.menu['Setup Soft']) for soft in software.Names: action = QtWidgets.QAction(soft, self) eval("action.triggered.connect(software.locate%s)" % soft) self.menu['Setup Soft'].addAction(action) # Software examples: self.menu['Examples'] = QtWidgets.QMenu('Examples') self.menu['Software'].addMenu(self.menu['Examples']) for soft in software.Names: action = QtWidgets.QAction(soft, self) eval("action.triggered.connect(software.example%s)" % soft) self.menu['Examples'].addAction(action) # Add permanent items to 'Configure': if not self.addMenu(self.menu['menu'], 'Configure'): self.menu['Configure'].addSeparator() action = QtWidgets.QAction('Execute in terminal', self) action.setCheckable(True) action.triggered.connect(cmd.triggerExecInTerminal) if cgruconfig.getVar('keeper_execute_in_terminal'): action.setChecked(True) self.menu['Configure'].addAction(action) self.menu['Configure'].addSeparator() if serverhttps.isRunning: self.addAction('Configure', False, 'HTTPS Server...', self.httpsServer) self.menu['Configure'].addSeparator() action = QtWidgets.QAction('Set Web Browser...', self) action.triggered.connect(cmd.setWebBrowser) self.menu['Configure'].addAction(action) action = QtWidgets.QAction('Set Open Folder...', self) action.triggered.connect(cmd.setOpenCmd) self.menu['Configure'].addAction(action) action = QtWidgets.QAction('Set Teminal...', self) action.triggered.connect(cmd.setTerminal) self.menu['Configure'].addAction(action) action = QtWidgets.QAction('Set Text Editor...', self) action.triggered.connect(cmd.setTextEditor) self.menu['Configure'].addAction(action) action = QtWidgets.QAction('Edit Config...', self) action.triggered.connect(cmd.editCGRUConfig) self.menu['Configure'].addAction(action) self.menu['Configure'].addSeparator() action = QtWidgets.QAction('Reload Config', self) action.triggered.connect(cmd.confReload) self.menu['Configure'].addAction(action) # Some general menu items: self.addAction('menu', True, 'Documentation...', cmd.cgruDocs) self.addAction('menu', False, 'Forum...', cmd.cgruForum) # System sub-menu: self.addMenu(self.menu['menu'], 'System') self.addAction('System', True, 'Show Info...', self.cgruInfo, 'info') # Update item only if CGRU_UPDATE_CMD defined: if cgruconfig.VARS['CGRU_UPDATE_CMD'] is not None: self.addAction('System', True, 'Update', cmd.update) self.addAction('System', True, 'Restart', cmd.restart) self.addAction('System', False, 'Quit', cmd.quit) self.setContextMenu(self.menu['menu']) # Tray tooltip: self.updateToolTip() # Tray icon: icon_filename = cgruconfig.VARS['tray_icon'] if icon_filename is None: icon_filename = 'keeper' icon_filename = cgruutils.getIconFileName(icon_filename) self.icon_pixmap = QtGui.QPixmap(icon_filename) self.icon_default = QtGui.QIcon(self.icon_pixmap) self.showIcon() # Show: self.activated.connect(self.activated_slot) self.show()
def __init__( self, parent = None): QtGui.QSystemTrayIcon.__init__( self, parent) self.parent = parent # Menu: self.menu = dict() self.menu['menu'] = QtGui.QMenu() # Update item only if CGRU_UPDATE_CMD defined: if cgruconfig.VARS['CGRU_UPDATE_CMD'] is not None: action = QtGui.QAction('Update', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.update) self.menu['menu'].addAction( action) self.menu['menu'].addSeparator() # Load menu: menu_path = os.path.join( os.path.join( cgruconfig.VARS['CGRU_LOCATION'],'start')) menu_paths = cgruconfig.VARS['menu_path'] if menu_paths is None: menu_paths = menu_path if menu_paths.find(';') != -1: menu_paths = menu_paths.split(';') elif sys.platform.find('win') == -1: menu_paths = menu_paths.split(':') else: menu_paths = [menu_paths] if not menu_path in menu_paths: menu_paths.append( menu_path) for menu_path in menu_paths: if not os.path.isdir( menu_path): continue for dirpath, dirnames, filenames in os.walk( menu_path, True, None, True): if dirpath.find('/.') != -1: continue if dirpath.find('\\.') != -1: continue menuname = os.path.basename( dirpath) if menuname == os.path.basename( menu_path): menuname = 'menu' else: self.addMenu( self.menu['menu'], menuname) filenames.sort() was_separator = True for filename in filenames: if filename[0] == '.' or filename[0] == '_': continue if sys.platform[:3] == 'win': if filename[-4:] != '.cmd': continue itemname = filename[:-4] else: if filename[-3:] != '.sh': continue itemname = filename[:-3] filename = os.path.join( dirpath, filename) file = open( filename,'r') lines = file.readlines() file.close() iconpath = None separator = False for line in lines: if line.find('Name=') != -1: itemname = line.split('Name=')[-1].strip() if line.find('Icon=') != -1: iconpath = line.split('Icon=')[-1].strip() if line.find('Separator') != -1: separator = True if separator: if not was_separator: self.menu[menuname].addSeparator() was_separator = True else: was_separator = False action = ActionCommand( self, itemname, filename, iconpath) self.menu[menuname].addAction( action) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), action.runCommand) if separator: self.menu[menuname].addSeparator() # Add permanent items to 'Afanasy': if not self.addMenu( self.menu['menu'], 'AFANASY'): self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Web GUI', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.afwebgui) self.menu['AFANASY'].addAction( action) self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Set nibmy', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), nimby.setnimby) self.menu['AFANASY'].addAction( action) action = QtGui.QAction('Set NIMBY', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), nimby.setNIMBY) self.menu['AFANASY'].addAction( action) action = QtGui.QAction('Set Free', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), nimby.setFree) self.menu['AFANASY'].addAction( action) action = QtGui.QAction('Eject Tasks', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), nimby.ejectTasks) self.menu['AFANASY'].addAction( action) action = QtGui.QAction('Eject Not My Tasks', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), nimby.ejectNotMyTasks) self.menu['AFANASY'].addAction( action) action = QtGui.QAction('Render Info', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), self.renderInfo) self.menu['AFANASY'].addAction( action) self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Nimby Schedule...', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), self.editNimby) self.menu['AFANASY'].addAction( action) self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Set Server...', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.setAFANASYServer) self.menu['AFANASY'].addAction( action) self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Exit Render', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.exitRender) self.menu['AFANASY'].addAction( action) action = QtGui.QAction('Exit Watch', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.exitMonitor) self.menu['AFANASY'].addAction( action) action = QtGui.QAction('Exit Talk', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.exitTalk) self.menu['AFANASY'].addAction( action) action = QtGui.QAction('Exit All Clients', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.exitClients) self.menu['AFANASY'].addAction( action) self.menu['menu'].addSeparator() # Add Software menu if it was not created by custom files: if not 'Software' in self.menu: self.addMenu( self.menu['menu'], 'Software') self.menu['menu'].addSeparator() action = QtGui.QAction( QtGui.QIcon( cgruutils.getIconFileName('folder')), '[ browse ]', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), software.browse) self.menu['Software'].addAction( action) for soft in software.Names: icon = software.getIcon( soft) if icon is None: action = QtGui.QAction( soft, self) else: action = QtGui.QAction( icon, soft, self) eval("QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), software.start%s)" % soft) self.menu['Software'].addAction( action) # Software setup: self.menu['Setup Soft'] = QtGui.QMenu('Setup Soft') self.menu['Software'].addMenu( self.menu['Setup Soft']) for soft in software.Names: action = QtGui.QAction( soft, self) eval("QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), software.locate%s)" % soft) self.menu['Setup Soft'].addAction( action) # Software examples: self.menu['Examples'] = QtGui.QMenu('Examples') self.menu['Software'].addMenu( self.menu['Examples']) for soft in software.Names: action = QtGui.QAction( soft, self) eval("QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), software.example%s)" % soft) self.menu['Examples'].addAction( action) # Add permanent items to 'Configure': if not self.addMenu( self.menu['menu'], 'Configure'): self.menu['Configure'].addSeparator() action = QtGui.QAction('Reload Config', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.confReload) self.menu['Configure'].addAction( action) action = QtGui.QAction('Set Docs URL...', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.setDocsURL) self.menu['Configure'].addAction( action) action = QtGui.QAction('Edit Config...', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.editCGRUConfig) self.menu['Configure'].addAction( action) action = QtGui.QAction('Set Web Browser...', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.setWebBrowser) self.menu['Configure'].addAction( action) action = QtGui.QAction('Set Text Editor...', self) QtCore.QObject.connect( action, QtCore.SIGNAL('triggered()'), cmd.setTextEditor) self.menu['Configure'].addAction( action) self.addAction('menu', True,'Show Info...', self.cgruInfo,'info') self.addAction('menu', True,'Documentation', cmd.cgruDocs) self.addAction('menu', True,'Restart', cmd.restart) self.addAction('menu', False,'Quit && Exit Clients', cmd.quitExitClients) self.addAction('menu', False,'Quit', cmd.quit) self.setContextMenu( self.menu['menu']) # Prepare Icons: self.icons = dict() icon_filename = cgruconfig.VARS['tray_icon'] if icon_filename is None: icon_filename = 'keeper' icon_filename = cgruutils.getIconFileName( icon_filename) self.icon_epmty = QtGui.QPixmap( icon_filename) self.icons['empty'] = QtGui.QIcon( self.icon_epmty) self.makeIcon('offline_free', online=False, nimby=False, busy=False) self.makeIcon('online_free', online=True, nimby=False, busy=False) self.makeIcon('offline_nimby', online=False, nimby=True, busy=False) self.makeIcon('online_nimby', online=True, nimby=True, busy=False) self.makeIcon('offline_free_busy', online=False, nimby=False, busy=True ) self.makeIcon('online_free_busy', online=True, nimby=False, busy=True ) self.makeIcon('offline_nimby_busy', online=False, nimby=True, busy=True ) self.makeIcon('online_nimby_busy', online=True, nimby=True, busy=True ) # Decorate and show: self.showIcon() self.setToolTip( cgruconfig.VARS['company'].upper() + ' Keeper ' + os.getenv('CGRU_VERSION', '')) QtCore.QObject.connect( self, QtCore.SIGNAL('activated( QSystemTrayIcon::ActivationReason)'), self.activated_slot) self.show()
def __init__(self, parent=None): QtWidgets.QSystemTrayIcon.__init__(self, parent) self.parent = parent # Menu: self.menu = dict() self.menu['menu'] = QtWidgets.QMenu() # Load menu: menu_path = os.path.join( os.path.join(cgruconfig.VARS['CGRU_LOCATION'], 'start') ) # TODO: why to use os.path.join() two times here, to add '/' at the end ??? menu_paths = cgruconfig.VARS['menu_path'] if menu_paths is None: menu_paths = menu_path if menu_paths.find(';') != -1: menu_paths = menu_paths.split(';') elif sys.platform.find('win') == -1: menu_paths = menu_paths.split(':') else: menu_paths = [menu_paths] if not menu_path in menu_paths: menu_paths.append(menu_path) for menu_path in menu_paths: if not os.path.isdir(menu_path): continue for dirpath, dirnames, filenames in os.walk(menu_path, True, None, True): if dirpath.find('/.') != -1: continue if dirpath.find('\\.') != -1: continue menuname = os.path.basename(dirpath) if menuname == os.path.basename(menu_path): menuname = 'menu' else: self.addMenu(self.menu['menu'], menuname) filenames.sort() was_separator = True for filename in filenames: if filename[0] == '.' or filename[0] == '_': continue if sys.platform[:3] == 'win': if filename[-4:] != '.cmd': continue itemname = filename[:-4] else: if filename[-3:] != '.sh': continue itemname = filename[:-3] filename = os.path.join(dirpath, filename) with open(filename, 'r') as f: lines = f.readlines() iconpath = None separator = False for line in lines: if line.find('Name=') != -1: itemname = line.split('Name=')[-1].strip() if line.find('Icon=') != -1: iconpath = line.split('Icon=')[-1].strip() if line.find('Separator') != -1: separator = True if separator: if not was_separator: self.menu[menuname].addSeparator() was_separator = True else: was_separator = False action = ActionCommand(self, itemname, filename, iconpath) self.menu[menuname].addAction(action) action.triggered.connect( action.runCommand) if separator: self.menu[menuname].addSeparator() # Add permanent items to 'Afanasy': if not self.addMenu(self.menu['menu'], 'AFANASY'): self.menu['AFANASY'].addSeparator() action = QtWidgets.QAction('Web GUI', self) action.triggered.connect( cmd.afwebgui) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() self.action_user = QtWidgets.QAction('Set User...', self) self.action_user.triggered.connect( render.setUserDialog) self.action_user.setToolTip('Change local render user name.') self.menu['AFANASY'].addAction(self.action_user) action = QtWidgets.QAction('Set nimby', self) action.triggered.connect( nimby.setnimby) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Set NIMBY', self) action.triggered.connect( nimby.setNIMBY) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Set Free && Unpause', self) action.triggered.connect( nimby.setFreeUnpause) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Eject Tasks', self) action.triggered.connect( nimby.ejectTasks) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Eject Not My Tasks', self) action.triggered.connect( nimby.ejectNotMyTasks) self.menu['AFANASY'].addAction(action) action = QtWidgets.QAction('Render Info', self) action.triggered.connect( self.renderInfo) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() action = QtWidgets.QAction('Nimby Schedule...', self) action.triggered.connect( self.editNimby) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() action = QtWidgets.QAction('Set Server...', self) action.triggered.connect( cmd.setAFANASYServer) self.menu['AFANASY'].addAction(action) self.menu['menu'].addSeparator() # Add Software menu if it was not created by custom files: if not 'Software' in self.menu: self.addMenu(self.menu['menu'], 'Software') self.menu['menu'].addSeparator() for soft in software.Names: icon = software.getIcon(soft) if icon is None: action = QtWidgets.QAction(soft, self) else: action = QtWidgets.QAction(icon, soft, self) eval("action.triggered.connect(software.start%s)" % soft) self.menu['Software'].addAction(action) # Software setup: self.menu['Setup Soft'] = QtWidgets.QMenu('Setup Soft') self.menu['Software'].addMenu(self.menu['Setup Soft']) for soft in software.Names: action = QtWidgets.QAction(soft, self) eval("action.triggered.connect(software.locate%s)" % soft) self.menu['Setup Soft'].addAction(action) # Software examples: self.menu['Examples'] = QtWidgets.QMenu('Examples') self.menu['Software'].addMenu(self.menu['Examples']) for soft in software.Names: action = QtWidgets.QAction(soft, self) eval("action.triggered.connect(software.example%s)" % soft) self.menu['Examples'].addAction(action) # Add permanent items to 'Configure': if not self.addMenu(self.menu['menu'], 'Configure'): self.menu['Configure'].addSeparator() action = QtWidgets.QAction('Execute in terminal', self) action.setCheckable(True) action.triggered.connect(cmd.triggerExecInTerminal) if cgruconfig.getVar('keeper_execute_in_terminal'): action.setChecked(True) self.menu['Configure'].addAction(action) self.menu['Configure'].addSeparator() if serverhttps.isRunning: self.addAction('Configure', False, 'HTTPS Server...', self.httpsServer) self.menu['Configure'].addSeparator() action = QtWidgets.QAction('Set Web Browser...', self) action.triggered.connect( cmd.setWebBrowser) self.menu['Configure'].addAction(action) action = QtWidgets.QAction('Set Open Folder...', self) action.triggered.connect( cmd.setOpenCmd) self.menu['Configure'].addAction(action) action = QtWidgets.QAction('Set Teminal...', self) action.triggered.connect(cmd.setTerminal) self.menu['Configure'].addAction(action) action = QtWidgets.QAction('Set Text Editor...', self) action.triggered.connect( cmd.setTextEditor) self.menu['Configure'].addAction(action) action = QtWidgets.QAction('Edit Config...', self) action.triggered.connect( cmd.editCGRUConfig) self.menu['Configure'].addAction(action) self.menu['Configure'].addSeparator() action = QtWidgets.QAction('Reload Config', self) action.triggered.connect( cmd.confReload) self.menu['Configure'].addAction(action) # Some general menu items: self.addAction('menu', True, 'Documentation...', cmd.cgruDocs) self.addAction('menu', False, 'Forum...', cmd.cgruForum) # System sub-menu: self.addMenu(self.menu['menu'],'System') self.addAction('System', True,'Show Info...', self.cgruInfo,'info') # Update item only if CGRU_UPDATE_CMD defined: if cgruconfig.VARS['CGRU_UPDATE_CMD'] is not None: self.addAction('System', True, 'Update', cmd.update) self.addAction('System', True, 'Restart', cmd.restart) self.addAction('System', False,'Quit', cmd.quit) self.setContextMenu(self.menu['menu']) # Tray tooltip: self.setToolTip('%s Keeper' % cgruconfig.VARS['company'].upper()) # Tray icon: icon_filename = cgruconfig.VARS['tray_icon'] if icon_filename is None: icon_filename = 'keeper' icon_filename = cgruutils.getIconFileName(icon_filename) self.icon_pixmap = QtGui.QPixmap(icon_filename) self.icon_default = QtGui.QIcon(self.icon_pixmap) self.showIcon() # Show: self.activated.connect( self.activated_slot) self.show()
def __init__(self, parent=None): QtGui.QSystemTrayIcon.__init__(self, parent) self.parent = parent # Menu: self.menu = dict() self.menu['menu'] = QtGui.QMenu() # Update item only if CGRU_UPDATE_CMD defined: if cgruconfig.VARS['CGRU_UPDATE_CMD'] is not None: action = QtGui.QAction('Update', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.update) self.menu['menu'].addAction(action) self.menu['menu'].addSeparator() # Load menu: menu_path = os.path.join( os.path.join(cgruconfig.VARS['CGRU_LOCATION'], 'start') ) # TODO: why to use os.path.join() two times here, to add '/' at the end ??? menu_paths = cgruconfig.VARS['menu_path'] if menu_paths is None: menu_paths = menu_path if menu_paths.find(';') != -1: menu_paths = menu_paths.split(';') elif sys.platform.find('win') == -1: menu_paths = menu_paths.split(':') else: menu_paths = [menu_paths] if not menu_path in menu_paths: menu_paths.append(menu_path) for menu_path in menu_paths: if not os.path.isdir(menu_path): continue for dirpath, dirnames, filenames in os.walk( menu_path, True, None, True): if dirpath.find('/.') != -1: continue if dirpath.find('\\.') != -1: continue menuname = os.path.basename(dirpath) if menuname == os.path.basename(menu_path): menuname = 'menu' else: self.addMenu(self.menu['menu'], menuname) filenames.sort() was_separator = True for filename in filenames: if filename[0] == '.' or filename[0] == '_': continue if sys.platform[:3] == 'win': if filename[-4:] != '.cmd': continue itemname = filename[:-4] else: if filename[-3:] != '.sh': continue itemname = filename[:-3] filename = os.path.join(dirpath, filename) with open(filename, 'r') as f: lines = f.readlines() iconpath = None separator = False for line in lines: if line.find('Name=') != -1: itemname = line.split('Name=')[-1].strip() if line.find('Icon=') != -1: iconpath = line.split('Icon=')[-1].strip() if line.find('Separator') != -1: separator = True if separator: if not was_separator: self.menu[menuname].addSeparator() was_separator = True else: was_separator = False action = ActionCommand(self, itemname, filename, iconpath) self.menu[menuname].addAction(action) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), action.runCommand) if separator: self.menu[menuname].addSeparator() # Add permanent items to 'Afanasy': if not self.addMenu(self.menu['menu'], 'AFANASY'): self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Web GUI', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.afwebgui) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() self.action_user = QtGui.QAction('Set User...', self) QtCore.QObject.connect(self.action_user, QtCore.SIGNAL('triggered()'), render.setUserDialog) self.action_user.setToolTip('Change local render user name.') self.menu['AFANASY'].addAction(self.action_user) action = QtGui.QAction('Set nimby', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), nimby.setnimby) self.menu['AFANASY'].addAction(action) action = QtGui.QAction('Set NIMBY', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), nimby.setNIMBY) self.menu['AFANASY'].addAction(action) action = QtGui.QAction('Set Free', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), nimby.setFree) self.menu['AFANASY'].addAction(action) action = QtGui.QAction('Eject Tasks', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), nimby.ejectTasks) self.menu['AFANASY'].addAction(action) action = QtGui.QAction('Eject Not My Tasks', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), nimby.ejectNotMyTasks) self.menu['AFANASY'].addAction(action) action = QtGui.QAction('Render Info', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), self.renderInfo) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Nimby Schedule...', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), self.editNimby) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Set Server...', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.setAFANASYServer) self.menu['AFANASY'].addAction(action) self.menu['AFANASY'].addSeparator() action = QtGui.QAction('Exit Render', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.exitRender) self.menu['AFANASY'].addAction(action) action = QtGui.QAction('Exit Watch', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.exitMonitor) self.menu['AFANASY'].addAction(action) action = QtGui.QAction('Exit All Clients', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.exitClients) self.menu['AFANASY'].addAction(action) self.menu['menu'].addSeparator() # Add Software menu if it was not created by custom files: if not 'Software' in self.menu: self.addMenu(self.menu['menu'], 'Software') self.menu['menu'].addSeparator() action = QtGui.QAction( QtGui.QIcon(cgruutils.getIconFileName('folder')), '[ browse ]', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), software.browse) self.menu['Software'].addAction(action) for soft in software.Names: icon = software.getIcon(soft) if icon is None: action = QtGui.QAction(soft, self) else: action = QtGui.QAction(icon, soft, self) eval("QtCore.QObject.connect(action," " QtCore.SIGNAL('triggered()')," " software.start%s)" % soft) self.menu['Software'].addAction(action) # Software setup: self.menu['Setup Soft'] = QtGui.QMenu('Setup Soft') self.menu['Software'].addMenu(self.menu['Setup Soft']) for soft in software.Names: action = QtGui.QAction(soft, self) eval("QtCore.QObject.connect(action," " QtCore.SIGNAL('triggered()')," " software.locate%s)" % soft) self.menu['Setup Soft'].addAction(action) # Software examples: self.menu['Examples'] = QtGui.QMenu('Examples') self.menu['Software'].addMenu(self.menu['Examples']) for soft in software.Names: action = QtGui.QAction(soft, self) eval("QtCore.QObject.connect(action," " QtCore.SIGNAL('triggered()')," " software.example%s)" % soft) self.menu['Examples'].addAction(action) # Add permanent items to 'Configure': if not self.addMenu(self.menu['menu'], 'Configure'): self.menu['Configure'].addSeparator() action = QtGui.QAction('Reload Config', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.confReload) self.menu['Configure'].addAction(action) action = QtGui.QAction('Set Docs URL...', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.setDocsURL) self.menu['Configure'].addAction(action) action = QtGui.QAction('Edit Config...', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.editCGRUConfig) self.menu['Configure'].addAction(action) action = QtGui.QAction('Set Web Browser...', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.setWebBrowser) self.menu['Configure'].addAction(action) action = QtGui.QAction('Set Text Editor...', self) QtCore.QObject.connect(action, QtCore.SIGNAL('triggered()'), cmd.setTextEditor) self.menu['Configure'].addAction(action) self.addAction('menu', True, 'Show Info...', self.cgruInfo, 'info') self.addAction('menu', True, 'Documentation', cmd.cgruDocs) self.addAction('menu', True, 'Restart', cmd.restart) self.addAction('menu', False, 'Quit && Exit Clients', cmd.quitExitClients) self.addAction('menu', False, 'Quit', cmd.quit) self.setContextMenu(self.menu['menu']) # Prepare Icons: self.icons = dict() icon_filename = cgruconfig.VARS['tray_icon'] if icon_filename is None: icon_filename = 'keeper' icon_filename = cgruutils.getIconFileName(icon_filename) self.icon_epmty = QtGui.QPixmap(icon_filename) self.icons['empty'] = QtGui.QIcon(self.icon_epmty) self.makeIcon('offline_free', online=False, nimby=False, busy=False) self.makeIcon('online_free', online=True, nimby=False, busy=False) self.makeIcon('offline_nimby', online=False, nimby=True, busy=False) self.makeIcon('online_nimby', online=True, nimby=True, busy=False) self.makeIcon('offline_free_busy', online=False, nimby=False, busy=True) self.makeIcon('online_free_busy', online=True, nimby=False, busy=True) self.makeIcon('offline_nimby_busy', online=False, nimby=True, busy=True) self.makeIcon('online_nimby_busy', online=True, nimby=True, busy=True) # Decorate and show: self.showIcon() self.setToolTip('%s Keeper %s' % (cgruconfig.VARS['company'].upper(), os.getenv('CGRU_VERSION', ''))) QtCore.QObject.connect( self, QtCore.SIGNAL('activated( QSystemTrayIcon::ActivationReason)'), self.activated_slot) self.show()
def __init__(self, parent=None): QtWidgets.QSystemTrayIcon.__init__(self, parent) self.parent = parent # Menu: self.menu = dict() self.menu['menu'] = QtWidgets.QMenu() # Update item only if CGRU_UPDATE_CMD defined: if cgruconfig.VARS['CGRU_UPDATE_CMD'] is not None: action = QtWidgets.QAction('Update', self) action.triggered.connect(cmd.update) self.menu['menu'].addAction(action) self.menu['menu'].addSeparator() # Load menu: menu_path = os.path.join( os.path.join(cgruconfig.VARS['CGRU_LOCATION'], 'start') ) # TODO: why to use os.path.join() two times here, to add '/' at the end ??? menu_paths = cgruconfig.VARS['menu_path'] if menu_paths is None: menu_paths = menu_path if menu_paths.find(';') != -1: menu_paths = menu_paths.split(';') elif sys.platform.find('win') == -1: menu_paths = menu_paths.split(':') else: menu_paths = [menu_paths] if not menu_path in menu_paths: menu_paths.append(menu_path) for menu_path in menu_paths: if not os.path.isdir(menu_path): continue for dirpath, dirnames, filenames in os.walk( menu_path, True, None, True): if dirpath.find('/.') != -1: continue if dirpath.find('\\.') != -1: continue menuname = os.path.basename(dirpath) if menuname == os.path.basename(menu_path): menuname = 'menu' else: self.addMenu(self.menu['menu'], menuname) filenames.sort() was_separator = True for filename in filenames: if filename[0] == '.' or filename[0] == '_': continue if sys.platform[:3] == 'win': if filename[-4:] != '.cmd': continue itemname = filename[:-4] else: if filename[-3:] != '.sh': continue itemname = filename[:-3] filename = os.path.join(dirpath, filename) with open(filename, 'r') as f: lines = f.readlines() iconpath = None separator = False for line in lines: if line.find('Name=') != -1: itemname = line.split('Name=')[-1].strip() if itemname == 'Scan Scan...': itemname = '影视搜索' if itemname == 'Dailies...': itemname = '影视剪辑' if itemname == 'Check RegExp...': itemname = '检测对象' if itemname == 'Start Watch...': itemname = '作业监控' if itemname == 'Submit Job...': itemname = '作业提交' if itemname == 'Local Render...': itemname = '本地渲染' if line.find('Icon=') != -1: iconpath = line.split('Icon=')[-1].strip() if line.find('Separator') != -1: separator = True if separator: if not was_separator: self.menu[menuname].addSeparator() was_separator = True else: was_separator = False action = ActionCommand(self, itemname, filename, iconpath) self.menu[menuname].addAction(action) action.triggered.connect(action.runCommand) if separator: self.menu[menuname].addSeparator() # Add permanent items to 'Afanasy': # if not self.addMenu(self.menu['menu'], 'AFANASY'): if not self.addMenu(self.menu['menu'], '渲染'): self.menu['渲染'].addSeparator() # action = QtWidgets.QAction('Web GUI', self) action = QtWidgets.QAction('Web页面', self) action.triggered.connect(cmd.afwebgui) self.menu['渲染'].addAction(action) self.menu['渲染'].addSeparator() # self.action_user = QtWidgets.QAction('Set User...', self) self.action_user = QtWidgets.QAction('用户设置', self) self.action_user.triggered.connect(render.setUserDialog) self.action_user.setToolTip('Change local render user name.') self.menu['渲染'].addAction(self.action_user) # action = QtWidgets.QAction('Set nimby', self) action = QtWidgets.QAction('后台设置', self) action.triggered.connect(nimby.setnimby) self.menu['渲染'].addAction(action) action = QtWidgets.QAction('Set NIMBY', self) action.triggered.connect(nimby.setNIMBY) self.menu['渲染'].addAction(action) # action = QtWidgets.QAction('Set Free && Unpause', self) action = QtWidgets.QAction('作业释放', self) action.triggered.connect(nimby.setFreeUnpause) self.menu['渲染'].addAction(action) # action = QtWidgets.QAction('Eject Tasks', self) action = QtWidgets.QAction('开始任务', self) action.triggered.connect(nimby.ejectTasks) self.menu['渲染'].addAction(action) # action = QtWidgets.QAction('Eject Not My Tasks', self) action = QtWidgets.QAction('关闭其它任务', self) action.triggered.connect(nimby.ejectNotMyTasks) self.menu['渲染'].addAction(action) # action = QtWidgets.QAction('Render Info', self) action = QtWidgets.QAction('渲染信息', self) action.triggered.connect(self.renderInfo) self.menu['渲染'].addAction(action) self.menu['渲染'].addSeparator() # action = QtWidgets.QAction('Nimby Schedule...', self) action = QtWidgets.QAction('运行模式', self) action.triggered.connect(self.editNimby) self.menu['渲染'].addAction(action) self.menu['渲染'].addSeparator() #action = QtWidgets.QAction('Set Server...', self) action = QtWidgets.QAction('服务器设置', self) action.triggered.connect(cmd.setAFANASYServer) self.menu['渲染'].addAction(action) self.menu['menu'].addSeparator() # Add Software menu if it was not created by custom files: if not '专业软件' in self.menu: self.addMenu(self.menu['menu'], '专业软件') self.menu['menu'].addSeparator() action = QtWidgets.QAction( QtGui.QIcon(cgruutils.getIconFileName('folder')), '[ browse ]', self) action.triggered.connect(software.browse) self.menu['专业软件'].addAction(action) for soft in software.Names: icon = software.getIcon(soft) if icon is None: action = QtWidgets.QAction(soft, self) else: action = QtWidgets.QAction(icon, soft, self) eval("action.triggered.connect(software.start%s)" % soft) self.menu['专业软件'].addAction(action) # Software setup: self.menu['Setup Soft'] = QtWidgets.QMenu('Setup Soft') self.menu['专业软件'].addMenu(self.menu['Setup Soft']) for soft in software.Names: action = QtWidgets.QAction(soft, self) eval("action.triggered.connect(software.locate%s)" % soft) self.menu['Setup Soft'].addAction(action) # Software examples: self.menu['Examples'] = QtWidgets.QMenu('Examples') self.menu['专业软件'].addMenu(self.menu['Examples']) for soft in software.Names: action = QtWidgets.QAction(soft, self) eval("action.triggered.connect(software.example%s)" % soft) self.menu['Examples'].addAction(action) # Add permanent items to 'Configure': #if not self.addMenu(self.menu['menu'], 'Configure'): if not self.addMenu(self.menu['menu'], '系统配置'): self.menu['系统配置'].addSeparator() if serverhttps.isRunning: self.addAction('系统配置', False, 'HTTPS Server...', self.httpsServer) self.menu['系统配置'].addSeparator() #action = QtWidgets.QAction('Set Web Browser...', self) action = QtWidgets.QAction('配置浏览器...', self) action.triggered.connect(cmd.setWebBrowser) self.menu['系统配置'].addAction(action) #action = QtWidgets.QAction('Set Open Folder...', self) action = QtWidgets.QAction('配置文件夹...', self) action.triggered.connect(cmd.setOpenCmd) self.menu['系统配置'].addAction(action) #action = QtWidgets.QAction('Set Docs URL...', self) action = QtWidgets.QAction('配置文件主机...', self) action.triggered.connect(cmd.setDocsURL) self.menu['系统配置'].addAction(action) #action = QtWidgets.QAction('Set Text Editor...', self) action = QtWidgets.QAction('配置文本编辑器...', self) action.triggered.connect(cmd.setTextEditor) self.menu['系统配置'].addAction(action) #action = QtWidgets.QAction('Edit Config...', self) action = QtWidgets.QAction('设置配置', self) action.triggered.connect(cmd.editCGRUConfig) self.menu['系统配置'].addAction(action) self.menu['系统配置'].addSeparator() #action = QtWidgets.QAction('Reload Config', self) action = QtWidgets.QAction('重置服务', self) action.triggered.connect(cmd.confReload) self.menu['系统配置'].addAction(action) #self.addAction('menu', True, 'Show Info...', self.cgruInfo, 'info') self.addAction('menu', True, '查看配置', self.cgruInfo, 'info') #self.addAction('menu', True, 'Documentation...', cmd.cgruDocs) #self.addAction('menu', False, 'Forum...', cmd.cgruForum) #self.addAction('menu', True, 'Restart', cmd.restart) self.addAction('menu', True, '重启服务', cmd.restart) #self.addAction('menu', False, 'Quit', cmd.quit) self.addAction('menu', False, '退出服务', cmd.quit) self.setContextMenu(self.menu['menu']) # Tray tooltip: #self.setToolTip('%s Keeper' % cgruconfig.VARS['company'].upper()) self.setToolTip('奇幻空间') # Tray icon: icon_filename = cgruconfig.VARS['tray_icon'] if icon_filename is None: icon_filename = 'keeper' icon_filename = cgruutils.getIconFileName(icon_filename) self.icon_pixmap = QtGui.QPixmap(icon_filename) self.icon_default = QtGui.QIcon(self.icon_pixmap) self.showIcon() # Show: self.activated.connect(self.activated_slot) self.show()