示例#1
0
    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

        actions = []

        self.__zoomList = QubZoomListAction(
            place="toolbar",
            zoomValList=[0.1, 0.25, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4],
            show=1,
            group="zoom",
        )
        actions.append(self.__zoomList)

        self.__zoomFitOrFill = QubZoomAction(place="toolbar",
                                             keepROI=True,
                                             group="zoom")
        self.__zoomFitOrFill.setList(self.__zoomList)
        self.__zoomList.setActionZoomMode(self.__zoomFitOrFill)
        actions.append(self.__zoomFitOrFill)

        zoomAction = QubZoomRectangle(
            label="Zoom Crop",
            place="toolbar",
            show=1,
            group="zoom",
            activate_click_drag=True,
            drawingObjectLayer=2**31,
            unactiveActionWhenDub=True,
        )
        qt.QObject.connect(zoomAction, qt.PYSIGNAL("RectangleSelected"),
                           self.__rectangleZoomChanged)
        actions.append(zoomAction)

        ####### CHANGE FOREGROUND COLOR #######
        fcoloraction = QubForegroundColorAction(name="color", group="image")
        actions.append(fcoloraction)

        ####### MEASURE #######
        measureAction = QubOpenDialogAction(
            parent=self,
            name="measure",
            iconName="measure",
            label="Measure",
            group="Tools",
        )
        measureAction.setConnectCallBack(self._measure_dialog_new)
        actions.append(measureAction)

        self.__mainView = QubMosaicView(self, actions=actions)

        layout = qt.QHBoxLayout(self)
        layout.addWidget(self.__mainView)

        ####### SLOT #######
        self.defineSlot("getView", ())
示例#2
0
    def __addActions(self):
        updateAction = QubToolbarToggleButtonAction(
            name='update',
            iconName='update',
            initState=True,
            group='image',
            tooltip='Start/Stop image refresh')
        Qt.QObject.connect(updateAction, Qt.SIGNAL('StateChanged'),
                           self.__setRefresh)
        self.addAction(updateAction)
        # a bug in Qub forces to set the state after adding the action
        updateAction.setState(True)
        self._updateAction = updateAction

        if EdfFile:
            saveAction = QubOpenDialogAction(
                name='save edf',
                iconName='save',
                label='Save data',
                group='admin',
                tooltip='Save image data in EDF format')

            saveDialog = Qt.QFileDialog(self, 'Save image as EDF')
            saveDialog.setAcceptMode(Qt.QFileDialog.AcceptSave)
            saveDialog.setDefaultSuffix('edf')
            nameFilters = list(saveDialog.nameFilters())
            nameFilters.insert(0, 'EDF Files (*.edf)')
            saveDialog.setNameFilters(nameFilters)
            Qt.QObject.connect(saveDialog,
                               Qt.SIGNAL('fileSelected(const QString &)'),
                               self.__saveEDF)
            Qt.QObject.connect(saveDialog,
                               Qt.SIGNAL('filesSelected(const QStringList &)'),
                               self.__saveEDFs)
            saveAction.setDialog(saveDialog)
            self._saveDataAction = saveAction

            plug = _EDFFileSavePlug()
            self.addDataAction(saveAction, plug)
            self._saveEDFPlug = plug
