コード例 #1
0
    def configureAction(self):
        """
        Move To action
        """
        if self.movetoMode is not None:
            if self.movetoAction is None:
                """
                create action
                """
                self.movetoAction = QubSelectPointAction(
                    name='Move to Beam',
                    place=self.movetoMode,
                    actionInfo='Move to Beam',
                    group='Tools')
                self.connect(self.movetoAction, qt.PYSIGNAL("StateChanged"),
                             self.movetoStateChanged)
                self.connect(self.movetoAction, qt.PYSIGNAL("PointSelected"),
                             self.pointSelected)

                if self.view is not None:
                    self.view.addAction(self.movetoAction)
                    self.oldMoveToActionColor = self.movetoAction.paletteBackgroundColor(
                    )

        else:
            if self.movetoAction is not None:
                """
                remove action
                """
                if self.view is not None:
                    self.view.delAction(self.movetoAction)
                """
                del action from view
                """
                self.disconnect(self.movetoAction,
                                qt.PYSIGNAL("PointSelected"),
                                self.pointSelected)
                self.movetoAction = None
        """
        Limits action
        """
        if self.limitsMode is not None:
            if self.limitsAction is None:
                """
                create action
                """
                self.limitsAction = QubRulerAction(name='Motor Limits',
                                                   place=self.limitsMode,
                                                   group='Tools')

                if self.view is not None:
                    self.view.addAction(self.limitsAction)
            """
            configure action
            """
            if self.horMotHwo is not None:
                mne = self.horMotHwo.getMotorMnemonic()
                self.limitsAction.setLabel(QubRulerAction.HORIZONTAL, 0, mne)

            if self.verMotHwo is not None:
                mne = self.verMotHwo.getMotorMnemonic()
                self.limitsAction.setLabel(QubRulerAction.VERTICAL, 0, mne)

        else:
            if self.limitsAction is not None:
                """
                remove action
                """
                if self.view is not None:
                    self.view.delAction(self.limitsAction)
                """
                del action from view
                """
                self.limitsAction = None

        if self.measureMode is not None:
            if self.measureAction is None:
                self.measureAction = QubOpenDialogAction(
                    parent=self,
                    name='measure',
                    iconName='measure',
                    label='Measure',
                    group='Tools',
                    place=self.measureMode)
                self.measureAction.setConnectCallBack(self._measure_dialog_new)
                logging.getLogger().info("setting measure mode")
                if self.view is not None:
                    logging.getLogger().info("adding action")
                    self.view.addAction(self.measureAction)
        else:
            if self.measureAction is not None:
                if self.view is not None:
                    self.view.delAction(self.measureAction)
                self.measureAction = None

        if self.movetoMode is not None:
            if self.__movetoActionMosaic is not None:
                self.__mosaicView.delAction(self.__movetoActionMosaic)
                self.disconnect(self.__movetoActionMosaic,
                                qt.PYSIGNAL("PointSelected"),
                                self.__mosaicPointSelected)
                self.diconnect(self.__movetoActionMosaic,
                               qt.PYSIGNAL("StateChanged"),
                               self.__movetoMosaicStateChanged)
                self.__movetoActionMosaic = None

            if self.__mosaicView is not None:
                self.__movetoActionMosaic = QubSelectPointAction(
                    name='Move to Beam',
                    place=self.movetoMode,
                    actionInfo='Move to Beam',
                    mosaicMode=True,
                    residualMode=True,
                    group='Tools')
                self.connect(self.__movetoActionMosaic,
                             qt.PYSIGNAL("PointSelected"),
                             self.__mosaicPointSelected)
                self.connect(self.__movetoActionMosaic,
                             qt.PYSIGNAL("StateChanged"),
                             self.__movetoMosaicStateChanged)

                self.__mosaicView.addAction(self.__movetoActionMosaic)
                self.__oldMoveToMosaicActionColor = self.__movetoActionMosaic.paletteBackgroundColor(
                )

        if self.focusMode is not None:
            if self.focusAction is None:
                self.focusAction = QubToggleAction(label='Autofocus',
                                                   name='autofocus',
                                                   place=self.focusMode,
                                                   group='Tools',
                                                   autoConnect=True)
                qt.QObject.connect(self.focusAction,
                                   qt.PYSIGNAL('StateChanged'),
                                   self.showFocusGrab)

            if self.view and self.drawing:
                self.focusDrawingRectangle, _ = QubAddDrawing(
                    self.drawing, QubPointDrawingMgr,
                    QubCanvasHomotheticRectangle)
                self.focusDrawingRectangle.setDrawingEvent(
                    QubMoveNPressed1Point)
                self.focusDrawingRectangle.setKeyPressedCallBack(
                    self.focusRawKeyPressed)

                qt.QObject.connect(self.drawing,
                                   qt.PYSIGNAL("ForegroundColorChanged"),
                                   self.focusDrawingRectangle.setColor)
                self.focusDrawingRectangle.setEndDrawCallBack(
                    self.setFocusPointSelected)
                self.focusRectangleSize = 12
                self.focusDrawingRectangle.setWidthNHeight(
                    self.focusRectangleSize, self.focusRectangleSize)
                self.view.addAction(self.focusAction)

        elif self.view is not None:
            self.view.delAction(self.focusAction)
            self.focusDrawingRectangle = None
