我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt5.QtWidgets.QMenu()。
def __init__(self, app, version): self.app = app self.version = version # build the icon and message line, which will be properly set below when calling the # set_message_number() method self.sti = sti = QtWidgets.QSystemTrayIcon() self.menu = menu = QtWidgets.QMenu() self._messages_action = menu.addAction('') self.set_message_number() self._messages_action.triggered.connect(self._show_messages) menu.addSeparator() action = menu.addAction("Configure") action.triggered.connect(self._configure) action = menu.addAction("About") action.triggered.connect(self._about) action = menu.addAction("Quit") action.triggered.connect(lambda _: self.app.quit()) sti.setContextMenu(menu) sti.show()
def user_list_right_click(self): user_menu = QtWidgets.QMenu() try: position = self.get_selected_view_index(self.user_list_view).row() user_settings = user_menu.addAction("User Settings") user_downloads = user_menu.addAction("View User Downloads") user_menu.addSeparator() open_user_folder = user_menu.addAction("Open Download Folder") user_menu.addSeparator() add_user = user_menu.addAction("Add User") remove_user = user_menu.addAction("Remove User") add_user.triggered.connect(self.add_user_dialog) remove_user.triggered.connect(self.remove_user) user_settings.triggered.connect(lambda: self.user_settings(0, False)) user_downloads.triggered.connect(lambda: self.user_settings(1, False)) open_user_folder.triggered.connect(self.open_user_download_folder) except AttributeError: add_user = user_menu.addAction("Add User") add_user.triggered.connect(self.add_user_dialog) user_menu.exec(QtGui.QCursor.pos())
def subreddit_list_right_click(self): subreddit_menu = QtWidgets.QMenu() try: position = self.get_selected_view_index(self.subreddit_list_view).row() subreddit_settings = subreddit_menu.addAction("Subreddit Settings") subreddit_downloads = subreddit_menu.addAction("View Subreddit Downloads") subreddit_menu.addSeparator() open_subreddit_folder = subreddit_menu.addAction("Open Download Folder") subreddit_menu.addSeparator() add_subreddit = subreddit_menu.addAction("Add Subreddit") remove_subreddit = subreddit_menu.addAction("Remove Subreddit") add_subreddit.triggered.connect(self.add_subreddit_dialog) remove_subreddit.triggered.connect(self.remove_subreddit) subreddit_settings.triggered.connect(lambda: self.subreddit_settings(0, False)) subreddit_downloads.triggered.connect(lambda: self.subreddit_settings(1, False)) open_subreddit_folder.triggered.connect(self.open_subreddit_download_folder) except AttributeError: add_subreddit = subreddit_menu.addAction("Add Subreddit") add_subreddit.triggered.connect(self.add_subreddit_dialog) subreddit_menu.exec(QtGui.QCursor.pos())
def setup_help_menu(self): bug_icon = QtGui.QIcon(icons.debug) help_menu = QtWidgets.QMenu('&Help', self.window) help_menu.addAction( self.window.icon, '&About Activity Browser', self.about) help_menu.addAction( '&About Qt', lambda: QtWidgets.QMessageBox.aboutQt(self.window) ) help_menu.addAction( bug_icon, '&Report Bug on github', self.raise_issue_github ) help_menu.addAction( bug_icon, '&Report Bug', self.raise_issue_from_app ) return help_menu
def __init__(self, parent=None): QSystemTrayIcon.__init__(self, QIcon_load("ball_green"), parent) menu = QMenu(parent) self.menu_about = menu.addAction(_("About")) self.menu_about.triggered.connect(self.callback_about) self.menu_man = menu.addAction(_("Manual")) self.menu_man.triggered.connect(self.callback_man) self.menu_youtube = menu.addAction("&"+_("Youtube channel")) self.menu_youtube.triggered.connect(self.callback_youtube) self.exitAction = menu.addSeparator() self.exitAction = menu.addAction(_("Quit")) self.exitAction.triggered.connect(self.callback_exit) self.setContextMenu(menu)
def _create_menu(self, parent, actions_list): for action_item in actions_list: if 'type' in action_item: if action_item['type'] == 'separator': parent.addSeparator() elif 'action' in action_item: action = QtWidgets.QAction(self) parent.addAction(action) action.setText(action_item['title']) action.triggered.connect(action_item['action']) if 'shortcut' in action_item: action.setShortcut(action_item['shortcut']) if 'icon' in action_item: action.setIcon(QtGui.QIcon(action_item['icon'])) if 'status_tip' in action_item: action.setStatusTip(action_item['status_tip']) if 'property' in action_item: self.menu_property[action_item['property']] = action else: menu = QtWidgets.QMenu(parent) menu.setTitle(action_item['title']) self._create_menu(menu, action_item['actions']) parent.addAction(menu.menuAction())
def __init__(self, view): QObject.__init__(self, view) self.view = view self.model = QStandardItemModel() self.view.setModel(self.model) self.nodesets = [] self.server_mgr = None self._nodeset_to_delete = None self.view.header().setSectionResizeMode(1) addNodeSetAction = QAction("Add Reference Node Set", self.model) addNodeSetAction.triggered.connect(self.add_nodeset) self.removeNodeSetAction = QAction("Remove Reference Node Set", self.model) self.removeNodeSetAction.triggered.connect(self.remove_nodeset) self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect(self.showContextMenu) self._contextMenu = QMenu() self._contextMenu.addAction(addNodeSetAction) self._contextMenu.addAction(self.removeNodeSetAction)
def setup_context_menu_tree(self): self.ui.treeView.setContextMenuPolicy(Qt.CustomContextMenu) self.ui.treeView.customContextMenuRequested.connect(self._show_context_menu_tree) self._contextMenu = QMenu() # tree view menu self._contextMenu.addAction(self.ui.actionCopy) self._contextMenu.addAction(self.ui.actionPaste) self._contextMenu.addAction(self.ui.actionDelete) self._contextMenu.addSeparator() self._contextMenu.addAction(self.tree_ui.actionReload) self._contextMenu.addSeparator() self._contextMenu.addAction(self.ui.actionAddFolder) self._contextMenu.addAction(self.ui.actionAddObject) self._contextMenu.addAction(self.ui.actionAddVariable) self._contextMenu.addAction(self.ui.actionAddProperty) self._contextMenu.addAction(self.ui.actionAddMethod) self._contextMenu.addAction(self.ui.actionAddObjectType) self._contextMenu.addAction(self.ui.actionAddVariableType) self._contextMenu.addAction(self.ui.actionAddDataType)
def __init__(self, view): QObject.__init__(self, view) self.view = view self.model = QStandardItemModel() self.view.setModel(self.model) delegate = MyDelegate(self.view, self) delegate.error.connect(self.error.emit) self.view.setItemDelegate(delegate) self.node = None self.view.header().setSectionResizeMode(1) self.addNamespaceAction = QAction("Add Namespace", self.model) self.addNamespaceAction.triggered.connect(self.add_namespace) self.removeNamespaceAction = QAction("Remove Namespace", self.model) self.removeNamespaceAction.triggered.connect(self.remove_namespace) self.view.setContextMenuPolicy(Qt.CustomContextMenu) self.view.customContextMenuRequested.connect(self.showContextMenu) self._contextMenu = QMenu() self._contextMenu.addAction(self.addNamespaceAction) self._contextMenu.addAction(self.removeNamespaceAction)
def qui_menu(self, action_list_str, menu_str): # qui menu creation # syntax: self.qui_menu('right_menu_createFolder_atn;Create Folder,Ctrl+D | right_menu_openFolder_atn;Open Folder', 'right_menu') if menu_str not in self.uiList.keys(): self.uiList[menu_str] = QtWidgets.QMenu() create_opt_list = [ x.strip() for x in action_list_str.split('|') ] for each_creation in create_opt_list: ui_info = [ x.strip() for x in each_creation.split(';') ] atn_name = ui_info[0] atn_title = '' atn_hotkey = '' if len(ui_info) > 1: options = ui_info[1].split(',') atn_title = '' if len(options) < 1 else options[0] atn_hotkey = '' if len(options) < 2 else options[1] if atn_name != '': if atn_name == '_': self.uiList[menu_str].addSeparator() else: if atn_name not in self.uiList.keys(): self.uiList[atn_name] = QtWidgets.QAction(atn_title, self) if atn_hotkey != '': self.uiList[atn_name].setShortcut(QtGui.QKeySequence(atn_hotkey)) self.uiList[menu_str].addAction(self.uiList[atn_name])
def qui_menubar(self, menu_list_str): if not isinstance(self, QtWidgets.QMainWindow): print("Warning: Only QMainWindow can have menu bar.") return menubar = self.menuBar() create_opt_list = [ x.strip() for x in menu_list_str.split('|') ] for each_creation in create_opt_list: ui_info = [ x.strip() for x in each_creation.split(';') ] menu_name = ui_info[0] menu_title = '' if len(ui_info) > 1: menu_title = ui_info[1] if menu_name not in self.uiList.keys(): self.uiList[menu_name] = QtWidgets.QMenu(menu_title) menubar.addMenu(self.uiList[menu_name]) # compatible hold function
def setLang(self, langName): uiList_lang_read = self.memoData['lang'][langName] for ui_name in uiList_lang_read: ui_element = self.uiList[ui_name] if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]: # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox if uiList_lang_read[ui_name] != "": ui_element.setText(uiList_lang_read[ui_name]) elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]: # uiType: QMenu, QGroupBox if uiList_lang_read[ui_name] != "": ui_element.setTitle(uiList_lang_read[ui_name]) elif type(ui_element) in [ QtWidgets.QTabWidget]: # uiType: QTabWidget tabCnt = ui_element.count() if uiList_lang_read[ui_name] != "": tabNameList = uiList_lang_read[ui_name].split(';') if len(tabNameList) == tabCnt: for i in range(tabCnt): if tabNameList[i] != "": ui_element.setTabText(i,tabNameList[i]) elif type(ui_element) == str: # uiType: string for msg if uiList_lang_read[ui_name] != "": self.uiList[ui_name] = uiList_lang_read[ui_name]
def contextMenuEvent(self, event): menu = QtWidgets.QMenu() listOfLabelsAndFunctions = [ ("interpolation Type", self.changeInterpolationType), ("CC Value", self.changeCCValue), ("delete", self.delete), #deletes the last hover item which is of course the current one. ] for text, function in listOfLabelsAndFunctions: if text == "separator": self.addSeparator() else: a = QtWidgets.QAction(text, menu) menu.addAction(a) a.triggered.connect(function) pos = QtGui.QCursor.pos() pos.setY(pos.y() + 5) self.ungrabMouse() #if we don't ungrab and the user clicks the context menu "away" by clicking in an empty area this will still get registered as mouseclick belonging to the current item and change the value to some insane amount, breaking the point. menu.exec_(pos)
def contextMenuEvent(self, event): menu = QtWidgets.QMenu() listOfLabelsAndFunctions = [ ("interpolation type", self.changeInterpolationType), ("units per minute", self.changeTempoUnits), ("reference note", self.changeTempoReference), ] if not self.staticExportItem["positionInBlock"] == 0: listOfLabelsAndFunctions.append(("delete", lambda: api.removeTempoItem(self.staticExportItem["id"]))) for text, function in listOfLabelsAndFunctions: if text == "separator": self.addSeparator() else: a = QtWidgets.QAction(text, menu) menu.addAction(a) a.triggered.connect(function) pos = QtGui.QCursor.pos() pos.setY(pos.y() + 5) self.ungrabMouse() #if we don't ungrab and the user clicks the context menu "away" by clicking in an empty area this will still get registered as mouseclick belonging to the current item menu.exec_(pos)
def deactivate_contextMenuEvent(self, event): menu = QtWidgets.QMenu() listOfLabelsAndFunctions = [ ("restore to full duration ", self.contextRestore), ] for text, function in listOfLabelsAndFunctions: if text == "separator": self.addSeparator() else: a = QtWidgets.QAction(text, menu) menu.addAction(a) a.triggered.connect(function) pos = QtGui.QCursor.pos() pos.setY(pos.y() + 5) self.ungrabMouse() #if we don't ungrab and the user clicks the context menu "away" by clicking in an empty area this will still get registered as mouseclick belonging to the current item menu.exec_(pos)
def __init__(self, items, parent=None): super(ButtonLineEdit, self).__init__(parent) self.menu = QtWidgets.QMenu() for i in items: self.menu.addAction(i) self.button = QtWidgets.QToolButton(self) self.button.setStyleSheet('border: 0px; padding: 0px;') self.button.setCursor(QtCore.Qt.ArrowCursor) self.button.triggered.connect(self.menu_action_triggered) self.button.setPopupMode(QtWidgets.QToolButton.InstantPopup) self.button.setMenu(self.menu) frameWidth = self.style().pixelMetric(QtWidgets.QStyle.PM_DefaultFrameWidth) buttonSize = self.button.sizeHint() self.setAlignment(QtCore.Qt.Alignment(QtCore.Qt.AlignHCenter)) self.setStyleSheet('QLineEdit {padding-right: %dpx; }' % (buttonSize.width() + frameWidth + 1)) self.setMinimumSize(max(self.minimumSizeHint().width(), buttonSize.width() + frameWidth*2 + 2), max(self.minimumSizeHint().height(), buttonSize.height() + frameWidth*2 + 2)) self.setMaximumWidth(100)
def __init__(self, api, parent=None): super().__init__(parent) self._api = api self.setModel(SubsModel(api, self)) self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows) self.setTabKeyNavigation(False) self.verticalHeader().setDefaultSectionSize( self.fontMetrics().height() + 2) for i, column_type in enumerate(self.model().column_order): if column_type in (SubsModelColumn.Text, SubsModelColumn.Note): self.horizontalHeader().setSectionResizeMode( i, QtWidgets.QHeaderView.Stretch) api.subs.loaded.connect(self._on_subs_load) api.subs.selection_changed.connect(self._on_api_selection_change) self.selectionModel().selectionChanged.connect( self._widget_selection_changed) self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) self.customContextMenuRequested.connect(self._open_menu) self.menu = QtWidgets.QMenu(self) bubblesub.ui.util.setup_cmd_menu( self._api, self.menu, self._api.opt.context_menu)
def item_display_list_right_click(self): menu = QtWidgets.QMenu() button_text = 'Remove Item' if len(self.item_display_list.selectedItems()) < 2 else 'Remove Items' open_link = menu.addAction('Open Link') remove_item = menu.addAction(button_text) menu.addSeparator() previous_downloads_list = menu.addAction('Previous Downloads') saved_content_list = menu.addAction('Saved Content') saved_submissions_list = menu.addAction('Saved Submissions') menu_dict = {'previous_downloads': previous_downloads_list, 'saved_content': saved_content_list, 'saved_submissions': saved_submissions_list} open_link.triggered.connect(self.open_link) remove_item.triggered.connect(self.remove_item_from_item_display_list) previous_downloads_list.triggered.connect(self.setup_previous_downloads_list) saved_content_list.triggered.connect(self.setup_saved_content_list) saved_submissions_list.triggered.connect(self.setup_saved_submission_list) menu_dict[self.current_item_display_list].setEnabled(False) menu.exec(QtGui.QCursor.pos())
def found_user_list_right_click(self): menu = QtWidgets.QMenu() try: position = self.found_user_list.currentRow() add_user = menu.addAction('Add User To List') remove_user = menu.addAction('Remove User') remove_user_and_blacklist = menu.addAction('Remove and Blacklist User') menu.addSeparator() open_user_folder = menu.addAction('Open User Download Folder') add_user.triggered.connect(self.add_found_user_to_main_list) remove_user.triggered.connect(self.remove_user_from_user_found_list) remove_user_and_blacklist.triggered.connect(self.remove_and_blacklist_user) open_user_folder.triggered.connect(self.open_folder) except AttributeError: print('Exception at line 282') menu.exec(QtGui.QCursor.pos())
def contextMenuEvent(self, event: QContextMenuEvent): menu = QMenu() sel_indexes = [index.row() for index in self.selectedIndexes()] edit_action = QAction("Edit", self) if len(sel_indexes) == 0: edit_action.setEnabled(False) menu.addAction(edit_action) if self.count() > 0: edit_all_action = QAction("Edit all", self) edit_all_action.triggered.connect(self.on_edit_all_action_triggered) menu.addAction(edit_all_action) action = menu.exec_(self.mapToGlobal(event.pos())) if action == edit_action: selected_indx = sel_indexes[0] self.item_edit_clicked.emit(selected_indx)
def create_context_menu(self): menu = QMenu() menu.setToolTipsVisible(True) self._add_zoom_actions_to_menu(menu) if self.something_is_selected: filter_bw = Filter.read_configured_filter_bw() text = self.tr("Apply bandpass filter (filter bw={0:n})".format(filter_bw)) create_from_frequency_selection = menu.addAction(text) create_from_frequency_selection.triggered.connect(self.on_create_from_frequency_selection_triggered) create_from_frequency_selection.setIcon(QIcon.fromTheme("view-filter")) try: cancel_button = " or ".join(k.toString() for k in QKeySequence.keyBindings(QKeySequence.Cancel)) except Exception as e: logger.debug("Error reading cancel button: " + str(e)) cancel_button = "Esc" create_from_frequency_selection.setToolTip("You can abort filtering with <b>{}</b>.".format(cancel_button)) configure_filter_bw = menu.addAction(self.tr("Configure filter bandwidth...")) configure_filter_bw.triggered.connect(self.on_configure_filter_bw_triggered) configure_filter_bw.setIcon(QIcon.fromTheme("configure")) return menu
def create_context_menu(self): menu = QMenu() if self.model().message is None or len(self.model().message.message_type) == 0: return menu edit_action = menu.addAction("Edit fuzzing label") edit_action.setIcon(QIcon.fromTheme("configure")) edit_action.triggered.connect(self.on_edit_action_triggered) del_action = menu.addAction("Delete fuzzing label") del_action.setIcon(QIcon.fromTheme("edit-delete")) del_action.triggered.connect(self.on_delete_action_triggered) menu.addSeparator() fuzz_all_action = menu.addAction("Check all") fuzz_all_action.triggered.connect(self.model().fuzzAll) unfuzz_all_action = menu.addAction("Uncheck all") unfuzz_all_action.triggered.connect(self.model().unfuzzAll) return menu
def create_context_menu(self): menu = QMenu() item = self.indexAt(self.context_menu_pos).row() if item < 0: return menu item_name = self.item(item).text() # Menu Entries rm_action = menu.addAction(self.tr("Delete")) rm_action.setIcon(QIcon.fromTheme("list-remove")) rm_action.triggered.connect(self.on_rm_action_triggered) if constants.DECODING_DISABLED_PREFIX in item_name: disable_function = menu.addAction(self.tr("Enable")) else: disable_function = menu.addAction(self.tr("Disable")) disable_function.triggered.connect(self.on_disable_function_triggered) menu.addSeparator() clear_all_action = menu.addAction(self.tr("Clear All")) clear_all_action.triggered.connect(self.on_clear_all_action_triggered) return menu
def contextMenuEvent(self, event: QContextMenuEvent): if self.signal is None: return menu = QMenu() apply_to_all_action = menu.addAction(self.tr("Apply values (BitLen, 0/1-Threshold, Tolerance) to all signals")) menu.addSeparator() auto_detect_action = menu.addAction(self.tr("Auto-Detect signal parameters")) action = menu.exec_(self.mapToGlobal(event.pos())) if action == apply_to_all_action: self.setCursor(Qt.WaitCursor) self.apply_to_all_clicked.emit(self.signal) self.unsetCursor() elif action == auto_detect_action: self.setCursor(Qt.WaitCursor) self.signal.auto_detect() self.unsetCursor()
def contextMenuEvent(self, event): global name,tmp_name,opt,list1_items,curR,nxtImg_cnt,home,site,pre_opt global base_url,category #print name menu = QtWidgets.QMenu(self) history = menu.addAction("History") anime = menu.addAction("Animes") movie = menu.addAction("Movies") action = menu.exec_(self.mapToGlobal(event.pos())) if action == history: ui.setPreOpt() elif action == anime: category = "Animes" elif action == movie: category = "Movies" #super(List2, self).keyPressEvent(event)
def contextMenuEvent(self, event): global name,tmp_name,opt,list1_items,curR,nxtImg_cnt,home,site,pre_opt global base_url,category #print name menu = QtWidgets.QMenu(self) hd = menu.addAction("Hide Search Table") sideBar = menu.addAction("Show Sidebar") history = menu.addAction("Show History") action = menu.exec_(self.mapToGlobal(event.pos())) if action == hd: self.hide() elif action == sideBar: if ui.dockWidget_3.isHidden(): ui.dockWidget_3.show() ui.btn1.setFocus() else: ui.dockWidget_3.hide() ui.list1.setFocus() elif action == history: ui.setPreOpt()
def applied_custom_menu(self, point): index = self.applied_tree_view.indexAt(point) address = index.data(FIRSTUI.ROLE_ADDRESS) if not address: return menu = QtWidgets.QMenu(self.applied_tree_view) goto_action = QtWidgets.QAction('&Go to Function', self.applied_tree_view) goto_action.triggered.connect(lambda:IDAW.Jump(address)) menu.addAction(goto_action) metadata_id = index.data(FIRSTUI.ROLE_ID) if metadata_id: history_action = QtWidgets.QAction('View &History', self.applied_tree_view) history_action.triggered.connect(lambda:self._metadata_history(metadata_id)) menu.addAction(history_action) menu.exec_(QtGui.QCursor.pos())
def custom_menu(self, point): index = self.tree_view.indexAt(point) address = index.data(FIRSTUI.ROLE_ADDRESS) if not address: return menu = QtWidgets.QMenu(self.tree_view) goto_action = QtWidgets.QAction('&Go to Function', self.tree_view) goto_action.triggered.connect(lambda:IDAW.Jump(address)) menu.addAction(goto_action) metadata_id = index.data(FIRSTUI.ROLE_ID) if metadata_id: history_action = QtWidgets.QAction('View &History', self.tree_view) history_action.triggered.connect(lambda:self.metadata_history(metadata_id)) menu.addAction(history_action) menu.exec_(QtGui.QCursor.pos())
def Tray_init(self): self.tray = QSystemTrayIcon() self.icon = self.windowIcon() self.tray.setIcon(self.icon) self.tray.activated[QSystemTrayIcon.ActivationReason].connect( self.TrayEvent) self.tray_menu = QtWidgets.QMenu(QtWidgets.QApplication.desktop()) self.ShowAction = QtWidgets.QAction( u'?? ', self, triggered=self.re_build) self.ShowLog = QtWidgets.QAction( u'???? ', self, triggered=self.logwindow.showlog) self.QuitAction = QtWidgets.QAction( u'?? ', self, triggered=self.app_quit) self.tray_menu.addAction(self.ShowLog) self.tray_menu.addAction(self.ShowAction) self.tray_menu.addAction(self.QuitAction) self.tray.setContextMenu(self.tray_menu) # ???????? self.tray.show() self.showMessage(u"shadowsocks-pyqt ?????")
def setup_file_menu(self): menu = QtWidgets.QMenu('&File', self.window) # Switch BW2 directory # switch_bw2_dir = QtWidgets.QAction(QtGui.QIcon('exit.png'), '&Database directory...', self.window) # # switch_bw2_dir.setShortcut('Ctrl+Q') # switch_bw2_dir.setStatusTip('Change database directory') # switch_bw2_dir.triggered.connect(signals.switch_bw2_dir_path.emit) # menu.addAction(switch_bw2_dir) menu.addAction( '&Database directory...', signals.switch_bw2_dir_path.emit ) menu.addAction( '&Import database...', signals.import_database.emit ) return menu # def setup_extensions_menu(self): # extensions_menu = QtWidgets.QMenu('&Extensions', self.window) # # extensions_menu.addAction( # # self.add_metaprocess_menu_item() # # ) # return extensions_menu
def __init__(self, parent=None): super().__init__(parent) self.context_menu = QMenu(self) header = self.header() header.sectionDoubleClicked.connect(self._header_double_clicked_handler) self._add_menu_action("Transfer", self._transfer_handler) # TODO: Implement # self._add_menu_action("Transfer changed", self._transfer_changed_handler) self.context_menu.addSeparator() self._destination_menu_action = self._add_menu_action( "Set as destination", self._set_transfer_directory_handler)
def __init__(self, icon, parent=None): super(SystemTrayIcon, self).__init__(icon, parent) self.parent = parent self.setToolTip("Grid Control") self.activated.connect(self.on_systemTrayIcon_activated) menu = QtWidgets.QMenu() showAction = menu.addAction("Hide/Show") showAction.triggered.connect(parent.toggle_visibility) menu.addSeparator() exitAction = menu.addAction("Exit") exitAction.triggered.connect(parent.close) self.setContextMenu(menu)
def __init__(self): import icons icon = QIcon(QPixmap(':icon.png')) super().__init__(icon) menu = QMenu() menu.addAction("About").triggered.connect(self.about) menu.addAction("Exit").triggered.connect(self.exit) self.setContextMenu(menu)
def __init__(self): from rockthetaskbar import icons icon = QIcon(QPixmap(':icon.png')) super().__init__(icon) menu = QMenu() menu.addAction("CPU").triggered.connect(self.cpu) menu.addAction("About").triggered.connect(self.about) menu.addAction("Exit").triggered.connect(self.exit) self.setContextMenu(menu) self.cpu_monitor = CPUMonitor() self.cpu_monitor.start()
def __setupTableContextMenu( self ): self.debugLog( '__setupTableContextMenu' ) # --- setup scm_type specific menu m = QtWidgets.QMenu( self ) self.ui_component.setupTableContextMenu( m, self._addMenu )
def __setupTableContextMenu( self ): self.debugLog( '__setupTableContextMenu' ) # --- setup scm_type specific menu m = QtWidgets.QMenu( self ) m.addSection( T_('File Actions') ) self._addMenu( m, T_('Edit'), self.table_view.tableActionEdit, self.table_view.enablerTableFilesExists, 'toolbar_images/edit.png' ) self._addMenu( m, T_('Open'), self.table_view.tableActionOpen, self.table_view.enablerTableFilesExists, 'toolbar_images/open.png' ) self.ui_component.setupTableContextMenu( m, self._addMenu )
def __setupTableContextMenus( self ): self.debugLog( '__setupTableContextMenus' ) m = QtWidgets.QMenu( self ) self.ui_component.setupTableContextMenu( m, self._addMenu ) m = QtWidgets.QMenu( self ) self.ui_component.setupChangedFilesContextMenu( m, self._addMenu )
def __setupTreeContextMenu( self ): self.debugLog( '__setupTreeContextMenu' ) # --- setup scm_type specific menu for scm_type in self.all_ui_components: self.debugLog( 'calling setupTreeContextMenu for %r' % (scm_type,) ) m = QtWidgets.QMenu( self ) m.addSection( T_('Folder Actions') ) self._addMenu( m, T_('&Command Shell'), self.treeActionShell, self.enablerFolderExists, 'toolbar_images/terminal.png' ) self._addMenu( m, T_('&File Browser'), self.treeActionFileBrowse, self.enablerFolderExists, 'toolbar_images/file_browser.png' ) self.all_ui_components[ scm_type ].setupTreeContextMenu( m, self._addMenu )
def __setupTableContextMenu( self ): self.debugLog( '__setupTableContextMenu' ) # --- setup scm_type specific menu for scm_type in self.all_ui_components: self.debugLog( 'calling setupTableContextMenu for %r' % (scm_type,) ) m = QtWidgets.QMenu( self ) m.addSection( T_('File Actions') ) self._addMenu( m, T_('Edit'), self.table_view.tableActionEdit, self.table_view.enablerTableFilesExists, 'toolbar_images/edit.png' ) self._addMenu( m, T_('Open'), self.table_view.tableActionOpen, self.table_view.enablerTableFilesExists, 'toolbar_images/open.png' ) self.all_ui_components[ scm_type ].setupTableContextMenu( m, self._addMenu )
def _createTrayIcon(self): self.trayIconMenu = QMenu(self) self.trayIconMenu.addAction(self.quitAction) self.trayIcon = QSystemTrayIcon(self) self.trayIcon.setContextMenu(self.trayIconMenu)
def select_maps_context_menu(self, position): global_position = self.general_map_selection.mapToGlobal(position) def get_header_action(parent, map_name): label = QLabel(map_name) font = label.font() font.setBold(True) label.setFont(font) label.setStyleSheet('color: black; margin:5px; margin-left: 15px;') action = QWidgetAction(parent) action.setDisabled(True) action.setDefaultWidget(label) return action if self.general_map_selection.count(): row = self.general_map_selection.indexAt(position) if row: element = self.general_map_selection.item(row.row()) if element: map_name = element.data(Qt.UserRole) file_path = self._controller.get_model().get_data().get_file_path(map_name) menu = QMenu() menu.addAction(get_header_action(menu, map_name)) menu.addSeparator() show_in_folder = menu.addAction('&Show in folder', lambda: QDesktopServices.openUrl(QUrl.fromLocalFile(os.path.dirname(file_path)))) if file_path is None: show_in_folder.setEnabled(False) menu.addAction('Use as &mask', lambda: self._controller.apply_action(SetGeneralMask(map_name))) menu.addAction('R&emove', lambda: self._controller.apply_action( NewDataAction(self._controller.get_model().get_data().get_updated(removals=[map_name])))) menu.exec(global_position)
def contextMenuEvent(self, event: QtGui.QContextMenuEvent, *args, **kwargs): context_ind = self.indexAt(event.pos()) context_focus = self.model().itemFromIndex(context_ind) print(context_focus) print(context_focus.text()) info_slot = functools.partial(self.flight_info, context_focus) menu = QtWidgets.QMenu() info_action = QtWidgets.QAction("Info") info_action.triggered.connect(info_slot) menu.addAction(info_action) menu.exec_(event.globalPos()) event.accept()