def __init__(self): super().__init__() self.setWindowTitle("My Awesome App") label = QLabel("THIS IS AWESOME!!!") label.setAlignment(Qt.AlignCenter) self.setCentralWidget(label) toolbar = QToolBar("My Main toolbar") toolbar.setIconSize(QSize(16, 16)) self.addToolBar(toolbar) button_action = QAction(QIcon("../../icons/bug.png"), "Your button", self) button_action.setStatusTip("This is your button") button_action.triggered.connect(self.onMyToolBarButtonClick) button_action.setCheckable(True) # True, False Toggle 됨 toolbar.addAction(button_action) toolbar.addSeparator() button_action2 = QAction(QIcon("../../icons/bug.png"), "Your button2", self) button_action2.setStatusTip("This is your button2") button_action2.triggered.connect(self.onMyToolBarButtonClick) button_action2.setCheckable(True) toolbar.addAction(button_action2) toolbar.addWidget(QLabel("Hello")) toolbar.addWidget(QCheckBox()) self.setStatusBar(QStatusBar(self))
def create_action( self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, ): #signal="triggered()"): action = QAction(text, self) if icon is not None: action.setIcon(QIcon(":/%s.png" % icon)) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if slot is not None: #self.connect(action, SIGNAL(signal), slot) # Qt5 style action.triggered.connect(slot) if checkable: action.setCheckable(True) return action
def create_servers_group(servers): """Create an action group for the specified servers.""" servers_group = QActionGroup(self) current_server = self._plugin.network.server for server in servers: is_connected = (current_server is not None and server["host"] == current_server["host"] and server["port"] == current_server["port"]) server_text = "%s:%d" % (server["host"], server["port"]) server_action = QAction(server_text, menu) server_action._server = server server_action.setCheckable(True) server_action.setChecked(is_connected) servers_group.addAction(server_action) def server_action_triggered(server_action): """ Called when a action is clicked. Connects to the new server or disconnects from the old server. """ server = server_action._server was_connected = self._plugin.network.server == server self._plugin.network.stop_server() self._plugin.network.disconnect() if not was_connected: self._plugin.network.connect(server) servers_group.triggered.connect(server_action_triggered) return servers_group
def init_ui(self): toggle_listening_action = QAction("Toggle &listening", parent=self) toggle_listening_action.setCheckable(True) toggle_listening_action.setChecked(False) toggle_listening_action.setShortcut('Ctrl+L') toggle_listening_action.triggered.connect(toggle_listening_callback) settings_action = QAction("&Settings", parent=self) settings_action.setShortcut("Ctrl+Shift+S") settings_action.triggered.connect(self.open_settings) exit_action = QAction(QIcon('images/exit.png'), '&Quit', self) exit_action.setShortcut('Ctrl+Q') exit_action.triggered.connect(qApp.quit) menu_bar = self.menuBar() file_menu = menu_bar.addMenu('File') file_menu.addAction(toggle_listening_action) file_menu.addAction(settings_action) file_menu.addAction(exit_action) self.setStyleSheet( ThemeLoader.loaded_theme.apply_to_stylesheet( styles.main_window_style)) self.setCentralWidget(RootWidget()) self.setGeometry(100, 100, 800, 800) self.setWindowTitle('Core Messenger') self.setWindowIcon(QIcon('images/app-icon.png'))
def _make_context_menu(self): global _TR m = QMenu(self) act1 = QAction( _TR("EditViewWidget","Mark Scannos","context menu item"), m ) act1.setCheckable(True) act1.setToolTip( _TR("EditViewWidget", "Turn on or off marking of words from the scanno file", "context menu tooltip") ) act1.toggled.connect(self._act_mark_scannos) m.addAction(act1) act2 = QAction( _TR("EditViewWidget","Mark Spelling","context menu item"), m ) act2.setCheckable(True) act2.setToolTip( _TR("EditViewWidget", "Turn on or off marking words that fail spellcheck", "context menu tooltip") ) act2.toggled.connect(self._act_mark_spelling) m.addAction(act2) act3 = QAction( _TR("EditViewWidget","Scanno File...","context menu item"), m ) act3.setToolTip( _TR("EditViewWidget", "Choose a file of scanno (common OCR error) words", "context menu tooltip") ) act3.triggered.connect(self._act_choose_scanno) m.addAction(act3) act4 = QAction( _TR("EditViewWidget","Dictionary...","context menu item"), m ) act4.setToolTip( _TR("EditViewWidget", "Choose the primary spelling dictionary for this book", "context menu tooltip") ) act4.triggered.connect(self._act_choose_dict) m.addAction(act4) return m
def add_menu_item(path, text, func, keys=None, checkable=False, checked=False): action = QAction(text, mw) if keys: action.setShortcut(QKeySequence(keys)) if checkable: action.setCheckable(checkable) action.toggled.connect(func) if not hasattr(mw, 'action_groups'): mw.action_groups = {} if path not in mw.action_groups: mw.action_groups[path] = QActionGroup(None) mw.action_groups[path].addAction(action) action.setChecked(checked) else: action.triggered.connect(func) if path == 'File': mw.form.menuCol.addAction(action) elif path == 'Edit': mw.form.menuEdit.addAction(action) elif path == 'Tools': mw.form.menuTools.addAction(action) elif path == 'Help': mw.form.menuHelp.addAction(action) else: add_menu(path) mw.custom_menus[path].addAction(action)
def add_toggle_action_to_menu(self, menu, caption, checked, call): action = QAction(caption, menu) action.setCheckable(True) action.setChecked(checked) menu.addAction(action) action.toggled.connect(call) return action
class Menu(QMenu): """this class defines the gui menu used by the tray class""" def __init__(self): super(Menu, self).__init__() self.toggle_wallpaper_action = QAction('Toggle - Wallpaper to Current Song Art') self.login_info_action = QAction('Login to Spotify') self.quit_action = QAction('Quit') self.setup_toggle_wallpaper_action() self.addSeparator() self.setup_login_info_action() self.setup_quit_action() def setup_toggle_wallpaper_action(self): """sets up the Toggle - Current Song option""" self.toggle_wallpaper_action.setCheckable(True) self.toggle_wallpaper_action.checked = False self.toggle_wallpaper_action.setEnabled(False) self.addAction(self.toggle_wallpaper_action) def setup_login_info_action(self): self.addAction(self.login_info_action) def setup_quit_action(self): self.addAction(self.quit_action)
def __init__(self): super().__init__() self.title = 'S.T.A.L.K.E.R config editor' self.left = 20 self.top = 30 self.width = 1600 self.height = 800 self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) # Add menu bar bar = self.menuBar() file = bar.addMenu("File") view = bar.addMenu("View") simple_view_toggle = QAction("Simple", self) simple_view_toggle.setCheckable(True) simple_view_toggle.setChecked(simple_view) view.addAction(simple_view_toggle) view.triggered[QAction].connect(self.process_trigger) file.addAction("Open") file.addAction("Read gamedata") file.addAction("Load icons") save = QAction("Save", self) save.setShortcut("Ctrl+S") file.addAction(save) exit_action = QAction("Quit", self) file.addAction(exit_action) file.triggered[QAction].connect(self.process_trigger) # Add main widget self.window_widget = MyWindowWidget(self) self.setCentralWidget(self.window_widget) self.show()
def addDocument(self, doc): a = QAction(self) a.setCheckable(True) if doc is self.mainwindow().currentDocument(): a.setChecked(True) self._acts[doc] = a self.setDocumentStatus(doc)
def menuItem(self, func, name, tip=None, shortcut="Null", isToggle=False, group=None): item = QAction(name, self) # self reminder: item is now a QAction item.setStatusTip(tip) if shortcut != "Null": item.setShortcut( shortcut ) # ;else: print("no shortcut for menu item \""+name+"\"") if isToggle != False: item.setCheckable(True) if group is not None: group.addAction(item) if isinstance(func, wrapper): def link(): func.call() # noinspection PyUnresolvedReferences item.triggered.connect(link) elif func is not None: #print(func.__name__ + " is not a wrapper. It is a " + type(func).__name__) # noinspection PyUnresolvedReferences item.triggered.connect(func) else: print("Menu item \"" + name + "\" has no function") return item
def create_action(parent=None, text="", shortcut=None, slot=None, tip=None, icon=None, checkable=False, signal="triggered", image=None): new_action = QAction(text, parent) if icon: new_action.setIcon(QIcon(icon)) if shortcut: new_action.setShortcut(shortcut) if tip: new_action.setToolTip(tip) new_action.setStatusTip(tip) if slot and callable(slot): if signal == "triggered": new_action.triggered.connect(slot) elif signal == "toggled": new_action.toggled.connect(slot) if checkable: new_action.setCheckable(True) if image: new_action.setIcon(QIcon(image)) return new_action
def addCustomWidget(self, text, widget, group=None, defaultVisibility=True): """ Adds a custom widget to the toolbar. `text` is the name that will displayed on the button to switch visibility. `widget` is the widget to control from the toolbar. `group` is an integer (or any hashable) if the current widget should not be displayed all the time. Call `collapsibleDockWidgets.setCurrentGroup` to switch to that group and hide other widgets. `defaultVisibility` is the default visibility of the item when it is added. This allows for the widget to be added to `collapsibleDockWidgets` after they've been created but before they are shown, and yet specify their desired visibility. Otherwise it creates troubles, see #167 on github: https://github.com/olivierkes/manuskript/issues/167. """ a = QAction(text, self) a.setCheckable(True) a.setChecked(defaultVisibility) a.toggled.connect(widget.setVisible) widget.setVisible(defaultVisibility) # widget.installEventFilter(self) b = verticalButton(self) b.setDefaultAction(a) #b.setChecked(widget.isVisible()) a2 = self.addWidget(b) self.otherWidgets.append((b, a2, widget, group))
def add_action(self, name, shortcut, callback, **kwargs): """ Ajoute une action au context menu et au widget navigation lui même. Créer une fonction à la volé pour fournir des arguments aux fonctions associé aux actions. """ action = QAction(self.tr(name), self) if 'icon' in kwargs: action.setIcon(kwargs['icon']) if 'checkable' in kwargs and kwargs['checkable']: action.setCheckable(True) if 'checked' in kwargs: checked = True if kwargs['checked'] == 'true' else False action.setChecked( checked ) action.setShortcut(shortcut) action.setShortcutContext(Qt.WidgetWithChildrenShortcut) if 'wrapped' in kwargs and kwargs['wrapped'] is False: action.triggered.connect(callback) else: action.triggered.connect(self.__wrapper(callback)) self.addAction(action) self.menu.addAction(action) self.editor_actions[name] = action
def createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered"): """Return a QAction given a number of common QAction attributes Just a shortcut function Originally borrowed from 'Rapid GUI Development with PyQT' by Mark Summerset """ action = QAction(text, self) if icon is not None: action.setIcon( QIcon.fromTheme(icon, QIcon(":/{}.png".format(icon)))) if shortcut is not None and not shortcut.isEmpty(): action.setShortcut(shortcut) tip += " ({})".format(shortcut.toString()) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if slot is not None: getattr(action, signal).connect(slot) if checkable: action.setCheckable() return action
class ObjectViewSelectionToggle(object): def __init__(self, name, menuparent): self.name = name self.menuparent = menuparent self.action_view_toggle = QAction("{0} visible".format(name), menuparent) self.action_select_toggle = QAction("{0} selectable".format(name), menuparent) self.action_view_toggle.setCheckable(True) self.action_view_toggle.setChecked(True) self.action_select_toggle.setCheckable(True) self.action_select_toggle.setChecked(True) self.action_view_toggle.triggered.connect(self.handle_view_toggle) self.action_select_toggle.triggered.connect(self.handle_select_toggle) menuparent.addAction(self.action_view_toggle) menuparent.addAction(self.action_select_toggle) def handle_view_toggle(self, val): if not val: self.action_select_toggle.setChecked(False) else: self.action_select_toggle.setChecked(True) def handle_select_toggle(self, val): if val: self.action_view_toggle.setChecked(True) def is_visible(self): return self.action_view_toggle.isChecked() def is_selectable(self): return self.action_select_toggle.isChecked()
def __init__(self, parent=None): super(Camera, self).__init__(parent) self.ui = Ui_Camera() self.pre_id = 0 self.cur_id = 0 self.count = 0 self.checked = 0 self.audio_settime = 0 self.allow_flag = 1 self.check_list = [] self.camera = None self.imageCapture = None self.isCapturingImage = False self.applicationExiting = False self.ui.setupUi(self) cameraDevice = QByteArray() videoDevicesGroup = QActionGroup(self) videoDevicesGroup.setExclusive(True) for deviceName in QCamera.availableDevices(): description = QCamera.deviceDescription(deviceName) videoDeviceAction = QAction(description, videoDevicesGroup) videoDeviceAction.setCheckable(True) videoDeviceAction.setData(deviceName) if cameraDevice.isEmpty(): cameraDevice = deviceName videoDeviceAction.setChecked(True) self.ui.menuDevices.addAction(videoDeviceAction) videoDevicesGroup.triggered.connect(self.updateCameraDevice) self.setCamera(cameraDevice) # Create and load model path_pretrained = "apis/models/facenet/20180402-114759.pb" path_SVM = "apis/models/SVM/SVM.pkl" self.recognizer = Recognizer() self.recognizer.create_graph(path_pretrained, path_SVM)
class MenuBarWidget(QMenuBar): def __init__(self, mainWidget): super().__init__() self.mainWidget: MainWidget = mainWidget self.file = self.addMenu("File") self.audio = self.addMenu("Audio") self.configDialog = QAction('Settings', self) self.configDialog.triggered.connect(ConfigDialog.showDialog) self.autoPlay = QAction('Autoplay disorder') self.autoPlay.setCheckable(True) self.autoPlay.setChecked(False) self.autoPlay.triggered.connect(self.changeBtn) self.playAudio = QAction('Play disorder') self.playAudio.triggered.connect(self.playSample) self.file.addAction(self.configDialog) self.audio.addAction(self.autoPlay) self.audio.addAction(self.playAudio) def playSample(self): QSound.play(ConfigControl.get_disorderPath()) def changeBtn(self): if self.autoPlay.isChecked(): self.mainWidget.playDisorder.setDisabled(1) else: self.mainWidget.playDisorder.setEnabled(1)
def on_context_menu(self, point): """ shows a menu on rightclick """ button_menu = QMenu() current_stylesheet = Settings.get_instance().get_settings().design.color_theme.current if current_stylesheet == 0: button_menu.setStyleSheet(open(Resources.files.qss_dark, "r").read()) elif current_stylesheet == 1: button_menu.setStyleSheet(open(Resources.files.qss_light, "r").read()) delete = QAction(str(Language.current.track.delete)) button_menu.addAction(delete) delete.triggered.connect(self.delete) add = QAction(str(Language.current.track.add)) button_menu.addAction(add) add.triggered.connect(self.add) if self.is_video: overlay = QAction(str(Language.current.track.overlay)) overlay.setCheckable(True) if self.is_overlay: overlay.setChecked(True) button_menu.addAction(overlay) overlay.changed.connect(self.overlay_toggle) button_menu.exec_(self.button.mapToGlobal(point) + QPoint(10, 0))
def addShowActions(self): """Adds a submenu giving access to the (other) opened viewer documents""" mds = self._actionCollection.viewer_document_select docs = mds.viewdocs() document_actions = {} multi_docs = len(docs) > 1 if self._panel.widget().currentViewdoc(): current_doc_filename = self._panel.widget().currentViewdoc().filename() m = self._menu sm = QMenu(m) sm.setTitle(_("Show...")) sm.setEnabled(multi_docs) ag = QActionGroup(m) ag.triggered.connect(self._panel.slotShowViewdoc) for d in docs: action = QAction(sm) action.setText(d.name()) action._document_filename = d.filename() # TODO: Tooltips aren't shown by Qt (it seems) action.setToolTip(d.filename()) action.setCheckable(True) action.setChecked(d.filename() == current_doc_filename) ag.addAction(action) sm.addAction(action) m.addSeparator() m.addMenu(sm)
def new_action(parent, text, icon_name=None, shortcut=None, slot=None, checkable=False): """Factory producing differnet actions. Args: parent (class): Parent class. text (str): Shown text. icon_name (str): Icon name in the path. Default: None. shortcut (str): Keyboard shortcut. Default: None. slot (func): Slot function. Default: None. checkable (bool): Default: False. """ action = QAction(text, parent) if icon_name: action.setIcon(QIcon(osp.join(ROOT_DIR, f'icons/{icon_name}'))) if shortcut: action.setShortcut(shortcut) # trigger action.triggered.connect(slot) if checkable: action.setCheckable(True) return action
def __init__(self): QLabel.__init__(self) self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint) self.setAttribute(Qt.WA_NoSystemBackground) self.setMouseTracking(True) self.dragPosition = QPoint(0, 0) self.mousePosition = QCursor.pos() self.actionFaces = QActionGroup(self) allFaceActions = [] for name in sorted(self.faces): action = QAction(name, self.actionFaces) action.setCheckable(True) allFaceActions.append(action) self.actionFaces.triggered.connect(self.actionUpdateFace) startAction = random.choice(allFaceActions) startAction.setChecked(True) self.actionUpdateFace(startAction) self.actionQuit = QAction("Quit", self) self.actionQuit.triggered.connect(QApplication.instance().quit) self.timer = QTimer() self.timer.timeout.connect(self.updateFromMousePosition) self.timer.start(self.update_interval) self.painter = None
class SettingsActionGroup(QActionGroup): settingsSignal = pyqtSignal() helpSignal = pyqtSignal() exportSignal = pyqtSignal() dockSignal = pyqtSignal() licenseSignal = pyqtSignal() def __init__(self, parent): super().__init__(parent) self.settingsAction = QAction("Settings", self) self.exportAction = QAction("Export", self) self.dockAction = QAction("Dock", self) self.licenseAction = QAction("License", self) self.helpAction = QAction("Help", self) self.initActions() def initActions(self): # set checkable self.settingsAction.setCheckable(False) self.helpAction.setCheckable(False) self.exportAction.setCheckable(False) self.dockAction.setCheckable(False) self.licenseAction.setCheckable(False) # connect to signals self.settingsAction.triggered.connect(self.settingsSignal.emit) self.helpAction.triggered.connect(self.helpSignal.emit) self.exportAction.triggered.connect(self.exportSignal.emit) self.dockAction.triggered.connect(self.dockSignal.emit) self.licenseAction.triggered.connect(self.licenseSignal.emit)
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("My Awesome App") label = QLabel("THIS IS AWESOME!!!") label.setAlignment(Qt.AlignCenter) self.setCentralWidget(label) toolbar = QToolBar("My main toolbar") self.addToolBar(toolbar) # Andriod Button button_action = QAction(QIcon("android.png"), "Your button", self) button_action.setStatusTip('This is your button') button_action.triggered.connect(self.onMyToolBarButtonClick) button_action.setCheckable(True) toolbar.addAction(button_action) toolbar.addSeparator() #Second Button button_action2 = QAction(QIcon('android.png'), 'Your button2', self) button_action2.setStatusTip('This is your button 2') button_action2.triggered.connect(self.onMyToolBarButtonClick) button_action2.setCheckable(True) toolbar.addAction(button_action2) #CheckBox toolbar.addWidget(QLabel('Hello')) toolbar.addWidget(QCheckBox()) self.setStatusBar(QStatusBar(self))
def _initUI(self): self.setWindowTitle("Nature of Code") self.statusBar() menubar = self.menuBar() actionMenu = menubar.addMenu("&Action") animateAct = QAction("&Animate", self) animateAct.setCheckable(True) animateAct.setChecked(True) animateAct.setShortcut("A") animateAct.triggered.connect(self._handleAnimate) actionMenu.addAction(animateAct) stepAct = QAction("&Step", self) stepAct.setShortcut("S") stepAct.triggered.connect(self._handleStep) actionMenu.addAction(stepAct) exitAct = QAction("&Quit", self) exitAct.setShortcut("Q") exitAct.triggered.connect(qApp.quit) actionMenu.addAction(exitAct) self.timer = QTimer(self) self.timer.setInterval(10) # 10ms = 100Hz self.timer.timeout.connect(self.update) self.timer.start()
def add_action(self, name, icon_path, text, callback, enabled_flag=True, add_to_menu=True, add_to_toolbar=True, status_tip=None, whats_this=None, parent=None, checkable=False): icon = QIcon(icon_path) action = QAction(icon, text, parent) action.triggered.connect(callback) action.setEnabled(enabled_flag) action.setCheckable(checkable) if status_tip is not None: action.setStatusTip(status_tip) if whats_this is not None: action.setWhatsThis(whats_this) if add_to_toolbar: self.toolbar.addAction(action) if add_to_menu: self.iface.addPluginToMenu(self.menu, action) self.toolbar_buttons[name] = action return action
def create_action(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, ischecked=False, settingSync=False): action = QAction(text, self) if icon: action.setIcon( QIcon(os.path.join(basePath, 'images', '%s.png' % icon))) if shortcut: action.setShortcut(shortcut) if tip: action.setToolTip(tip) action.setStatusTip(tip) if slot: action.triggered.connect(slot) if checkable: action.setCheckable(True) if ischecked: action.setChecked(True) if settingSync: assert checkable action.triggered.connect(lambda: self.action_setting(text)) # initialize if self.qsettings.value(text, ischecked, type=bool) != ischecked: action.setChecked(not ischecked) if slot: slot() return action
def newAction(parent, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, enabled=True): """Create a new action and assign callbacks, shortcuts, etc.""" a = QAction(text, parent) if icon is not None: a.setIcon(newIcon(icon)) if shortcut is not None: if isinstance(shortcut, (list, tuple)): a.setShortcuts(shortcut) else: a.setShortcut(shortcut) if tip is not None: a.setToolTip(tip) a.setStatusTip(tip) if slot is not None: a.triggered.connect(slot) if checkable: a.setCheckable(True) a.setEnabled(enabled) return a
def createMenus(self): # File menu file_menu = self.menuBar().addMenu('File') open_action = QAction('Open', self) open_action.triggered.connect(self.openSource) file_menu.addAction(open_action) quit_action = QAction('Quit', self) quit_action.triggered.connect(qApp.quit) file_menu.addAction(quit_action) modules_dict = { 'Finder': self.lacv.finders, 'Targeter': self.lacv.targeters, 'Generator': self.lacv.generators } for name, modules in modules_dict.items(): menu = self.menuBar().addMenu(name) menu.setObjectName(name + '_menu') group = QActionGroup(self) for m in modules: action = QAction(m.name, self) action.setCheckable(True) action.triggered.connect(partial(self.setModule, m)) menu.addAction(action) group.addAction(action) finder_menu = self.menuBar().findChildren(QMenu, 'Finder_menu')[0] finder_menu.addSeparator() finder_settings_action = QAction('Global settings', self) finder_settings_action.triggered.connect(self.showFinderSettings) finder_menu.addAction(finder_settings_action)
def toolbar(self) -> QToolBar: toolbar = QToolBar() set_grid_size_action = QAction(QIcon(":/icons/grid.png"), "Grid Size", self) set_grid_size_action.triggered.connect(self.set_grid_size) toolbar.addAction(set_grid_size_action) show_grid_action = QAction("Show Grid", self) show_grid_action.setCheckable(True) show_grid_action.triggered.connect(self.show_grid) toolbar.addAction(show_grid_action) go_to_action = QAction("Go To", self) go_to_action.triggered.connect(self.go_to) toolbar.addAction(go_to_action) take_screenshot_action = QAction("Take Screenshot", self) take_screenshot_action.triggered.connect(self.take_screenshot) toolbar.addAction(take_screenshot_action) print_items_action = QAction("Print Items", self) print_items_action.triggered.connect(self.print_items) toolbar.addAction(print_items_action) print_slide_view_params_action = QAction("Print Slide View Params", self) print_slide_view_params_action.triggered.connect(self.print_slide_view_params) toolbar.addAction(print_slide_view_params_action) return toolbar
def create_action(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): # 创建事件 action = QAction(text, self) if icon is not None: # action.setIcon(QIcon(":/%s.png" % button_icon)) pass if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) # bottons = QPushButton(text, self) # bottons.setti action.setStatusTip(tip) if slot is not None: action.triggered.connect(slot) if checkable: action.setCheckable(True) return action
def _create_action(self, icon, title, menu, handler=None, group=None, toggle=False, toolbar=True, key=None): if group is None: parent = self else: parent = group action = QAction(title, parent) if icon is not None: action.setIcon(icon) if key is not None: action.setShortcut(key) if toggle: action.setCheckable(True) if toolbar: self.toolbar.addAction(action) menu.addAction(action) if handler: action.triggered.connect(handler) return action
def init_menu(self): # add preset into the Import menu self.import_preset_menus = [] self.import_preset_slots = [] self.addon_menus = [] self.addon_slots = [] self.menu_import_file.clear() # generate import_file_as menu for preset in self.core_data.import_presets: temp = QAction() temp.setObjectName("action_preset_{p}".format(p=preset)) temp.setCheckable(1) temp.setText(preset) if preset == self.core_data.get_default_preset(): temp.setChecked(1) self.import_preset_slots.append(lambda state, p=preset: self.choose_import_preset(state, p)) self.import_preset_menus.append(temp) self.menu_import_file.addAction(temp) # generate addon menu for package in self.core_data.addon_dict: menu_group = QMenu(self) menu_group.setObjectName('action_' + package) menu_group.setTitle(package) self.menu_addon.addMenu(menu_group) for addon_name in self.core_data.addon_dict[package]: temp = QAction(self) temp.setObjectName("action_addon_{a}".format(a=addon_name)) temp.setText(addon_name) self.addon_menus.append(temp) self.addon_slots.append(lambda state, a=addon_name: self.choose_addon(state, a)) menu_group.addAction(temp)
def _InitWindowsMenu(self): def UpdateWindowsStatue(): dMap = {oAction.text(): oAction for oAction in oWindowsMenu.actions()} for oChild in lstChilde: dMap[oChild.windowTitle()].setChecked(oChild.isVisible()) def OnWindows(): for oChild in lstChilde: oSender = self.sender() if oSender.text() != oChild.windowTitle(): continue if oSender.isChecked(): oChild.show() else: oChild.hide() return oMenu = menumgr.GetMenu(self) oWindowsMenu = oMenu.GetSubMenu("窗口") oWindowsMenu.aboutToShow.connect(UpdateWindowsStatue) oWindowsMenu.clear() lstChilde = [] for oChild in self.children(): if not isinstance(oChild, (QDockWidget,)): continue lstChilde.append(oChild) for oChild in lstChilde: oAction = QAction(oChild.windowTitle(), self) oAction.triggered.connect(OnWindows) oAction.setCheckable(True) oWindowsMenu.addAction(oAction)
def toolbar(self) -> QToolBar: toolbar = QToolBar(self) toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) label = QLabel("Blend:") toolbar.addWidget(label) blend_combo_box = QComboBox() modes_list = [ o for o in getmembers(QPainter) if o[0].startswith('CompositionMode_') ] blend_combo_box.addItems( [f[0].replace('CompositionMode_', '') for f in modes_list]) blend_combo_box.setCurrentText('Screen') blend_combo_box.currentTextChanged.connect( self._blend_current_text_changed) toolbar.addWidget(blend_combo_box) toolbar.addSeparator() show_scale_bar_action = QAction(QIcon(":/icons/icons8-ruler-16.png"), "Scale Bar", self) show_scale_bar_action.triggered.connect(self._show_scale_bar) show_scale_bar_action.setCheckable(True) toolbar.addAction(show_scale_bar_action) show_mask_action = QAction(QIcon(":/icons/icons8-ruler-16.png"), "Mask", self) show_mask_action.triggered.connect(self._show_mask) show_mask_action.setCheckable(True) toolbar.addAction(show_mask_action) return toolbar
def addBranch(self, branch): a = QAction(self) a.setCheckable(True) if branch == vcs.app_repo.current_branch(): a.setChecked(True) a.setEnabled(False) self._acts[branch] = a self.setBranchStatus(branch)
def addAction(name, checked=False): action = QAction(name, self) action.setText(name) action.setCheckable(True) action.setChecked(checked) action.setActionGroup(self.lyricGroup) return action
def generateViewMenu(self): values = [ (self.tr("Nothing"), "Nothing"), (self.tr("POV"), "POV"), (self.tr("Label"), "Label"), (self.tr("Progress"), "Progress"), (self.tr("Compile"), "Compile"), ] menus = [ (self.tr("Tree"), "Tree"), (self.tr("Index cards"), "Cork"), (self.tr("Outline"), "Outline") ] submenus = { "Tree": [ (self.tr("Icon color"), "Icon"), (self.tr("Text color"), "Text"), (self.tr("Background color"), "Background"), ], "Cork": [ (self.tr("Icon"), "Icon"), (self.tr("Text"), "Text"), (self.tr("Background"), "Background"), (self.tr("Border"), "Border"), (self.tr("Corner"), "Corner"), ], "Outline": [ (self.tr("Icon color"), "Icon"), (self.tr("Text color"), "Text"), (self.tr("Background color"), "Background"), ], } self.menuView.clear() self.menuView.addMenu(self.menuMode) self.menuView.addSeparator() # print("Generating menus with", settings.viewSettings) for mnu, mnud in menus: m = QMenu(mnu, self.menuView) for s, sd in submenus[mnud]: m2 = QMenu(s, m) agp = QActionGroup(m2) for v, vd in values: a = QAction(v, m) a.setCheckable(True) a.setData("{},{},{}".format(mnud, sd, vd)) if settings.viewSettings[mnud][sd] == vd: a.setChecked(True) a.triggered.connect(self.setViewSettingsAction, AUC) agp.addAction(a) m2.addAction(a) m.addMenu(m2) self.menuView.addMenu(m)
def action(self): icon = self.icon if isinstance(icon, QStyle.StandardPixmap): icon = self.plot.style().standardIcon(icon) action = QAction(icon, self.text, self.plot) action.setCheckable(True) action.toggled.connect(self.onToggle) self.plot.addCapture(self.mode, action.setChecked) return action
def addCustomWidget(self, text, widget, group=None): a = QAction(text, self) a.setCheckable(True) a.setChecked(widget.isVisible()) a.toggled.connect(widget.setVisible) # widget.installEventFilter(self) b = verticalButton(self) b.setDefaultAction(a) #b.setChecked(widget.isVisible()) a2 = self.addWidget(b) self.otherWidgets.append((b, a2, widget, group))
def populate_channel_menu(*args): if sip.isdeleted(channel_button): return self.channel_menu.clear() self.channel_actions = [] for ch in range(op.Input.meta.getTaggedShape()['c']): action = QAction("Channel {}".format(ch), self.channel_menu) action.setCheckable(True) self.channel_menu.addAction(action) self.channel_actions.append(action) configure_update_handlers( action.toggled, op.ChannelSelections )
class ActionSelector(TitledToolbar): def __init__(self, parent): TitledToolbar.__init__(self, parent, 'Actions') toolbar = QToolBar(self) toolbar.setFloatable(False) toolbar.setMovable(False) self.saveAction = QAction(QIcon(":/icons/file-save.png"), "Save (Ctrl-S)", toolbar) self.saveAction.setShortcut(Qt.CTRL + Qt.Key_S); self.saveAction.triggered.connect(parent.save) toolbar.addAction(self.saveAction) self.nonprintableAction = QAction(QIcon(":/icons/view-nonprintable.png"), "View nonprintable chars", toolbar) self.nonprintableAction.setCheckable(True); self.nonprintableAction.triggered.connect(parent.toggleNonprintable) toolbar.addAction(self.nonprintableAction) self.undoAction = QAction(QIcon(":/icons/edit-undo.png"), "Undo (Ctrl-Z)", toolbar) # saveAction.setShortcut(Qt.CTRL + Qt.Key_Z); self.undoAction.triggered.connect(parent.undo) toolbar.addAction(self.undoAction) self.redoAction = QAction(QIcon(":/icons/edit-redo.png"), "Redo (Ctrl-Y)", toolbar) # saveAction.setShortcut(Qt.CTRL + Qt.Key_Y); self.redoAction.triggered.connect(parent.redo) toolbar.addAction(self.redoAction) self.backAction = QAction(QIcon(":/icons/view-back.png"), "Back", toolbar) self.backAction.setEnabled(False) self.backAction.triggered.connect(parent.navigateBack) toolbar.addAction(self.backAction) self.forwardAction = QAction(QIcon(":/icons/view-forward.png"), "Forward", toolbar) self.forwardAction.setEnabled(False) self.forwardAction.triggered.connect(parent.navigateForward) toolbar.addAction(self.forwardAction) insertImageAction = QAction(QIcon(":/icons/edit-insert-image.png"), "Insert Image", toolbar) insertImageAction.triggered.connect(parent.insertImage) toolbar.addAction(insertImageAction) insertFormulaAction = QAction("f(x)", toolbar) insertFormulaAction.triggered.connect(parent.insertFormula) toolbar.addAction(insertFormulaAction) findInPageAction = QAction(QIcon(":/icons/edit-find.png"), "Find in page (CTRL-F)", toolbar) findInPageAction.setShortcut(Qt.CTRL + Qt.Key_F); findInPageAction.triggered.connect(parent.findInPage) toolbar.addAction(findInPageAction) self.addWidget(toolbar)
def updateDevices(self): for action in self.deviceGroup.actions(): self.deviceGroup.removeAction(action) self.menuDevice.removeAction(action) for device in self.devices: action = QAction(device.name, self.menuDevice) action.setCheckable(True) action.setData(device) self.menuDevice.addAction(action) self.deviceGroup.addAction(action) action.setChecked(True) self.device = device
def createGroup(self): self.bottomMenu = QFrame() self.searchText = QLineEdit(self) self.replaceText = QLineEdit(self) toolBar = QToolBar() # Create new action undoAction = QAction(QIcon.fromTheme('edit-undo'), 'Undo', self) undoAction.setStatusTip('Undo') undoAction.triggered.connect(self.undoCall) toolBar.addAction(undoAction) # create redo action redoAction = QAction(QIcon.fromTheme('edit-redo'), 'Redo', self) redoAction.setStatusTip('Undo') redoAction.triggered.connect(self.redoCall) toolBar.addAction(redoAction) toolBar.addSeparator() # create replace action replaceAction = QAction(QIcon.fromTheme('edit-find-replace'), 'Replace', self) replaceAction.triggered.connect(self.replaceCall) toolBar.addAction(replaceAction) # create find action findAction = QAction(QIcon.fromTheme('edit-find'), 'Find', self) findAction.triggered.connect(self.findCall) toolBar.addAction(findAction) # create next action nextAction = QAction(QIcon.fromTheme('go-previous'), 'Find Previous', self) nextAction.triggered.connect(self.nextCall) toolBar.addAction(nextAction) toolBar.addSeparator() # create case action caseAction = QAction(QIcon.fromTheme('edit-case'), 'Aa', self) caseAction.setCheckable(1) caseAction.triggered.connect(self.caseCall) toolBar.addAction(caseAction) box = QHBoxLayout() box.addWidget(toolBar) box.addWidget(self.searchText) box.addWidget(self.replaceText) box.addStretch(1) self.bottomMenu.setLayout(box) return self.bottomMenu
def setup_terrain_display_toggles(self): for mode, name in ((SHOW_TERRAIN_REGULAR, "Show Heightmap"), (SHOW_TERRAIN_LIGHT, "Show Lightmap")): toggle = self.make_terrain_toggle(mode) toggle_action = QAction(name, self) toggle_action.setCheckable(True) if mode == SHOW_TERRAIN_REGULAR: toggle_action.setChecked(True) else: toggle_action.setChecked(False) toggle_action.triggered.connect(toggle) self.terrain_menu.addAction(toggle_action) self.terrain_display_actions.append((toggle_action, toggle, mode))
def create_action(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal_name='triggered'): action = QAction(text, self) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if slot is not None: getattr(action, signal_name).connect(slot) if checkable: action.setCheckable(True) return action
def __init__(self, toolbar): TitledToolbar.__init__(self, toolbar, 'Text style') self.currentStyle = None toolbar = QToolBar(self) toolbar.setFloatable(False) toolbar.setMovable(False) self.styleToAction = {} textKeywordAction = QAction(QIcon(':/icons/format-keyword.png'), 'Notepad link', toolbar) textKeywordAction.setCheckable(True); selector = ('olink', None, None) textKeywordAction.setProperty('style', selector) self.styleToAction[selector] = textKeywordAction textKeywordAction.triggered.connect(self.styleSelected) toolbar.addAction(textKeywordAction) textLinkAction = QAction(QIcon(':/icons/format-link.png'), 'Internet link', toolbar) textLinkAction.setCheckable(True); selector = ('link', None, None) textLinkAction.setProperty('style', selector) self.styleToAction[selector] = textLinkAction textLinkAction.triggered.connect(self.styleSelected) toolbar.addAction(textLinkAction) textBoldAction = QAction(QIcon(':/icons/format-text-emphasized.png'), 'Emphasize', toolbar) textBoldAction.setCheckable(True); selector = ('emphasis', None, None) textBoldAction.setProperty('style', selector) self.styleToAction[selector] = textBoldAction textBoldAction.triggered.connect(self.styleSelected) toolbar.addAction(textBoldAction) textHighlightAction = QAction(QIcon(':/icons/format-text-highlight.png'), 'Highlight', toolbar) textHighlightAction.setCheckable(True); selector = ('emphasis', 'role', 'highlight') textHighlightAction.setProperty('style', selector) self.styleToAction[selector] = textHighlightAction textHighlightAction.triggered.connect(self.styleSelected) toolbar.addAction(textHighlightAction) textCodeAction = QAction(QIcon(':/icons/format-text-code.png'), 'Code', toolbar) textCodeAction.setCheckable(True); selector = ('code', None, None) textCodeAction.setProperty('style', selector) self.styleToAction[selector] = textCodeAction textCodeAction.triggered.connect(self.styleSelected) toolbar.addAction(textCodeAction) self.addWidget(toolbar)
class Actions(actioncollection.ActionCollection): name = "documentactions" def createActions(self, parent): self.edit_cut_assign = QAction(parent) self.edit_move_to_include_file = QAction(parent) self.view_highlighting = QAction(parent) self.view_highlighting.setCheckable(True) self.view_goto_file_or_definition = QAction(parent) self.tools_indent_auto = QAction(parent) self.tools_indent_auto.setCheckable(True) self.tools_indent_indent = QAction(parent) self.tools_reformat = QAction(parent) self.tools_remove_trailing_whitespace = QAction(parent) self.tools_convert_ly = QAction(parent) self.tools_quick_remove_comments = QAction(parent) self.tools_quick_remove_articulations = QAction(parent) self.tools_quick_remove_ornaments = QAction(parent) self.tools_quick_remove_instrument_scripts = QAction(parent) self.tools_quick_remove_slurs = QAction(parent) self.tools_quick_remove_beams = QAction(parent) self.tools_quick_remove_ligatures = QAction(parent) self.tools_quick_remove_dynamics = QAction(parent) self.tools_quick_remove_fingerings = QAction(parent) self.tools_quick_remove_markup = QAction(parent) self.edit_cut_assign.setIcon(icons.get('edit-cut')) self.edit_move_to_include_file.setIcon(icons.get('edit-cut')) self.view_goto_file_or_definition.setShortcut(QKeySequence(Qt.ALT + Qt.Key_Return)) self.edit_cut_assign.setShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_X)) def translateUI(self): self.edit_cut_assign.setText(_("Cut and Assign...")) self.edit_move_to_include_file.setText(_("Move to Include File...")) self.view_highlighting.setText(_("Syntax &Highlighting")) self.view_goto_file_or_definition.setText(_("View File or Definition at &Cursor")) self.tools_indent_auto.setText(_("&Automatic Indent")) self.tools_indent_indent.setText(_("Re-&Indent")) self.tools_reformat.setText(_("&Format")) self.tools_remove_trailing_whitespace.setText(_("Remove Trailing &Whitespace")) self.tools_convert_ly.setText(_("&Update with convert-ly...")) self.tools_quick_remove_comments.setText(_("Remove &Comments")) self.tools_quick_remove_articulations.setText(_("Remove &Articulations")) self.tools_quick_remove_ornaments.setText(_("Remove &Ornaments")) self.tools_quick_remove_instrument_scripts.setText(_("Remove &Instrument Scripts")) self.tools_quick_remove_slurs.setText(_("Remove &Slurs")) self.tools_quick_remove_beams.setText(_("Remove &Beams")) self.tools_quick_remove_ligatures.setText(_("Remove &Ligatures")) self.tools_quick_remove_dynamics.setText(_("Remove &Dynamics")) self.tools_quick_remove_fingerings.setText(_("Remove &Fingerings")) self.tools_quick_remove_markup.setText(_("Remove Text &Markup (from music)"))
def generateMenu(self): m = QMenu() for i in [ self.tr("Show Plots"), self.tr("Show Characters"), self.tr("Show Objects"), ]: a = QAction(i, m) a.setCheckable(True) a.setEnabled(False) m.addAction(a) self.btnSettings.setMenu(m)
def act(self, name, icon=None, trig=None, trigbool=None, shct=None): if not isinstance(shct, QKeySequence): shct = QKeySequence(shct) if icon: action = QAction(self.actIcon(icon), name, self) else: action = QAction(name, self) if trig: action.triggered.connect(trig) elif trigbool: action.setCheckable(True) action.triggered[bool].connect(trigbool) if shct: action.setShortcut(shct) return action
def createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered"): action = QAction(text, self) if icon is not None: action.setIcon(QtGui.QIcon(":/{}.png".format(icon))) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if slot is not None: getattr(action, signal).connect(slot) #old-style: self.connect(action, SIGNAL(signal), slot) if checkable: action.setCheckable(True) return action
def createaction (self, text, slot=None, shortcuts=None, icon=None, tip=None, checkable=False): action = QAction(text, self) if icon is not None: action.setIcon(QIcon.fromTheme(icon)) if shortcuts is not None: action.setShortcuts(shortcuts) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if slot is not None: action.triggered.connect(slot) if checkable: action.setCheckable(True) return action
def updateMenuDict(self): if not enchant: return self.menuDict.clear() for i in enchant.list_dicts(): a = QAction(str(i[0]), self) a.setCheckable(True) if settings.dict is None: settings.dict = enchant.get_default_language() if str(i[0]) == settings.dict: a.setChecked(True) a.triggered.connect(self.setDictionary, AUC) self.menuDictGroup.addAction(a) self.menuDict.addAction(a)
def create_action(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): action = QAction(text, self) if icon is not None: action.setIcon(QIcon(":/%s.png" % icon)) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) # if slot is not None: # action.connect(slot) ## self.connect(action, SIGNAL(signal), slot) if checkable: action.setCheckable(True) return action
def create_action(parent, text, shortcut=None, icon=None, tip=None, triggered=None, toggled=None, context=Qt.WindowShortcut): """Create a QAction with the given attributes.""" action = QAction(text, parent) if triggered is not None: action.triggered.connect(triggered) if toggled is not None: action.toggled.connect(toggled) action.setCheckable(True) if icon is not None: action.setIcon( icon ) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) action.setShortcutContext(context) return action
def _create_action(self, action_name, icon_file, text, shortcuts): if action_name == '*separator*': action = QAction(self.window) action.setSeparator(True) else: if icon_file: action = QAction(QIcon(utils.resource_path(icon_file)), text, self.window) else: action = QAction(text, self.window) if shortcuts: sequences = [QKeySequence(s) for s in shortcuts] action.setShortcuts(sequences) if action_name.startswith('+'): action.setCheckable(True) if action_name.startswith('++'): action.setChecked(True) return action
class SessionActions(actioncollection.ActionCollection): name = "session" def createActions(self, parent=None): self.session_new = QAction(parent) self.session_save = QAction(parent) self.session_manage = QAction(parent) self.session_none = QAction(parent) self.session_none.setCheckable(True) self.session_new.setIcon(icons.get('document-new')) self.session_save.setIcon(icons.get('document-save')) self.session_manage.setIcon(icons.get('view-choose')) def translateUI(self): self.session_new.setText(_("New Session", "&New...")) self.session_save.setText(_("&Save")) self.session_manage.setText(_("&Manage...")) self.session_none.setText(_("No Session"))
def on_main_window_start(main_window): main_window.theme_menu = main_window.menuBar().addMenu( main_window.tr('Themes')) themes_directory = QFileInfo('themes') if themes_directory.exists(): active_theme = ThemeManager.get_active_theme() path = themes_directory.absoluteFilePath() group_action = QActionGroup(main_window) group_action.setExclusive(True) for theme in os.listdir(path): action = QAction(theme, main_window) action.setData(theme) action.setCheckable(True) if theme == active_theme: action.setChecked(True) action.changed.connect(ThemeManager.wrapper(main_window)) group_action.addAction(action) group_action.addAction(action) main_window.theme_menu.addAction(action)