コード例 #2
0
    def run(self):
        key = {}
        self.emit(qt.PYSIGNAL('getView'), (key, ))
        try:
            view = key['view']
            drawing = key['drawing']

            self.__snapAction = QubToolButtonAction(name='MosaicSnap',
                                                    iconName='snapshot',
                                                    toolButtonStyle=True,
                                                    place='toolbar',
                                                    group='image',
                                                    autoConnect=True)
            qt.QObject.connect(self.__snapAction, qt.PYSIGNAL('ButtonPressed'),
                               self.__snapCBK)
            view.addAction([self.__snapAction])
        except KeyError:
            logging.getLogger().error(
                'getView is not connected to CameraOffLineImageManager!!!')

        mosaicKey = {}
        self.emit(qt.PYSIGNAL('getMosaicView'), (mosaicKey, ))
        try:
            self.mosaicView = mosaicKey['view']
            self.drawing = mosaicKey['drawing']

            class _openDialog(QubOpenDialogAction):
                def __init__(self, *args, **keys):
                    QubOpenDialogAction.__init__(self, *args, **keys)

                def setCanvas(self, canvas):
                    self.__canvas = canvas

                def _showDialog(self):
                    if self._dialog.exec_loop() == qt.QDialog.Accepted:
                        file_path = self._dialog.selectedFile().ascii()
                        dirName, file_name = os.path.split(file_path)
                        base, ext = os.path.splitext(file_name)
                        QubImageSave.save(
                            os.path.join(dirName, '%s.svg' % base), None,
                            self.__canvas, 1, 'svg', True)

            self.__saveMosaicAction = _openDialog(parent=self,
                                                  label='Save image',
                                                  name="save",
                                                  iconName='save',
                                                  group="admin")
            saveMosaicDialogue = qt.QFileDialog('.', 'Mosaic Images (*.svg)',
                                                self, 'Save mosaic Images',
                                                True)
            saveMosaicDialogue.setMode(saveMosaicDialogue.AnyFile)
            self.__saveMosaicAction.setDialog(saveMosaicDialogue)
            self.__saveMosaicAction.setCanvas(self.drawing.canvas())

            self.__imageMosaicPosition = QubRulerAction(name='Motor Position',
                                                        place='toolbar',
                                                        group='Tools')

            self.__mouseMotorPosition = _MouseOrMotorPosition(
                name='mouse motor position',
                place='statusbar',
                group='info',
                mouseFlag=True)

            self.__currentMotorPosition = _MouseOrMotorPosition(
                name='current motor position', place='statusbar', group='info')

            self.mosaicView.addAction([
                self.__imageMosaicPosition, self.__saveMosaicAction,
                self.__currentMotorPosition, self.__mouseMotorPosition
            ])

            if self.__vMotor is not None:
                self.__imageMosaicPosition.setLabel(
                    QubRulerAction.VERTICAL, 0,
                    self.__vMotor.getMotorMnemonic())
                self.__imageMosaicPosition.setCursorPosition(
                    QubRulerAction.VERTICAL, 0, self.__vMotor.getPosition())
                limits = self.__vMotor.getLimits()
                self.__imageMosaicPosition.setLimits(QubRulerAction.VERTICAL,
                                                     0, *limits)
                self.__imageMosaicPosition.setLimits(QubRulerAction.VERTICAL,
                                                     1, *limits)

                self.__imageMosaicPosition.setLabel(QubRulerAction.VERTICAL, 1,
                                                    '')
                for label in [
                        self.__mouseMotorPosition, self.__currentMotorPosition
                ]:
                    label.setMotyName(self.__vMotor.getMotorMnemonic())
                    label.setYValue(self.__vMotor.getPosition())

            if self.__hMotor is not None:
                self.__imageMosaicPosition.setLabel(
                    QubRulerAction.HORIZONTAL, 0,
                    self.__hMotor.getMotorMnemonic())
                limits = self.__hMotor.getLimits()
                self.__imageMosaicPosition.setLimits(QubRulerAction.HORIZONTAL,
                                                     0, *limits)
                self.__imageMosaicPosition.setLimits(QubRulerAction.HORIZONTAL,
                                                     1, *limits)

                self.__imageMosaicPosition.setCursorPosition(
                    QubRulerAction.HORIZONTAL, 0, self.__hMotor.getPosition())
                self.__imageMosaicPosition.setLabel(QubRulerAction.HORIZONTAL,
                                                    1, '')

                for label in [
                        self.__mouseMotorPosition, self.__currentMotorPosition
                ]:
                    label.setMotxName(self.__hMotor.getMotorMnemonic())
                    label.setXValue(self.__hMotor.getPosition())

            for ruler in self.__imageMosaicPosition._QubRulerAction__ruler:
                ruler.setZ(99)  # upper layer

            #Add a follow mulot
            class _MouseFollow(_DrawingEventNDrawingMgr):
                def __init__(self, aDrawingMgr, oneShot, **keys):
                    _DrawingEventNDrawingMgr.__init__(self, aDrawingMgr, False)

                def mouseMove(self, x, y):
                    d = self._drawingMgr()
                    if d:
                        d.move(x, y)
                        d.endDraw()

            self.__followPointMouse, _ = QubAddDrawing(
                self.drawing, QubMosaicPointDrawingMgr, QubCanvasTarget)
            self.__followPointMouse.setDrawingEvent(_MouseFollow)
            self.__followPointMouse.setExclusive(False)
            self.__followPointMouse.startDrawing()
            self.__followPointMouse.setEndDrawCallBack(
                self.__displayMotorsPositionUnderMouse)
        except KeyError:
            pass

        if self.__camDecompNPlug:
            camera, decomp, plug = self.__camDecompNPlug
            try:
                plug.addImage()
                try:
                    plug.move(self.__hMotor.getPosition(),
                              self.__vMotor.getPosition())
                except:
                    pass
                else:
                    try:
                        plug.setCalibration(*self.__currentCalib)
                        plug.setBeamPosition(*self.__currentBeamPos)
                    except (AttributeError, TypeError):
                        pass
            except AttributeError:
                liveCheckBox = self.child('__liveCheckBox')
                liveCheckBox.hide()