def __windowMenuSetup(self, menu): """Creates the menu items for dealing with multiple main windows""" self.windowMenu = menu # Menu Bar: Window -> Change Window Title changeTitle = QtWidgets.QAction("Change Window Title", self) changeTitle.triggered.connect(self.__windowMenuHandleChangeTitle) menu.addAction(changeTitle) # Menu Bar: Window -> Save Window Settings saveWindowSettings = QtWidgets.QAction("Save Window Settings", self) saveWindowSettings.triggered.connect(self.__saveSettings) menu.addAction(saveWindowSettings) menu.addSeparator() # Load list of window titles if not self.windows_titles: for name in self.windows_names: self.windows_titles[name] = str( self.settings.value("%s/Title" % name, name)) # Create menu items for Window -> Open/Raise/Add Window "?" for name in self.windows_names: if name not in self.windows_actions: self.windows_actions[name] = QtWidgets.QAction("", self) menu.addAction(self.windows_actions[name]) self.windowMenu.triggered.connect(self.__windowMenuHandle) self.__windowMenuUpdate()
def setupPluginMenu(self, menu): """Adds a plugin menu option to the supplied menubar @param menu: The menu to add the loaded plugins to @type menu: QMenu""" menu.triggered.connect(self._handlePluginMenu) # Create the submenus (ordered) submenus = {} menu_locations = {"root": []} for category in set([ plugin[CATEGORY] for plugin in self.__plugins.values() if CATEGORY in plugin ]): submenus[category] = QtWidgets.QMenu(category, menu) menu.addMenu(submenus[category]) menu_locations[category] = [] # Store the plugin name in the proper menu_locations category for plugin in self.__plugins: category = self.__plugins[plugin].get(CATEGORY, "root") menu_locations[category].append(plugin) # Create the QAction and add it to the correct menu (sorted) for category in menu_locations: for plugin in sorted(menu_locations[category]): action = QtWidgets.QAction("{}".format(plugin), menu) if category in submenus: submenus[category].addAction(action) else: menu.addAction(action) return menu
def _filterStatusSetup(self, layout): """Sets up the filter status menu, adds it to the given layout @param layout: The layout to add the menu to @type layout: QLayout""" btn = QtWidgets.QPushButton("Filter Status") btn.setFocusPolicy(QtCore.Qt.NoFocus) btn.setContentsMargins(0,0,0,0) btn.setFlat(True) menu = QtWidgets.QMenu(self) btn.setMenu(menu) menu.triggered.connect(self._filterStatusHandle) for item in [("Clear", QtCore.Qt.ALT + QtCore.Qt.Key_QuoteLeft), None, ("Succeeded", QtCore.Qt.ALT + QtCore.Qt.Key_1), ("Running", QtCore.Qt.ALT + QtCore.Qt.Key_2), ("Waiting", QtCore.Qt.ALT + QtCore.Qt.Key_3), ("Depend", QtCore.Qt.ALT + QtCore.Qt.Key_4), ("Dead", QtCore.Qt.ALT + QtCore.Qt.Key_5), ("Eaten", QtCore.Qt.ALT + QtCore.Qt.Key_6)]: if item: a = QtWidgets.QAction(item[0], menu) if item[0] != "Clear": a.setCheckable(True) if item[1]: a.setShortcut(item[1]) menu.addAction(a) else: menu.addSeparator() layout.addWidget(btn) self._filterStatusButton = btn self.frameMonitorTree.job_changed.connect(self._filterStatusClear)
def _filterLayersUpdate(self): """Updates the filter layers menu with the layers in the current job""" btn = self._filterLayersButton menu = btn.menu() if menu: for action in menu.actions(): menu.removeAction(action) else: menu = QtWidgets.QMenu(self) btn.setMenu(menu) menu.triggered[QtWidgets.QAction].connect(self._filterLayersHandle) if self.frameMonitorTree.getJob(): layers = [x.data.name for x in self.frameMonitorTree.getJob().getLayers()] else: layers = [] for item in ["Clear", None ] + sorted(layers): if item: a = QtWidgets.QAction(menu) a.setText(item) if item != "Clear": a.setCheckable(True) menu.addAction(a) else: menu.addSeparator()
def __filterHardwareStateSetup(self, layout): self.__filterHardwareStateList = sorted( [state for state in dir( opencue.api.host_pb2.HardwareState) if not state.startswith("_")]) btn = QtWidgets.QPushButton("Filter HardwareState") btn.setMaximumHeight(FILTER_HEIGHT) btn.setFocusPolicy(QtCore.Qt.NoFocus) btn.setContentsMargins(0,0,0,0) btn.setFlat(True) menu = QtWidgets.QMenu(self) btn.setMenu(menu) QtCore.QObject.connect(menu, QtCore.SIGNAL("triggered(QAction*)"), self.__filterHardwareStateHandle) for item in ["Clear", None] + self.__filterHardwareStateList: if item: a = QtWidgets.QAction(menu) a.setText(str(item)) if item != "Clear": a.setCheckable(True) menu.addAction(a) else: menu.addSeparator() layout.addWidget(btn) self.__filterHardwareStateButton = btn
def __filterAllocationSetup(self, layout): self.__filterAllocationList = sorted( [alloc.name() for alloc in opencue.api.getAllocations()]) btn = QtWidgets.QPushButton("Filter Allocation") btn.setMaximumHeight(FILTER_HEIGHT) btn.setFocusPolicy(QtCore.Qt.NoFocus) btn.setContentsMargins(0,0,0,0) btn.setFlat(True) menu = QtWidgets.QMenu(self) btn.setMenu(menu) QtCore.QObject.connect(menu, QtCore.SIGNAL("triggered(QAction*)"), self.__filterAllocationHandle) for item in ["Clear", None] + self.__filterAllocationList: if item: a = QtWidgets.QAction(menu) a.setText(str(item)) if item != "Clear": a.setCheckable(True) menu.addAction(a) else: menu.addSeparator() layout.addWidget(btn) self.__filterAllocationButton = btn
def __toggleFullscreenSetup(self, menu): # Menu Bar: Window -> Toggle Full-Screen fullscreen = QtWidgets.QAction(QtGui.QIcon('icons/fullscreen.png'), 'Toggle Full-Screen', self) fullscreen.setShortcut('Ctrl+F') fullscreen.setStatusTip('Toggle Full-Screen') fullscreen.triggered.connect(self.__toggleFullscreen) menu.addAction(fullscreen)
def __populate_menu(self): self.__menu.clear() for group in self.__show.getGroups(): if opencue.id(group) in self.__actions: self.__menu.addAction(self.__actions[opencue.id(group)]) else: action = QtWidgets.QAction(self) action.setText(group.data.name) action.setCheckable(True) self.__actions[opencue.id(group)] = action self.__menu.addAction(action)
def create(parent, text, tip, callback=None, icon=None): """create(QtGui.QWidget, string text, string tip, callable callback=None, string icon=None) creates a QtGui.QAction and optionally connects it to a slot """ a = QtWidgets.QAction(parent) a.setText(text) if tip: a.setToolTip(tip) if icon: a.setIcon(QtGui.QIcon(":%s.png" % (icon))) if callback: connectActionSlot(a,callback) return a
def __createMenus(self): """Creates the menus at the top of the window""" self.menuBar().setFont(Constants.STANDARD_FONT) # Menu bar self.fileMenu = self.menuBar().addMenu("&File") self.facilityMenu = self.__facilityMenuSetup( self.menuBar().addMenu("&Cuebot")) self.PluginMenu = self.menuBar().addMenu("&Views/Plugins") self.windowMenu = self.menuBar().addMenu("&Window") self.helpMenu = self.menuBar().addMenu("&Help") # Menu Bar: File -> Close Window close = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'), '&Close Window', self) close.setStatusTip('Close Window') close.triggered.connect(self.__windowCloseWindow) self.fileMenu.addAction(close) # Menu Bar: File -> Exit Application exit = QtWidgets.QAction(QtGui.QIcon('icons/exit.png'), 'E&xit Application', self) exit.setShortcut('Ctrl+Q') exit.setStatusTip('Exit application') exit.triggered.connect(self.__windowCloseApplication) self.fileMenu.addAction(exit) self.__windowMenuSetup(self.windowMenu) self.windowMenu.addSeparator() self.__toggleFullscreenSetup(self.windowMenu) # Menu Bar: Help -> Online User Guide. action = QtWidgets.QAction('Online User Guide', self) action.triggered.connect(self.openUserGuide) self.helpMenu.addAction(action) # Menu Bar: Help -> Make a Suggestion action = QtWidgets.QAction('Make a Suggestion', self) action.triggered.connect(self.openSuggestionPage) self.helpMenu.addAction(action) # Menu Bar: Help -> Report a Bug action = QtWidgets.QAction('Report a Bug', self) action.triggered.connect(self.openBugPage) self.helpMenu.addAction(action) self.helpMenu.addSeparator() # Menu Bar: Help -> About about = QtWidgets.QAction(QtGui.QIcon('icons/about.png'), 'About', self) about.setShortcut('F1') about.setStatusTip('About') about.triggered.connect(self.displayAbout) self.helpMenu.addAction(about)
def __displayColumnMenu(self): point = self.__dropdown.mapToGlobal( QtCore.QPoint(self.__dropdown.width(), self.__dropdown.height())) menu = QtWidgets.QMenu(self) menu.triggered.connect(self.__handleColumnMenu) for col in range(self.columnCount()): if self.columnWidth(col) or self.isColumnHidden(col): name = self.__columnInfoByType[ self.__columnPrimaryType][col][COLUMN_NAME] a = QtWidgets.QAction(menu) a.setText("%s. %s" % (col, name)) a.setCheckable(True) a.setChecked(not self.isColumnHidden(col)) menu.addAction(a) menu.exec_(point)
def createAction(parent, id, text, tip, callback=None, icon=None): """create(QtWidgets.QWidget, string text, string tip, callable callback=None, string icon=None) creates a QtGui.QAction and optionally connects it to a slot """ if id in Actions: raise Exception("Action %s has already been created" % (id)) a = QtWidgets.QAction(parent) a.setText(text) if tip: a.setToolTip(tip) if icon: a.setIcon(QtGui.QIcon(":/images/%s.png" % icon)) if callback: connectActionSlot(a,callback) Actions[id] = a return a
def refresh(self): """ Refresh the full list of allocations. """ allocs = opencue.api.getAllocations() allocs.sort(lambda x, y: cmp(x.data.name, y.data.name)) self.__menu.clear() checked = 0 for alloc in allocs: a = QtWidgets.QAction(self.__menu) a.setText(alloc.data.name) a.setCheckable(True) if alloc.data.name in AllocFilter.default: a.setChecked(True) checked += 1 self.__menu.addAction(a) self.__setSelected() self.setText("Allocations (%d)" % checked)
def __facilityMenuSetup(self, menu): """Creates the facility menu actions @param menu: The QMenu that the actions should be added to @type menu: QMenu @return: The QMenu that the actions were added to @rtype: QMenu""" self.__actions_facility = {} menu.setFont(Constants.STANDARD_FONT) menu.triggered.connect(self.__facilityMenuHandle) cue_config = opencue.Cuebot.getConfig() self.facility_default = cue_config.get("cuebot.facility_default") self.facility_dict = cue_config.get("cuebot.facility") for facility in self.facility_dict: self.__actions_facility[facility] = QtWidgets.QAction( facility, menu) self.__actions_facility[facility].setCheckable(True) menu.addAction(self.__actions_facility[facility]) self.__actions_facility[self.facility_default].setChecked(True) return menu