def updateFileMenu(self): """ Updates the file menu dynamically, so that recent files can be shown. """ self.menuFile.clear() # self.menuFile.addAction(self.actionNew) # disable for now self.menuFile.addAction(self.actionOpen) self.menuFile.addAction(self.actionSave) self.menuFile.addAction(self.actionSave_as) self.menuFile.addAction(self.actionClose_Model) recentFiles = [] for filename in self.recentFiles: if QFile.exists(filename): recentFiles.append(filename) if len(self.recentFiles) > 0: self.menuFile.addSeparator() for i, filename in enumerate(recentFiles): action = QAction("&%d %s" % (i + 1, QFileInfo(filename).fileName()), self) action.setData(filename) action.setStatusTip("Opens recent file %s" % QFileInfo(filename).fileName()) action.setShortcut(QKeySequence(Qt.CTRL | (Qt.Key_1 + i))) action.triggered.connect(self.load_model) self.menuFile.addAction(action) self.menuFile.addSeparator() self.menuFile.addAction(self.actionQuit)
def popup_menu(self, position): selected_row = self.view.rowAt(position.y()) if selected_row >= 0 and self._used_categories and len( self._used_categories) > 1: category_menu = QMenu(_("Categories")) selected_doc = self.model.object_at(selected_row) category_actions = [] for category in self._used_categories: a = QAction(category.full_name, category_menu) a.setData(category) a.setEnabled(selected_doc.document_category_id != category.document_category_id) category_menu.addAction(a) category_actions.append(a) action = category_menu.exec_(QCursor.pos()) if action: new_category = action.data() if selected_doc.document_category_id != new_category.document_category_id: selected_doc.document_category_id = new_category.document_category_id self.model.signal_object_change(selected_doc)
def updateRecentFilesMenu(self): #If there is a current file open, add it to the recent files list. if self.file_name and MainWindow.recentFiles.count(self.file_name) == 0: #Prepend the file to recentFiles MainWindow.recentFiles.insert(0, self.file_name) #This this is the only time files get added to recentFiles, #enforce the maximum length of recentFiles now. while len(MainWindow.recentFiles) > 9: MainWindow.recentFiles.pop() recent_files = [] #For each file in recentFiles, check that it exists and is readable. for fname in MainWindow.recentFiles: if os.access(fname, os.F_OK): recent_files.append(fname) MainWindow.recentFiles = recent_files #Now create an action for each file. if recent_files: action_list = [] for i, fname in enumerate(recent_files): new_action = QAction("%d. %s"%(i, fname), self, triggered=self.openRecentFile) new_action.setData(fname) action_list.append(new_action) #Now update the recent files menu on every window. for window in MainWindow.instances: window.menuRecent.clear() window.menuRecent.addActions(action_list)
def updateFileMenu(self): """ Updates the file menu dynamically, so that recent files can be shown. """ self.menuFile.clear() # self.menuFile.addAction(self.actionNew) # disable for now self.menuFile.addAction(self.actionOpen) self.menuFile.addAction(self.actionSave) self.menuFile.addAction(self.actionSave_as) self.menuFile.addAction(self.actionClose_Model) recentFiles = [] for filename in self.recentFiles: if QFile.exists(filename): recentFiles.append(filename) if len(self.recentFiles) > 0: self.menuFile.addSeparator() for i, filename in enumerate(recentFiles): action = QAction("&%d %s" % (i + 1, QFileInfo(filename).fileName()), self) action.setData(filename) action.setStatusTip("Opens recent file %s" % QFileInfo(filename).fileName()) action.setShortcut(QKeySequence(Qt.CTRL | (Qt.Key_1+i))) action.triggered.connect(self.load_model) #self.connect(action, SIGNAL("triggered()"), self.load_model) self.menuFile.addAction(action) self.menuFile.addSeparator() self.menuFile.addAction(self.actionQuit)
def traverseForInit(arr, target): for item in arr[1:]: if isinstance(item, list): target.addMenu(ContextMenu(item, target)) elif isinstance(item, basestring): target.addAction(QAction(target.tr(item), target)) elif isinstance(item, tuple): title, data = item action = QAction(target.tr(title), target) action.setData(data) target.addAction(action) else: target.addSeparator()
def updateWindowMenu(self): #aboutToShow() does not do what Mark Summerfield thinks it does--at least in PySide. #Generate a list of actions to add to the Window menu. window_menu_actions = [] for i, window in enumerate(MainWindow.instances): #The following line removes the "[*]" from the titleName. title_name = ''.join(window.titleName.split("[*]")) action_text = "%d. %s" % (i, title_name) new_action = QAction(action_text, self, triggered=self.raiseWindow) new_action.setData(window.titleName) window_menu_actions.append(new_action) for window in MainWindow.instances: window.menuWindow.clear() for new_action in window_menu_actions: window.menuWindow.addAction(new_action)
def __init__(self, parent=None): super(Status, self).__init__(parent) self.setupUi(self) self.base = parent self.wait_anim = QMovie(":/stuff/wait.gif") self.anim_lbl.setMovie(self.wait_anim) self.anim_lbl.hide() self.show_menu = QMenu(self) for i in [ self.act_page, self.act_date, self.act_text, self.act_comment ]: self.show_menu.addAction(i) # noinspection PyUnresolvedReferences i.triggered.connect(self.on_show_items) i.setChecked(True) sort_menu = QMenu(self) ico_sort = QIcon(":/stuff/sort.png") group = QActionGroup(self) action = QAction(_("Date"), sort_menu) action.setCheckable(True) action.setChecked(not self.base.high_by_page) action.triggered.connect(self.base.set_highlight_sort) action.setData(False) group.addAction(action) sort_menu.addAction(action) action = QAction(_("Page"), sort_menu) action.setCheckable(True) action.setChecked(self.base.high_by_page) action.triggered.connect(self.base.set_highlight_sort) action.setData(True) group.addAction(action) sort_menu.addAction(action) sort_menu.setIcon(ico_sort) sort_menu.setTitle(_("Sort by")) self.show_menu.addMenu(sort_menu) self.show_items_btn.setMenu(self.show_menu)
def addRecentOntology(self, ontology): count = len(self.menuRecent_Ontologies.actions()) count = count - 2 # remove the separator action and the clear history action. name = str(count + 1) name += ". " name += ontology.name name += ".kif" found = False for a in self.menuRecent_Ontologies.actions(): o = a.data() if o is None: continue if o.__eq__(ontology): found = True break if not found: befAction = self.menuRecent_Ontologies.actions()[count] action = QAction(self.menuRecent_Ontologies) action.setText(name) action.setData(ontology) callback = partial(self.addOntology, ontology) action.triggered.connect(callback) self.menuRecent_Ontologies.insertAction(befAction, action)
def makeVersionActionForSingleClip(self, version): """This is used to populate the QAction list of Versions when a single Clip is selected in the BinView. It also triggers the Version Update action based on the version passed to it. (Not sure if this is good design practice, but it's compact!)""" action = QAction(version.name(),None) action.setData(lambda: version) def updateAllTrackItems(): currentClip = version.item() trackItems = currentClip.whereAmI() if not trackItems: return proj = currentClip.project() # A Sequence-Shot manifest dictionary sequenceShotManifest = {} # Make this all undo-able in a single Group undo with proj.beginUndo("Update All Versions for %s" % currentClip.name()): for shot in trackItems: seq = shot.parentSequence() if seq not in sequenceShotManifest.keys(): sequenceShotManifest[seq] = [shot] else: sequenceShotManifest[seq]+=[shot] shot.setCurrentVersion(version) # We also should update the current Version of the selected Clip for completeness... currentClip.binItem().setActiveVersion(version) # Now disaplay a Dialog which informs the user of where and what was changed self.showVersionUpdateReportFromShotManifest(sequenceShotManifest) action.triggered.connect( updateAllTrackItems ) return action
def _make_days_off_menu_and_action_group(self): # We use a action group to be able to use the data() of actions # when action is tigerred # Call this ONLY ONCE because there are signal/slot connections. self.days_off_menu = QMenu(_("Day off")) self.days_off_add_submenu = QMenu(_("Set day off")) self.days_off_action_group = QActionGroup(self) for det in DayEventType.symbols(): a_one = QAction(_("Set one day"), self.days_off_action_group) a_one.setData((det.value, 1)) a_half = QAction(_("Set half day"), self.days_off_action_group) a_half.setData((det.value, 0.5)) a_period = QAction(_("Set period"), self.days_off_action_group) a_period.setData((det.value, 2)) self.days_off_action_group.addAction(a_one) self.days_off_action_group.addAction(a_half) self.days_off_action_group.addAction(a_period) m = QMenu(_("Set time off for {}").format(det.description)) m.addAction(a_one) m.addAction(a_half) m.addAction(a_period) self.days_off_add_submenu.addMenu(m) self.days_off_action_group.triggered.connect(self._add_day_off) self.day_off_remove_action = QAction(_("Remove day off"), self) self.day_off_remove_action.triggered.connect(self._remove_day_off) # Now we have the actions, we build the menu self.days_off_menu.addMenu(self.days_off_add_submenu) self.days_off_menu.addAction(self.day_off_remove_action)
from hiero.ui import registerAction from PySide.QtGui import QAction, QIcon # This creates an action with an icon and effect named 'Awesome OCIO' action = QAction(QIcon("icons:TCStop.png"), "Slug", None) # Soft effect actions can be found by prefixing the QAction's objectName with: 'foundry.timeline.effect' action.setObjectName("foundry.timeline.effect.addSlug") # You can optionally set a tooltip for this action action.setToolTip("Will apply a Slug Gizmo") # Setting of Data here will point to the Nuke node class name. # Here, we assume there is a plugin with a Class name 'AwesomeOCIO' # Note: for soft effects to work, the Nuke node must use a gpuEngine implementation. action.setData("Slug") # This registers your custom action with the Effects Menu registerAction(action) # This creates an action with an icon and effect named 'SuperGrade' action = QAction(QIcon("icons:LUT.png"), "SuperGrade", None) # Soft effect actions can be found by prefixing the QAction's objectName with: 'foundry.timeline.effect.' action.setObjectName("foundry.timeline.effect.addCustomGrade") # You can optionally set a tooltip for this action action.setToolTip("Will apply a Custom Grade soft effect") action.setData("SuperGrade")