def setupMenu(self): super().setupMenu() #Add actions for catalogs. # http://docs.python.org/library/pkgutil.html#pkgutil.walk_packages menu = self.menu.catalogs from wic import menus catalogs = ('persons', 'locations', 'districts', 'regions', 'streets') for catalog in catalogs: modelName = catalog.capitalize() modelPath = 'papp.catalogs.' + catalog + '.' + modelName menus.addActionsToMenu(menu, ( menus.createAction(menu, modelName, lambda *args, p = modelPath: forms.openCatalogForm(p, db), icon = ':/icons/fugue/cards-address.png'), )) menu = self.menu.reports reports = ('phone_number_search', 'test', 'lissajous', 'repayment_schedule') for report in reports: reportName = report.capitalize() reportPath = 'papp.reports.' + report + '.Form' menus.addActionsToMenu(menu, ( menus.createAction(menu, reportName, lambda *args, p = reportPath: forms.openForm(p), icon = ':/icons/fugue/application-form.png'), ))
def showContextMenu(self, coord): if not hasattr(self, 'menu'): # create the context menu for Message Window self.menu = QtGui.QMenu(self.textEdit) menus.addActionsToMenu(self.menu, ( menus.createAction(self.textEdit, 'Clear', self.textEdit.clear, icon = ':/icons/fugue/eraser.png'), menus.createAction(self.textEdit, 'Copy', self.textEdit.copy, QtGui.QKeySequence.Copy, ':/icons/fugue/document-copy.png'), menus.createAction(self.textEdit, 'Select all', self.textEdit.selectAll, QtGui.QKeySequence.SelectAll, ':/icons/fugue/selection-select.png'), )) self.menu.popup(self.textEdit.mapToGlobal(coord))
def setupToolbar(self, toolbar): assert isinstance(toolbar, QtGui.QToolBar) menu = Bunch() menu.createItem = menus.createAction(toolbar, 'Create new item', self.createItem, 'Insert', ':/icons/fugue/plus.png') menu.editItem = menus.createAction(toolbar, 'Edit selected item', self.editItem, 'Enter', ':/icons/fugue/pencil.png') menu.deleteItem = menus.createAction(toolbar, 'Delete selected item', self.deleteItem, 'Delete', ':/icons/fugue/cross.png') menus.addActionsToMenu(toolbar, (menu.createItem, menu.editItem, menu.deleteItem)) toolbar.setIconSize(QtCore.QSize(16, 16)) self.menu = menu
def contextMenuEvent(self, qContextMenuEvent): menu = getattr(self, 'menu', None) if not menu: from wic import menus menu = QtGui.QMenu(self) # context menu menus.addActionsToMenu(menu, ( menus.createAction(menu, 'Select', self.selectItem, 'Insert', ':/icons/fugue/cards-stack.png'), menus.createAction(menu, 'Open', self.openItem, 'Space', ':/icons/fugue/card-address.png'), menus.createAction(menu, 'Clear', self.clear, 'Delete', ':/icons/fugue/eraser.png'), )) self.menu = menu menu.popup(qContextMenuEvent.globalPos())
def onContextMenuRequested(self, coord): from wic import menus menu = QtGui.QMenu(self) menus.addActionsToMenu(menu, (menus.createAction(menu, "Save this form into a *.ui file.", self.saveFormToUi),)) menu.popup(self.mapToGlobal(coord))
def onTableViewContextMenuRequested(self, coord): menu = QtGui.QMenu(self.tableView) menus.addActionsToMenu(menu, (self.menu.createItem, self.menu.editItem, self.menu.deleteItem)) menu.popup(self.tableView.viewport().mapToGlobal(coord))