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
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 _onTvFilesCustomContextMenuRequested(self, pos ): """Connected automatically by uic """ menu = QMenu() menu.addAction( core.actionManager().action( "mFile/mClose/aCurrent" ) ) menu.addAction( core.actionManager().action( "mFile/mSave/aCurrent" ) ) menu.addAction( core.actionManager().action( "mFile/mReload/aCurrent" ) ) menu.addSeparator() # sort menu sortMenu = QMenu( self ) group = QActionGroup( sortMenu ) group.addAction( self.tr( "Opening order" ) ) group.addAction( self.tr( "File name" ) ) group.addAction( self.tr( "URL" ) ) group.addAction( self.tr( "Suffixes" ) ) group.triggered.connect(self._onSortTriggered) sortMenu.addActions( group.actions() ) for i, sortMode in enumerate(["OpeningOrder", "FileName", "URL", "Suffixes"]): action = group.actions()[i] action.setData( sortMode ) action.setCheckable( True ) if sortMode == self.model.sortMode(): action.setChecked( True ) aSortMenu = QAction( self.tr( "Sorting" ), self ) aSortMenu.setMenu( sortMenu ) aSortMenu.setIcon( QIcon( ":/enkiicons/sort.png" )) aSortMenu.setToolTip( aSortMenu.text() ) menu.addAction( sortMenu.menuAction() ) menu.exec_( self.tvFiles.mapToGlobal( pos ) )
def 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
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
class Actions(actioncollection.ActionCollection): name = "pitch" def createActions(self, parent): self.pitch_language = QAction(parent) self.pitch_rel2abs = QAction(parent) self.pitch_abs2rel = QAction(parent) self.pitch_transpose = QAction(parent) self.pitch_modal_transpose = QAction(parent) self.pitch_language.setIcon(icons.get('tools-pitch-language')) self.pitch_transpose.setIcon(icons.get('tools-transpose')) self.pitch_modal_transpose.setIcon(icons.get('tools-transpose')) def translateUI(self): self.pitch_language.setText(_("Pitch Name &Language")) self.pitch_language.setToolTip(_( "Change the LilyPond language used for pitch names " "in this document or in the selection.")) self.pitch_rel2abs.setText(_("Convert Relative to &Absolute")) self.pitch_rel2abs.setToolTip(_( "Converts the notes in the document or selection from relative to " "absolute pitch.")) self.pitch_abs2rel.setText(_("Convert Absolute to &Relative")) self.pitch_abs2rel.setToolTip(_( "Converts the notes in the document or selection from absolute to " "relative pitch.")) self.pitch_transpose.setText(_("&Transpose...")) self.pitch_transpose.setToolTip(_( "Transposes all notes in the document or selection.")) self.pitch_modal_transpose.setText(_("&Modal Transpose...")) self.pitch_modal_transpose.setToolTip(_( "Transposes all notes in the document or selection within a given mode."))
class Actions(actioncollection.ActionCollection): name = "pitch" def createActions(self, parent): self.pitch_language = QAction(parent) self.pitch_rel2abs = QAction(parent) self.pitch_abs2rel = QAction(parent) self.pitch_transpose = QAction(parent) self.pitch_modal_transpose = QAction(parent) self.pitch_language.setIcon(icons.get('tools-pitch-language')) self.pitch_transpose.setIcon(icons.get('tools-transpose')) self.pitch_modal_transpose.setIcon(icons.get('tools-transpose')) def translateUI(self): self.pitch_language.setText(_("Pitch Name &Language")) self.pitch_language.setToolTip( _("Change the LilyPond language used for pitch names " "in this document or in the selection.")) self.pitch_rel2abs.setText(_("Convert Relative to &Absolute")) self.pitch_rel2abs.setToolTip( _("Converts the notes in the document or selection from relative to " "absolute pitch.")) self.pitch_abs2rel.setText(_("Convert Absolute to &Relative")) self.pitch_abs2rel.setToolTip( _("Converts the notes in the document or selection from absolute to " "relative pitch.")) self.pitch_transpose.setText(_("&Transpose...")) self.pitch_transpose.setToolTip( _("Transposes all notes in the document or selection.")) self.pitch_modal_transpose.setText(_("&Modal Transpose...")) self.pitch_modal_transpose.setToolTip( _("Transposes all notes in the document or selection within a given mode." ))
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
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 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 __init__(self, config): QSystemTrayIcon.__init__(self) self.config = config self.setIcon(QIcon(QPixmap(os.path.join(get_main_dir(), 'Spider.web.logo.png')))) self.menu = QMenu(QString("WebScard Menu")) self.setContextMenu(self.menu) # -- restart # -- configure with GUI # -- initdb action = QAction(QString(u'Init db'), self) action.setToolTip(u'Initialize the database as configured') action.triggered.connect(self.on_initdb) self.menu.addAction(action) # -- Quit action = QAction(QString(u'Quit'), self) action.setToolTip(u'Quit everything') action.triggered.connect(self.on_quit) self.menu.addAction(action) self.setToolTip(QString(u'WebSCard: Smart card WSGI server')) self.webserverthread = WebServerThread(config) self.webserverthread.start() self.show()
def action(self, parent, slot, icon=None, text='', tooltip=None): action = QAction(text, parent) if type(icon) == str: action.setIcon(PIcon(icon)) if type(tooltip) == str: action.setToolTip(tooltip) self.__addAction(action, parent, slot) return action
class Actions(actioncollection.ActionCollection): name = "file_import" def createActions(self, parent): self.import_musicxml = QAction(parent) def translateUI(self): self.import_musicxml.setText(_("Import MusicXML...")) self.import_musicxml.setToolTip(_("Import a MusicXML file using musicxml2ly."))
class Actions(actioncollection.ActionCollection): name = "file_export" def createActions(self, parent): self.export_musicxml = QAction(parent) def translateUI(self): self.export_musicxml.setText(_("Export Music&XML...")) self.export_musicxml.setToolTip(_("Export current document as MusicXML."))
def setup_toolbars(self): source_toolbar = self.addToolBar('SourceToolbar') self.user_interface.tbrActionToggleSourceView = QAction('C/C++', self) self.user_interface.tbrActionToggleSourceView.triggered.connect( self.toggle_source_view) self.user_interface.tbrActionToggleSourceView.setToolTip( "Toggle source code view") self.user_interface.tbrActionToggleSourceView.setCheckable(True) self.user_interface.tbrActionToggleSourceView.setChecked(True) source_toolbar.addAction(self.user_interface.tbrActionToggleSourceView) search_toolbar = self.addToolBar("SearchToolbar") search_toolbar.setAllowedAreas(Qt.TopToolBarArea | Qt.BottomToolBarArea) self.ledSearchBox = QLineEdit() self.ledSearchBox.textChanged.connect(self.invalidate_search_criteria) self.ledSearchBox.keyPressEvent = self.search_box_key_pressed search_toolbar.addWidget(self.ledSearchBox) tbrActionPrevSearchMatch = QAction('<<', self) tbrActionPrevSearchMatch.triggered.connect( functools.partial(self.select_search_match, False)) tbrActionPrevSearchMatch.setToolTip("Go to previous search match") tbrActionNextSearchMatch = QAction('>>', self) tbrActionNextSearchMatch.triggered.connect( functools.partial(self.select_search_match, True)) tbrActionNextSearchMatch.setToolTip("Go to next search match") tbrActionIgnoreCase = QAction('Ignore Case', self) tbrActionIgnoreCase.setCheckable(True) tbrActionIgnoreCase.setChecked(True) tbrActionIgnoreCase.triggered.connect(self.set_search_case_sensitivity, tbrActionIgnoreCase.isChecked()) tbrActionIgnoreCase.setToolTip("Ignore case") tbrActionWrapSearch = QAction('Wrap Search', self) tbrActionWrapSearch.setCheckable(True) tbrActionWrapSearch.setChecked(True) tbrActionWrapSearch.triggered.connect(self.set_search_wrap, tbrActionWrapSearch.isChecked()) tbrActionWrapSearch.setToolTip("Wrap Search") tbrActionMatchWholeWord = QAction('Match Whole Word', self) tbrActionMatchWholeWord.setCheckable(True) tbrActionMatchWholeWord.setChecked(False) tbrActionMatchWholeWord.triggered.connect( self.set_match_whole_word, tbrActionMatchWholeWord.isChecked()) tbrActionMatchWholeWord.setToolTip("Match Whole Word") search_toolbar.addAction(tbrActionPrevSearchMatch) search_toolbar.addAction(tbrActionNextSearchMatch) search_toolbar.addAction(tbrActionIgnoreCase) search_toolbar.addAction(tbrActionMatchWholeWord) search_toolbar.addAction(tbrActionWrapSearch)
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 act(name, parent, tip='', icon=None, shortcut=None): """ Factory for making a new action """ a = QAction(name, parent) a.setToolTip(tip) if icon: a.setIcon(QIcon(':icons/%s' % icon)) if shortcut: a.setShortcut(shortcut) return a
class Actions(actioncollection.ActionCollection): name = "file_import" def createActions(self, parent): self.import_musicxml = QAction(parent) def translateUI(self): self.import_musicxml.setText(_("Import MusicXML...")) self.import_musicxml.setToolTip( _("Import a MusicXML file using musicxml2ly."))
class Actions(actioncollection.ActionCollection): name = "file_export" def createActions(self, parent): self.export_musicxml = QAction(parent) self.export_audio = QAction(parent) def translateUI(self): self.export_musicxml.setText(_("Export Music&XML...")) self.export_musicxml.setToolTip(_("Export current document as MusicXML.")) self.export_audio.setText(_("Export Audio...")) self.export_audio.setToolTip(_("Export to different audio formats."))
class QGIS_IPython(object): def __init__(self, iface): # Save reference to the QGIS interface self.iface = iface self.kernel = None def initGui(self): self.launch_external_console = QAction( QIcon(":/plugins/ipython_console/icons/launch_external_python.png"), "External IPython Console", self.iface.mainWindow()) self.launch_external_console.setToolTip( "IPython console running in an external process") self.launch_external_console.connect( self.launch_external_console, SIGNAL("triggered()"), self.launch_console) # Add toolbar menu item self.iface.pluginMenu().addAction(self.launch_external_console) self.iface.addToolBarIcon(self.launch_external_console) def init_kernel(self): self.kernel = InternalIPKernel() def unload(self): if not IPYTHON_LOADED: return # Remove the plugin menu item and icon. self.iface.pluginMenu().removeAction(self.launch_external_console) self.iface.removeToolBarIcon(self.launch_external_console) if self.kernel is not None: # Tear down any running consoles and then stop the kernel. self.kernel.cleanup_consoles() def launch_console(self): # If IPython failed to load, bail out. if not IPYTHON_LOADED: QMessageBox.warning( self.iface.mainWindow(), 'Error', 'Could not load IPython components. Please make sure IPython version 0.12 or newer is installed along with the Pygments module.' ) return if self.kernel is None: self.init_kernel() self.kernel.new_qt_console()
def __init__(self, parent = None): QMainWindow.__init__(self, parent) self.setIconSize(QSize(48, 48)) self.widtab = QTabWidget() #widtab.addTab(QLabel("Tab1"), "Tab 1") self._bba = {} #self._bba_plot_data = [] self._canvas_wid = [] # self.setCentralWidget(self.widtab) # # file menu # self.fileMenu = self.menuBar().addMenu("&File") fileQuitAction = QAction(QIcon(":/file_quit.png"), "&Quit", self) fileQuitAction.setShortcut("Ctrl+Q") fileQuitAction.setToolTip("Quit the application") fileQuitAction.setStatusTip("Quit the application") self.connect(fileQuitAction, SIGNAL("triggered()"), self.close) fileConfigAction = QAction("&Config", self) # fileOpenAction = QAction(QIcon(":file_quit.png"), "&Open...", self) fileOpenAction.setToolTip("Open an existing data file") self.connect(fileOpenAction, SIGNAL("triggered()"), self.fileOpen) self.fileMenu.addAction(fileOpenAction) self.fileMenu.addAction(fileQuitAction) self.fileMenu.addAction(fileConfigAction) self.controlMenu = self.menuBar().addMenu("&Control") controlGoAction = QAction(QIcon(":/control_play.png"), "&Go", self) controlGoAction.setShortcut("Ctrl+G") #fileQuitAction.setToolTip("Quit the application") #fileQuitAction.setStatusTip("Quit the application") #fileQuitAction.setIcon(Qt.QIcon(":/filequit.png")) self.controlMenu.addAction(controlGoAction) self.connect(controlGoAction, SIGNAL("triggered()"), self.align) # help self.helpMenu = self.menuBar().addMenu("&Help") #toolbar = QToolBar(self) #self.addToolBar(toolbar) fileToolBar = self.addToolBar("File") fileToolBar.setObjectName("FileToolBar") fileToolBar.addAction(fileQuitAction) fileToolBar.addAction(controlGoAction)
def __insertItem(self, index, item): """ Insert a widget action from `item` (`QModelIndex`) at `index`. """ value = qtcompat.qunwrap(item.data(self.__actionRole)) if isinstance(value, QAction): action = value else: action = QAction(item_text(item), self) action.setIcon(item_icon(item)) action.setToolTip(item_tooltip(item)) self.insertAction(index, action)
def __insertItem(self, index, item): """ Insert a widget action from `item` (`QModelIndex`) at `index`. """ value = item.data(self.__actionRole) if value.isValid(): action = value.toPyObject() else: action = QAction(item_text(item), self) action.setIcon(item_icon(item)) action.setToolTip(item_tooltip(item)) self.insertAction(index, action)
def testShortcut(self): a = QAction("Test Action", None) a.setToolTip("Test Tooltip") p = ProxyAction() p.setAttribute(ProxyActionAttribute.UpdateText) p.action = a p.setShortcut(QKeySequence("Ctrl+T")) self.assertEqual(p.text(), "Test Action") p.setShortcutVisibleInToolTip(True) self.assertEqual(p.toolTip(), "Test Tooltip <span style=\"color: gray; font-size: small\">Ctrl+T</span>") p.setShortcutVisibleInToolTip(False) self.assertEqual(p.toolTip(), "Test Tooltip")
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.setIconSize(QSize(48, 48)) self.widtab = QTabWidget() # widtab.addTab(QLabel("Tab1"), "Tab 1") self._bba = {} # self._bba_plot_data = [] self._canvas_wid = [] # self.setCentralWidget(self.widtab) # # file menu # self.fileMenu = self.menuBar().addMenu("&File") fileQuitAction = QAction(QIcon(":/file_quit.png"), "&Quit", self) fileQuitAction.setShortcut("Ctrl+Q") fileQuitAction.setToolTip("Quit the application") fileQuitAction.setStatusTip("Quit the application") self.connect(fileQuitAction, SIGNAL("triggered()"), self.close) fileConfigAction = QAction("&Config", self) # fileOpenAction = QAction(QIcon(":file_quit.png"), "&Open...", self) fileOpenAction.setToolTip("Open an existing data file") self.connect(fileOpenAction, SIGNAL("triggered()"), self.fileOpen) self.fileMenu.addAction(fileOpenAction) self.fileMenu.addAction(fileQuitAction) self.fileMenu.addAction(fileConfigAction) self.controlMenu = self.menuBar().addMenu("&Control") controlGoAction = QAction(QIcon(":/control_play.png"), "&Go", self) controlGoAction.setShortcut("Ctrl+G") # fileQuitAction.setToolTip("Quit the application") # fileQuitAction.setStatusTip("Quit the application") # fileQuitAction.setIcon(Qt.QIcon(":/filequit.png")) self.controlMenu.addAction(controlGoAction) self.connect(controlGoAction, SIGNAL("triggered()"), self.align) # help self.helpMenu = self.menuBar().addMenu("&Help") # toolbar = QToolBar(self) # self.addToolBar(toolbar) fileToolBar = self.addToolBar("File") fileToolBar.setObjectName("FileToolBar") fileToolBar.addAction(fileQuitAction) fileToolBar.addAction(controlGoAction)
def createAction(parent, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): action = QAction(text, parent) 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: parent.connect(action, SIGNAL(signal), slot) if checkable: action.setCheckable(True) return action
def setup_toolbars(self): source_toolbar = self.addToolBar('SourceToolbar') self.user_interface.tbrActionToggleSourceView = QAction('C/C++', self) self.user_interface.tbrActionToggleSourceView.triggered.connect(self.toggle_source_view) self.user_interface.tbrActionToggleSourceView.setToolTip("Toggle source code view") self.user_interface.tbrActionToggleSourceView.setCheckable(True) self.user_interface.tbrActionToggleSourceView.setChecked(True) source_toolbar.addAction(self.user_interface.tbrActionToggleSourceView) search_toolbar = self.addToolBar("SearchToolbar") search_toolbar.setAllowedAreas(Qt.TopToolBarArea | Qt.BottomToolBarArea) self.ledSearchBox = QLineEdit() self.ledSearchBox.textChanged.connect(self.invalidate_search_criteria) self.ledSearchBox.keyPressEvent = self.search_box_key_pressed search_toolbar.addWidget(self.ledSearchBox) tbrActionPrevSearchMatch = QAction('<<', self) tbrActionPrevSearchMatch.triggered.connect(functools.partial(self.select_search_match, False)) tbrActionPrevSearchMatch.setToolTip("Go to previous search match") tbrActionNextSearchMatch = QAction('>>', self) tbrActionNextSearchMatch.triggered.connect(functools.partial(self.select_search_match, True)) tbrActionNextSearchMatch.setToolTip("Go to next search match") tbrActionIgnoreCase = QAction('Ignore Case', self) tbrActionIgnoreCase.setCheckable(True) tbrActionIgnoreCase.setChecked(True) tbrActionIgnoreCase.triggered.connect(self.set_search_case_sensitivity, tbrActionIgnoreCase.isChecked()) tbrActionIgnoreCase.setToolTip("Ignore case") tbrActionWrapSearch = QAction('Wrap Search', self) tbrActionWrapSearch.setCheckable(True) tbrActionWrapSearch.setChecked(True) tbrActionWrapSearch.triggered.connect(self.set_search_wrap, tbrActionWrapSearch.isChecked()) tbrActionWrapSearch.setToolTip("Wrap Search") tbrActionMatchWholeWord = QAction('Match Whole Word', self) tbrActionMatchWholeWord.setCheckable(True) tbrActionMatchWholeWord.setChecked(False) tbrActionMatchWholeWord.triggered.connect(self.set_match_whole_word, tbrActionMatchWholeWord.isChecked()) tbrActionMatchWholeWord.setToolTip("Match Whole Word") search_toolbar.addAction(tbrActionPrevSearchMatch) search_toolbar.addAction(tbrActionNextSearchMatch) search_toolbar.addAction(tbrActionIgnoreCase) search_toolbar.addAction(tbrActionMatchWholeWord) search_toolbar.addAction(tbrActionWrapSearch)
class Actions(actioncollection.ActionCollection): name = "midiinputtool" def createActions(self, parent=None): self.capture_start = QAction(parent) self.capture_stop = QAction(parent) self.capture_start.setIcon(icons.get('media-record')) self.capture_stop.setIcon(icons.get('process-stop')) def translateUI(self): self.capture_start.setText(_("midi input", "Start capturing")) self.capture_start.setToolTip(_("midi input", "Start MIDI capturing")) self.capture_stop.setText(_("midi input", "Stop capturing")) self.capture_stop.setToolTip(_("midi input", "Stop MIDI capturing"))
class Actions(actioncollection.ActionCollection): name = "midiinputtool" def createActions(self, parent=None): self.capture_start = QAction(parent) self.capture_stop = QAction(parent) self.capture_start.setIcon(icons.get('media-record')) self.capture_stop.setIcon(icons.get('process-stop')) def translateUI(self): self.capture_start.setText(_("midi input", "Start MIDI capturing")) self.capture_start.setToolTip(_("midi input", "Start MIDI capturing")) self.capture_stop.setText(_("midi input", "Stop MIDI capturing")) self.capture_stop.setToolTip(_("midi input", "Stop MIDI capturing"))
def createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False): action = QAction(text, self) if slot is not None: action.triggered.connect(slot) if shortcut is not None: action.setShortcut(shortcut) if icon is not None: action.setIcon(QIcon(":/{}.png".format(icon))) if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) if checkable: action.setCheckable(True) return action
def add_action(self, icon_path, text, callback, enabled_flag=True, add_to_menu=True, add_to_toolbar=True, tool_tip=None, status_tip=None, whats_this=None, parent=None): """Add a toolbar icon to the toolbar. Args: icon_path (str): Path to the icon for this action. Can be a resource path (e.g. ':/plugins/foo/bar.png') or a normal file system path. text (str): Text that should be shown in menu items for this action. callback (function): Function to be called when the action is triggered. enabled_flag (bool): A flag indicating if the action should be enabled by default. Defaults to True. add_to_menu (bool): Flag indicating whether the action should also be added to the menu. Defaults to True. add_to_toolbar (bool): Flag indicating whether the action should also be added to the toolbar. Defaults to True. tool_tip (str): Optional text to show in a popup when mouse pointer hovers over the action. status_tip (str): Optional text to show in the status bar when mouse pointer hovers over the action. whats_this (QWidget): Parent widget for the new action. Defaults None. parent (): Optional text to show in the status bar when the mouse pointer hovers over the action. Returns: QAction: The action that was created. Note that the action is also added to self.actions list. """ icon = QIcon(icon_path) action = QAction(icon, text, parent) action.triggered.connect(callback) action.setEnabled(enabled_flag) if tool_tip is not None: action.setToolTip(tool_tip) 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.menuPrecAg.addAction(action) self.actions.append(action) return action
def act(self, name, trig, shortcut=None, checkable=False, icon=None, tooltip=None): """ A wrapper to several QAction methods """ if icon: action = QAction(icon, name, self) else: action = QAction(name, self) if shortcut: action.setShortcut(QKeySequence(shortcut)) action.setCheckable(checkable) if tooltip: action.setToolTip(tooltip) action.triggered.connect(trig) return action
class QGIS_IPython(object): def __init__(self, iface): # Save reference to the QGIS interface self.iface = iface self.kernel = None def initGui(self): self.launch_external_console = QAction( QIcon( ":/plugins/ipython_console/icons/launch_external_python.png"), "External IPython Console", self.iface.mainWindow()) self.launch_external_console.setToolTip( "IPython console running in an external process") self.launch_external_console.connect(self.launch_external_console, SIGNAL("triggered()"), self.launch_console) # Add toolbar menu item self.iface.pluginMenu().addAction(self.launch_external_console) self.iface.addToolBarIcon(self.launch_external_console) def init_kernel(self): self.kernel = InternalIPKernel() def unload(self): if not IPYTHON_LOADED: return # Remove the plugin menu item and icon. self.iface.pluginMenu().removeAction(self.launch_external_console) self.iface.removeToolBarIcon(self.launch_external_console) if self.kernel is not None: # Tear down any running consoles and then stop the kernel. self.kernel.cleanup_consoles() def launch_console(self): # If IPython failed to load, bail out. if not IPYTHON_LOADED: QMessageBox.warning( self.iface.mainWindow(), 'Error', 'Could not load IPython components. Please make sure IPython version 0.12 or newer is installed along with the Pygments module.' ) return if self.kernel is None: self.init_kernel() self.kernel.new_qt_console()
def create_action(parent, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): '''Helper function that creates QActions with a given QObject parent.''' action = QAction(text, parent) 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: QObject.connect(action, SIGNAL(signal), slot) if checkable: action.setCheckable(True) return action
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, QtCore.SIGNAL(signal), slot) if checkable: action.setCheckable(True) return action
def __init__(self, canvas, parent, coordinates=True): super(CustomNavigationToolbar, self).__init__(canvas, parent, coordinates) gear = resourceIcon("ide/cog_edit.png") customize_action = QAction(gear, "Customize", self) customize_action.setToolTip("Customize plot settings") customize_action.triggered.connect(self.customizationTriggered) for action in self.actions(): if str(action.text()).lower() == "subplots": self.removeAction(action) if str(action.text()).lower() == "customize": self.insertAction(action, customize_action) self.removeAction(action) break
def __init__(self): QMainWindow.__init__(self) self.menubar = QMenuBar() file_ = self.menubar.addMenu(u"&Fichier") exit = QAction(u"Quitter", self) exit.setShortcut("Ctrl+Q") exit.setToolTip("Quitter l'application") self.menubar.connect(exit, SIGNAL("triggered()"), \ self, \ SLOT("close()")) file_.addAction(exit) self.setMenuBar(self.menubar) self.web = QWebView() self.web.load(QUrl(APP_URL)) self.setCentralWidget(self.web)
def createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): """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(":/%s.png" % icon))) if shortcut is not None and not shortcut.isEmpty(): action.setShortcut(shortcut) tip += " (%s)" % shortcut.toString() 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() 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_debug = QAction(parent) self.engrave_custom = QAction(parent) self.engrave_abort = QAction(parent) self.engrave_autocompile = QAction(parent) self.engrave_autocompile.setCheckable(True) self.engrave_show_available_fonts = QAction(parent) self.engrave_open_lilypond_datadir = 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_debug.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_runner.setToolTip( _("Engrave (preview; Shift-click for custom)")) self.engrave_preview.setText(_("&Engrave (preview)")) self.engrave_publish.setText(_("Engrave (&publish)")) self.engrave_debug.setText(_("Engrave (&layout control)")) self.engrave_custom.setText(_("Engrave (&custom)...")) self.engrave_abort.setText(_("Abort Engraving &Job")) self.engrave_autocompile.setText(_("Automatic E&ngrave")) self.engrave_open_lilypond_datadir.setText( _("Open LilyPond &Data Directory")) self.engrave_show_available_fonts.setText( _("Show Available &Fonts..."))
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 createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): action = QAction(text, self) if icon is not None: icon_path = "./icons/{0}.png".format(icon) if path.exists(icon_path): action.setIcon(QIcon(icon_path)) else: logging.warning('Warning: icon {} does not exist'.format(icon_path)) 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 createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered"): """ Crear un objeto acción @param text: El texto de la acción @type text: string @param slot: El slot que se ejecutara cuando se dispare esta acción @type slot: callable @param shortcut: El acceso directo que tiene asignada esta acción @type shortcut: QKeySequence @param icon: El icono de esta acción @type icon: string @param tip: El tooltip que tendra esta acción @type tip: string @param checkable: Si esta acción es checkable o no @type checkable: bool @param signal: La señal en la que esta acción ejecutara el slot @type signal: string @rtype: QAction """ action = QAction(text, self) if icon is not None: if type(icon) == QIcon: action.setIcon(icon) else: action.setIcon(QIcon(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) if checkable: action.setCheckable(True) 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_debug = QAction(parent) self.engrave_custom = QAction(parent) self.engrave_abort = QAction(parent) self.engrave_autocompile = QAction(parent) self.engrave_autocompile.setCheckable(True) self.engrave_show_available_fonts = QAction(parent) self.engrave_open_lilypond_datadir = 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_debug.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_runner.setToolTip(_("Engrave (preview; Shift-click for custom)")) self.engrave_preview.setText(_("&Engrave (preview)")) self.engrave_publish.setText(_("Engrave (&publish)")) self.engrave_debug.setText(_("Engrave (&layout control)")) self.engrave_custom.setText(_("Engrave (&custom)...")) self.engrave_abort.setText(_("Abort Engraving &Job")) self.engrave_autocompile.setText(_("Automatic E&ngrave")) self.engrave_open_lilypond_datadir.setText(_("Open LilyPond &Data Directory")) self.engrave_show_available_fonts.setText(_("Show Available &Fonts..."))
def createAction(self, text, slot=None, shortcut=None, icon=None, tip=None, checkable=False, signal="triggered()"): # Create the action action = QAction(text, self) # Give it its icon if icon is not None: action.setIcon(QIcon(":/{icon}.png".format(icon=icon))) # Give it its shortcut if shortcut is not None: action.setShortcut(shortcut) # Set up its help/tip text if tip is not None: action.setToolTip(tip) action.setStatusTip(tip) # Connect it to a signal if slot is not None: self.connect(action, SIGNAL(signal), slot) # Make it checkable if checkable: action.setCheckable(True) return action
def addTab(self, widget, text, toolTip=None, icon=None): if self.__macUnified: action = QAction(text, self) if toolTip: action.setToolTip(toolTip) if icon: action.setIcon(toolTip) action.setData(len(self.tab.actions())) self.tab.addAction(action) self.stack.addWidget(widget) else: i = self.tab.addTab(widget, text) if toolTip: self.tab.setTabToolTip(i, toolTip) if icon: self.tab.setTabIcon(i, icon)
def createAction(parent: QObject, text: str, icon: object = None, shortcut: str = None, tooltip: str = None, enabled: bool = False, signal: str = "triggered", slot: object = None) -> object: action = QAction(parent) action.setText(text) if icon: action.setIcon( QIcon(icon)) # icon is expected as a string argument if shortcut: action.setShortcut(shortcut) if tooltip: action.setToolTip(tooltip) if enabled: action.setEnabled(enabled) if slot and signal == "triggered": action.pyqtConfigure(triggered=slot) return action
def _onTvFilesCustomContextMenuRequested(self, pos): """Connected automatically by uic """ menu = QMenu() menu.addAction(core.actionManager().action("mFile/mClose/aCurrent")) menu.addAction(core.actionManager().action("mFile/mSave/aCurrent")) menu.addAction(core.actionManager().action("mFile/mReload/aCurrent")) menu.addSeparator() # sort menu sortMenu = QMenu(self) group = QActionGroup(sortMenu) group.addAction(self.tr("Opening order")) group.addAction(self.tr("File name")) group.addAction(self.tr("URL")) group.addAction(self.tr("Suffixes")) group.triggered.connect(self._onSortTriggered) sortMenu.addActions(group.actions()) for i, sortMode in enumerate( ["OpeningOrder", "FileName", "URL", "Suffixes"]): action = group.actions()[i] action.setData(sortMode) action.setCheckable(True) if sortMode == self.model.sortMode(): action.setChecked(True) aSortMenu = QAction(self.tr("Sorting"), self) aSortMenu.setMenu(sortMenu) aSortMenu.setIcon(QIcon(":/enkiicons/sort.png")) aSortMenu.setToolTip(aSortMenu.text()) menu.addAction(sortMenu.menuAction()) menu.exec_(self.tvFiles.mapToGlobal(pos))
def 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
class Actions(actioncollection.ActionCollection): name = "file_import" def createActions(self, parent): self.import_all = QAction(parent) self.import_musicxml = QAction(parent) self.import_midi = QAction(parent) self.import_abc = QAction(parent) def translateUI(self): self.import_all.setText(_("Import...")) self.import_all.setToolTip(_("Generic import for all LilyPond tools.")) self.import_musicxml.setText(_("Import MusicXML...")) self.import_musicxml.setToolTip( _("Import a MusicXML file using musicxml2ly.")) self.import_midi.setText(_("Import Midi...")) self.import_midi.setToolTip(_("Import a Midi file using midi2ly.")) self.import_abc.setText(_("Import abc...")) self.import_abc.setToolTip(_("Import an abc file using abc2ly."))
def __init__(self, parent=None): super(SR785_Widget, self).__init__(parent=parent) self.screenActions = [] action = QAction('Screen', self) action.setToolTip('Refresh the entire screen') action.triggered.connect(self.refreshAll) self.screenActions.append(action) self.refreshScreenAction = action action = QAction('Status', self) action.setToolTip('Refresh only the status area') action.triggered.connect(self.refreshStatus) self.screenActions.append(action) self.refreshStatusAction = action action = QAction('Menu', self) action.setToolTip('Refresh only the menu area') action.triggered.connect(self.refreshMenu) self.screenActions.append(action) self.refreshMenuAction = action action = QAction('Graphs', self) action.setToolTip('Refresh only the graph area') action.triggered.connect(self.refreshGraphs) self.screenActions.append(action) self.refreshGraphsAction = action self.setupUi()
class Actions(actioncollection.ActionCollection): name = "rest" def createActions(self, parent): self.rest_fmrest2spacer = QAction(parent) self.rest_spacer2fmrest = QAction(parent) self.rest_restcomm2rest = QAction(parent) def translateUI(self): self.rest_fmrest2spacer.setText(_( "Replace full measure rests with spacer rests")) self.rest_fmrest2spacer.setToolTip(_( "Change all R to s " "in this document or in the selection.")) self.rest_spacer2fmrest.setText(_( "Replace spacer rests with full measure rests")) self.rest_spacer2fmrest.setToolTip(_( "Change all s to R " "in this document or in the selection.")) self.rest_restcomm2rest.setText(_( "Replace positioned rests with plain rests")) self.rest_restcomm2rest.setToolTip(_( "Change all \\rest with r " "in this document or in the selection."))
class QtAction(QtToolkitObject, ProxyAction): """ A Qt implementation of an Enaml ProxyAction. """ #: A reference to the widget created by the proxy. widget = Typed(QAction) #: Cyclic notification guard. This a bitfield of multiple guards. _guard = Int(0) # FIXME Currently, the checked state of the action is lost when # switching from checkable to non-checkable and back again. #-------------------------------------------------------------------------- # Initialization API #-------------------------------------------------------------------------- def create_widget(self): """ Create the underlying QAction object. """ self.widget = QAction(self.parent_widget()) def init_widget(self): """ Initialize the underlying control. """ super(QtAction, self).init_widget() d = self.declaration if d.text: self.set_text(d.text) if d.tool_tip: self.set_tool_tip(d.tool_tip) if d.status_tip: self.set_status_tip(d.status_tip) if d.icon: self.set_icon(d.icon) self.set_checkable(d.checkable) self.set_checked(d.checked) self.set_enabled(d.enabled) self.set_visible(d.visible) self.set_separator(d.separator) widget = self.widget widget.triggered.connect(self.on_triggered) widget.toggled.connect(self.on_toggled) #-------------------------------------------------------------------------- # Signal Handlers #-------------------------------------------------------------------------- def on_triggered(self, checked): """ The signal handler for the 'triggered' signal. """ if not self._guard & CHECKED_GUARD: self.declaration.checked = checked self.declaration.triggered(checked) def on_toggled(self, checked): """ The signal handler for the 'toggled' signal. """ if not self._guard & CHECKED_GUARD: self.declaration.checked = checked self.declaration.toggled(checked) #-------------------------------------------------------------------------- # ProxyAction API #-------------------------------------------------------------------------- def set_text(self, text): """ Set the text on the underlying control. """ widget = self.widget widget.setText(text) parts = text.split('\t') if len(parts) > 1: shortcut = QKeySequence(parts[-1]) widget.setShortcut(shortcut) def set_tool_tip(self, tool_tip): """ Set the tool tip on the underlying control. """ self.widget.setToolTip(tool_tip) def set_status_tip(self, status_tip): """ Set the status tip on the underyling control. """ self.widget.setStatusTip(status_tip) def set_icon(self, icon): """ Set the icon for the action. """ if icon: qicon = get_cached_qicon(icon) else: qicon = QIcon() self.widget.setIcon(qicon) def set_checkable(self, checkable): """ Set the checkable state on the underlying control. """ self.widget.setCheckable(checkable) def set_checked(self, checked): """ Set the checked state on the underlying control. """ self._guard |= CHECKED_GUARD try: self.widget.setChecked(checked) finally: self._guard &= ~CHECKED_GUARD def set_enabled(self, enabled): """ Set the enabled state on the underlying control. """ self.widget.setEnabled(enabled) def set_visible(self, visible): """ Set the visible state on the underlying control. """ self.widget.setVisible(visible) def set_separator(self, separator): """ Set the separator state on the underlying control. """ self.widget.setSeparator(separator)
def __init__(self): super().__init__() self.in_data = None self.in_distance = None self.in_learner = None self.in_classifier = None self.in_object = None self.auto_execute = False for s in self.libraryListSource: s.flags = 0 self._cachedDocuments = {} self.infoBox = gui.widgetBox(self.controlArea, 'Info') gui.label( self.infoBox, self, "<p>Execute python script.</p><p>Input variables:<ul><li> " + \ "<li>".join(t.name for t in self.inputs) + \ "</ul></p><p>Output variables:<ul><li>" + \ "<li>".join(t.name for t in self.outputs) + \ "</ul></p>" ) self.libraryList = itemmodels.PyListModel( [], self, flags=Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable) self.libraryList.wrap(self.libraryListSource) self.controlBox = gui.widgetBox(self.controlArea, 'Library') self.controlBox.layout().setSpacing(1) self.libraryView = QListView( editTriggers=QListView.DoubleClicked | QListView.EditKeyPressed, sizePolicy=QSizePolicy(QSizePolicy.Ignored, QSizePolicy.Preferred)) self.libraryView.setItemDelegate(ScriptItemDelegate(self)) self.libraryView.setModel(self.libraryList) self.libraryView.selectionModel().selectionChanged.connect( self.onSelectedScriptChanged) self.controlBox.layout().addWidget(self.libraryView) w = itemmodels.ModelActionsWidget() self.addNewScriptAction = action = QAction("+", self) action.setToolTip("Add a new script to the library") action.triggered.connect(self.onAddScript) w.addAction(action) action = QAction(unicodedata.lookup("MINUS SIGN"), self) action.setToolTip("Remove script from library") action.triggered.connect(self.onRemoveScript) w.addAction(action) action = QAction("Update", self) action.setToolTip("Save changes in the editor to library") action.setShortcut(QKeySequence(QKeySequence.Save)) action.triggered.connect(self.commitChangesToLibrary) w.addAction(action) action = QAction("More", self, toolTip="More actions") new_from_file = QAction("Import a script from a file", self) save_to_file = QAction("Save selected script to a file", self) save_to_file.setShortcut(QKeySequence(QKeySequence.SaveAs)) new_from_file.triggered.connect(self.onAddScriptFromFile) save_to_file.triggered.connect(self.saveScript) menu = QMenu(w) menu.addAction(new_from_file) menu.addAction(save_to_file) action.setMenu(menu) button = w.addAction(action) button.setPopupMode(QToolButton.InstantPopup) w.layout().setSpacing(1) self.controlBox.layout().addWidget(w) self.runBox = gui.widgetBox(self.controlArea, 'Run') gui.button(self.runBox, self, "Execute", callback=self.execute) gui.checkBox(self.runBox, self, "auto_execute", "Auto execute", tooltip="Run the script automatically whenever " + "the inputs to the widget change.") self.splitCanvas = QSplitter(Qt.Vertical, self.mainArea) self.mainArea.layout().addWidget(self.splitCanvas) self.defaultFont = defaultFont = \ "Monaco" if sys.platform == "darwin" else "Courier" self.textBox = gui.widgetBox(self, 'Python script') self.splitCanvas.addWidget(self.textBox) self.text = PythonScriptEditor(self) self.textBox.layout().addWidget(self.text) self.textBox.setAlignment(Qt.AlignVCenter) self.text.setTabStopWidth(4) self.text.modificationChanged[bool].connect(self.onModificationChanged) self.saveAction = action = QAction("&Save", self.text) action.setToolTip("Save script to file") action.setShortcut(QKeySequence(QKeySequence.Save)) action.setShortcutContext(Qt.WidgetWithChildrenShortcut) action.triggered.connect(self.saveScript) self.consoleBox = gui.widgetBox(self, 'Console') self.splitCanvas.addWidget(self.consoleBox) self.console = PythonConsole(self.__dict__, self) self.consoleBox.layout().addWidget(self.console) self.console.document().setDefaultFont(QFont(defaultFont)) self.consoleBox.setAlignment(Qt.AlignBottom) self.console.setTabStopWidth(4) select_row(self.libraryView, self.currentScriptIndex) self.splitCanvas.setSizes([2, 1]) if self.splitterState is not None: self.splitCanvas.restoreState(QByteArray(self.splitterState)) self.splitCanvas.splitterMoved[int, int].connect(self.onSpliterMoved) self.controlArea.layout().addStretch(1) self.resize(800, 600)