예제 #1
0
    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.actionOpen.triggered[bool].connect(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.actionSaveAs.triggered[bool].connect(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.actionSave.triggered[bool].connect(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.actionPrint.triggered[bool].connect(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)
        qApp = qt.QApplication.instance()
        self.actionQuit.triggered[bool].connect(qApp.closeAllWindows)
예제 #2
0
    def __init__(self, parent=None):
        SilxMaskImageWidget.SilxMaskImageWidget.__init__(self, parent=parent)

        # Additional actions added to action group
        self.cropIcon = qt.QIcon(qt.QPixmap(IconDict["crop"]))
        self.cropButton = qt.QToolButton(self)
        self.cropButton.setIcon(self.cropIcon)
        self.cropButton.setToolTip("Crop image to current zoomed area")
        self.cropButton.clicked.connect(self._cropIconChecked)

        self.hFlipIcon = qt.QIcon(qt.QPixmap(IconDict["gioconda16mirror"]))
        self.hFlipToolButton = qt.QToolButton(self)
        self.hFlipToolButton.setIcon(self.hFlipIcon)
        self.hFlipToolButton.setToolTip("Flip image and data, not the scale.")
        self._flipMenu = qt.QMenu()
        self._flipMenu.addAction(QString("Flip Image Left-Right"),
                                 self._flipLeftRight)
        self._flipMenu.addAction(QString("Flip Image Up-Down"),
                                 self._flipUpDown)

        self.hFlipToolButton.setMenu(self._flipMenu)
        self.hFlipToolButton.setPopupMode(qt.QToolButton.InstantPopup)

        self.rotateLeftIcon = qt.QIcon(qt.QPixmap(IconDict["rotate_left"]))
        self.rotateRightIcon = qt.QIcon(qt.QPixmap(IconDict["rotate_right"]))
        self.rotateButton = qt.QToolButton(self)
        self.rotateButton.setIcon(self.rotateLeftIcon)
        self.rotateButton.setToolTip("Rotate image by 90 degrees")
        self._rotateMenu = qt.QMenu()
        self.rotateLeftAction = qt.QAction(self.rotateLeftIcon,
                                           QString("Rotate left"), self)
        self.rotateLeftAction.triggered.connect(self._rotateLeft)
        self._rotateMenu.addAction(self.rotateLeftAction)
        self.rotateRightAction = qt.QAction(self.rotateRightIcon,
                                            QString("Rotate right"), self)
        self.rotateRightAction.triggered.connect(self._rotateRight)
        self._rotateMenu.addAction(self.rotateRightAction)

        self.rotateButton.setMenu(self._rotateMenu)
        self.rotateButton.setPopupMode(qt.QToolButton.InstantPopup)

        toolbar = qt.QToolBar("Image edition", parent=self)

        # custom widgets added to the end
        toolbar.addWidget(self.cropButton)
        toolbar.addWidget(self.hFlipToolButton)
        toolbar.addWidget(self.rotateButton)
        self.addToolBar(toolbar)

        # hide stack image slider, show transparency slider
        self.slider.hide()
        self.setAlphaSliderVisible(True)
        self.setImagesAlpha(0.)
예제 #3
0
    def _initActions(self):
        # Reset zoom
        self.actionResetZoom = qt.QAction(qt.QIcon(
            qt.QPixmap(IconDict['zoomreset'])),
                                          'Reset Zoom (Ctrl-0)',
                                          self,
                                          triggered=self.resetZoom)
        self.actionResetZoom.setShortcut('Ctrl+0')

        # keep data aspect ratio
        self.actionKeepDataAspectRatio = qt.QAction(
            qt.QIcon(qt.QPixmap(IconDict['solidellipse'])),
            'Keep data aspect ratio',
            self,
            toggled=self._imagePlot.keepDataAspectRatio)
        # No need to ask for replot here
        # No need to sync histogram limits, this is automatic
        # Change icon
        self.actionKeepDataAspectRatio.toggled.connect(
            self._setKeepDataAspectRatio)
        self.actionKeepDataAspectRatio.setCheckable(True)
        self.actionKeepDataAspectRatio.setChecked(
            self._imagePlot.isKeepDataAspectRatio())

        # Change colormap
        cmapDialog = _ColormapDialogHelper(self)
        cmapDialog.colormapChanged.connect(self.setColormap)

        self.actionChangeColormap = qt.QAction(qt.QIcon(
            qt.QPixmap(IconDict['colormap'])),
                                               'Change colormap',
                                               self,
                                               triggered=cmapDialog.showDialog)
        self.actionChangeColormap._cmapDialog = cmapDialog  # Store a ref

        # Invert Y axis
        self.actionInvertYAxis = qt.QAction(qt.QIcon(
            qt.QPixmap(IconDict["gioconda16mirror"])),
                                            'Flip Horizontal',
                                            self,
                                            toggled=self._setYAxisInverted)
        self.actionInvertYAxis.setCheckable(True)
        self.actionInvertYAxis.setChecked(self._imagePlot.isYAxisInverted())
예제 #4
0
    def _openMenu(self, checked):
        # note: opening a context menu over a QGLWidget causes a warning (fixed in Qt 5.4.1)
        #       See: https://bugreports.qt.io/browse/QTBUG-42464
        menu = qt.QMenu(self._sceneGlWindow)

        loadPixmapAction = qt.QAction("Pixmap", self)
        loadPixmapAction.triggered[bool].connect(self._onLoadPixmap)
        menu.addAction(loadPixmapAction)

        load3DMeshAction = qt.QAction("3D mesh", self)
        load3DMeshAction.triggered[bool].connect(self._onLoad3DMesh)
        menu.addAction(load3DMeshAction)

        load4DStackAction = qt.QAction("4D stack", self)
        load4DStackAction.triggered[bool].connect(self._onLoad4DStack)
        menu.addAction(load4DStackAction)

        loadChimeraAction = qt.QAction("4D chimera", self)
        loadChimeraAction.triggered[bool].connect(self._onLoadChimeraStack)
        menu.addAction(loadChimeraAction)

        a = menu.exec_(qt.QCursor.pos())
    def _showMenu(self):
        """Create a show menu allowing to show any of the existing external
        image windows"""
        if len(self.windows) == 1:
            label = self.windows.keys()[0]
            self.windows[label].showAndRaise()
            return
        showMenu = qt.QMenu()
        for label in self.windows:
            action = qt.QAction(label, showMenu)
            action.setToolTip('Show window displaying image "%s"' % label)
            action.triggered.connect(self.windows[label].showAndRaise)
            showMenu.addAction(action)

        showMenu.exec_(qt.QCursor.pos())
예제 #6
0
    def _pluginClicked(self):
        actionNames = []
        menu = qt.QMenu(self)
        menu.addAction("Reload Plugins")
        actionNames.append("Reload Plugins")
        menu.addAction("Set User Plugin Directory")
        actionNames.append("Set User Plugin Directory")

        if _logger.getEffectiveLevel() == logging.DEBUG:
            text = "Toggle DEBUG mode OFF"
        else:
            text = "Toggle DEBUG mode ON"

        menu.addAction(text)
        menu.addSeparator()
        actionNames.append(text)
        callableKeys = ["Dummy0", "Dummy1", "Dummy2"]
        pluginInstances = self.pluginInstanceDict
        for pluginName in self.pluginList:
            if pluginName in ["PyMcaPlugins.Plugin1DBase", "Plugin1DBase"]:
                continue
            module = sys.modules[pluginName]
            if hasattr(module, 'MENU_TEXT'):
                text = module.MENU_TEXT
            else:
                text = os.path.basename(module.__file__)
                if text.endswith('.pyc'):
                    text = text[:-4]
                elif text.endswith('.py'):
                    text = text[:-3]

            methods = pluginInstances[pluginName].getMethods(
                plottype=self._plotType)
            if not len(methods):
                continue
            elif len(methods) == 1:
                pixmap = pluginInstances[pluginName].getMethodPixmap(
                    methods[0])
                tip = pluginInstances[pluginName].getMethodToolTip(methods[0])
                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)
            else:
                menu.addAction(text)
            actionNames.append(text)
            callableKeys.append(pluginName)
        menu.hovered.connect(self._actionHovered)
        a = menu.exec_(qt.QCursor.pos())
        if a is None:
            return None

        idx = actionNames.index(a.text())
        if a.text() == "Reload Plugins":
            n, message = self.getPlugins(exceptions=True)
            if n < 1:
                msg = qt.QMessageBox(self)
                msg.setIcon(qt.QMessageBox.Information)
                msg.setWindowTitle("No plugins")
                msg.setInformativeText(" Problem loading plugins ")
                msg.setDetailedText(message)
                msg.exec()
            return
        if a.text() == "Set User Plugin Directory":
            dirName = qt.QFileDialog.getExistingDirectory(
                self, "Enter user plugins directory", os.getcwd())
            if len(dirName):
                pluginsDir = self.getPluginDirectoryList()
                pluginsDirList = [pluginsDir[0], dirName]
                self.setPluginDirectoryList(pluginsDirList)
            return
        if "Toggle DEBUG mode" in a.text():
            _toggleLogger()
            return
        key = callableKeys[idx]

        methods = pluginInstances[key].getMethods(plottype=self._plotType)
        if len(methods) == 1:
            idx = 0
        else:
            actionNames = []
            # allow the plugin designer to specify the order
            #methods.sort()
            menu = qt.QMenu(self)
            for method in methods:
                text = method
                pixmap = pluginInstances[key].getMethodPixmap(method)
                tip = pluginInstances[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)
                actionNames.append((text, pixmap, tip, action))
            #qt.QObject.connect(menu, qt.SIGNAL("hovered(QAction *)"), self._actionHovered)
            menu.hovered.connect(self._actionHovered)
            a = menu.exec_(qt.QCursor.pos())
            if a is None:
                return None
            idx = -1
            for action in actionNames:
                if a.text() == action[0]:
                    idx = actionNames.index(action)
        try:
            pluginInstances[key].applyMethod(methods[idx])
        except:
            msg = qt.QMessageBox(self)
            msg.setIcon(qt.QMessageBox.Critical)
            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()
예제 #7
0
파일: ImageView.py 프로젝트: dnaudet/pymca
    def __init__(self,
                 plotWindow,
                 profileWindow=None,
                 title='Profile Selection',
                 parent=None):
        """

        :param plotWindow: :class:`PlotWindow` instance on which to operate.
        :param profileWindow: :class:`ProfileScanWidget` instance where to
                              display the profile curve or None to create one.
        :param str title: See :class:`QToolBar`.
        :param parent: See :class:`QToolBar`.
        """
        super(ProfileToolBar, self).__init__(title, parent)
        assert plotWindow is not None
        self.plotWindow = plotWindow
        self.plotWindow.sigPlotSignal.connect(self._plotWindowSlot)

        self._overlayColor = None

        self._roiInfo = None
        if profileWindow is None:
            self.profileWindow = ProfileScanWidget(actions=False)
        else:
            self.profileWindow = profileWindow

        # Actions
        self.browseAction = qt.QAction(
            qt.QIcon(qt.QPixmap(IconDict["normal"])), 'Browsing Mode', None)
        self.browseAction.setToolTip('Enables zooming interaction mode')
        self.browseAction.setCheckable(True)

        self.hLineAction = qt.QAction(
            qt.QIcon(qt.QPixmap(IconDict["horizontal"])),
            'Horizontal Profile Mode', None)
        self.hLineAction.setToolTip(
            'Enables horizontal profile selection mode')
        self.hLineAction.setCheckable(True)

        self.vLineAction = qt.QAction(
            qt.QIcon(qt.QPixmap(IconDict["vertical"])),
            'Vertical Profile Mode', None)
        self.vLineAction.setToolTip('Enables vertical profile selection mode')
        self.vLineAction.setCheckable(True)

        self.lineAction = qt.QAction(
            qt.QIcon(qt.QPixmap(IconDict["diagonal"])),
            'Fee Line Profile Mode', None)
        self.lineAction.setToolTip('Enables line profile selection mode')
        self.lineAction.setCheckable(True)

        self.clearAction = qt.QAction(qt.QIcon(qt.QPixmap(IconDict["image"])),
                                      'Clear Profile', None)
        self.clearAction.setToolTip('Clear the profile Region of interest')
        self.clearAction.setCheckable(False)
        self.clearAction.triggered.connect(self.clearProfile)

        # ActionGroup
        self.actionGroup = qt.QActionGroup(self)
        self.actionGroup.addAction(self.browseAction)
        self.actionGroup.addAction(self.hLineAction)
        self.actionGroup.addAction(self.vLineAction)
        self.actionGroup.addAction(self.lineAction)
        self.actionGroup.triggered.connect(self._actionGroupTriggeredSlot)

        self.browseAction.setChecked(True)

        # Add actions to ToolBar
        self.addAction(self.browseAction)
        self.addAction(self.hLineAction)
        self.addAction(self.vLineAction)
        self.addAction(self.lineAction)
        self.addAction(self.clearAction)

        # Add width spin box to toolbar
        self.addWidget(qt.QLabel('W:'))
        self.lineWidthSpinBox = qt.QSpinBox(self)
        self.lineWidthSpinBox.setRange(0, 1000)
        self.lineWidthSpinBox.setValue(1)
        self.lineWidthSpinBox.valueChanged[int].connect(
            self._lineWidthSpinBoxValueChangedSlot)
        self.addWidget(self.lineWidthSpinBox)
예제 #8
0
 def _pluginClicked(self):
     actionList = []
     menu = qt.QMenu(self)
     text = QString("Reload Plugins")
     menu.addAction(text)
     actionList.append(text)
     text = QString("Set User Plugin Directory")
     menu.addAction(text)
     actionList.append(text)
     global DEBUG
     if DEBUG:
         text = QString("Toggle DEBUG mode OFF")
     else:
         text = QString("Toggle DEBUG mode ON")
     menu.addAction(text)
     actionList.append(text)
     menu.addSeparator()
     callableKeys = ["Dummy0", "Dummy1", "Dummy2"]
     additionalItems = []
     SORTED = True
     for m in self.pluginList:
         if m == "PyMcaPlugins.StackPluginBase":
             continue
         module = sys.modules[m]
         if hasattr(module, 'MENU_TEXT'):
             text = 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 = QString(text)
         methods = self.pluginInstanceDict[m].getMethods()
         if not len(methods):
             continue
         if SORTED:
             additionalItems.append((text, m))
         else:
             menu.addAction(text)
             actionList.append(text)
             callableKeys.append(m)
     additionalItems.sort()
     for text, m in additionalItems:
         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
     if idx == 1:
         dirName = qt.safe_str(
             qt.QFileDialog.getExistingDirectory(
                 self, "Enter user plugins directory", os.getcwd()))
         if len(dirName):
             pluginsDir = self.getPluginDirectoryList()
             pluginsDirList = [pluginsDir[0], dirName]
             self.setPluginDirectoryList(pluginsDirList)
         return
     if idx == 2:
         if DEBUG:
             DEBUG = 0
         else:
             DEBUG = 1
         StackBase.DEBUG = DEBUG
         return
     key = callableKeys[idx]
     methods = self.pluginInstanceDict[key].getMethods()
     if len(methods) == 1:
         idx = 0
     else:
         actionList = []
         #methods.sort()
         menu = qt.QMenu(self)
         for method in methods:
             text = QString(method)
             pixmap = self.pluginInstanceDict[key].getMethodPixmap(method)
             tip = 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))
         menu.hovered.connect(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)
         msg.setWindowTitle("Plugin error")
         msg.setText("An error has occured while executing the plugin:")
         msg.setInformativeText(qt.safe_str(sys.exc_info()[1]))
         msg.setDetailedText(traceback.format_exc())
         msg.exec_()
         if DEBUG:
             raise