示例#3
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
示例#4
0
    def __init__(self, *args):
        BlissWidget.__init__(self, *args)

        self.camera       = None
        self.update_disabled = False
        self.__cameraName = None

        self.__zoomList = [1.5,2,2.5,3,3.5,4]
        self.__initZoom = 2

        self.__fixWidth  = -1
        self.__fixHeight = -1

        self.__swapRgb = True
                        ####### PRINT #######
        self.__printWidget = QubPrintPreview(self)
        self.__printWidget.resize(400,500)
        printer = qt.QPrinter()
        printer.setOutputToFile(1)
        printer.setOutputFileName('/tmp/print_file.ps')
        self.__printWidget.setPrinter(printer)
        self.__printWidget.update()

        self.__beamAction    = None
        self.__scaleAction   = None
        self.__chosenActions = {}
        self.__wholeActions  = []
        self.__measureDialog = None

        ####### PRINT ACTION #######
        printAction = QubPrintPreviewAction(name="print",group="admin",withVectorMenu=True)
        printAction.previewConnect(self.__printWidget)
        self.__wholeActions.append(printAction)

        ####### SAVE IMAGE #######
        self.__saveAction = QubSaveImageAction(parent=self, label='Save falcon image',
                                               name="save", group="admin")
        self.__saveAction.setConnectCallBack(self._save_dialog_new)
        self.__wholeActions.append(self.__saveAction)
        self.__defaultSavePath = '/tmp'

        ####### UPDATE #######
        update = QubToggleAction(name="update",group="image",initState=True)
        self.connect(update,qt.PYSIGNAL("StateChanged"),self.__cameraUpdate)
        self.__wholeActions.append(update)

        ####### Start Camera ######
        startCamera = QubToggleAction(name="startCamera", group="image", iconName = 'bright-cont', initState=True)
        self.connect(startCamera, qt.PYSIGNAL("StateChanged"), self.__cameraStart)
        self.__wholeActions.append(startCamera)


        ####### BRIGHTNESS/CONTRAST #######
        self.__brightcount = QubOpenDialogAction(name="bright-cont",
                                                 iconName = 'bright-cont', group="image")
        self.__brightcount.setDialog(QubBrightnessContrastDialog(self))
        self.__wholeActions.append(self.__brightcount)

        ###### Grid TOOL ######
        self.__gridToolAction = QubOpenDialogAction(parent=self, name='grid_tool',
                                                    iconName='rectangle', label='Grid tool',
                                                    group="Tools") #place="contextmenu")
        self.__gridDialog = GridDialog(self, "Grid Dialog", flags = qt.Qt.WStyle_StaysOnTop)
        self.__gridToolAction.setConnectCallBack(self._grid_dialog_connect_hdlr)
        self.__wholeActions.append(self.__gridToolAction)

        self.__previous_pos_dict = {}
        self.__beamWidth = 0
        self.__beamHeight = 0

        ####### BEAM ACTION #######
        self.__beamAction = QubBeamAction(name="beam", group="Tools")
        self.__wholeActions.append(self.__beamAction)
        self.connect(self.__beamAction,qt.PYSIGNAL("BeamSelected"),
                     self.beamSelection)

        ####### SCALE #######
        self.__scaleAction = QubScaleAction(name='scale',group='Tools')
        self.__wholeActions.append(self.__scaleAction)
        self.__wholeActions.extend(self.__creatStdActions())

        ####### ACTION INFO #######
        actionInfo = QubInfoAction(name="actionInfo", group="image",place="statusbar")
        self.__wholeActions.append(actionInfo)

        ####### CHANGE FOREGROUND COLOR #######
        self.__fcoloraction = QubForegroundColorAction(name="color", group="image")
        self.__wholeActions.append(self.__fcoloraction)

        ####### MEASURE #######
        self.__measureAction = QubOpenDialogAction(parent=self, name='measure',
                                            iconName='measure', label='Measure',
                                            group="Tools")
        self.__measureAction.setConnectCallBack(self._measure_dialog_new)
        self.__wholeActions.append(self.__measureAction)

        # ###### POSITION TOOL ######
        # self.__posToolAction = QubOpenDialogAction(parent=self, name='pos_tool',
        #                                            iconName='circle', label='Position tool',
        #                                            group="Tools")
        # self.__posToolAction.setConnectCallBack(self._line_dialog_new)
        # self.__wholeActions.append(self.__posToolAction)

        ####### ZOOM LIST #######
        zoomActionList = QubZoomListAction(place = "toolbar",
                                           initZoom = 1,zoomValList = [0.1,0.25,0.5,0.75,1,1.5,2],
                                           show = 1,group = "zoom")
        self.__wholeActions.append(zoomActionList)

        ####### ZOOM Action #######
        self.__zoomFitOrFill = QubZoomAction(place = "toolbar",group = "zoom")
        self.__wholeActions.append(self.__zoomFitOrFill)

        ####### LINK ZOOM ACTION #######
        self.__zoomFitOrFill.setList(zoomActionList)
        zoomActionList.setActionZoomMode(self.__zoomFitOrFill)

        ####### ZOOM WINDOW #######
        self.__zoomAction = QubZoomRectangle(label='Zoom Crop',place="toolbar", show=1, group="zoom")
        self.connect(self.__zoomAction,qt.PYSIGNAL("Actif"),self.__hide_show_zoom)
        self.__wholeActions.append(self.__zoomAction)

        self.__splitter = qt.QSplitter(qt.Qt.Horizontal,self)
        self.__splitter.show()

        self.__mainVideo = QubPixmapDisplayView(self.__splitter)
        self.__mainVideo.show()
        self.__mainVideo.setScrollbarMode('Auto')
        self.__mainPlug = _MainVideoPlug(self.__mainVideo,self.__zoomAction)

        actions = self.__creatStdActions()

        ####### ZOOM LIST #######
        self.__zoomActionList = QubZoomListAction(place = "toolbar",keepROI = True,
                                                  initZoom = self.__initZoom,zoomValList = self.__zoomList,
                                                  show = 1,group = "zoom")
        actions.insert(0,self.__zoomActionList)

        ####### ZOOM Action #######
        zoomFitOrFill = QubZoomAction(place = "toolbar",keepROI = True,group = "zoom")
        zoomFitOrFill.setList(self.__zoomActionList)
        self.__zoomActionList.setActionZoomMode(zoomFitOrFill)
        actions.append(zoomFitOrFill)

        self.__zoomVideo = QubPixmapDisplayView(self.__splitter,None,actions)
        self.__zoomVideo.hide()
        self.__zoomPlug = _ZoomPlug(self.__zoomVideo)
        self.__zoomPlug.zoom().setZoom(2,2)
        self.__cbk = _rectangleZoom(self.__zoomAction,self.__zoomPlug)

        layout = qt.QHBoxLayout(self,0,0,"layout")
        layout.addWidget(self.__splitter)

        self.__image2Pixmap = QubImage2Pixmap()
        self.__image2Pixmap.plug(self.__mainPlug)
        self.__zoomPlug.setPoller(self.__image2Pixmap)

        self.__jpegDecompress = QubStdData2Image()
        self.__jpegDecompress.setSwapRGB(True)
        self.__jpeg2image = None

        ####### PROPERTY #######
        self.addProperty('camera','string','')
        self.addProperty('zoom list','string',','.join([str(x) for x in self.__zoomList]))
        self.addProperty('init zoom','integer',self.__initZoom)
        self.addProperty('swap rgb','boolean',True)

        self.addProperty('fix : width','integer',-1)
        self.addProperty('fix : height','integer',-1)

        self.addProperty('action : print','boolean',True)
        self.addProperty('action : save image','boolean',True)
        self.addProperty('action : update','boolean',True)
        self.addProperty('action : startCamera','boolean',True)
        self.addProperty('action : brightness contrast','boolean',True)
        self.addProperty('action : beam','boolean',True)
        self.addProperty('action : scale','boolean',True)
        self.addProperty('action : change foreground color','boolean',True)
        self.addProperty('action : measure','boolean',True)
        self.addProperty('action : measure (place)', 'combo', ('toolbar','contextmenu'),'toolbar')
        self.addProperty('action : zoom window','boolean',True)
        self.addProperty('action : zoom fit or fill','boolean',True)
        self.addProperty('action : zoom list','boolean',True)
        self.addProperty('action : x,y coordinates','boolean',True)
        self.addProperty('action : default color','combo',('black','red','green'),'black')

        self.addProperty('action : save image (place)',"combo",('toolbar','contextmenu'),'toolbar')
        self.addProperty('action : save image (default path)',"string",'/tmp')
        self.addProperty('action : save image (show always configure)',"boolean",True)

        self.addProperty("diffractometer", "string", "")
        self.diffractometerHwobj = None


        ####### SIGNAL #######
        self.defineSignal("BeamPositionChanged", ())

        ####### SLOT #######
        self.defineSlot("changeBeamPosition", ())
        self.defineSlot("changePixelScale",())
        self.defineSlot('getView',())
        self.defineSlot('getImage',())

        ####### LINK VIEW AND SUB VIEW #######
        mainView = self.__mainVideo.view()
        zoomView = self.__zoomVideo.view()
        mainView.addEventMgrLink(zoomView,
                                 mainView.canvas(),zoomView.canvas(),
                                 mainView.matrix(),zoomView.matrix())

        self.imageReceivedConnected = None