def customContext(self, pos): index = self.listView.indexAt(pos) index = self.proxyModel.mapToSource(index) if not index.isValid(): self.rmAction.setEnabled(False) self.openAction.setEnabled(False) self.loadAction.setEnabled(False) elif not self.model.isDir(index): info = self.model.fileInfo(index) suffix = info.suffix() if suffix in ("Rd","Rdata","RData"): self.loadAction.setEnabled(True) self.openAction.setEnabled(False) self.loadExternal.setEnabled(False) elif suffix in ("txt","csv","R","r"): self.openAction.setEnabled(True) self.loadAction.setEnabled(False) self.loadExternal.setEnabled(True) else: self.loadAction.setEnabled(False) self.openAction.setEnabled(False) self.loadExternal.setEnabled(True) menu = QMenu(self) for action in self.actions: menu.addAction(action) menu.exec_(self.listView.mapToGlobal(pos))
class FlowWidget(QGraphicsView): def __init__(self, parent=None): QGraphicsView.__init__(self, parent) self.setAcceptDrops(True) self.setScene(FlowScene(self)) self.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) self.setAlignment(Qt.AlignLeft | Qt.AlignTop) self.autoConnecter = ItemAutoConnecter(self.scene()) self.setupMenu() #self.scrollControl = ScrollControl( self ) #self.scrollControl.setScrollingEnabled( False ) def setupMenu(self): self.setContextMenuPolicy(Qt.CustomContextMenu) self.menu = QMenu(self) self.connect(self, SIGNAL('customContextMenuRequested( const QPoint& )'), self.slotContextMenu) def slotContextMenu(self, pos): self.menu.clear() item = self.itemAt(pos) if isinstance(item, FlowSceneGraphEdge): self.menu.addAction(item.delete_action) self.menu.addAction(self.autoConnecter.action()) self.autoConnecter.updateAction() self.menu.exec_(self.mapToGlobal(pos)) # Zoom by scroll event # def wheelEvent( self, event ): # factor = 1.2 # if event.delta() < 0: # factor = 1.0 / factor # self.scale( factor, factor ) # #self.updateZoomValue() # return QGraphicsView.wheelEvent( self, event ) def dragEnterEvent(self, event): if isinstance(event.source(), FlowItemTreeWidget): event.acceptProposedAction() def dragMoveEvent(self, event): pass def dropEvent(self, event): type_ = event.source().selectedIndexes()[0].data( Qt.UserRole).toPyObject() item = type_() item.setParent(self) item.setPos(self.mapToScene(event.pos())) self.scene().addItem(item)
def showMenu(self): """ Creates a menu to display for the editing of template information. """ item = self.uiMenuTREE.currentItem() menu = QMenu(self) act = menu.addAction('Add Menu...') act.setIcon(QIcon(projexui.resources.find('img/folder.png'))) act.triggered.connect(self.createMenu) if (item and item.data(0, Qt.UserRole) == 'menu'): act = menu.addAction('Rename Menu...') ico = QIcon(projexui.resources.find('img/edit.png')) act.setIcon(ico) act.triggered.connect(self.renameMenu) act = menu.addAction('Add Separator') act.setIcon(QIcon(projexui.resources.find('img/ui/splitter.png'))) act.triggered.connect(self.createSeparator) menu.addSeparator() act = menu.addAction('Remove Item') act.setIcon(QIcon(projexui.resources.find('img/remove.png'))) act.triggered.connect(self.removeItem) act.setEnabled(item is not None) menu.exec_(QCursor.pos())
def textEffectMenu(self): format = self.currentCharFormat() cursor = self.textCursor() blockformat = cursor.blockFormat() menu = QMenu("Text Effect") for text, shortcut, data, checked in ( ("&Bold", "Ctrl+B", notetextedit.Bold, self.fontWeight() > QFont.Normal), ("&Italic", "Ctrl+I", notetextedit.Italic, self.fontItalic()), ("&Monospaced", None, notetextedit.Code, self.fontFixedPitch()) ): action = menu.addAction(text, self.setTextEffect) #if shortcut is not None: #action.setShortcut(QKeySequence(shortcut)) # becau action.setData(QVariant(data)) action.setCheckable(True) action.setChecked(checked) menu.addSeparator() action = menu.addAction("Anchor", self.setTextEffect) action.setData(notetextedit.Anchor) action = menu.addAction("Code Block", self.setTextEffect) action.setData(notetextedit.Pre) action = menu.addAction("Numbered List", self.setTextEffect) action.setData(notetextedit.List) header_menu = QMenu("Header") action = header_menu.addAction('H1', self.setTextEffect) action.setData(notetextedit.H1) action.setCheckable(True) action.setChecked(self.which_header()=='H1') action = header_menu.addAction('H2', self.setTextEffect) action.setData(notetextedit.H2) action.setCheckable(True) action.setChecked(self.which_header()=='H2') action = header_menu.addAction('H3', self.setTextEffect) action.setData(notetextedit.H3) action.setCheckable(True) action.setChecked(self.which_header()=='H3') action = menu.addAction("Remove All Formatting", self.setTextEffect) action.setData(notetextedit.Remove) menu.addMenu(header_menu) menu.addSeparator() action = menu.addAction("Save", self.setTextEffect) action.setData(notetextedit.Save) self.ensureCursorVisible() menu.exec_(self.viewport().mapToGlobal(self.cursorRect().center()))
def contextMenuEvent(self, event): menu = QMenu(self) Action = menu.addAction("delete row") Action.triggered.connect(self.deleteRow) menu.exec_(event.globalPos())
def contextMenuEvent(self, e): menu = QMenu(self) subMenu = QMenu(menu) titleHistoryMenu = QCoreApplication.translate("PythonConsole", "Command History") subMenu.setTitle(titleHistoryMenu) subMenu.addAction(QCoreApplication.translate("PythonConsole", "Show"), self.showHistory, 'Ctrl+Shift+SPACE') subMenu.addSeparator() subMenu.addAction(QCoreApplication.translate("PythonConsole", "Save"), self.writeHistoryFile) subMenu.addSeparator() subMenu.addAction( QCoreApplication.translate("PythonConsole", "Clear File"), self.clearHistory) subMenu.addAction( QCoreApplication.translate("PythonConsole", "Clear Session"), self.clearHistorySession) menu.addMenu(subMenu) menu.addSeparator() copyAction = menu.addAction( QCoreApplication.translate("PythonConsole", "Copy"), self.copy, QKeySequence.Copy) pasteAction = menu.addAction( QCoreApplication.translate("PythonConsole", "Paste"), self.paste, QKeySequence.Paste) copyAction.setEnabled(False) pasteAction.setEnabled(False) if self.hasSelectedText(): copyAction.setEnabled(True) if QApplication.clipboard().text(): pasteAction.setEnabled(True) menu.exec_(self.mapToGlobal(e.pos()))
def showSnippets(self, evt): popupmenu = QMenu() for name, snippet in self.snippets.iteritems(): action = QAction(self.tr(name), self.btnSnippets) action.triggered[()].connect(lambda snippet=snippet: self.editor.insert(snippet)) popupmenu.addAction(action) popupmenu.exec_(QCursor.pos())
def on_right_button(self, point): """Right button was pressed, build a menu.""" index = self.indexAt(point) row = index.row() episode_id = self._model.episodes[row].episode_id self._adjust_gui(episode_id) episode = self.main_window.programs_data[episode_id] menu = QMenu() mw = self.main_window act_play = menu.addAction(u"&Reproducir", lambda: mw.play_episode(episode)) act_cancel = menu.addAction(u"&Cancelar descarga", lambda: mw.cancel_download(episode)) act_download = menu.addAction(u"&Descargar", lambda: mw.queue_download(episode)) # set menu options according status state = episode.state if state == Status.downloaded: act_play.setEnabled(True) act_cancel.setEnabled(False) act_download.setEnabled(False) elif state == Status.downloading or state == Status.waiting: act_play.setEnabled(False) act_cancel.setEnabled(True) act_download.setEnabled(False) elif state == Status.none: act_play.setEnabled(False) act_cancel.setEnabled(False) if self.main_window.have_config(): act_download.setEnabled(True) else: act_download.setEnabled(False) menu.exec_(self.viewport().mapToGlobal(point))
def selectOutput(self): if isinstance(self.output, OutputDirectory): self.selectDirectory() else: popupMenu = QMenu() actionSaveToTempFile = QAction( self.tr('Save to a temporary file'), self.btnSelect) actionSaveToTempFile.triggered.connect(self.saveToTemporaryFile) popupMenu.addAction(actionSaveToTempFile) actionSaveToFile = QAction( self.tr('Save to file...'), self.btnSelect) actionSaveToFile.triggered.connect(self.selectFile) popupMenu.addAction(actionSaveToFile) if isinstance(self.output, OutputVector) \ and self.alg.provider.supportsNonFileBasedOutput(): actionSaveToMemory = QAction( self.tr('Save to memory layer'), self.btnSelect) actionSaveToMemory.triggered.connect(self.saveToMemory) popupMenu.addAction(actionSaveToMemory) actionSaveToPostGIS = QAction( self.tr('Save to PostGIS table...'), self.btnSelect) actionSaveToPostGIS.triggered.connect(self.saveToPostGIS) settings = QSettings() settings.beginGroup('/PostgreSQL/connections/') names = settings.childGroups() settings.endGroup() actionSaveToPostGIS.setEnabled(bool(names)) popupMenu.addAction(actionSaveToPostGIS) popupMenu.exec_(QCursor.pos())
def process_custom_menu(self, point): ''' See XmlController for documentation ''' item = self.select_item_at(point) if not item: return menu = QMenu() node = item.node if node.get('executable') == 'True': menu.addAction(self.actRunScenario) elif node.get('type') in ['selectable', 'model_choice']: menu.addAction(self.actMoveNodeUp) menu.addAction(self.actMoveNodeDown) elif node.tag == 'models_to_run': # special case of a selectable list models_menu = QMenu(menu) models_menu.setTitle('Add model to run') models_menu.setIcon(IconLibrary.icon('add')) available_model_names = get_model_names(self.project) for model_name in available_model_names: cb = lambda x=model_name, y=self.selected_index( ): self.addModel(y, x) action = self.create_action('model', model_name, cb) models_menu.addAction(action) menu.addMenu(models_menu) self.add_default_menu_items_for_node(node, menu) if not menu.isEmpty(): menu.exec_(QCursor.pos())
def showHeaderMenu( self, point ): # determine the column that was clicked on index = self.uiPlaylistTREE.header().logicalIndexAt(point) self._currentHeaderColumn = index # create the menu menu = QMenu(self) act = menu.addAction( 'Sort Ascending' ) act.setIcon( resources.icon( 'img/playlist/sort_ascending.png' ) ) act.triggered.connect( self.sortAscending ) act = menu.addAction( 'Sort Descending' ) act.setIcon( resources.icon( 'img/playlist/sort_descending.png' ) ) act.triggered.connect( self.sortDescending ) menu.addSeparator() # create a columns menu columns = menu.addMenu( 'Columns...' ) columns.setIcon( resources.icon( 'img/playlist/columns.png' ) ) for c, col in enumerate(self.COLUMNS): act = columns.addAction( col ) act.setCheckable(True) act.setChecked( not self.uiPlaylistTREE.isColumnHidden(c) ) columns.triggered.connect( self.toggleColumnTriggered ) # popup the menu menu.exec_( QCursor.pos() )
def contextMenuEvent(self, event): menu = QMenu(self) Action = menu.addAction("print selected rows") Action.triggered.connect(self.printName) menu.exec_(event.globalPos())
def _load_menu_for_root(self, point): """ Carga el menú para el root """ menu = QMenu(self) create_file_action = menu.addAction(QIcon(":image/add"), self.tr("Agregar Archivo")) create_folder_action = menu.addAction(QIcon(":image/new-folder"), self.tr("Agregar Carpeta")) menu.addSeparator() refresh_project_action = menu.addAction(QIcon(":image/reload"), self.tr("Recargar Proyecto")) close_project_action = menu.addAction(QIcon(":image/exit"), self.tr("Cerrar Proyecto")) # Conexiones self.connect(create_file_action, SIGNAL("triggered()"), self._create_file) self.connect(create_folder_action, SIGNAL("triggered()"), self._create_folder) self.connect(refresh_project_action, SIGNAL("triggered()"), self._refresh_project) self.connect(close_project_action, SIGNAL("triggered()"), self._close_project) menu.exec_(self.mapToGlobal(point))
def _load_menu_for_edis_project(self, point): """ Carga el menú para el root (proyecto de Edis) """ menu = QMenu(self) create_file_action = menu.addAction(QIcon(":image/add"), self.tr("Agregar Archivo")) create_main_file_action = menu.addAction( self.tr("Agregar Archivo main")) menu.addSeparator() build_project_action = menu.addAction(QIcon(":image/build"), self.tr("Compilar Proyecto")) clean_project_action = menu.addAction(self.tr("Limpiar")) menu.addSeparator() properties_action = menu.addAction(self.tr("Propiedades del Proyecto")) menu.addSeparator() close_project_action = menu.addAction(QIcon(":image/exit"), self.tr("Cerrar Proyecto")) # Conexiones self.connect(create_file_action, SIGNAL("triggered()"), self._create_file) self.connect(create_main_file_action, SIGNAL("triggered()"), self._create_main_file) self.connect(build_project_action, SIGNAL("triggered()"), self._build_project) self.connect(clean_project_action, SIGNAL("triggered()"), self._clean_project) self.connect(properties_action, SIGNAL("triggered()"), self._project_properties) self.connect(close_project_action, SIGNAL("triggered()"), self._close_project) menu.exec_(self.mapToGlobal(point))
def showContextMenu(self): opts = [ [_("Mark Note"), "*", self.onMark], [_("Bury Note"), "-", self.onBuryNote], [_("Suspend Card"), "@", self.onSuspendCard], [_("Suspend Note"), "!", self.onSuspend], [_("Delete Note"), "Delete", self.onDelete], [_("Options"), "O", self.onOptions], None, [_("Replay Audio"), "R", self.replayAudio], [_("Record Own Voice"), "Shift+V", self.onRecordVoice], [_("Replay Own Voice"), "V", self.onReplayRecorded], ] m = QMenu(self.mw) for row in opts: if not row: m.addSeparator() continue label, scut, func = row a = m.addAction(label) a.setShortcut(QKeySequence(scut)) a.connect(a, SIGNAL("triggered()"), func) #Only change is the following statement runHook("Reviewer.contextMenuEvent", self, m) m.exec_(QCursor.pos())
def displayHandMenu(self, pt): def flipCard(): for index in self.lvHand.selectedIndexes(): self.handModel.flipCardAtIndex(index) menu = QMenu(self) menu.addAction("Flip", flipCard) menu.exec_(self.lvHand.mapToGlobal(pt))
def _menu_context_tree(self, point): index = self.indexAt(point) if not index.isValid(): return menu = QMenu(self) f_all = menu.addAction(self.tr("Fold all")) u_all = menu.addAction(self.tr("Unfold all")) menu.addSeparator() u_class = menu.addAction(self.tr("Unfold classes")) u_class_method = menu.addAction(self.tr("Unfold classes and methods")) u_class_attr = menu.addAction(self.tr("Unfold classes and attributes")) menu.addSeparator() #save_state = menu.addAction(self.tr("Save State")) self.connect(f_all, SIGNAL("triggered()"), lambda: self.collapseAll()) self.connect(u_all, SIGNAL("triggered()"), lambda: self.expandAll()) self.connect(u_class, SIGNAL("triggered()"), self._unfold_class) self.connect(u_class_method, SIGNAL("triggered()"), self._unfold_class_method) self.connect(u_class_attr, SIGNAL("triggered()"), self._unfold_class_attribute) #self.connect(save_state, SIGNAL("triggered()"), #self._save_symbols_state) menu.exec_(QCursor.pos())
def showCellContextMenu(self, point): """Display the menu that occurs when right clicking on a table cell.""" clickedCell = self.indexAt(point) if not clickedCell.isValid(): # User clicked on a part of the table without a cell return False cellMenu = QMenu(self) insertCellAction = QAction("Insert Cells", cellMenu) deleteCellAction = QAction("Delete Cells", cellMenu) cellMenu.addAction(insertCellAction) cellMenu.addAction(deleteCellAction) # Connect signals insertCellAction.triggered.connect(self.insertCells) deleteCellAction.triggered.connect(self.deleteCells) # Display menu cellMenu.exec_(self.mapToGlobal(point)) # Disconnect signals insertCellAction.triggered.disconnect(self.insertCells) deleteCellAction.triggered.disconnect(self.deleteCells)
def _menu_context_tree(self, point): index = self.indexAt(point) if not index.isValid(): return item = self.itemAt(point) handler = None menu = QMenu(self) if item.isFolder or item.parent() is None: self._add_context_menu_for_folders(menu, item) elif not item.isFolder: self._add_context_menu_for_files(menu, item) if item.parent() is None: #get the extra context menu for this projectType handler = settings.get_project_type_handler(item.projectType) self._add_context_menu_for_root(menu, item) menu.addMenu(self._folding_menu) #menu for all items (legacy API)! extra_menus = self.extra_menus.get('all', ()) #menu for all items! for m in extra_menus: if isinstance(m, QMenu): menu.addSeparator() menu.addMenu(m) #menu for the Project Type(if present) if handler: for m in handler.get_context_menus(): if isinstance(m, QMenu): menu.addSeparator() menu.addMenu(m) #show the menu! menu.exec_(QCursor.pos())
def activated(self, reason): if reason == QSystemTrayIcon.DoubleClick: self.setup() elif reason == QSystemTrayIcon.Trigger: menu = QMenu() self.populateMenuFromSettings(menu) menu.exec_(QCursor.pos())
def showPopupMenu(self, point): item = self.algorithmTree.itemAt(point) if isinstance(item, TreeAlgorithmItem): alg = item.alg popupmenu = QMenu() executeAction = QAction(self.tr('Execute'), self.algorithmTree) executeAction.triggered.connect(self.executeAlgorithm) popupmenu.addAction(executeAction) if alg.canRunInBatchMode and not alg.allowOnlyOpenedLayers: executeBatchAction = QAction( self.tr('Execute as batch process'), self.algorithmTree) executeBatchAction.triggered.connect( self.executeAlgorithmAsBatchProcess) popupmenu.addAction(executeBatchAction) popupmenu.addSeparator() editRenderingStylesAction = QAction( self.tr('Edit rendering styles for outputs'), self.algorithmTree) editRenderingStylesAction.triggered.connect( self.editRenderingStyles) popupmenu.addAction(editRenderingStylesAction) actions = Processing.contextMenuActions if len(actions) > 0: popupmenu.addSeparator() for action in actions: action.setData(alg, self) if action.isEnabled(): contextMenuAction = QAction(action.name, self.algorithmTree) contextMenuAction.triggered.connect(action.execute) popupmenu.addAction(contextMenuAction) popupmenu.exec_(self.algorithmTree.mapToGlobal(point))
def showMenu( self ): """ Creates a menu to display for the editing of template information. """ item = self.uiMenuTREE.currentItem() menu = QMenu(self) act = menu.addAction('Add Menu...') act.setIcon(QIcon(projexui.resources.find('img/folder.png'))) act.triggered.connect(self.createMenu) if ( item and item.data(0, Qt.UserRole) == 'menu' ): act = menu.addAction('Rename Menu...') ico = QIcon(projexui.resources.find('img/edit.png')) act.setIcon(ico) act.triggered.connect(self.renameMenu) act = menu.addAction('Add Separator') act.setIcon(QIcon(projexui.resources.find('img/ui/splitter.png'))) act.triggered.connect(self.createSeparator) menu.addSeparator() act = menu.addAction('Remove Item') act.setIcon(QIcon(projexui.resources.find('img/remove.png'))) act.triggered.connect(self.removeItem) act.setEnabled(item is not None) menu.exec_(QCursor.pos())
def _menu_context_tree(self, point, isRoot=False, root_path=None): index = self.indexAt(point) if not index.isValid() and not isRoot: return handler = None menu = QMenu(self) if isRoot or self.model().isDir(index): self._add_context_menu_for_folders(menu, isRoot, root_path) else: filename = self.model().fileName(index) lang = file_manager.get_file_extension(filename) self._add_context_menu_for_files(menu, lang) if isRoot: #get the extra context menu for this projectType handler = settings.get_project_type_handler( self.project.project_type) self._add_context_menu_for_root(menu) menu.addMenu(self._folding_menu) #menu for the Project Type(if present) if handler: for m in handler.get_context_menus(): if isinstance(m, QMenu): menu.addSeparator() menu.addMenu(m) #show the menu! menu.exec_(QCursor.pos())
def _onTvFilesCustomContextMenuRequested(self, pos ): """Connected automatically by uic """ menu = QMenu() menu.addAction( core.actionManager().action( "mFile/mClose/aCurrent" ) ) menu.addAction( core.actionManager().action( "mFile/mSave/aCurrent" ) ) menu.addAction( core.actionManager().action( "mFile/mReload/aCurrent" ) ) menu.addSeparator() # sort menu sortMenu = QMenu( self ) group = QActionGroup( sortMenu ) group.addAction( self.tr( "Opening order" ) ) group.addAction( self.tr( "File name" ) ) group.addAction( self.tr( "URL" ) ) group.addAction( self.tr( "Suffixes" ) ) group.triggered.connect(self._onSortTriggered) sortMenu.addActions( group.actions() ) for i, sortMode in enumerate(["OpeningOrder", "FileName", "URL", "Suffixes"]): action = group.actions()[i] action.setData( sortMode ) action.setCheckable( True ) if sortMode == self.model.sortMode(): action.setChecked( True ) aSortMenu = QAction( self.tr( "Sorting" ), self ) aSortMenu.setMenu( sortMenu ) aSortMenu.setIcon( QIcon( ":/enkiicons/sort.png" )) aSortMenu.setToolTip( aSortMenu.text() ) menu.addAction( sortMenu.menuAction() ) menu.exec_( self.tvFiles.mapToGlobal( pos ) )
def slotShowContextMenu(self, pos): hit = self.webview.page().currentFrame().hitTestContent(pos) menu = QMenu() if hit.linkUrl().isValid(): a = self.webview.pageAction(QWebPage.CopyLinkToClipboard) a.setIcon(icons.get("edit-copy")) a.setText(_("Copy &Link")) menu.addAction(a) menu.addSeparator() a = menu.addAction(icons.get("window-new"), _("Open Link in &New Window")) a.triggered.connect( (lambda url: lambda: self.slotNewWindow(url))(hit.linkUrl())) else: if hit.isContentSelected(): a = self.webview.pageAction(QWebPage.Copy) a.setIcon(icons.get("edit-copy")) a.setText(_("&Copy")) menu.addAction(a) menu.addSeparator() a = menu.addAction(icons.get("window-new"), _("Open Document in &New Window")) a.triggered.connect((lambda url: lambda: self.slotNewWindow(url))( self.webview.url())) if menu.actions(): menu.exec_(self.webview.mapToGlobal(pos))
def show_popup_menu(self, point): """ Right click in the tree @param point:Cursor's point @type point:QPoint """ item = self.treeQueries.itemAt(point) if isinstance(item, TreeQueryItem): config = item.query.getContent() # We set the query self.current_query = config['metadata']['query'] # We create the menu popup_menu = QMenu() execute_action = QAction( tr('QuickOSM', 'Execute'), self.treeQueries) # noinspection PyUnresolvedReferences execute_action.triggered.connect(self.open_and_run_query) popup_menu.addAction(execute_action) show_action = QAction( tr('QuickOSM', 'Show query'), self.treeQueries) # noinspection PyUnresolvedReferences show_action.triggered.connect(self.show_query) popup_menu.addAction(show_action) delete_action = QAction( tr('QuickOSM', 'Delete'), self.treeQueries) # noinspection PyUnresolvedReferences delete_action.triggered.connect(self.delete_query) popup_menu.addAction(delete_action) popup_menu.exec_(self.treeQueries.mapToGlobal(point))
def showPopupMenu(self, point): item = self.algorithmTree.itemAt(point) if isinstance(item, TreeAlgorithmItem): alg = item.alg popupmenu = QMenu() executeAction = QAction(self.tr("Execute"), self.algorithmTree) executeAction.triggered.connect(self.executeAlgorithm) popupmenu.addAction(executeAction) if alg.canRunInBatchMode and not alg.allowOnlyOpenedLayers: executeBatchAction = QAction(self.tr("Execute as batch process"), self.algorithmTree) executeBatchAction.triggered.connect(self.executeAlgorithmAsBatchProcess) popupmenu.addAction(executeBatchAction) popupmenu.addSeparator() editRenderingStylesAction = QAction(self.tr("Edit rendering styles for outputs"), self.algorithmTree) editRenderingStylesAction.triggered.connect(self.editRenderingStyles) popupmenu.addAction(editRenderingStylesAction) actions = Processing.contextMenuActions if len(actions) > 0: popupmenu.addSeparator() for action in actions: action.setData(alg, self) if action.isEnabled(): contextMenuAction = QAction(action.name, self.algorithmTree) contextMenuAction.triggered.connect(action.execute) popupmenu.addAction(contextMenuAction) popupmenu.exec_(self.algorithmTree.mapToGlobal(point))
def contextMenuRequested(point): " quick and dirty custom context menu " menu = QMenu() menu.addActions( ( qaqq, qamin, qanor, qamax, qasrc, qakb, qacol, qati, qasb, qatb, qatim, qatit, qafnt, qapic, qadoc, qali, qaslf, qaqt, qapy, qabug, ) ) menu.exec_(self.mapToGlobal(point))
def show_context_menu(self, item, resource, where): menu = QMenu() # Load layers action action_open_layer = QAction(self.tr(u'Carregar camada'), None) action_open_layer.triggered.connect( lambda: self._load_layer_on_qgis(resource)) menu.addAction(action_open_layer) # Load layers as... # action_open_layer_as = QAction(self.tr(u'Carregar camada como...'), None) # action_open_layer_as.triggered.connect(lambda: self._load_layer_from_url(item.text(0), item.text(1))) # menu.addAction(action_open_layer_as) menu.addSeparator() # Montar Operações action_open_editor = QAction(self.tr(u'Montar operações'), None) action_open_editor.triggered.connect( lambda: self.open_operations_editor(item.text(0), item.text(1))) menu.addAction(action_open_editor) menu.addSeparator() action_edit = QAction(self.tr(u'Editar'), None) action_edit.triggered.connect(lambda: self.open_edit_dialog(item)) menu.addAction(action_edit) menu.exec_(self.list_resource.viewport().mapToGlobal(where))
def on_context_menu(self, point): item = self.dock.treeWidget.itemAt(point) if item is None: return if item.actiontype is None: return actionDict = {'application': ('Copy Application', 'Load all layers to QGIS', 'Application Settings', 'View Application in web browser', 'Delete Application'), 'layer': ('Add Layer to QGIS','Layer Settings', 'Delete Layer'), 'qgisLayerReference': ('Upload New Style', 'Apply Original Style'), 'applicationsItem': ('Create New Application', 'Refresh Applications'), 'layersItem':('Upload New Layer from QGIS', 'Refresh Layers'), 'connection':('Refresh Connection', 'Remove Connection'), 'topitem':['New Connection']} actions = actionDict[item.actiontype] menu = QMenu() acts = [] for actionName in actions: action = QAction(actionName, None) self.connectAction(action, actionName, item) acts.append(action) menu.addActions(acts) point = self.dock.treeWidget.mapToGlobal(point) menu.exec_(point)
def textEffectMenu(self): format = self.currentCharFormat() menu = QMenu("Text Effect") for text, shortcut, data, checked in ( ("&Bold", "Ctrl+B", RichTextLineEdit.Bold, self.fontWeight() > QFont.Normal), ("&Italic", "Ctrl+I", RichTextLineEdit.Italic, self.fontItalic()), ("Strike &out", None, RichTextLineEdit.StrikeOut, format.fontStrikeOut()), ("&Underline", "Ctrl+U", RichTextLineEdit.Underline, self.fontUnderline()), ("&Monospaced", None, RichTextLineEdit.Monospaced, format.fontFamily() == self.monofamily), ("&Serifed", None, RichTextLineEdit.Serif, format.fontFamily() == self.seriffamily), ("S&ans Serif", None, RichTextLineEdit.Sans, format.fontFamily() == self.sansfamily), ("&No super or subscript", None, RichTextLineEdit.NoSuperOrSubscript, format.verticalAlignment() == QTextCharFormat.AlignNormal), ("Su&perscript", None, RichTextLineEdit.Superscript, format.verticalAlignment() == QTextCharFormat.AlignSuperScript), ("Subs&cript", None, RichTextLineEdit.Subscript, format.verticalAlignment() == QTextCharFormat.AlignSubScript)): action = menu.addAction(text, self.setTextEffect) if shortcut is not None: action.setShortcut(QKeySequence(shortcut)) action.setData(QVariant(data)) action.setCheckable(True) action.setChecked(checked) self.ensureCursorVisible() menu.exec_(self.viewport().mapToGlobal(self.cursorRect().center()))
def contextMenuEvent(self, event): from_index = self._table.indexAt(event.pos()) if not (0 <= from_index.row() < self.model.rowCount()): return # The context menu event is the same regardless of the selected column # Therefore ColumnID is set such that the label name is retrieved from_index_to_name = self.model.index(from_index.row(), LabelListModel.ColumnID.Name) from_name = self.model.data(from_index_to_name, Qt.DisplayRole) menu = QMenu(parent=self) menu.addAction( "Clear {}".format(from_name), partial(self.clearRequested.emit, from_index_to_name.row(), str(from_name))) if self.support_merges and self.allowDelete: for to_row in range(self.model.rowCount()): to_index = self.model.index(to_row, LabelListModel.ColumnID.Name) to_name = self.model.data(to_index, Qt.DisplayRole) action = menu.addAction( "Merge {} into {}".format(from_name, to_name), partial(self.mergeRequested.emit, from_index_to_name.row(), str(from_name), to_row, str(to_name))) if to_row == from_index_to_name.row(): action.setEnabled(False) menu.exec_(self.mapToGlobal(event.pos()))
def process_custom_menu(self, point): item = self.select_item_at(point) if not item: return node = item.node menu = QMenu(self.view) # Populate menu if node.tag == 'run': menu.addAction(self.actGetInfoSimulationRuns) menu.addAction(self.actDeleteRun) elif node.tag == 'indicator_batches': menu.addAction(self.actAddNewIndicatorBatch) elif node.tag == 'simulation_runs': menu.addAction(self.actImportRun) elif node.tag == 'indicator_batch': menu.addAction(self.actAddVisualizationToBatch) run_batch_on_menu = QMenu('Run indicator batch on...') self._createBatchRunMenu(run_batch_on_menu) menu.addMenu(run_batch_on_menu) elif node.tag == 'batch_visualization': # get('type') == 'batch_visualization': menu.addAction(self.actConfigureExistingBatchIndicatorVis) self.add_default_menu_items_for_node(node, menu) if not menu.isEmpty(): menu.exec_(QCursor.pos())
def show_popup_menu(self, point): """ Right click in the tree @param point:Cursor's point @type point:QPoint """ item = self.treeQueries.itemAt(point) if isinstance(item, TreeQueryItem): config = item.query.getContent() # We set the query self.current_query = config['metadata']['query'] # We create the menu popup_menu = QMenu() execute_action = QAction(tr('QuickOSM', 'Execute'), self.treeQueries) # noinspection PyUnresolvedReferences execute_action.triggered.connect(self.open_and_run_query) popup_menu.addAction(execute_action) show_action = QAction(tr('QuickOSM', 'Show query'), self.treeQueries) # noinspection PyUnresolvedReferences show_action.triggered.connect(self.show_query) popup_menu.addAction(show_action) delete_action = QAction(tr('QuickOSM', 'Delete'), self.treeQueries) # noinspection PyUnresolvedReferences delete_action.triggered.connect(self.delete_query) popup_menu.addAction(delete_action) popup_menu.exec_(self.treeQueries.mapToGlobal(point))
def layercontextmenu(layer, pos, parent=None): '''Show a context menu to manipulate properties of layer. layer -- a volumina layer instance pos -- QPoint ''' menu = QMenu("Menu", parent) # Title title = QAction("%s" % layer.name, menu) title.setEnabled(False) menu.addAction(title) # Export global _has_lazyflow if _has_lazyflow: export = QAction("Export...", menu) export.setStatusTip("Export Layer...") export.triggered.connect( partial(get_settings_and_export_layer, layer, menu)) menu.addAction(export) menu.addSeparator() _add_actions(layer, menu) # Layer-custom context menu items menu.addSeparator() for name, callback in layer.contexts: action = QAction(name, menu) action.triggered.connect(callback) menu.addAction(action) menu.exec_(pos)
def layercontextmenu( layer, pos, parent=None, volumeEditor = None ): '''Show a context menu to manipulate properties of layer. layer -- a volumina layer instance pos -- QPoint ''' def onExport(): if _has_lazyflow: inputArray = layer.datasources[0].request((slice(None),)).wait() expDlg = ExportDialog(parent = menu) g = Graph() piper = OpArrayPiper(g) piper.inputs["Input"].setValue(inputArray) expDlg.setInput(piper.outputs["Output"],g) expDlg.show() menu = QMenu("Menu", parent) title = QAction("%s" % layer.name, menu) title.setEnabled(False) export = QAction("Export...",menu) export.setStatusTip("Export Layer...") export.triggered.connect(onExport) menu.addAction(title) menu.addAction(export) menu.addSeparator() _add_actions( layer, menu ) menu.exec_(pos)
def contextMenuEvent(self, e): menu = QMenu(self) subMenu = QMenu(menu) titleHistoryMenu = QCoreApplication.translate("PythonConsole", "Command History") subMenu.setTitle(titleHistoryMenu) subMenu.addAction( QCoreApplication.translate("PythonConsole", "Show"), self.showHistory, 'Ctrl+Shift+SPACE') subMenu.addSeparator() subMenu.addAction( QCoreApplication.translate("PythonConsole", "Save"), self.writeHistoryFile) subMenu.addSeparator() subMenu.addAction( QCoreApplication.translate("PythonConsole", "Clear File"), self.clearHistory) subMenu.addAction( QCoreApplication.translate("PythonConsole", "Clear Session"), self.clearHistorySession) menu.addMenu(subMenu) menu.addSeparator() copyAction = menu.addAction( QCoreApplication.translate("PythonConsole", "Copy"), self.copy, QKeySequence.Copy) pasteAction = menu.addAction( QCoreApplication.translate("PythonConsole", "Paste"), self.paste, QKeySequence.Paste) copyAction.setEnabled(False) pasteAction.setEnabled(False) if self.hasSelectedText(): copyAction.setEnabled(True) if QApplication.clipboard().text(): pasteAction.setEnabled(True) menu.exec_(self.mapToGlobal(e.pos()))
def createMenuAssigned(self, position): menu = QMenu() item = self.treeWidget.itemAt(position) if item: menu.addAction(self.tr('Show properties'), self.showAssignedProperties) menu.exec_(self.treeWidget.viewport().mapToGlobal(position))
def _load_menu_combo_file(self, point): """ Muestra el menú """ menu = QMenu() editor_container = Edis.get_component("principal") save_as_action = menu.addAction(QIcon(":image/save-as"), self.tr("Guardar como...")) reload_action = menu.addAction(QIcon(":image/reload"), self.tr("Recargar")) menu.addSeparator() compile_action = menu.addAction(QIcon(":image/build"), self.tr("Compilar")) execute_action = menu.addAction(QIcon(":image/run"), self.tr("Ejecutar")) menu.addSeparator() close_action = menu.addAction(QIcon(":image/close"), self.tr("Cerrar archivo")) # Conexiones self.connect(save_as_action, SIGNAL("triggered()"), editor_container.save_file_as) self.connect(reload_action, SIGNAL("triggered()"), editor_container.reload_file) self.connect(compile_action, SIGNAL("triggered()"), editor_container.build_source_code) self.connect(execute_action, SIGNAL("triggered()"), editor_container.run_binary) self.connect(close_action, SIGNAL("triggered()"), editor_container.close_file) menu.exec_(self.mapToGlobal(point))
def onBrowseConnection(self): s = QSettings() base = "/PostgreSQL/connections" s.beginGroup("/PostgreSQL/connections") children = s.childGroups() connections = {} map = { "dbname": "database", "host": "host", "port": "port", "service": "service", "password": "******", "user": "******" } for g in children: s.beginGroup(g) cstring = "" for k, v in map.items(): if s.value(v): cstring += k + "=" + s.value(v) + " " connections[g] = cstring s.endGroup() menu = QMenu(self) for k in sorted(connections.keys()): menu.addAction(k) def onMenu(action): self.dbConnectionText.setText(connections[action.text()]) self.reloadBtn.click() menu.triggered.connect(onMenu) menu.exec_(self.dbConnectionBtn.mapToGlobal(QPoint(0, 0)))
def process_custom_menu(self, point): ''' See XmlController for documentation ''' item = self.select_item_at(point) if not item: return menu = QMenu() node = item.node if node.get('executable') == 'True': menu.addAction(self.actRunScenario) elif node.get('type') in ['selectable', 'model_choice']: menu.addAction(self.actMoveNodeUp) menu.addAction(self.actMoveNodeDown) elif node.tag == 'models_to_run': # special case of a selectable list models_menu = QMenu(menu) models_menu.setTitle('Add model to run') models_menu.setIcon(IconLibrary.icon('add')) available_model_names = get_model_names(self.project) for model_name in available_model_names: cb = lambda x = model_name, y = self.selected_index(): self.addModel(y, x) action = self.create_action('model', model_name, cb) models_menu.addAction(action) menu.addMenu(models_menu) self.add_default_menu_items_for_node(node, menu) if not menu.isEmpty(): menu.exec_(QCursor.pos())
def _menu_context_tree(self, point): """Context menu""" index = self.tree.indexAt(point) if not index.isValid(): return menu = QMenu(self) f_all = menu.addAction(translations.TR_FOLD_ALL) u_all = menu.addAction(translations.TR_UNFOLD_ALL) menu.addSeparator() u_class = menu.addAction(translations.TR_UNFOLD_CLASSES) u_class_method = menu.addAction( translations.TR_UNFOLD_CLASSES_AND_METHODS) u_class_attr = menu.addAction( translations.TR_UNFOLD_CLASSES_AND_ATTRIBUTES) menu.addSeparator() #save_state = menu.addAction(self.tr("Save State")) self.connect(f_all, SIGNAL("triggered()"), lambda: self.tree.collapseAll()) self.connect(u_all, SIGNAL("triggered()"), lambda: self.tree.expandAll()) self.connect(u_class, SIGNAL("triggered()"), self._unfold_class) self.connect(u_class_method, SIGNAL("triggered()"), self._unfold_class_method) self.connect(u_class_attr, SIGNAL("triggered()"), self._unfold_class_attribute) #self.connect(save_state, SIGNAL("triggered()"), #self._save_symbols_state) menu.exec_(QCursor.pos())
def menuContextTree(self, point): index = self.indexAt(point) if not index.isValid(): return item = self.itemAt(point) name = str(item.text(0)) if item.isClickable: self.emit(SIGNAL("itemClicked(QTreeWidgetItem *, int)"), item, item.lineno) menu = QMenu(self) if item.isAttribute: createPropertyAction = menu.addAction('Create Property') self.connect( createPropertyAction, SIGNAL("triggered()"), lambda: self._main._central.obtain_editor().create_property( item.lineno, name)) if item.isClickable: renameAction = menu.addAction('Rename') self.connect( renameAction, SIGNAL("triggered()"), lambda: self._main._central.obtain_editor().refactor_rename( item.lineno, name)) menu.exec_(QCursor.pos())
def contextMenuEvent(self, ev): index = self.indexAt(ev.pos()) if not index.isValid(): return if index != self.currentIndex(): self.itemChanged(index) item = self.currentItem() menu = QMenu(self) if isinstance(item, (Table, Schema)): menu.addAction(self.tr("Rename"), self.rename) menu.addAction(self.tr("Delete"), self.delete) if isinstance(item, Table) and item.canBeAddedToCanvas(): menu.addSeparator() menu.addAction(self.tr("Add to canvas"), self.addLayer) elif isinstance(item, DBPlugin): if item.database() is not None: menu.addAction(self.tr("Re-connect"), self.reconnect) menu.addAction(self.tr("Remove"), self.delete) elif not index.parent().isValid() and item.typeName() == "spatialite": menu.addAction(self.tr("New Connection..."), self.newConnection) if not menu.isEmpty(): menu.exec_(ev.globalPos()) menu.deleteLater()
def showHeaderMenu(self, point): # determine the column that was clicked on index = self.uiPlaylistTREE.header().logicalIndexAt(point) self._currentHeaderColumn = index # create the menu menu = QMenu(self) act = menu.addAction('Sort Ascending') act.setIcon(resources.icon('img/playlist/sort_ascending.png')) act.triggered.connect(self.sortAscending) act = menu.addAction('Sort Descending') act.setIcon(resources.icon('img/playlist/sort_descending.png')) act.triggered.connect(self.sortDescending) menu.addSeparator() # create a columns menu columns = menu.addMenu('Columns...') columns.setIcon(resources.icon('img/playlist/columns.png')) for c, col in enumerate(self.COLUMNS): act = columns.addAction(col) act.setCheckable(True) act.setChecked(not self.uiPlaylistTREE.isColumnHidden(c)) columns.triggered.connect(self.toggleColumnTriggered) # popup the menu menu.exec_(QCursor.pos())
def eventFilter(self, obj, event): ''' @param obj QObject @paramn event QEvent ''' # if (event.type() == QEvent.MouseButtonPress): # print "Mouse pressed" # if (event.type() == QEvent.ContextMenu): # Now we know that event is an instance of QContextMenuEvent menu = QMenu(self) newPos = self.adjustPosition(event.pos()) modelIndex = self.indexAt(newPos) self.showTransactions = QAction(self.tr("Show transactions"), self) menu.addAction(self.showTransactions) self.connect(self.showTransactions, SIGNAL("triggered()"), lambda : self.parentWindow.showTransactionsForPosition(modelIndex)) self.openWebpage = QAction(self.tr("Open Google Finance webpage"), self) menu.addAction(self.openWebpage) self.connect(self.openWebpage, SIGNAL("triggered()"), lambda : self.parentWindow.openWebpageForPosition(modelIndex)) menu.exec_(event.globalPos()) return QListView.eventFilter(self, obj, event)
def layercontextmenu( layer, pos, parent=None ): '''Show a context menu to manipulate properties of layer. layer -- a volumina layer instance pos -- QPoint ''' menu = QMenu("Menu", parent) # Title title = QAction("%s" % layer.name, menu) title.setEnabled(False) menu.addAction(title) # Export global _has_lazyflow if _has_lazyflow: export = QAction("Export...",menu) export.setStatusTip("Export Layer...") export.triggered.connect( partial( get_settings_and_export_layer, layer, menu ) ) menu.addAction(export) menu.addSeparator() _add_actions( layer, menu ) # Layer-custom context menu items menu.addSeparator() for name, callback in layer.contexts: action = QAction(name, menu) action.triggered.connect(callback) menu.addAction(action) menu.exec_(pos)
class TabNavigator(QWidget): def __init__(self): QWidget.__init__(self) self.setContextMenuPolicy(Qt.DefaultContextMenu) self.setMinimumHeight(38) hbox = QHBoxLayout(self) self.btnPrevious = QPushButton(QIcon(resources.IMAGES["nav-code-left"]), "") self.btnPrevious.setToolTip(self.tr("Right click to change navigation options")) styles.set_style(self.btnPrevious, "tab-navigator") self.btnNext = QPushButton(QIcon(resources.IMAGES["nav-code-right"]), "") self.btnNext.setToolTip(self.tr("Right click to change navigation options")) styles.set_style(self.btnNext, "tab-navigator") hbox.addWidget(self.btnPrevious) hbox.addWidget(self.btnNext) self.setContentsMargins(0, 0, 0, 0) self.menuNavigate = QMenu(self.tr("Navigate")) self.codeAction = self.menuNavigate.addAction(self.tr("Code Jumps")) self.codeAction.setCheckable(True) self.codeAction.setChecked(True) self.bookmarksAction = self.menuNavigate.addAction(self.tr("Bookmarks")) self.bookmarksAction.setCheckable(True) self.breakpointsAction = self.menuNavigate.addAction(self.tr("Breakpoints")) self.breakpointsAction.setCheckable(True) # 0 = Code Jumps # 1 = Bookmarks # 2 = Breakpoints self.operation = 0 self.connect(self.codeAction, SIGNAL("triggered()"), self._show_code_nav) self.connect(self.breakpointsAction, SIGNAL("triggered()"), self._show_breakpoints) self.connect(self.bookmarksAction, SIGNAL("triggered()"), self._show_bookmarks) def contextMenuEvent(self, event): self.menuNavigate.exec_(event.globalPos()) def _show_bookmarks(self): self.btnPrevious.setIcon(QIcon(resources.IMAGES["book-left"])) self.btnNext.setIcon(QIcon(resources.IMAGES["book-right"])) self.bookmarksAction.setChecked(True) self.breakpointsAction.setChecked(False) self.codeAction.setChecked(False) self.operation = 1 def _show_breakpoints(self): self.btnPrevious.setIcon(QIcon(resources.IMAGES["break-left"])) self.btnNext.setIcon(QIcon(resources.IMAGES["break-right"])) self.bookmarksAction.setChecked(False) self.breakpointsAction.setChecked(True) self.codeAction.setChecked(False) self.operation = 2 def _show_code_nav(self): self.btnPrevious.setIcon(QIcon(resources.IMAGES["nav-code-left"])) self.btnNext.setIcon(QIcon(resources.IMAGES["nav-code-right"])) self.bookmarksAction.setChecked(False) self.breakpointsAction.setChecked(False) self.codeAction.setChecked(True) self.operation = 0