def updateActionList(self, functionList): self.actionCBox.clear() for (name, function) in functionList: fName = name if name is not '' else function.func_name act = qt.QAction(fName, self) act.triggered.connect(function) self.actionList += [act] self.actionCBox.addItem(fName)
def createActions(self): #fileopen self.actionOpen = qt.QAction(self) self.actionOpen.setText(QString("&Open")) self.actionOpen.setIcon(self.Icons["fileopen"]) self.actionOpen.setShortcut(qt.Qt.CTRL + qt.Qt.Key_O) self.connect(self.actionOpen, qt.SIGNAL("triggered(bool)"), self.onOpen) #filesaveas self.actionSaveAs = qt.QAction(self) self.actionSaveAs.setText(QString("&Save")) self.actionSaveAs.setIcon(self.Icons["filesave"]) self.actionSaveAs.setShortcut(qt.Qt.CTRL + qt.Qt.Key_S) self.connect(self.actionSaveAs, qt.SIGNAL("triggered(bool)"), self.onSaveAs) #filesave self.actionSave = qt.QAction(self) self.actionSave.setText(QString("Save &Defaults")) #self.actionSave.setIcon(self.Icons["filesave"]) #self.actionSave.setShortcut(qt.Qt.CTRL+qt.Qt.Key_S) self.connect(self.actionSave, qt.SIGNAL("triggered(bool)"), self.onSave) #fileprint self.actionPrint = qt.QAction(self) self.actionPrint.setText(QString("&Print")) self.actionPrint.setIcon(self.Icons["fileprint"]) self.actionPrint.setShortcut(qt.Qt.CTRL + qt.Qt.Key_P) self.connect(self.actionPrint, qt.SIGNAL("triggered(bool)"), self.onPrint) #filequit self.actionQuit = qt.QAction(self) self.actionQuit.setText(QString("&Quit")) #self.actionQuit.setIcon(self.Icons["fileprint"]) self.actionQuit.setShortcut(qt.Qt.CTRL + qt.Qt.Key_Q) qt.QObject.connect(self.actionQuit, qt.SIGNAL("triggered(bool)"), qt.qApp, qt.SLOT("closeAllWindows()"))
def __init__(self, parent, functionList): ''' List functions has to have the form (functionName, function) Default is ('', function) ''' qt.QMenu.__init__(self, parent) for (name, function) in functionList: if name != '': fName = name else: fName = function.func_name act = qt.QAction(fName, self) act.triggered.connect(function) self.addAction(act)
def __init__(self, parent): ''' Constructor ''' qt.QToolBar.__init__(self, parent) self.setIconSize(qt.QSize(25, 25)) self.zoomAutoAction = qt.QAction(qt.QIcon('Icones/autozoom.png'), '&Zoom', self) self.zoomAutoAction.setStatusTip('Fit window') self.zoomAutoAction.setCheckable(False) self.zoomAutoAction.setChecked(False) self.zoomActive = False qt.QObject.connect(self.zoomAutoAction, qt.SIGNAL("triggered()"), self.zoomAutoPushed) self.zone1Action = qt.QAction(qt.QIcon('Icones/zone.png'), '&ZoneSelection', self) self.zone1Action.setStatusTip('Select Zone') self.zone1Action.setCheckable(True) self.zone1Action.setChecked(False) qt.QObject.connect(self.zone1Action, qt.SIGNAL("triggered()"), self.zone1Selected) self.pointerAction = qt.QAction(qt.QIcon('Icones/cursor.png'), '&PointerSelection', self) self.pointerAction.setStatusTip('Select Pointer') self.pointerAction.setCheckable(True) self.pointerAction.setChecked(True) qt.QObject.connect(self.pointerAction, qt.SIGNAL("triggered()"), self.pointerSelected) self.drawingAction = qt.QAction(qt.QIcon('Icones/circle18.png'), '&DrawingSelection', self) self.drawingAction.setStatusTip('Select Drawing') self.drawingAction.setCheckable(True) self.drawingAction.setChecked(False) qt.QObject.connect(self.drawingAction, qt.SIGNAL("triggered()"), self.drawingSelected) self.polygonAction = qt.QAction(qt.QIcon('Icones/polygon.png'), '&PolygonSelection', self) self.polygonAction.setStatusTip('Select Polygone') self.polygonAction.setCheckable(True) self.polygonAction.setChecked(False) qt.QObject.connect(self.polygonAction, qt.SIGNAL("triggered()"), self.polygonSelected) self.pointRemoveAction = qt.QAction(qt.QIcon('Icones/remove.png'), '&DeletePoint', self) self.pointRemoveAction.setStatusTip('remove Point') self.pointRemoveAction.setCheckable(False) self.pointRemoveAction.setChecked(False) self.radius = LabelEditAndButton(True, "", True, str(100), False) self.doubleSlider = DoubleSlider(self) self.setMinAndMaxToolBar(0, 0) self.doubleSlider.setMaximumWidth(800) self.colorChoice = qt.QComboBox() self.colormapList = [] colorMapDefault = "GrayLevel", range(256), range(256), range(256) self.colormapList.append(colorMapDefault) self.colorChoice.addItems([self.colormapList[0][0]]) self.addColorMap('Jet', './jet_color.txt') self.addAction(self.zoomAutoAction) self.addSeparator() self.addAction(self.pointerAction) self.addAction(self.zone1Action) self.addAction(self.drawingAction) self.ActionRadius = self.addWidget(self.radius) self.ActionRadius.setVisible(False) self.addAction(self.polygonAction) self.addAction(self.pointRemoveAction) self.addWidget(self.doubleSlider) self.addWidget(self.colorChoice)
def _pluginClicked(self): actionList = [] menu = qt.QMenu(self) text = qt.QString("Reload") menu.addAction(text) actionList.append(text) menu.addSeparator() callableKeys = ["Dummy"] for m in self.pluginList: if m == "PyMcaPlugins.Plugin1DBase": continue module = sys.modules[m] if hasattr(module, 'MENU_TEXT'): text = qt.QString(module.MENU_TEXT) else: text = os.path.basename(module.__file__) if text.endswith('.pyc'): text = text[:-4] elif text.endswith('.py'): text = text[:-3] text = qt.QString(text) methods = self.pluginInstanceDict[m].getMethods(plottype="SCAN") if not len(methods): continue menu.addAction(text) actionList.append(text) callableKeys.append(m) a = menu.exec_(qt.QCursor.pos()) if a is None: return None idx = actionList.index(a.text()) if idx == 0: n = self.getPlugins() if n < 1: msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Information) msg.setText("Problem loading plugins") msg.exec_() return key = callableKeys[idx] methods = self.pluginInstanceDict[key].getMethods(plottype="SCAN") if len(methods) == 1: idx = 0 else: actionList = [] methods.sort() menu = qt.QMenu(self) for method in methods: text = qt.QString(method) pixmap = self.pluginInstanceDict[key].getMethodPixmap(method) tip = qt.QString( self.pluginInstanceDict[key].getMethodToolTip(method)) if pixmap is not None: action = qt.QAction(qt.QIcon(qt.QPixmap(pixmap)), text, self) else: action = qt.QAction(text, self) if tip is not None: action.setToolTip(tip) menu.addAction(action) actionList.append((text, pixmap, tip, action)) qt.QObject.connect(menu, qt.SIGNAL("hovered(QAction *)"), self._actionHovered) a = menu.exec_(qt.QCursor.pos()) if a is None: return None idx = -1 for action in actionList: if a.text() == action[0]: idx = actionList.index(action) try: self.pluginInstanceDict[key].applyMethod(methods[idx]) except: msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) if QTVERSION < '4.0.0': msg.setText("%s" % sys.exc_info()[1]) else: msg.setWindowTitle("Plugin error") msg.setText("An error has occured while executing the plugin:") msg.setInformativeText(str(sys.exc_info()[1])) msg.setDetailedText(traceback.format_exc()) msg.exec_()