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
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
class CameraMotorToolsBrick(BlissWidget): def __init__(self, parent, name): BlissWidget.__init__(self, parent, name) """ variables """ self.YBeam = None self.ZBeam = None self.YSize = None self.ZSize = None self.view = None self.firstCall = True self.motorArrived = 0 self.__mosaicView, self.__mosaicDraw = None, None """ property """ self.addProperty("Hor. Motor", "string", "") self.horMotHwo = None self.addProperty("Vert. Motor", "string", "") self.verMotHwo = None #self.addProperty("Focus Motor","string","") #self.focusMotHwo = None #self.addProperty("Focus min step","float",0.05) #self.focusMinStep = None self.addProperty("Move To", "combo", ("none", "toolbar", "popup"), "none") self.movetoMode = None self.movetoAction = None self.addProperty("Move to color when activate", "combo", ("none", "blue", "green", "yellow", "red", "orange"), "none") self.movetoColorWhenActivate = None self.addProperty("Limits", "combo", ("none", "toolbar", "popup"), "none") self.limitsMode = None self.limitsAction = None self.addProperty("Measure", "combo", ("none", "toolbar", "popup"), "none") self.measureMode = None self.measureAction = None self.addProperty("Focus", "combo", ("none", "toolbar", "popup"), "none") self.focusMode = None self.focusAction = None self.focusState = None self.focusDrawingRectangle = None self.focusPointSelected = None self.__movetoActionMosaic = None """ Signal """ self.defineSignal('getView', ()) self.defineSignal('getMosaicView', ()) self.defineSignal('getCalibration', ()) self.defineSignal('getBeamPosition', ()) self.defineSignal('getImage', ()) self.defineSignal('moveDone', ()) self.defineSignal('mosaicImageSelected', ()) """ Slot """ self.defineSlot('beamPositionChanged', ()) self.defineSlot('pixelCalibrationChanged', ()) self.defineSlot('setMoveToMode', ()) self.defineSlot('setLimitsDisplay', ()) self.defineSlot('setMoveToState', ()) """ widgets - NO APPEARANCE """ self.setFixedSize(0, 0) def propertyChanged(self, prop, oldValue, newValue): if prop == "Hor. Motor": if self.horMotHwo is not None: self.disconnect(self.horMotHwo, qt.PYSIGNAL('positionChanged'), self.setHorizontalPosition) self.disconnect(self.horMotHwo, qt.PYSIGNAL("limitsChanged"), self.setHorizontalLimits) self.horMotHwo = self.getHardwareObject(newValue) if self.horMotHwo is not None: self.connect(self.horMotHwo, qt.PYSIGNAL('positionChanged'), self.setHorizontalPosition) self.connect(self.horMotHwo, qt.PYSIGNAL("limitsChanged"), self.setHorizontalLimits) elif prop == "Vert. Motor": if self.verMotHwo is not None: self.disconnect(self.verMotHwo, qt.PYSIGNAL('positionChanged'), self.setVerticalPosition) self.disconnect(self.verMotHwo, qt.PYSIGNAL("limitsChanged"), self.setVerticalLimits) self.verMotHwo = self.getHardwareObject(newValue) if self.verMotHwo is not None: self.connect(self.verMotHwo, qt.PYSIGNAL('positionChanged'), self.setVerticalPosition) self.connect(self.verMotHwo, qt.PYSIGNAL("limitsChanged"), self.setVerticalLimits) #elif prop == "Focus Motor": # if self.focusMotHwo is not None: # self.disconnect(self.focusMotHwo,qt.PYSIGNAL('positionChanged'), # self.setFocusPosition) # self.disconnect(self.focusMotHwo,qt.PYSIGNAL('limitsChanged'), # self.setFocusLimits) # self.focusMotHwo = self.getHardwareObject(newValue) # self.focusState = FocusState(self,self.focusMotHwo) # if self.focusMotHwo is not None: # self.connect(self.focusMotHwo,qt.PYSIGNAL('positionChanged'), # self.setFocusPosition) # self.connect(self.focusMotHwo,qt.PYSIGNAL('limitsChanged'), # self.setFocusLimits) # self.connect(self.focusMotHwo, qt.PYSIGNAL("moveDone"), # self.focusMoveFinished) elif prop == "Move To": self.movetoMode = _enumTranslate[newValue] elif prop == "Limits": self.limitsMode = _enumTranslate[newValue] elif prop == "Focus": self.focusMode = _enumTranslate[newValue] elif prop == "Measure": self.measureMode = _enumTranslate[newValue] elif prop == "Focus min step": self.focusMinStep = newValue elif prop == "Move to color when activate": if newValue == "none": self.movetoColorWhenActivate = None else: self.movetoColorWhenActivate = newValue if not self.firstCall: self.configureAction() def run(self): """ get view """ view = {} self.emit(qt.PYSIGNAL("getView"), (view, )) try: self.drawing = view["drawing"] self.view = view["view"] except: print "No View" """ get calibration """ calib = {} self.emit(qt.PYSIGNAL("getCalibration"), (calib, )) try: # in all this brick we work with pixel calibration in mm self.YSize = calib["ycalib"] self.ZSize = calib["zcalib"] if calib["ycalib"] is not None and calib["zcalib"] is not None: self.YSize = self.YSize * 1000 self.ZSize = self.ZSize * 1000 except: print "No Calibration" """ get beam position """ position = {} self.emit(qt.PYSIGNAL("getBeamPosition"), (position, )) try: self.YBeam = position["ybeam"] self.ZBeam = position["zbeam"] except: print "No Beam Position" """ get mosaic view """ mosaicView = {} self.emit(qt.PYSIGNAL('getMosaicView'), (mosaicView, )) try: self.__mosaicView = mosaicView['view'] self.__mosaicDraw = mosaicView['drawing'] except KeyError: self.__mosaicView, self.__mosaicDraw = None, None self.configureAction() self.firstCall = False 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 def _measure_dialog_new(self, openDialogAction, aQubImage): if self.YSize is not None and self.ZSize is not None: self.__measureDialog = QubMeasureListDialog( self, canvas=aQubImage.canvas(), matrix=aQubImage.matrix(), eventMgr=aQubImage) self.__measureDialog.setXPixelSize(self.YSize / 1000.0) self.__measureDialog.setYPixelSize(self.ZSize / 1000.0) self.__measureDialog.connect(aQubImage, qt.PYSIGNAL("ForegroundColorChanged"), self.__measureDialog.setDefaultColor) openDialogAction.setDialog(self.__measureDialog) def setHorizontalPosition(self, newPosition): if self.limitsAction is not None: self.limitsAction.setCursorPosition(QubRulerAction.HORIZONTAL, 0, newPosition) def setHorizontalLimits(self, limit): if self.limitsAction is not None: self.limitsAction.setLimits(QubRulerAction.HORIZONTAL, 0, limit[0], limit[1]) def setVerticalPosition(self, newPosition): if self.limitsAction is not None: self.limitsAction.setCursorPosition(QubRulerAction.VERTICAL, 0, newPosition) def setVerticalLimits(self, limit): if self.limitsAction is not None: self.limitsAction.setLimits(QubRulerAction.VERTICAL, 0, limit[0], limit[1]) #def setFocusLimits(self,limit) : # self.focusState.setLimit(limit) #def setFocusPosition(self,newPosition) : # self.focusState.newPosition(newPosition) #def focusMoveFinished(self, ver, mne): # self.focusState.endMovement(ver) #def focusRawKeyPressed(self,keyevent) : # key = keyevent.key() # if key == qt.Qt.Key_Plus: # self.focusRectangleSize += 3 # if self.focusRectangleSize > 99: # self.focusRectangleSize = 99 # elif key == qt.Qt.Key_Minus: # self.focusRectangleSize -= 3 # if self.focusRectangleSize < 12: # self.focusRectangleSize = 12 # else: return # # self.focusDrawingRectangle.setWidthNHeight(self.focusRectangleSize,self.focusRectangleSize) #def showFocusGrab(self,state) : # self.focusPointSelected = None # if state: # self.focusDrawingRectangle.startDrawing() # else: # self.focusDrawingRectangle.stopDrawing() # self.focusDrawingRectangle.hide() # self.focusPointSelected = None #def setFocusPointSelected(self,drawingMgr) : # self.focusPointSelected = drawingMgr.point() # if self.focusMotHwo is not None: # self.focusState.start() def beamPositionChanged(self, beamy, beamz): self.YBeam = beamy self.ZBeam = beamz def pixelCalibrationChanged(self, sizey, sizez): if sizey is not None: self.YSize = sizey * 1000 try: self.__measureDialog.setXPixelSize(sizey) except: pass else: self.YSize = None if sizez is not None: self.ZSize = sizez * 1000 try: self.__measureDialog.setYPixelSize(sizez) except: pass else: self.ZSize = None def setMoveToState(self, state): if self.movetoAction is not None: self.movetoAction.setState(state) def movetoStateChanged(self, state): if self.movetoColorWhenActivate: if state: self.movetoAction.setPaletteBackgroundColor( qt.QColor(self.movetoColorWhenActivate)) else: self.movetoAction.setPaletteBackgroundColor( self.oldMoveToActionColor) def pointSelected(self, drawingMgr): if self.horMotHwo is not None and self.verMotHwo is not None: if self.YSize is not None and \ self.ZSize is not None and \ self.YBeam is not None and \ self.ZBeam is not None : self.drawingMgr = drawingMgr (y, z) = drawingMgr.point() self.drawingMgr.stopDrawing() sign = 1 if self.horMotHwo.unit < 0: sign = -1 movetoy = -sign * (self.YBeam - y) * self.YSize sign = 1 if self.verMotHwo.unit < 0: sign = -1 movetoz = -sign * (self.ZBeam - z) * self.ZSize self.motorArrived = 0 self.connect(self.horMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.connect(self.verMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.horMotHwo.moveRelative(movetoy) self.verMotHwo.moveRelative(movetoz) def __movetoMosaicStateChanged(self, state): if self.movetoColorWhenActivate: if state: self.__movetoActionMosaic.setPaletteBackgroundColor( qt.QColor(self.movetoColorWhenActivate)) else: self.__movetoActionMosaic.setPaletteBackgroundColor( self.__oldMoveToMosaicActionColor) def __mosaicPointSelected(self, drawingMgr): point = drawingMgr.mosaicPoints() try: point = point[0] beamY, beamZ = point.refPoint YSize, ZSize = point.calibration horMotorPos, verMotorPos = point.absPoint y, z = point.point imageId = point.imageId except TypeError: return # The click wasn't on image self.drawingMgr = drawingMgr drawingMgr.stopDrawing() sign = 1 if self.horMotHwo.unit < 0: sign = -1 movetoy = horMotorPos - sign * (beamY - y) * YSize sign = 1 if self.verMotHwo.unit < 0: sign = -1 movetoz = verMotorPos - sign * (beamZ - z) * ZSize self.motorArrived = 0 self.connect(self.horMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.connect(self.verMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.horMotHwo.move(movetoy) self.verMotHwo.move(movetoz) self.emit(qt.PYSIGNAL("mosaicImageSelected"), (imageId, )) def moveFinished(self, ver, mne): if mne == self.horMotHwo.getMotorMnemonic(): self.disconnect(self.horMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.motorArrived = self.motorArrived + 1 if mne == self.verMotHwo.getMotorMnemonic(): self.disconnect(self.verMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.motorArrived = self.motorArrived + 1 if self.motorArrived == 2: self.drawingMgr.startDrawing() self.motorArrived = 0 self.emit(qt.PYSIGNAL("moveDone"), (self.YBeam, self.ZBeam))
class CameraMotorToolsBrick(BlissWidget): def __init__(self, parent, name): BlissWidget.__init__(self, parent, name) """ variables """ self.YBeam = None self.ZBeam = None self.YSize = None self.ZSize = None self.view = None self.firstCall = True self.motorArrived = 0 self.__mosaicView,self.__mosaicDraw = None,None """ property """ self.addProperty("Hor. Motor", "string", "") self.horMotHwo = None self.addProperty("Vert. Motor", "string", "") self.verMotHwo = None #self.addProperty("Focus Motor","string","") #self.focusMotHwo = None #self.addProperty("Focus min step","float",0.05) #self.focusMinStep = None self.addProperty("Move To", "combo", ("none", "toolbar", "popup"), "none") self.movetoMode = None self.movetoAction = None self.addProperty("Move to color when activate","combo", ("none","blue","green","yellow","red","orange"),"none") self.movetoColorWhenActivate = None self.addProperty("Limits", "combo", ("none", "toolbar", "popup"), "none") self.limitsMode = None self.limitsAction = None self.addProperty("Measure", "combo", ("none", "toolbar", "popup"), "none") self.measureMode = None self.measureAction = None self.addProperty("Focus","combo", ("none", "toolbar", "popup"), "none") self.focusMode = None self.focusAction = None self.focusState = None self.focusDrawingRectangle = None self.focusPointSelected = None self.__movetoActionMosaic = None """ Signal """ self.defineSignal('getView',()) self.defineSignal('getMosaicView',()) self.defineSignal('getCalibration',()) self.defineSignal('getBeamPosition',()) self.defineSignal('getImage',()) self.defineSignal('moveDone', ()) self.defineSignal('mosaicImageSelected', ()) """ Slot """ self.defineSlot('beamPositionChanged',()) self.defineSlot('pixelCalibrationChanged',()) self.defineSlot('setMoveToMode',()) self.defineSlot('setLimitsDisplay',()) self.defineSlot('setMoveToState',()) """ widgets - NO APPEARANCE """ self.setFixedSize(0, 0) def propertyChanged(self, prop, oldValue, newValue): if prop == "Hor. Motor": if self.horMotHwo is not None: self.disconnect(self.horMotHwo, qt.PYSIGNAL('positionChanged'), self.setHorizontalPosition) self.disconnect(self.horMotHwo, qt.PYSIGNAL("limitsChanged"), self.setHorizontalLimits) self.horMotHwo = self.getHardwareObject(newValue) if self.horMotHwo is not None: self.connect(self.horMotHwo, qt.PYSIGNAL('positionChanged'), self.setHorizontalPosition) self.connect(self.horMotHwo, qt.PYSIGNAL("limitsChanged"), self.setHorizontalLimits) elif prop == "Vert. Motor": if self.verMotHwo is not None: self.disconnect(self.verMotHwo, qt.PYSIGNAL('positionChanged'), self.setVerticalPosition) self.disconnect(self.verMotHwo, qt.PYSIGNAL("limitsChanged"), self.setVerticalLimits) self.verMotHwo = self.getHardwareObject(newValue) if self.verMotHwo is not None: self.connect(self.verMotHwo, qt.PYSIGNAL('positionChanged'), self.setVerticalPosition) self.connect(self.verMotHwo, qt.PYSIGNAL("limitsChanged"), self.setVerticalLimits) #elif prop == "Focus Motor": # if self.focusMotHwo is not None: # self.disconnect(self.focusMotHwo,qt.PYSIGNAL('positionChanged'), # self.setFocusPosition) # self.disconnect(self.focusMotHwo,qt.PYSIGNAL('limitsChanged'), # self.setFocusLimits) # self.focusMotHwo = self.getHardwareObject(newValue) # self.focusState = FocusState(self,self.focusMotHwo) # if self.focusMotHwo is not None: # self.connect(self.focusMotHwo,qt.PYSIGNAL('positionChanged'), # self.setFocusPosition) # self.connect(self.focusMotHwo,qt.PYSIGNAL('limitsChanged'), # self.setFocusLimits) # self.connect(self.focusMotHwo, qt.PYSIGNAL("moveDone"), # self.focusMoveFinished) elif prop == "Move To": self.movetoMode = _enumTranslate[newValue] elif prop == "Limits": self.limitsMode = _enumTranslate[newValue] elif prop == "Focus": self.focusMode = _enumTranslate[newValue] elif prop == "Measure": self.measureMode = _enumTranslate[newValue] elif prop == "Focus min step": self.focusMinStep = newValue elif prop == "Move to color when activate" : if newValue == "none" : self.movetoColorWhenActivate = None else: self.movetoColorWhenActivate = newValue if not self.firstCall: self.configureAction() def run(self): """ get view """ view = {} self.emit(qt.PYSIGNAL("getView"), (view,)) try: self.drawing = view["drawing"] self.view = view["view"] except: print "No View" """ get calibration """ calib = {} self.emit(qt.PYSIGNAL("getCalibration"), (calib,)) try: # in all this brick we work with pixel calibration in mm self.YSize = calib["ycalib"] self.ZSize = calib["zcalib"] if calib["ycalib"] is not None and calib["zcalib"] is not None: self.YSize = self.YSize * 1000 self.ZSize = self.ZSize * 1000 except: print "No Calibration" """ get beam position """ position = {} self.emit(qt.PYSIGNAL("getBeamPosition"), (position,)) try: self.YBeam = position["ybeam"] self.ZBeam = position["zbeam"] except: print "No Beam Position" """ get mosaic view """ mosaicView = {} self.emit(qt.PYSIGNAL('getMosaicView'),(mosaicView,)) try: self.__mosaicView = mosaicView['view'] self.__mosaicDraw = mosaicView['drawing'] except KeyError: self.__mosaicView,self.__mosaicDraw = None,None self.configureAction() self.firstCall = False 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 def _measure_dialog_new(self,openDialogAction,aQubImage) : if self.YSize is not None and self.ZSize is not None: self.__measureDialog = QubMeasureListDialog(self, canvas=aQubImage.canvas(), matrix=aQubImage.matrix(), eventMgr=aQubImage) self.__measureDialog.setXPixelSize(self.YSize/1000.0) self.__measureDialog.setYPixelSize(self.ZSize/1000.0) self.__measureDialog.connect(aQubImage, qt.PYSIGNAL("ForegroundColorChanged"), self.__measureDialog.setDefaultColor) openDialogAction.setDialog(self.__measureDialog) def setHorizontalPosition(self, newPosition): if self.limitsAction is not None: self.limitsAction.setCursorPosition(QubRulerAction.HORIZONTAL, 0, newPosition) def setHorizontalLimits(self, limit): if self.limitsAction is not None: self.limitsAction.setLimits(QubRulerAction.HORIZONTAL, 0, limit[0], limit[1]) def setVerticalPosition(self, newPosition): if self.limitsAction is not None: self.limitsAction.setCursorPosition(QubRulerAction.VERTICAL, 0, newPosition) def setVerticalLimits(self, limit): if self.limitsAction is not None: self.limitsAction.setLimits(QubRulerAction.VERTICAL, 0, limit[0], limit[1]) #def setFocusLimits(self,limit) : # self.focusState.setLimit(limit) #def setFocusPosition(self,newPosition) : # self.focusState.newPosition(newPosition) #def focusMoveFinished(self, ver, mne): # self.focusState.endMovement(ver) #def focusRawKeyPressed(self,keyevent) : # key = keyevent.key() # if key == qt.Qt.Key_Plus: # self.focusRectangleSize += 3 # if self.focusRectangleSize > 99: # self.focusRectangleSize = 99 # elif key == qt.Qt.Key_Minus: # self.focusRectangleSize -= 3 # if self.focusRectangleSize < 12: # self.focusRectangleSize = 12 # else: return # # self.focusDrawingRectangle.setWidthNHeight(self.focusRectangleSize,self.focusRectangleSize) #def showFocusGrab(self,state) : # self.focusPointSelected = None # if state: # self.focusDrawingRectangle.startDrawing() # else: # self.focusDrawingRectangle.stopDrawing() # self.focusDrawingRectangle.hide() # self.focusPointSelected = None #def setFocusPointSelected(self,drawingMgr) : # self.focusPointSelected = drawingMgr.point() # if self.focusMotHwo is not None: # self.focusState.start() def beamPositionChanged(self, beamy, beamz): self.YBeam = beamy self.ZBeam = beamz def pixelCalibrationChanged(self, sizey, sizez): if sizey is not None: self.YSize = sizey * 1000 try: self.__measureDialog.setXPixelSize(sizey) except: pass else: self.YSize = None if sizez is not None: self.ZSize = sizez * 1000 try: self.__measureDialog.setYPixelSize(sizez) except: pass else: self.ZSize = None def setMoveToState(self,state): if self.movetoAction is not None: self.movetoAction.setState(state) def movetoStateChanged(self,state) : if self.movetoColorWhenActivate: if state: self.movetoAction.setPaletteBackgroundColor(qt.QColor(self.movetoColorWhenActivate)) else: self.movetoAction.setPaletteBackgroundColor(self.oldMoveToActionColor) def pointSelected(self, drawingMgr): if self.horMotHwo is not None and self.verMotHwo is not None: if self.YSize is not None and \ self.ZSize is not None and \ self.YBeam is not None and \ self.ZBeam is not None : self.drawingMgr = drawingMgr (y, z) = drawingMgr.point() self.drawingMgr.stopDrawing() sign = 1 if self.horMotHwo.unit < 0: sign = -1 movetoy = - sign*(self.YBeam - y) * self.YSize sign = 1 if self.verMotHwo.unit < 0: sign = -1 movetoz = - sign*(self.ZBeam - z) * self.ZSize self.motorArrived = 0 self.connect(self.horMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.connect(self.verMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.horMotHwo.moveRelative(movetoy) self.verMotHwo.moveRelative(movetoz) def __movetoMosaicStateChanged(self,state): if self.movetoColorWhenActivate: if state: self.__movetoActionMosaic.setPaletteBackgroundColor(qt.QColor(self.movetoColorWhenActivate)) else: self.__movetoActionMosaic.setPaletteBackgroundColor(self.__oldMoveToMosaicActionColor) def __mosaicPointSelected(self,drawingMgr) : point = drawingMgr.mosaicPoints() try: point = point[0] beamY,beamZ = point.refPoint YSize,ZSize = point.calibration horMotorPos,verMotorPos = point.absPoint y,z = point.point imageId = point.imageId except TypeError: return # The click wasn't on image self.drawingMgr = drawingMgr drawingMgr.stopDrawing() sign = 1 if self.horMotHwo.unit < 0: sign = -1 movetoy = horMotorPos - sign*(beamY - y) * YSize sign = 1 if self.verMotHwo.unit < 0: sign = -1 movetoz = verMotorPos - sign*(beamZ - z) * ZSize self.motorArrived = 0 self.connect(self.horMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.connect(self.verMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.horMotHwo.move(movetoy) self.verMotHwo.move(movetoz) self.emit(qt.PYSIGNAL("mosaicImageSelected"), (imageId,)) def moveFinished(self, ver, mne): if mne == self.horMotHwo.getMotorMnemonic(): self.disconnect(self.horMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.motorArrived = self.motorArrived + 1 if mne == self.verMotHwo.getMotorMnemonic(): self.disconnect(self.verMotHwo, qt.PYSIGNAL("moveDone"), self.moveFinished) self.motorArrived = self.motorArrived + 1 if self.motorArrived == 2: self.drawingMgr.startDrawing() self.motorArrived = 0 self.emit(qt.PYSIGNAL("moveDone"), (self.YBeam, self.ZBeam))
class CameraOffLineImageManagerBrick(BlissWidget): def __init__(self,parent,name,**keys) : BlissWidget.__init__(self,parent,name) self.__hMotor = None self.__vMotor = None self.__motor_pos_save = [] self.__master_motor = None self.__masterPosition2Item = weakref.WeakValueDictionary() self.__currentCalib = None self.__currentBeamPos = None self.__camDecompNPlug = None self.mosaicView = None self.drawing = None self.__saveImageTreeDirName = '.' self.__imageMosaicPosition = None ####### Property ####### self.addProperty('horizontal','string','') self.addProperty('vertical','string','') self.addProperty('save_motors','string','') self.addProperty('master_motor','string','') self.addProperty('focus_motor','string','') self.addProperty('live_camera','string','') self.addProperty("formatString", "formatString", "###.##") ####### SIGNAL ####### self.defineSignal("getImage",()) self.defineSignal('getView',()) self.defineSignal('getMosaicView',()) ####### SLOT ####### self.defineSlot("ChangePixelCalibration", ()) self.defineSlot("ChangeBeamPosition", ()) self.defineSlot('setMosaicImageSelected',()) self.__widgetTree = self.loadUIFile('CameraOffLineImageManager.ui') self.__frame = self.__widgetTree.child('__frame') self.__frame.reparent(self,qt.QPoint(0,0)) layout = qt.QHBoxLayout(self) layout.addWidget(self.__frame) snapButton = self.child('__snapShoot') iconSet = qt.QIconSet(loadIcon("snapshot.png")) snapButton.setIconSet(iconSet) qt.QObject.connect(snapButton,qt.SIGNAL('clicked()'),self.__snapCBK) liveCheckBox = self.child('__liveCheckBox') liveCheckBox.hide() qt.QObject.connect(liveCheckBox,qt.SIGNAL('toggled(bool)'),self.__liveOnOff) self.__imageList = self.child('__imageList') self.__imageList.setSelectionMode(qt.QListView.Extended) self.__imageList.setSortColumn(-1) self.__popUpMenu = qt.QPopupMenu(self) self.__popUpMenu.insertItem('layer up',self.__layerUp) self.__popUpMenu.insertItem('layer down',self.__layerDown) self.__popUpMenu.insertItem('remove',self.__removeImage) self.__popUpMenu.insertSeparator() self.__popUpMenu.insertItem('load',self.__loadImageTree) self.__popUpMenu.insertItem('save',self.__saveImageTree) qt.QObject.connect(self.__imageList,qt.SIGNAL('rightButtonPressed(QListViewItem*,const QPoint &,int)'), self.__popUpDisplay) def propertyChanged(self,propertyName,oldValue,newValue) : if propertyName == 'horizontal' : if self.__hMotor: self.disconnect(self.__hMotor, qt.PYSIGNAL("positionChanged"), self.__hMotorPositionChanged) self.__hMotor = self.getHardwareObject(newValue) self.connect(self.__hMotor, qt.PYSIGNAL("positionChanged"), self.__hMotorPositionChanged) self.connect(self.__hMotor,qt.PYSIGNAL("limitsChanged"),self.__hMotorLimitsChanged) elif propertyName == 'vertical' : if self.__vMotor: self.disconnect(self.__vMotor, qt.PYSIGNAL("positionChanged"), self.__vMotorPositionChanged) self.__vMotor = self.getHardwareObject(newValue) self.connect(self.__vMotor, qt.PYSIGNAL("positionChanged"), self.__vMotorPositionChanged) self.connect(self.__vMotor,qt.PYSIGNAL("limitsChanged"),self.__vMotorLimitsChanged) elif propertyName == 'save_motors' : equipment = self.getHardwareObject(newValue) self.__motor_pos_save = [] if equipment : try: ho = equipment['motors'] except KeyError: print(equipment.userName(), 'is not an Equipment : no <motors> section.') return for motor in ho.getDevices() : self.__motor_pos_save.append(motor) #Refresh Tree column nbColumn = self.__imageList.columns() for columnId in range(1,self.__imageList.columns()) : self.__imageList.removeColumn(columnId) for motor in self.__motor_pos_save: self.__imageList.addColumn(motor.userName()) elif propertyName == 'master_motor': if self.__master_motor is not None: self.__imageList.takeItem(self.__masterControler) self.__master_motor = self.getHardwareObject(newValue) if self.__master_motor is not None: self.__masterControler = qt.QCheckListItem(self.__imageList,self.__master_motor.userName()) self.__masterControler.setSelectable(False) self.__masterControler.setOpen(True) elif propertyName == 'focus_motor': self.__focus_motor = self.getHardwareObject(newValue) moveFocusCheckBox = self.child('__moveFocusCheckBox') if self.__focus_motor is not None: moveFocusCheckBox.show() else: moveFocusCheckBox.hide() elif propertyName == 'live_camera' : if self.__camDecompNPlug : camera,decomp,_ = self.__camDecompNPlug self.disconnect(camera,qt.PYSIGNAL('imageReceived'),decomp.putData) self.__camDecompNPlug = None camera = self.getHardwareObject(newValue) liveCheckBox = self.child('__liveCheckBox') if camera is not None: decomp = QubStdData2Image() plug = _LiveImagePlug(self) decomp.plug(plug) imageInfo = camera.imageType() if imageInfo and imageInfo.type() == 'bayer': imType = decomp.BAYER_RG elif imageInfo and imageInfo.type() == 'raw': imType = decomp.RAW else: imType = decomp.STANDARD # JPEG decomp.setImageType(imType) self.__camDecompNPlug = camera,decomp,plug liveCheckBox.show() else: liveCheckBox.hide() elif propertyName == 'formatString': self._formatString = self['formatString'] def ChangePixelCalibration(self,sizeX,sizeY) : if sizeX is not None and sizeY is not None: motorXUnit = self.__hMotor.getProperty('unit') if motorXUnit is None : motorXUnit = 1e-3 motorYUnit = self.__vMotor.getProperty('unit') if motorYUnit is None : motorYUnit = 1e-3 self.__currentCalib = sizeX / motorXUnit,sizeY / motorYUnit if self.__camDecompNPlug : camera,decomp,plug = self.__camDecompNPlug plug.setPixelCalibration(*self.__currentCalib) else: self.__currentCalib = None def ChangeBeamPosition(self,x,y) : self.__currentBeamPos = x,y if self.__camDecompNPlug : camera,decomp,plug = self.__camDecompNPlug plug.setBeamPosition(*self.__currentBeamPos) def setMosaicImageSelected(self,imageSelectedID) : moveFocusCheckBox = self.child('__moveFocusCheckBox') if moveFocusCheckBox.isChecked() : position = self.__focus_motor.getPosition() def _recursfind(item,lookinId) : while item: if id(item) == lookinId: return item else: returnItem = _recursfind(item.firstChild(),lookinId) if returnItem: return returnItem item = item.nextSibling() item = _recursfind(self.__imageList.firstChild(),imageSelectedID) try: if item and item.focusMotorPosition != position: self.__focus_motor.move(item.focusMotorPosition) except AttributeError: pass def __displayMotorsPositionUnderMouse(self,drawingManager) : point = drawingManager.mosaicPoints() try: point = point[0] beamY,beamZ = point.refPoint YSize,ZSize = point.calibration horMotorPos,verMotorPos = point.absPoint y,z = point.point imageId = point.imageId except TypeError: return movetoy = horMotorPos - (beamY - y) * YSize movetoz = verMotorPos - (beamZ - z) * ZSize if self.__imageMosaicPosition: self.__imageMosaicPosition.setCursorPosition(QubRulerAction.HORIZONTAL,1, movetoy) self.__imageMosaicPosition.setCursorPosition(QubRulerAction.VERTICAL,1, movetoz) self.__mouseMotorPosition.setXValue(movetoy) self.__mouseMotorPosition.setYValue(movetoz) def __hMotorPositionChanged(self,position) : if self.__imageMosaicPosition: self.__imageMosaicPosition.setCursorPosition(QubRulerAction.HORIZONTAL, 0, position) self.__currentMotorPosition.setXValue(position) if self.__camDecompNPlug : camera,decomp,plug = self.__camDecompNPlug plug.setHMotorPosition(position) def __hMotorLimitsChanged(self,limit) : if self.__imageMosaicPosition: self.__imageMosaicPosition.setLimits(QubRulerAction.HORIZONTAL,0, *limit) self.__imageMosaicPosition.setLimits(QubRulerAction.HORIZONTAL,1, *limit) def __vMotorPositionChanged(self,position) : if self.__imageMosaicPosition: self.__imageMosaicPosition.setCursorPosition(QubRulerAction.VERTICAL, 0, position) self.__currentMotorPosition.setYValue(position) if self.__camDecompNPlug : camera,decomp,plug = self.__camDecompNPlug plug.setVMotorPosition(position) def __vMotorLimitsChanged(self,limit) : if self.__imageMosaicPosition: self.__imageMosaicPosition.setLimits(QubRulerAction.VERTICAL,0, *limit) self.__imageMosaicPosition.setLimits(QubRulerAction.VERTICAL,1, *limit) def __getMasterItem(self,position = None) : if self.__master_motor is not None: if position is None: position = self.__master_motor.getPosition() try: master_item = self.__masterPosition2Item[position] except KeyError: positionString = self._formatString % position master_item = _MasterCheckItem(self.__masterControler,'p_%d (%s)' % (len(self.__masterPosition2Item),positionString)) self.__masterPosition2Item[position] = master_item else: master_item = self.__imageList position = None return master_item,position def __snapCBK(self) : key = {} self.emit(qt.PYSIGNAL('getImage'),(key,)) image = key.get('image',None) if image: master_item,position = self.__getMasterItem() if self.__focus_motor is not None: focusPosition = self.__focus_motor.getPosition() else: focusPosition = None try: item = _CheckItem(master_item,'image',self,image, self.__currentBeamPos,self.__currentCalib, self.__hMotor,self.__vMotor,self.__motor_pos_save,position,focusPosition) except: logging.getLogger().error('CameraOffLineImageManager : Spec not connected') else: logging.getLogger().error('CameraOffLineImageManager : getImage is not connected to CameraOffLineImageManager!!!') def __liveOnOff(self,state) : camera,decomp,plug = self.__camDecompNPlug if state: self.connect(camera,qt.PYSIGNAL('imageReceived'),decomp.putData) plug.show() else: self.disconnect(camera,qt.PYSIGNAL('imageReceived'),decomp.putData) plug.hide() def __saveImageTree(self,i) : pickleObjects = [] self.__saveImageRecurse(self.__imageList.firstChild(),pickleObjects) if pickleObjects: fullpathname = qt.QFileDialog.getSaveFileName(self.__saveImageTreeDirName,'Camera mosaic (*.mosaic)',self, 'Save mosaic images', "Choose a filename to save under") if fullpathname: fullpathname = fullpathname.latin1() self.__saveImageTreeDirName,fname = os.path.split(fullpathname) filename,ext = os.path.splitext(fname) fullpathname = os.path.join(self.__saveImageTreeDirName,'%s.mosaic' % filename) pickle.dump(pickleObjects,file(fullpathname,'w')) else: errorMess = qt.QErrorMessage(self) errorMess.message('Nothing to Save!!!') def __loadImageTree(self,i) : fullpathname = qt.QFileDialog.getOpenFileName(self.__saveImageTreeDirName,'Camera mosaic (*.mosaic)',self, 'Load mosaic images', "Load a image tree") if fullpathname: fullpathname = fullpathname.latin1() self.__imageList.selectAll(True) self.__removeImage(0) for saveItem in pickle.load(file(fullpathname)): master_item,position = self.__getMasterItem(saveItem.masterPosition) _CheckItem(master_item,saveItem,self) def __saveImageRecurse(self,item,pickleObjects) : while item: NextItem = item.nextSibling() try: pickleObjects.append(item.getSavePickleObject()) except AttributeError: pass self.__saveImageRecurse(item.firstChild(),pickleObjects) item = NextItem @_foreachSelectedItems def __removeImage(self,item,i) : try: item.parent().takeItem(item) except AttributeError: self.__imageList.takeItem(item) return True @_foreachSelectedItems def __layerUp(self,item,i) : item.layerUp() @_foreachSelectedItems def __layerDown(self,item,i) : item.layerDown() def __popUpDisplay(self,item,point,columnid) : self.__popUpMenu.exec_loop(point) 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()
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()
class CameraOffLineImageManagerBrick(BlissWidget): def __init__(self, parent, name, **keys): BlissWidget.__init__(self, parent, name) self.__hMotor = None self.__vMotor = None self.__motor_pos_save = [] self.__master_motor = None self.__masterPosition2Item = weakref.WeakValueDictionary() self.__currentCalib = None self.__currentBeamPos = None self.__camDecompNPlug = None self.mosaicView = None self.drawing = None self.__saveImageTreeDirName = '.' self.__imageMosaicPosition = None ####### Property ####### self.addProperty('horizontal', 'string', '') self.addProperty('vertical', 'string', '') self.addProperty('save_motors', 'string', '') self.addProperty('master_motor', 'string', '') self.addProperty('focus_motor', 'string', '') self.addProperty('live_camera', 'string', '') self.addProperty("formatString", "formatString", "###.##") ####### SIGNAL ####### self.defineSignal("getImage", ()) self.defineSignal('getView', ()) self.defineSignal('getMosaicView', ()) ####### SLOT ####### self.defineSlot("ChangePixelCalibration", ()) self.defineSlot("ChangeBeamPosition", ()) self.defineSlot('setMosaicImageSelected', ()) self.__widgetTree = self.loadUIFile('CameraOffLineImageManager.ui') self.__frame = self.__widgetTree.child('__frame') self.__frame.reparent(self, qt.QPoint(0, 0)) layout = qt.QHBoxLayout(self) layout.addWidget(self.__frame) snapButton = self.child('__snapShoot') iconSet = qt.QIconSet(loadIcon("snapshot.png")) snapButton.setIconSet(iconSet) qt.QObject.connect(snapButton, qt.SIGNAL('clicked()'), self.__snapCBK) liveCheckBox = self.child('__liveCheckBox') liveCheckBox.hide() qt.QObject.connect(liveCheckBox, qt.SIGNAL('toggled(bool)'), self.__liveOnOff) self.__imageList = self.child('__imageList') self.__imageList.setSelectionMode(qt.QListView.Extended) self.__imageList.setSortColumn(-1) self.__popUpMenu = qt.QPopupMenu(self) self.__popUpMenu.insertItem('layer up', self.__layerUp) self.__popUpMenu.insertItem('layer down', self.__layerDown) self.__popUpMenu.insertItem('remove', self.__removeImage) self.__popUpMenu.insertSeparator() self.__popUpMenu.insertItem('load', self.__loadImageTree) self.__popUpMenu.insertItem('save', self.__saveImageTree) qt.QObject.connect( self.__imageList, qt.SIGNAL('rightButtonPressed(QListViewItem*,const QPoint &,int)'), self.__popUpDisplay) def propertyChanged(self, propertyName, oldValue, newValue): if propertyName == 'horizontal': if self.__hMotor: self.disconnect(self.__hMotor, qt.PYSIGNAL("positionChanged"), self.__hMotorPositionChanged) self.__hMotor = self.getHardwareObject(newValue) self.connect(self.__hMotor, qt.PYSIGNAL("positionChanged"), self.__hMotorPositionChanged) self.connect(self.__hMotor, qt.PYSIGNAL("limitsChanged"), self.__hMotorLimitsChanged) elif propertyName == 'vertical': if self.__vMotor: self.disconnect(self.__vMotor, qt.PYSIGNAL("positionChanged"), self.__vMotorPositionChanged) self.__vMotor = self.getHardwareObject(newValue) self.connect(self.__vMotor, qt.PYSIGNAL("positionChanged"), self.__vMotorPositionChanged) self.connect(self.__vMotor, qt.PYSIGNAL("limitsChanged"), self.__vMotorLimitsChanged) elif propertyName == 'save_motors': equipment = self.getHardwareObject(newValue) self.__motor_pos_save = [] if equipment: try: ho = equipment['motors'] except KeyError: print equipment.userName( ), 'is not an Equipment : no <motors> section.' return for motor in ho.getDevices(): self.__motor_pos_save.append(motor) #Refresh Tree column nbColumn = self.__imageList.columns() for columnId in range(1, self.__imageList.columns()): self.__imageList.removeColumn(columnId) for motor in self.__motor_pos_save: self.__imageList.addColumn(motor.userName()) elif propertyName == 'master_motor': if self.__master_motor is not None: self.__imageList.takeItem(self.__masterControler) self.__master_motor = self.getHardwareObject(newValue) if self.__master_motor is not None: self.__masterControler = qt.QCheckListItem( self.__imageList, self.__master_motor.userName()) self.__masterControler.setSelectable(False) self.__masterControler.setOpen(True) elif propertyName == 'focus_motor': self.__focus_motor = self.getHardwareObject(newValue) moveFocusCheckBox = self.child('__moveFocusCheckBox') if self.__focus_motor is not None: moveFocusCheckBox.show() else: moveFocusCheckBox.hide() elif propertyName == 'live_camera': if self.__camDecompNPlug: camera, decomp, _ = self.__camDecompNPlug self.disconnect(camera, qt.PYSIGNAL('imageReceived'), decomp.putData) self.__camDecompNPlug = None camera = self.getHardwareObject(newValue) liveCheckBox = self.child('__liveCheckBox') if camera is not None: decomp = QubStdData2Image() plug = _LiveImagePlug(self) decomp.plug(plug) imageInfo = camera.imageType() if imageInfo and imageInfo.type() == 'bayer': imType = decomp.BAYER_RG elif imageInfo and imageInfo.type() == 'raw': imType = decomp.RAW else: imType = decomp.STANDARD # JPEG decomp.setImageType(imType) self.__camDecompNPlug = camera, decomp, plug liveCheckBox.show() else: liveCheckBox.hide() elif propertyName == 'formatString': self._formatString = self['formatString'] def ChangePixelCalibration(self, sizeX, sizeY): if sizeX is not None and sizeY is not None: motorXUnit = self.__hMotor.getProperty('unit') if motorXUnit is None: motorXUnit = 1e-3 motorYUnit = self.__vMotor.getProperty('unit') if motorYUnit is None: motorYUnit = 1e-3 self.__currentCalib = sizeX / motorXUnit, sizeY / motorYUnit if self.__camDecompNPlug: camera, decomp, plug = self.__camDecompNPlug plug.setPixelCalibration(*self.__currentCalib) else: self.__currentCalib = None def ChangeBeamPosition(self, x, y): self.__currentBeamPos = x, y if self.__camDecompNPlug: camera, decomp, plug = self.__camDecompNPlug plug.setBeamPosition(*self.__currentBeamPos) def setMosaicImageSelected(self, imageSelectedID): moveFocusCheckBox = self.child('__moveFocusCheckBox') if moveFocusCheckBox.isChecked(): position = self.__focus_motor.getPosition() def _recursfind(item, lookinId): while item: if id(item) == lookinId: return item else: returnItem = _recursfind(item.firstChild(), lookinId) if returnItem: return returnItem item = item.nextSibling() item = _recursfind(self.__imageList.firstChild(), imageSelectedID) try: if item and item.focusMotorPosition != position: self.__focus_motor.move(item.focusMotorPosition) except AttributeError: pass def __displayMotorsPositionUnderMouse(self, drawingManager): point = drawingManager.mosaicPoints() try: point = point[0] beamY, beamZ = point.refPoint YSize, ZSize = point.calibration horMotorPos, verMotorPos = point.absPoint y, z = point.point imageId = point.imageId except TypeError: return movetoy = horMotorPos - (beamY - y) * YSize movetoz = verMotorPos - (beamZ - z) * ZSize if self.__imageMosaicPosition: self.__imageMosaicPosition.setCursorPosition( QubRulerAction.HORIZONTAL, 1, movetoy) self.__imageMosaicPosition.setCursorPosition( QubRulerAction.VERTICAL, 1, movetoz) self.__mouseMotorPosition.setXValue(movetoy) self.__mouseMotorPosition.setYValue(movetoz) def __hMotorPositionChanged(self, position): if self.__imageMosaicPosition: self.__imageMosaicPosition.setCursorPosition( QubRulerAction.HORIZONTAL, 0, position) self.__currentMotorPosition.setXValue(position) if self.__camDecompNPlug: camera, decomp, plug = self.__camDecompNPlug plug.setHMotorPosition(position) def __hMotorLimitsChanged(self, limit): if self.__imageMosaicPosition: self.__imageMosaicPosition.setLimits(QubRulerAction.HORIZONTAL, 0, *limit) self.__imageMosaicPosition.setLimits(QubRulerAction.HORIZONTAL, 1, *limit) def __vMotorPositionChanged(self, position): if self.__imageMosaicPosition: self.__imageMosaicPosition.setCursorPosition( QubRulerAction.VERTICAL, 0, position) self.__currentMotorPosition.setYValue(position) if self.__camDecompNPlug: camera, decomp, plug = self.__camDecompNPlug plug.setVMotorPosition(position) def __vMotorLimitsChanged(self, limit): if self.__imageMosaicPosition: self.__imageMosaicPosition.setLimits(QubRulerAction.VERTICAL, 0, *limit) self.__imageMosaicPosition.setLimits(QubRulerAction.VERTICAL, 1, *limit) def __getMasterItem(self, position=None): if self.__master_motor is not None: if position is None: position = self.__master_motor.getPosition() try: master_item = self.__masterPosition2Item[position] except KeyError: positionString = self._formatString % position master_item = _MasterCheckItem( self.__masterControler, 'p_%d (%s)' % (len(self.__masterPosition2Item), positionString)) self.__masterPosition2Item[position] = master_item else: master_item = self.__imageList position = None return master_item, position def __snapCBK(self): key = {} self.emit(qt.PYSIGNAL('getImage'), (key, )) image = key.get('image', None) if image: master_item, position = self.__getMasterItem() if self.__focus_motor is not None: focusPosition = self.__focus_motor.getPosition() else: focusPosition = None try: item = _CheckItem(master_item, 'image', self, image, self.__currentBeamPos, self.__currentCalib, self.__hMotor, self.__vMotor, self.__motor_pos_save, position, focusPosition) except: logging.getLogger().error( 'CameraOffLineImageManager : Spec not connected') else: logging.getLogger().error( 'CameraOffLineImageManager : getImage is not connected to CameraOffLineImageManager!!!' ) def __liveOnOff(self, state): camera, decomp, plug = self.__camDecompNPlug if state: self.connect(camera, qt.PYSIGNAL('imageReceived'), decomp.putData) plug.show() else: self.disconnect(camera, qt.PYSIGNAL('imageReceived'), decomp.putData) plug.hide() def __saveImageTree(self, i): pickleObjects = [] self.__saveImageRecurse(self.__imageList.firstChild(), pickleObjects) if pickleObjects: fullpathname = qt.QFileDialog.getSaveFileName( self.__saveImageTreeDirName, 'Camera mosaic (*.mosaic)', self, 'Save mosaic images', "Choose a filename to save under") if fullpathname: fullpathname = fullpathname.latin1() self.__saveImageTreeDirName, fname = os.path.split( fullpathname) filename, ext = os.path.splitext(fname) fullpathname = os.path.join(self.__saveImageTreeDirName, '%s.mosaic' % filename) pickle.dump(pickleObjects, file(fullpathname, 'w')) else: errorMess = qt.QErrorMessage(self) errorMess.message('Nothing to Save!!!') def __loadImageTree(self, i): fullpathname = qt.QFileDialog.getOpenFileName( self.__saveImageTreeDirName, 'Camera mosaic (*.mosaic)', self, 'Load mosaic images', "Load a image tree") if fullpathname: fullpathname = fullpathname.latin1() self.__imageList.selectAll(True) self.__removeImage(0) for saveItem in pickle.load(file(fullpathname)): master_item, position = self.__getMasterItem( saveItem.masterPosition) _CheckItem(master_item, saveItem, self) def __saveImageRecurse(self, item, pickleObjects): while item: NextItem = item.nextSibling() try: pickleObjects.append(item.getSavePickleObject()) except AttributeError: pass self.__saveImageRecurse(item.firstChild(), pickleObjects) item = NextItem @_foreachSelectedItems def __removeImage(self, item, i): try: item.parent().takeItem(item) except AttributeError: self.__imageList.takeItem(item) return True @_foreachSelectedItems def __layerUp(self, item, i): item.layerUp() @_foreachSelectedItems def __layerDown(self, item, i): item.layerDown() def __popUpDisplay(self, item, point, columnid): self.__popUpMenu.exec_loop(point) 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()
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()