def _refresh_presets(self): pmenu = self.presetmenu pmenu.clear() delmenu = QMenu('Delete', self) try: for preset, info in iteritems(self.presetdict): paction = QAction(preset, self) pdelaction = QAction(preset, self) info = info.copy() def launchpreset(on, info=info): self._createViewFromDialog(info) def delpreset(on, name=preset, act=paction, delact=pdelaction): pmenu.removeAction(act) delmenu.removeAction(delact) self.presetdict.pop(name, None) self._refresh_presets() paction.triggered[bool].connect(launchpreset) pmenu.addAction(paction) pdelaction.triggered[bool].connect(delpreset) delmenu.addAction(pdelaction) except AttributeError: self.presetdict = {} if self.presetdict: pmenu.addSeparator() pmenu.addMenu(delmenu) else: pmenu.addAction('(no presets created)')
def __init__(self, client, icon, text, options, parent=None): QAction.__init__(self, icon, text, parent) # the default menu rule is TextHeuristicRole, which moves 'setup' to # the 'Preferences' Menu on a Mac -> this is not what we want self.setMenuRole(self.NoRole) setups = options.get('setups', '') self.setupSpec = setups if self.setupSpec: client.register(self, 'session/mastersetup')
def addToRecentf(self, fn): new_action = QAction(fn.replace('&', '&&'), self) new_action.setData(fn) new_action.triggered.connect(self.openRecentFile) if self.recentf_actions: self.menuRecent.insertAction(self.recentf_actions[0], new_action) self.recentf_actions.insert(0, new_action) del self.recentf_actions[10:] else: self.menuRecent.addAction(new_action) self.recentf_actions.append(new_action) with self.sgroup as settings: settings.setValue('recentf', [a.data() for a in self.recentf_actions])
def createToolMenu(window, config, menuitem): """Create menu entries for tools in *config* under *menuitem*. Use *window* as the parent window for dialogs. """ for tconfig in config: if isinstance(tconfig, menu): submenu = menuitem.addMenu(tconfig.name) createToolMenu(window, tconfig.items, submenu) else: def tool_callback(on, tconfig=tconfig): runTool(window, tconfig) action = QAction(tconfig.name, window) menuitem.addAction(action) action.triggered.connect(tool_callback)
def __init__(self, parent, client, options): LokiPanelBase.__init__(self, parent, client, options) loadUi(self, findResource('nicos_ess/loki/gui/ui_files/scriptbuilder.ui')) self.window = parent self.runBtn.setVisible(False) self.mapping = {} self.expertmode = self.mainwindow.expertmode self._cmdlet = self.sender() self._layout = self.frame.layout() self.index = self._layout.indexOf(self._cmdlet) self.initialise_connection_status_listeners() modules = options.get('modules', []) for module in modules: importString(module) # should register cmdlets for cmdlet in all_cmdlets: def callback(on, cmdlet=cmdlet): inst = cmdlet(self, self.client) inst.cmdletUp.connect(self.on_cmdletUp) inst.cmdletDown.connect(self.on_cmdletDown) inst.cmdletRemove.connect(self.on_cmdletRemove) self.runBtn.setVisible(True) self.frame.layout().insertWidget( self.frame.layout().count() - 2, inst) action = QAction(cmdlet.name, self) action.triggered.connect(callback) self.mapping.setdefault(cmdlet.category, []).append(action) for category in all_categories[::-1]: if category not in self.mapping: return toolbtn = QToolButton(self) toolbtn.setText(category) toolbtn.setPopupMode(QToolButton.InstantPopup) menu = QMenu(self) menu.addActions(self.mapping[category]) toolbtn.setMenu(menu) self.btnLayout.insertWidget(1, toolbtn)
def on_roiItemClicked(self, event): if event.getButtons() & MouseEvent.RIGHT_BUTTON: if isinstance(event.roi.reference, FitResult): menu = QMenu(self) actionClipboard = QAction("Copy fit values to clipboard", menu) menu.addAction(actionClipboard) p0dc = event.getDC() selectedItem = menu.exec_( self.mapToGlobal(QPoint(p0dc.x, p0dc.y))) if selectedItem == actionClipboard: res = event.roi.reference text = '\n'.join( (n + '\t' if n else '\t') + (v + '\t' if isinstance(v, string_types) else '%g\t' % v) + (dv if isinstance(dv, string_types) else '%g' % dv) for (n, v, dv) in res.label_contents) QApplication.clipboard().setText(text)
def __init__(self, parent, client, options): Panel.__init__(self, parent, client, options) loadUi(self, self.ui) self.window = parent self.mapping = {} self.current_cmdlet = None self.expertmode = self.mainwindow.expertmode # collect values of all cmdlets that have been added # so that the common fields carry over to the next cmdlet self.value_collection = {} self.commandInput.history = self.cmdhistory self.commandInput.completion_callback = self.completeInput self.console = None client.initstatus.connect(self.on_client_initstatus) client.mode.connect(self.on_client_mode) client.simresult.connect(self.on_client_simresult) modules = options.get('modules', []) for module in modules: importString(module) # should register cmdlets for cmdlet in all_cmdlets: action = QAction(cmdlet.name, self) def callback(on, cmdlet=cmdlet): self.selectCmdlet(cmdlet) action.triggered.connect(callback) self.mapping.setdefault(cmdlet.category, []).append(action) for category in all_categories[::-1]: if category not in self.mapping: continue toolbtn = QToolButton(self) toolbtn.setText(category) toolbtn.setPopupMode(QToolButton.InstantPopup) menu = QMenu(self) menu.addActions(self.mapping[category]) toolbtn.setMenu(menu) self.btnLayout.insertWidget(1, toolbtn)
def on_tree_customContextMenuRequested(self, point): item = self.tree.itemAt(point) if item is None: return if item.type() == DEVICE_TYPE: self._menu_dev = item.text(0) ldevname = self._menu_dev.lower() if charmpowersupply in self._devinfo[ldevname].classes: params = self.client.getDeviceParams(ldevname) self.cpsmenu = QMenu() self.cps_actions = [] i = 0 for menuItem in params['transitions']: self.cps_actions.append(QAction(menuItem)) self.cpsmenu.addAction(self.cps_actions[i]) self.cps_actions[i].triggered.connect( partial(self.on_actionApply_triggered, i)) i = i + 1 self.cpsmenu.addSeparator() self.cpsmenu.addAction(self.actionMove) self.cpsmenu.addAction(self.actionReset) self.cpsmenu.addSeparator() if self.mainwindow.history_wintype is not None: self.cpsmenu.addAction(self.actionPlotHistory) self.cpsmenu.addSeparator() self.cpsmenu.addAction(self.actionShutDown) self.cpsmenu.addAction(self.actionHelp) self.cpsmenu.popup(self.tree.viewport().mapToGlobal(point)) return if roimanager in self._devinfo[ldevname].classes: params = self.client.getDeviceParams(ldevname) self.cpsmenu = QMenu() self.cps_actions = [] self.cps_actions.append(QAction('Edit...')) self.cpsmenu.addAction(self.cps_actions[0]) self.cps_actions[0].triggered.connect( partial(self.on_roimanagerEdit, ldevname)) self.cpsmenu.addSeparator() self.cpsmenu.addAction(self.actionMove) self.cpsmenu.addAction(self.actionReset) self.cpsmenu.addSeparator() if self.mainwindow.history_wintype is not None: self.cpsmenu.addAction(self.actionPlotHistory) self.cpsmenu.addSeparator() self.cpsmenu.addAction(self.actionShutDown) self.cpsmenu.addAction(self.actionHelp) self.cpsmenu.popup(self.tree.viewport().mapToGlobal(point)) return if compareimage in self._devinfo[ldevname].classes: params = self.client.getDeviceParams(ldevname) self.cpsmenu = QMenu() self.cps_actions = [] self.cps_actions.append(QAction('Show &Compare...')) self.cpsmenu.addAction(self.cps_actions[0]) self.cps_actions[0].triggered.connect( partial(self.on_images_compare, ldevname)) self.cpsmenu.addSeparator() self.cpsmenu.addAction(self.actionMove) self.cpsmenu.addAction(self.actionReset) self.cpsmenu.addSeparator() if self.mainwindow.history_wintype is not None: self.cpsmenu.addAction(self.actionPlotHistory) self.cpsmenu.addSeparator() self.cpsmenu.addAction(self.actionShutDown) self.cpsmenu.addAction(self.actionHelp) self.cpsmenu.popup(self.tree.viewport().mapToGlobal(point)) return if playlistmanager in self._devinfo[ldevname].classes: params = self.client.getDeviceParams(ldevname) self.cpsmenu = QMenu() self.cps_actions = [] self.cps_actions.append(QAction('Edit...')) self.cpsmenu.addAction(self.cps_actions[0]) self.cps_actions[0].triggered.connect( partial(self.on_playlist_edit, ldevname)) self.cpsmenu.addSeparator() self.cpsmenu.addAction(self.actionMove) self.cpsmenu.addAction(self.actionReset) self.cpsmenu.addSeparator() if self.mainwindow.history_wintype is not None: self.cpsmenu.addAction(self.actionPlotHistory) self.cpsmenu.addSeparator() self.cpsmenu.addAction(self.actionShutDown) self.cpsmenu.addAction(self.actionHelp) self.cpsmenu.popup(self.tree.viewport().mapToGlobal(point)) return return super().on_tree_customContextMenuRequested(point)
def _show_context_menu(self): menu = QMenu() copy_action = QAction("Copy", self) copy_action.triggered.connect(self._handle_copy_cells) copy_action.setIcon(get_icon("file_copy-24px.svg")) menu.addAction(copy_action) cut_action = QAction("Cut", self) cut_action.triggered.connect(self._handle_cut_cells) cut_action.setIcon(get_icon("cut_24px.svg")) menu.addAction(cut_action) paste_action = QAction("Paste", self) paste_action.triggered.connect(self._handle_table_paste) paste_action.setIcon(get_icon("paste_24px.svg")) menu.addAction(paste_action) delete_action = QAction("Delete", self) delete_action.triggered.connect(self._delete_rows) delete_action.setIcon(get_icon("remove-24px.svg")) menu.addAction(delete_action) menu.exec_(QCursor.pos())
def __init__(self, parent, client, options): Panel.__init__(self, parent, client, options) loadUi(self, 'panels/editor.ui') self.window = parent self.custom_font = None self.custom_back = None self.mainwindow.codeGenerated.connect(self.on_codeGenerated) if not has_scintilla: self.actionComment.setEnabled(False) self.menus = None self.bar = None self.current_status = None self.recentf_actions = [] self.searchdlg = None self.menuRecent = QMenu('Recent files') self.menuToolsActions = [] for fn in self.recentf: action = QAction(fn.replace('&', '&&'), self) action.setData(fn) action.triggered.connect(self.openRecentFile) self.recentf_actions.append(action) self.menuRecent.addAction(action) self.tabber = QTabWidget(self, tabsClosable=True, documentMode=True) self.tabber.currentChanged.connect(self.on_tabber_currentChanged) self.tabber.tabCloseRequested.connect(self.on_tabber_tabCloseRequested) self.toolconfig = options.get('tools') self.sim_window = options.get('sim_window', 'inline') if self.sim_window not in ('single', 'multi', 'inline'): self.log.warning('invalid sim_window option %r, using inline', self.sim_window) self.sim_window = 'inline' hlayout = QHBoxLayout() hlayout.setContentsMargins(0, 0, 0, 0) hlayout.addWidget(self.tabber) self.mainFrame.setLayout(hlayout) self.editors = [] # tab index -> editor self.filenames = {} # editor -> filename self.watchers = {} # editor -> QFileSystemWatcher self.currentEditor = None self.saving = False # True while saving self.warnWidget.hide() self.simFrame = SimResultFrame(self, None, self.client) self.simPaneFrame.layout().addWidget(self.simFrame) self.simPane.hide() self.simWindows = [] self.splitter.restoreState(self.splitterstate) self.treeModel = QFileSystemModel() idx = self.treeModel.setRootPath('/') self.treeModel.setNameFilters(['*.py', '*.txt']) self.treeModel.setNameFilterDisables(False) # hide them self.fileTree.setModel(self.treeModel) self.fileTree.header().hideSection(1) self.fileTree.header().hideSection(2) self.fileTree.header().hideSection(3) self.fileTree.header().hide() self.fileTree.setRootIndex(idx) if not options.get('show_browser', True): self.scriptsPane.hide() self.actionShowScripts = self.scriptsPane.toggleViewAction() self.actionShowScripts.setText('Show Script Browser') self.activeGroup = QActionGroup(self) self.activeGroup.addAction(self.actionRun) self.activeGroup.addAction(self.actionSimulate) self.activeGroup.addAction(self.actionUpdate) client.simresult.connect(self.on_client_simresult) if self.client.connected: self.on_client_connected() else: self.on_client_disconnected() client.connected.connect(self.on_client_connected) client.disconnected.connect(self.on_client_disconnected) client.setup.connect(self.on_client_connected) client.cache.connect(self.on_client_cache) client.experiment.connect(self.on_client_experiment) if self.openfiles: for fn in self.openfiles: self.openFile(fn, quiet=True) else: self.newFile()
def __init__(self, client, icon, text, options, parent=None): QAction.__init__(self, icon, text, parent) setups = options.get('setups', '') self.setupSpec = setups if self.setupSpec: client.register(self, 'session/mastersetup')