def createTabButton(self, widget, text, icon=None, toolTip=None): """ Create the tab button for `widget`. """ action = QAction(text, self) action.setCheckable(True) if icon: action.setIcon(icon) if toolTip: action.setToolTip(toolTip) self.__tabActionGroup.addAction(action) self.__actionMapper.setMapping(action, action) action.toggled.connect(self.__actionMapper.map) button = ToolBoxTabButton(self, objectName="toolbox-tab-button") button.setDefaultAction(action) button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) if self.__tabIconSize.isValid(): button.setIconSize(self.__tabIconSize) if self.__tabButtonHeight > 0: button.setFixedHeight(self.__tabButtonHeight) return button
class Plugin: def __init__(self): self.timer = QTimer(None) self.timer.setInterval(10000) self.timer.timeout.connect(self.Timeout) self.timer.setSingleShot(True) self.action = QAction("Preview mode", None) self.action.setCheckable(True) self.action.triggered.connect(self.Enabled) clementine.ui.AddAction("playlist_menu", self.action) clementine.player.Playing.connect(self.Playing) clementine.player.Paused.connect(self.Stopped) clementine.player.Stopped.connect(self.Stopped) self.enabled = False def Enabled(self, enabled): self.enabled = enabled if enabled: if clementine.player.GetState() == 2: # Playing self.timer.start() else: self.timer.stop() def Playing(self): if self.enabled: self.timer.start() def Stopped(self): self.timer.stop() def Timeout(self): if clementine.player.GetState() == 2: clementine.player.Next()
def addAction(self, action, checked=None, autoBuild=True): """ Adds the inputed action to this widget's action group. This will auto-\ create a new group if no group is already defined. :param action | <QAction> || <str> :return <QAction> """ # clear the holder actions = self._actionGroup.actions() if actions and actions[0].objectName() == 'place_holder': self._actionGroup.removeAction(actions[0]) actions[0].deleteLater() # create an action from the name if not isinstance(action, QAction): action_name = str(action) action = QAction(action_name, self) action.setObjectName(action_name) action.setCheckable(self.isCheckable()) # auto-check the first option if checked or (not self._actionGroup.actions() and checked is None): action.setChecked(True) self._actionGroup.addAction(action) if autoBuild: self.rebuild() return action
def createAction(self, text="", slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): """Create action out of keyword arguments. Return action. Keyword arguments: text -- User visible text (default "") slot -- function to call (default None) shortcut -- Key sequence (default None) icon -- Name of icon file (default None) tip -- Tooltip (default None) checkable -- Should action be checkable (default None) signal -- Signal to emit (default "triggered()") """ action = QAction(text, self) if icon is not None: action.setIcon(QIcon(":/resource/{0}.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: self.connect(action, SIGNAL(signal), slot) if checkable: action.setCheckable(True) return action
def _addDrawingTool(self, classCode, category, toolName, icon, featureType, query=None): data = {} data['class'] = classCode data['category'] = category action = QAction(icon, category, self) action.setData(data) action.setToolTip(toolName) action.setCheckable(True) mapTool = MapToolAddFeature(self._iface, featureType, toolName) mapTool.setAction(action) mapTool.setPanningEnabled(True) mapTool.setZoomingEnabled(True) mapTool.setSnappingEnabled(True) mapTool.activated.connect(self._mapToolActivated) if query is not None: field = Config.fields[query] mapTool.setAttributeQuery(field['attribute'], field['type'], field['default'], field['label'], field['query'], field['min'], field['max'], field['decimals']) self._addToolButton(action, featureType) self._actions[category] = action self._mapTools[category] = mapTool
def create_action(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): u""" :param text: :param slot: :param shortcut: :param icon: :param tip: :param checkable: :param signal: :return: """ action = QAction(text, self) if slot is not None: self.connect(action, SIGNAL(signal), slot) if shortcut is not None: action.setShortcut(shortcut) if icon is not None: action.setIcon(icon) if tip is not None: action.setToolTip(tip) if checkable is not None: action.setCheckable(checkable) return 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 MapSwipePlugin: def __init__(self, iface): def translate(): # # For create file 'qm' # 1) Define that files need for translation: mapswipetool.pro # 2) Create 'ts': pylupdate4 -verbose mapswipetool.pro # 3) Edit your translation: QtLinquist # 4) Create 'qm': lrelease *.ts # dirname = os.path.dirname( os.path.abspath(__file__) ) locale = QSettings().value("locale/userLocale") localePath = os.path.join( dirname, "i18n", "%s_%s.qm" % ( name_src, locale ) ) if os.path.exists(localePath): self.translator = QTranslator() self.translator.load(localePath) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) self.iface = iface self.canvas = iface.mapCanvas() self.action = None # Define by initGui self.tool = MapSwipeTool( self.iface ) self.prevTool = None # Define by run name_src = "mapswipetool" translate() def initGui(self): title = "Map swipe tool" icon = QIcon( os.path.join( os.path.dirname(__file__), 'mapswipetool.png' ) ) self.action = QAction( icon, title, self.iface.mainWindow() ) self.action.setObjectName( "MapSwipeTool" ) self.action.setWhatsThis( title ) self.action.setStatusTip( title ) self.action.triggered.connect( self.run ) self.menu = "&Map swipe tool" # Maptool self.action.setCheckable( True ) self.tool.setAction( self.action ) self.iface.addToolBarIcon( self.action ) self.iface.addPluginToMenu( self.menu, self.action ) def unload(self): self.canvas.unsetMapTool( self.tool ) self.iface.removeToolBarIcon( self.action ) self.iface.removePluginMenu( self.menu, self.action ) del self.action @pyqtSlot() def run(self): if self.canvas.mapTool() != self.tool: self.prevTool = self.canvas.mapTool() self.canvas.setMapTool( self.tool ) else: self.canvas.setMapTool( self.prevTool )
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 create_action(parent, text, shortcut=None, icon=None, tip=None, toggled=None, triggered=None, data=None, menurole=None, context=Qt.WindowShortcut): """Create a QAction""" action = QAction(text, parent) if triggered is not None: parent.connect(action, SIGNAL("triggered()"), triggered) if toggled is not None: parent.connect(action, SIGNAL("toggled(bool)"), toggled) action.setCheckable(True) if icon is not None: if is_text_string(icon): icon = get_icon(icon) action.setIcon(icon) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if data is not None: action.setData(data) if menurole is not None: action.setMenuRole(menurole) #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut # (this will avoid calling shortcuts from another dockwidget # since the context thing doesn't work quite well with these widgets) action.setShortcutContext(context) return action
def createCaptureButtons(self, form, wasselected): tool = form.getMaptool()(self.canvas) action = QAction(QIcon(":/icons/capture"), "Capture", None) action.setObjectName("capture") action.setCheckable(True) action.toggled.connect(partial(self.setMapTool, tool)) if isinstance(tool, PointTool): add = partial(self.addNewFeature, form) tool.geometryComplete.connect(add) else: tool.finished.connect(self.openForm) tool.error.connect(partial(self.showToolError, form.label)) # Set the action as a data entry button so we can remove it later. action.setProperty("dataentry", True) self.actionGPSFeature.setVisible(not tool.isEditTool()) self.projecttoolbar.insertAction(self.topspaceraction, action) self.projecttoolbar.insertAction(self.topspaceraction, self.actionGPSFeature) self.editgroup.addAction(action) self.layerbuttons.append(action) action.setChecked(wasselected)
def _addDrawingTool(self, classCode, category, toolName, icon, featureType, query=None): data = {} data['class'] = classCode data['category'] = category action = QAction(icon, category, self) action.setData(data) action.setToolTip(toolName) action.setCheckable(True) mapTool = MapToolAddFeature(self._iface, featureType, toolName) mapTool.setAction(action) mapTool.setPanningEnabled(True) mapTool.setZoomingEnabled(True) mapTool.setSnappingEnabled(True) mapTool.activated.connect(self._mapToolActivated) if query is not None: field = Config.fields[query] mapTool.setAttributeQuery( field['attribute'], field['type'], field['default'], field['label'], field['query'], field['min'], field['max'], field['decimals'] ) self._addToolButton(action, featureType) self._actions[category] = action self._mapTools[category] = mapTool
def initGui(self): icon_path = ':/icons/NewLayerIcon.png' actionGenerateLayer = QAction(QIcon(icon_path), u"Generate Layer", None) actionGenerateLayer.triggered.connect(self.generateLayer) actionGenerateLayer.setStatusTip(None) actionGenerateLayer.setWhatsThis(None) self.toolbar.addAction(actionGenerateLayer) self.iface.addPluginToMenu(self.menu, actionGenerateLayer) actionGenerateLayer.setEnabled(True) self.actions.append(actionGenerateLayer) self.guideInfoMapTool = GuideInfoCommonMapTool(self.iface.mapCanvas()) icon_path = ':/icons/GuideIcon.png' actionShowGuideInfo = QAction(QIcon(icon_path), u"Show GuideInfo", None) actionShowGuideInfo.triggered.connect(self.showGuideInfo) actionShowGuideInfo.setStatusTip(None) actionShowGuideInfo.setWhatsThis(None) self.toolbar.addAction(actionShowGuideInfo) self.iface.addPluginToMenu(self.menu, actionShowGuideInfo) actionShowGuideInfo.setEnabled(True) actionShowGuideInfo.setCheckable(True) self.actions.append(actionShowGuideInfo) self.guideInfoMapTool.setAction(actionShowGuideInfo) return
def create_action(parent, text, shortcut=None, icon=None, tip=None, toggled=None, triggered=None, data=None, context=Qt.WindowShortcut): """Create a QAction""" action = QAction(text, parent) if triggered is not None: parent.connect(action, SIGNAL("triggered()"), triggered) if toggled is not None: parent.connect(action, SIGNAL("toggled(bool)"), toggled) action.setCheckable(True) if icon is not None: if isinstance(icon, (str, unicode)): icon = get_icon(icon) action.setIcon( icon ) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if data is not None: action.setData(QVariant(data)) #TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut # (this will avoid calling shortcuts from another dockwidget # since the context thing doesn't work quite well with these widgets) action.setShortcutContext(context) return action
class Actions(actioncollection.ActionCollection): name = "engrave" def createActions(self, parent=None): self.engrave_sticky = QAction(parent) self.engrave_sticky.setCheckable(True) self.engrave_runner = QAction(parent) self.engrave_preview = QAction(parent) self.engrave_publish = QAction(parent) self.engrave_custom = QAction(parent) self.engrave_abort = QAction(parent) self.engrave_preview.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_M)) self.engrave_publish.setShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_P)) self.engrave_custom.setShortcut(QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_M)) self.engrave_abort.setShortcut(QKeySequence(Qt.CTRL + Qt.Key_Pause)) self.engrave_sticky.setIcon(icons.get('pushpin')) self.engrave_preview.setIcon(icons.get('lilypond-run')) self.engrave_publish.setIcon(icons.get('lilypond-run')) self.engrave_custom.setIcon(icons.get('lilypond-run')) self.engrave_abort.setIcon(icons.get('process-stop')) def translateUI(self): self.engrave_runner.setText(_("Engrave")) self.engrave_preview.setText(_("&Engrave (preview)")) self.engrave_publish.setText(_("Engrave (&publish)")) self.engrave_custom.setText(_("Engrave (&custom)...")) self.engrave_abort.setText(_("Abort Engraving &Job"))
class MapSwipePlugin: def __init__(self, iface): def translate(): # # For create file 'qm' # 1) Define that files need for translation: mapswipetool.pro # 2) Create 'ts': pylupdate4 -verbose mapswipetool.pro # 3) Edit your translation: QtLinquist # 4) Create 'qm': lrelease *.ts # dirname = os.path.dirname(os.path.abspath(__file__)) locale = QSettings().value("locale/userLocale") localePath = os.path.join(dirname, "i18n", "%s_%s.qm" % (name_src, locale)) if os.path.exists(localePath): self.translator = QTranslator() self.translator.load(localePath) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) self.iface = iface self.canvas = iface.mapCanvas() self.action = None # Define by initGui self.tool = MapSwipeTool(self.iface) self.prevTool = None # Define by run name_src = "mapswipetool" translate() def initGui(self): title = "Map swipe tool" icon = QIcon( os.path.join(os.path.dirname(__file__), 'mapswipetool.png')) self.action = QAction(icon, title, self.iface.mainWindow()) self.action.setObjectName("MapSwipeTool") self.action.setWhatsThis(title) self.action.setStatusTip(title) self.action.triggered.connect(self.run) self.menu = "&Map swipe tool" # Maptool self.action.setCheckable(True) self.tool.setAction(self.action) self.iface.addToolBarIcon(self.action) self.iface.addPluginToMenu(self.menu, self.action) def unload(self): self.canvas.unsetMapTool(self.tool) self.iface.removeToolBarIcon(self.action) self.iface.removePluginMenu(self.menu, self.action) del self.action @pyqtSlot() def run(self): if self.canvas.mapTool() != self.tool: self.prevTool = self.canvas.mapTool() self.canvas.setMapTool(self.tool) else: self.canvas.setMapTool(self.prevTool)
def addNewAction( self, iconPath, text, callback=None, enabled=True, checkable=False, addToMenu=True, addToToolbar=True, tip=None, whatsThis=None, parent=None): """Add a toolbar icon to the toolbar""" if parent is None: parent = self.iface.mainWindow() action = QAction(QIcon(iconPath), text, parent) if tip is not None: action.setStatusTip(tip) if whatsThis is not None: action.setWhatsThis(whatsThis) if callback is not None: action.triggered.connect(callback) action.setEnabled(enabled) action.setCheckable(checkable) self.addAction(action, addToMenu, addToToolbar) return action
class Actions(actioncollection.ActionCollection): name = "documentactions" def createActions(self, parent): self.file_open_file_at_cursor = QAction(parent) self.edit_cut_assign = QAction(parent) self.view_highlighting = QAction(parent) self.view_highlighting.setCheckable(True) 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_convert_ly = QAction(parent) self.edit_cut_assign.setIcon(icons.get('edit-cut')) self.file_open_file_at_cursor.setShortcut(QKeySequence("Alt+Ctrl+O")) self.edit_cut_assign.setShortcut(QKeySequence(Qt.SHIFT + Qt.CTRL + Qt.Key_X)) def translateUI(self): self.file_open_file_at_cursor.setText(_("Open File at C&ursor")) self.edit_cut_assign.setText(_("Cut and Assign...")) self.view_highlighting.setText(_("Syntax &Highlighting")) self.tools_indent_auto.setText(_("&Automatic Indent")) self.tools_indent_indent.setText(_("Re-&Indent")) self.tools_reformat.setText(_("&Format")) self.tools_convert_ly.setText(_("&Update with convert-ly..."))
def setupLanguageMenu(self): self.languages = QDir(":/languages").entryList() if self.current_language is None: self.current_language = QLocale.system().name( ) # Retrieve Current Locale from the operating system. log.debug("Detected user's locale as %s" % self.current_language) for language in self.languages: translator = QTranslator( ) # Create a translator to translate Language Display Text. translator.load(":/languages/%s" % language) language_display_text = translator.translate( "Translation", "Language Display Text") languageAction = QAction(self) languageAction.setCheckable(True) languageAction.setText(language_display_text) languageAction.setData(language) self.menuLanguage.addAction(languageAction) self.langActionGroup.addAction(languageAction) if self.current_language == str(language).strip("tr_").rstrip( ".qm"): languageAction.setChecked(True)
def add_action(self, tool, parent, enable=True, isMapTool=True, inToolBar=True): """To add an available action. :param tool: the tool linked to the action :param parent: the interface main window :param enable: if the action is enabled at the beginning :param isMapTool: if the action is a map tool or not :param inToolBar: if the action has to be in the menu with an icon :return: the added action """ icon = QIcon(tool.icon_path) action = QAction(icon, tool.text, parent) if isMapTool: tool.setAction(action) action.triggered.connect(tool.setTool) action.setEnabled(enable) else: action.triggered.connect(tool.start) action.setCheckable(True) if inToolBar: self.toolbar.addAction(action) self.iface.addPluginToMenu(self.menu, action) self.actions.append(action) return action
def captureLayer(self, layer): text = layer.icontext tool = layer.getMaptool(self.iface.mapCanvas()) # Hack until I fix it later if isinstance(tool, PointTool): add = functools.partial(self.addNewFeature, qgslayer) tool.geometryComplete.connect(add) else: tool.finished.connect(self.openForm) tool.error.connect(functools.partial(self.showToolError, text)) action = QAction(QIcon(layer.icon), text, self.mainwindow) action.setData(layer) action.setCheckable(True) action.toggled.connect(functools.partial(self.setMapTool, tool)) self.toolbar.insertAction(self.editingmodeaction, action) if not tool.isEditTool(): # Connect the GPS tools strip to the action pressed event. showgpstools = (functools.partial(self.extraaddtoolbar.showToolbar, action, None)) action.toggled.connect(showgpstools) self.actionGroup.addAction(action) self.actions.append(action)
def addNewAction(self, iconPath, text, callback=None, enabled=True, checkable=False, addToMenu=True, addToToolbar=True, tip=None, whatsThis=None, parent=None): """Add a toolbar icon to the toolbar""" if parent is None: parent = self.iface.mainWindow() action = QAction(QIcon(iconPath), text, parent) if tip is not None: action.setStatusTip(tip) if whatsThis is not None: action.setWhatsThis(whatsThis) if callback is not None: action.triggered.connect(callback) action.setEnabled(enabled) action.setCheckable(checkable) self.addAction(action, addToMenu, addToToolbar) return action
class ToggleActiveLayerPlugin: def __init__(self, iface): self.iface = iface self.canvas = iface.mapCanvas() self.action = None self.tool = ToggleActiveLayerMapTool( self.iface ) def initGui(self): title = "Toggle visibility of active layer" icon = QIcon( os.path.join( os.path.dirname(__file__), 'toggleactivelayer.png' ) ) self.action = QAction( icon, title, self.iface.mainWindow() ) self.action.setObjectName( "ToggleActiveLayerPlugin" ) self.action.setWhatsThis( title ) self.action.setStatusTip( title ) self.action.triggered.connect( self.run ) # Maptool self.action.setCheckable( True ) self.tool.setAction( self.action ) self.iface.addToolBarIcon( self.action ) def unload(self): self.canvas.unsetMapTool( self.tool ) self.iface.removeToolBarIcon( self.action ) del self.action @pyqtSlot() def run(self): if self.canvas.mapTool() != self.tool: self.canvas.setMapTool( self.tool)
def initOptions(self): self.options = {} for o in ["Fit-to-window mode"]: action = QAction(o, self) action.setCheckable(True) self.ui.menuOptions.addAction(action) self.options[o] = action
def _addFilterAction(self, filterAction, text): action = QAction(text, self) action.setCheckable(True) action.setData(filterAction) action.triggered.connect(self._filterActionSelected) self._filterActionGroup.addAction(action) return action
def loadpages(self, pages): def safe_connect(method, to): try: method.connect(to) except AttributeError: pass for PageClass in pages: action = QAction(self.menutoolbar) text = PageClass.title.ljust(13) action.setIconText(text) action.setIcon(QIcon(PageClass.icon)) action.setCheckable(True) if PageClass.projectpage: action.setVisible(False) self.projectbuttons.append(action) self.menutoolbar.insertAction(self.spaceraction, action) else: self.menutoolbar.insertAction(self.actionProject, action) iface = RoamInterface(RoamEvents, GPS, self) pagewidget = PageClass(iface, self) safe_connect(RoamEvents.selectionchanged, pagewidget.selection_changed) safe_connect(RoamEvents.projectloaded, pagewidget.project_loaded) pageindex = self.stackedWidget.insertWidget(-1, pagewidget) action.setProperty('page', pageindex) self.pluginactions.append(action) self.menuGroup.addAction(action)
def _addDrawingAction(self, drawingAction, text): action = QAction(text, self) action.setCheckable(True) action.setData(drawingAction) action.triggered.connect(self._drawingActionSelected) self._drawingActionGroup.addAction(action) return action
def create_action(parent, text, shortcut=None, icon=None, tip=None, toggled=None, triggered=None, data=None, window_context=True): """Create a QAction""" action = QAction(text, parent) if triggered is not None: parent.connect(action, SIGNAL("triggered()"), triggered) if toggled is not None: parent.connect(action, SIGNAL("toggled(bool)"), toggled) action.setCheckable(True) if icon is not None: if isinstance(icon, (str, unicode)): icon = get_icon(icon) action.setIcon(icon) if shortcut is not None: action.setShortcut(shortcut) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if data is not None: action.setData(QVariant(data)) if window_context: action.setShortcutContext(Qt.WindowShortcut) else: #TODO: Hard-code all shortcuts and choose window_context=False # (this will avoid calling shortcuts from another dockwidget # since the context thing doesn't work quite well with these) action.setShortcutContext(Qt.WidgetShortcut) return action
class MiTraceView(QWidget): def __init__(self, do, parent): QWidget.__init__(self, parent) self.ui = Ui_MiTraceView() self.ui.setupUi(self) self.__do = do self.ui.commandEdit.lineEdit().returnPressed.connect(self.executeMiCommand) self.__do.gdb_connector.commandExecuted.connect(self.appendCommand) self.__do.gdb_connector.reader.asyncRecordReceived.connect(self.appendAsync) self.__timeAction = QAction(Icons.time, "Show Elapsed Time", self) self.__timeAction.setCheckable(True) self.__timeAction.setChecked(True) parent.titleBarWidget().addAction(self.__timeAction) parent.addClearAction() parent.clearRequested.connect(self.ui.traceView.clear) def appendCommand(self, cmd, rec, time): timestr = "[<i>%.3f</i>] " % time if self.__timeAction.isChecked() else "" self.ui.traceView.append("%s<b>%s</b>" % (timestr, cmd)) color = 'color="#ff3333"' if rec.class_ == GdbOutput.ERROR else "" self.ui.traceView.append("<font %s>%s</font>" % (color, rec.raw)) def appendAsync(self, rec): self.ui.traceView.append('<font color="#777777">%s</font>' % rec.raw) def executeMiCommand(self): cmd = str(self.ui.commandEdit.lineEdit().text()) self.ui.commandEdit.lineEdit().setText("") self.__do.gdb_connector.execute(cmd)
class Interpreter(MDockWidget): def __init__(self, mainWindow=None): MDockWidget.__init__(self, mainWindow) self.__mainWindow = mainWindow self.icon = QIcon(":interpreter.png") self.addAction(mainWindow) self.g_display() def g_display(self): self.setWidget(InterpreterView(self)) self.setWindowTitle(QApplication.translate("Interpreter", "Interpreter", None, QApplication.UnicodeUTF8)) def addAction(self, mainWindow): self.__action = QAction(self) self.__action.setCheckable(True) self.__action.setChecked(True) self.__action.setObjectName("actionCoreInformations") self.__action.setText(QApplication.translate("MainWindow", "DFF interpreter", None, QApplication.UnicodeUTF8)) mainWindow.menuWindow.addAction(self.__action) self.connect(self.__action, SIGNAL("triggered()"), self.changeVisibleInformations) def changeVisibleInformations(self): if not self.isVisible() : self.setVisible(True) self.__action.setChecked(True) else : self.setVisible(False) self.__action.setChecked(False)
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)
class Tool(object): def __init__(self, name, help_link="", icon=None, enabled=True, checkable=False, popup_menu=False): super(Tool, self).__init__() self.__icon = icon self.__name = name self.__parent = None self.__enabled = enabled self.__checkable = checkable self.__help_link = help_link self.__is_popup_menu = popup_menu self.__action = QAction(self.getIcon(), self.getName(), None) self.__action.setIconText(self.getName()) self.__action.setEnabled(self.isEnabled()) self.__action.setCheckable(checkable) self.__action.triggered.connect(self.trigger) HelpCenter.addHelpToAction(self.__action, self.getHelpLink()) def getIcon(self): return self.__icon def getName(self): return self.__name def trigger(self): raise NotImplementedError() def setParent(self, parent): self.__parent = parent self.__action.setParent(parent) def parent(self): return self.__parent def isEnabled(self): return self.__enabled def getHelpLink(self): return self.__help_link def getAction(self): return self.__action def setVisible(self, visible): self.__action.setVisible(visible) def setEnabled(self, enabled): self.__action.setEnabled(enabled) def isPopupMenu(self): return self.__is_popup_menu
def createAction( parent, label, callback=None, icon = None, tip = None, shortcut = None, data = None, toggled = False, tooltip=None, cb_arg=None, iconText=None, checkable=None): """ Create a QAction @param parent: @type parent: @param label: @type label: @param callback: @type callback: @param icon: @type icon: @param tip: @type tip: @param shortcut: @type shortcut: @param data: @type data: @param toggled: @type toggled: @return: @rtype: """ action = QAction(label, parent) if toggled: if callback is not None: action.toggled.connect(callback) action.setCheckable(True) else: if callback is not None: if cb_arg is None: action.triggered.connect(callback) else: action.triggered.connect(lambda: callback(cb_arg) ) if icon: action.setIcon(icon) if shortcut: action.setShortcut(shortcut) if tip: action.setStatusTip(tip) if tooltip: action.setToolTip(tooltip) if data is not None: action.setData( QVariant(data) ) if iconText is not None: action.setIconText(iconText) if checkable is not None: action.setCheckable(checkable) return action
def get_actions(self, menu_class): actions = [] for menu_item in menu_class.ALL: action = QAction(menu_item.name, self) action.setCheckable(True) if menu_item == menu_class.DEFAULT: action.setChecked(True) actions.append(action) return actions
def makeActions(): for col, title in enumerate(model.columnLabels()): action = QAction(title, header) action.setCheckable(True) action.setChecked(Qt.Checked) handler = partial(self.setTickersColumnEnabled, column=col) connect(action, Signals.toggled, handler) header.setResizeMode(col, header.Stretch) yield action
def getActions(self): """ @rtype: list of QAction """ advanced_toggle_action = QAction("Show Advanced Options", self) advanced_toggle_action.setObjectName("AdvancedSimulationOptions") advanced_toggle_action.setCheckable(True) advanced_toggle_action.setChecked(False) advanced_toggle_action.toggled.connect(self.toggleAdvanced) return [advanced_toggle_action]
def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu='toolbar', add_to_toolbar=True, status_tip=None, whats_this=None, isMenu=None, checkable=None, checked=None, parent=None): if not parent: parent = self.iface.mainWindow() icon = QIcon(icon_path) if add_to_menu == 'toolbar': action = QAction(icon, text, parent) else: action = self.tools[add_to_menu].menu().addAction(text) action.setActionGroup(self.tools[add_to_menu].actionGroup) add_to_toolbar = False if checkable: action.setCheckable(True) if checked: action.setChecked(True) if callback: action.toggled.connect(callback) else: if callback: action.triggered.connect(callback) action.setEnabled(enabled_flag) 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 isMenu: newMenu = QMenu() action.setMenu(newMenu) newActionGroup = QActionGroup(newMenu) action.actionGroup = newActionGroup if add_to_menu == 'toolbar': self.iface.addPluginToMenu(self.menu, action) self.actions.append(action) return action
class FunderingGeometryEditor(): def __init__(self, iface): self.iface = iface self.mapCanvas = iface.mapCanvas() self.mapTool = None # initialize plugin directory self.plugin_dir = os.path.dirname(__file__) def initGui(self): """ runs when plugin is activated from the plugin menu """ # help self.helpAction = QAction(QIcon(":/funderingsherstel/icons/help.svg"), "Help", self.iface.mainWindow()) self.helpAction.triggered.connect(lambda: QDesktopServices().openUrl(QUrl("mailto:[email protected]"))) # Create the dock (after translation) and keep reference self.dock = DockEditorDialog(self.iface, self.mapCanvas) self.dock.setVisible(False) self.dock.visibilityChanged.connect(self.dockVisibilityChanged) # map tool actionand default state self.mapToolAction = QAction(QIcon(":/funderingsherstel/icons/fundering.svg"), u"Funderingsherstel", self.iface.mainWindow()) self.mapToolAction.setCheckable(True) self.mapToolAction.setChecked(False) self.mapToolAction.triggered.connect(self.dock.setVisible) self.iface.addToolBarIcon(self.mapToolAction) # menu self.iface.addPluginToMenu("&Funderingsherstel", self.mapToolAction) self.iface.addPluginToMenu("&Funderingsherstel", self.helpAction) def unload(self): # Unset the map tool in case it's set self.mapToolAction.setChecked(False) self.iface.removePluginMenu("&Funderingsherstel", self.helpAction) self.iface.removePluginMenu("&Funderingsherstel", self.mapToolAction) self.iface.removeToolBarIcon(self.mapToolAction) self.dock.hide() self.dock.deleteLater() def dockVisibilityChanged(self): if self.dock.isVisible() is True: self.mapTool = IdentifyGeometry(self.mapCanvas) self.mapTool.geomIdentified.connect(self.editGeometry) self.mapTool.setAction(self.mapToolAction) self.mapCanvas.setMapTool(self.mapTool) else: self.dock.close() self.mapCanvas.unsetMapTool(self.mapTool) def editGeometry(self, layer, feature): self.dock.featureSelected(layer, feature)
def addWindow(self, window): action = QAction(QString(window.windowTitle()), self.menu) action.setCheckable(True) action.setChecked(window.isVisible()) self.menu.addAction(action) self.windows.append(window) self.actions.append(action) self.menu.connect(action, SIGNAL("toggled(bool)"), self.makeActionSignal(action, window))
def populate_switch_effect_menu(self, target_menu, checked_item): effect_menu = QMenu(i18n("Effect"), target_menu) for preset in LADSPAEffects().effects(): action = QAction(preset["preset_name"],effect_menu) effect_menu.addAction(action) if checked_item == preset["label"]: action.setCheckable(True) action.setChecked(True) action.setEnabled(False) target_menu.addMenu(effect_menu)
def create_action(parent, callback, text, checkable, checked, icon_path): pixmap = QPixmap(icon_path) icon = QIcon(pixmap) action = QAction(icon, text, parent) # action.setIcon(icon) # action.setIconText(text) action.triggered.connect(callback) action.setCheckable(checkable) action.setChecked(checked) return action
def _buildOutputs(self): self.menuOutputs.clear() if self.mpdclient.connected(): print 'debug: Building output menu.' for output in self.mpdclient.outputs(): action = QAction(output.get('outputname', 'No name'), self.menuOutputs) action.setCheckable(True) action.setChecked(output.get('outputenabled', '0') == '1') action.outputid = output.get('outputid') self.menuOutputs.addAction(action)
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 )
def initGui(self): icon_path = ':/icons/GuideIcon.png' actionRdbNavi = QAction(QIcon(icon_path), u"Rdb Navi Simulator", None) actionRdbNavi.triggered.connect(self.actionRdbNaviTriggered) actionRdbNavi.setStatusTip(None) actionRdbNavi.setWhatsThis(None) self.toolbar.addAction(actionRdbNavi) self.iface.addPluginToMenu(self.menu, actionRdbNavi) actionRdbNavi.setEnabled(True) actionRdbNavi.setCheckable(True) self.actions.append(actionRdbNavi) return
class Actions(actioncollection.ActionCollection): name = "documentactions" def createActions(self, parent): self.edit_cut_assign = 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_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.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.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_dynamics.setText(_("Remove &Dynamics")) self.tools_quick_remove_fingerings.setText(_("Remove &Fingerings")) self.tools_quick_remove_markup.setText( _("Remove Text &Markup (from music)"))
def context_menu_create_custom(self): self.context_menu_create_ports() self.context_menu_create_sounddevices() action_device = QAction(i18n("Default Sink"), self.popup_menu) self.popup_menu.addAction(action_device) action_device.setCheckable(True) if self.isDefaultSink(): action_device.setChecked(True) action_device.setEnabled(False) else: action_device.setChecked(False) action_device.setEnabled(True) action_device.triggered.connect(self.on_set_default_sink_triggered)
def initAnnotationMenu(self): self.annotationMenu = {} for a in ["Copy from previous"]: action = QAction(a, self) action.setCheckable(True) self.ui.menuAnnotation.addAction(action) self.annotationMenu[a] = action for a in ["Interpolate range"]: action = QAction(a, self) action.setCheckable(True) self.ui.menuAnnotation.addAction(action) self.annotationMenu[a] = action