-
Notifications
You must be signed in to change notification settings - Fork 9
/
CameraOffLineImageManagerBrick.py
748 lines (637 loc) · 32.3 KB
/
CameraOffLineImageManagerBrick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
"""
[Name] Camera Off Line Image Manager
[Description]
The brick managed camera snap image for off line scan or motor movement
[Properties]
----------------------------------------------------------------------
| name | type | description
----------------------------------------------------------------------
| horizontal | string | horizontal motor
| vertical | string | vertical motor
| save_motors | string | an equipment containing a motor list in order to save snap motors position
| live_camera | string | the live camera
----------------------------------------------------------------------
[Signals]
----------------------------------------------------------------------
| name | arguments | description
----------------------------------------------------------------------
| getImage | a dictionnary | emitted when an image snap is required (usualy connected on getImage CameraBrick Slot)
| getView | a dictionnary | emitted to get a reference on the image viewer object. At returned of the emit function, the key "drawing" exists and its value is the reference of the image viewer or the key "drawing" does not exists which mean that the image viewer object does not exist.
----------------------------------------------------------------------
"""
__category__ = "Camera"
import os
import logging
import pickle
import qt
from BlissFramework.BaseComponents import BlissWidget
from Qub.Icons.QubIcons import loadIcon
from Qub.Objects.Mosaic.QubMosaicImage import QubMosaicImage
from Qub.Objects.Mosaic.QubMosaicDrawingManager import QubMosaicPointDrawingMgr
from Qub.Objects.QubDrawingCanvasTools import QubCanvasTarget
from Qub.Objects.QubDrawingEvent import _DrawingEventNDrawingMgr
from Qub.Objects.QubDrawingManager import QubAddDrawing
from Qub.Objects.QubStdData2Image import QubStdData2Image,QubStdData2ImagePlug
from Qub.Widget.QubActionSet import QubToolButtonAction
from Qub.Widget.QubActionSet import QubOpenDialogAction
from Qub.Widget.QubActionSet import QubRulerAction
from Qub.Tools import QubImageSave
import weakref
def _foreachSelectedItems(func) :
def _eachRecurs(classname,item,*args,**keys) :
while item :
if item.isSelected() :
NextItem = item.nextSibling()
if(not func(classname,item,*args,**keys)) :
_eachRecurs(classname,item.firstChild(),*args,**keys)
item = NextItem
else:
_eachRecurs(classname,item.firstChild(),*args,**keys)
item = item.nextSibling()
def _eachSelected(classname,*args,**keys) :
_eachRecurs(classname,classname._CameraOffLineImageManagerBrick__imageList.firstChild(),
*args,**keys)
return _eachSelected
###
### Brick to managed already stored camera's images
###
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()
class _SavePickleItem:
def __init__(self,checkitem,image,layer,state,cnt,masterPosition,focusPosition) :
self.image = image
self.textcolumn = []
for i in xrange(cnt._CameraOffLineImageManagerBrick__imageList.columns()) :
self.textcolumn.append(checkitem.text(i).latin1())
self.layer = layer
self.state = state == qt.QCheckListItem.On
self.masterPosition = masterPosition
self.focusMotorPosition = focusPosition
class _CheckItem(qt.QCheckListItem):
def __init__(self,parent,name,cnt,image = None,
beamPos = None,calib = None,
hMotor = None,vMotor = None,motorList = None,masterPosition = None,
focusMotorPosition = None) :
try:
lastItem = parent.lastItem()
except AttributeError:
firstChild = parent.firstChild()
if firstChild:
childCount = parent.childCount()
lastItem = firstChild
try:
for i in range(1,childCount) :
lastItem = lastItem.itemBelow()
except AttributeError:
lastItem = None
else:
lastItem = None
if isinstance(name,_SavePickleItem) :
if lastItem:
qt.QCheckListItem.__init__(self,parent,lastItem,name.textcolumn[0],qt.QCheckListItem.CheckBox)
else:
qt.QCheckListItem.__init__(self,parent,name.textcolumn[0],qt.QCheckListItem.CheckBox)
saveItem = name
self.__image = saveItem.image
for i,text in enumerate(saveItem.textcolumn):
self.setText(i,text)
self.__masterPosition = masterPosition
try:
self.focusMotorPosition = saveItem.focusMotorPosition
except AttributeError: # compatibility with old save mosaic
self.focusMotorPosition = None
self.__layer = saveItem.layer
self.__cnt = cnt
cnt.mosaicView.addImage(self.__image) # adding image to MosaicDisplay
self.setState(saveItem.masterPosition and qt.QCheckListItem.On or qt.QCheckListItem.Off)
self.setRenameEnabled(0,True)
else:
self.__image = QubMosaicImage(image,hMotor.getPosition(),vMotor.getPosition(),0)
if lastItem:
qt.QCheckListItem.__init__(self,parent,lastItem,name,qt.QCheckListItem.CheckBox)
else:
qt.QCheckListItem.__init__(self,parent,name,qt.QCheckListItem.CheckBox)
icon = image.smoothScale(16,16,qt.QImage.ScaleMin)
self.setPixmap(0,qt.QPixmap(icon))
try:
self.__image.setRefPos(*beamPos)
self.__image.setCalibration(*calib)
except TypeError:
logging.getLogger().error('You have to connect ChangeBeamPosition and ChangePixelCalibration slot')
return
for i,motor in enumerate(motorList) :
self.setText(i + 1,'%f' % motor.getPosition())
self.__masterPosition = masterPosition
self.focusMotorPosition = focusMotorPosition
self.setRenameEnabled(0,True)
self.__layer = 0
self.__cnt = cnt
cnt.mosaicView.addImage(self.__image) # adding image to MosaicDisplay
try:
self.__state = parent.isSelected() and qt.QCheckListItem.On or qt.QCheckListItem.Off
self.setState(self.__state)
except TypeError:
self.__state = qt.QCheckListItem.On
self.setState(qt.QCheckListItem.On)
self.__image.setImageId(id(self))
def getSavePickleObject(self) :
return _SavePickleItem(self,self.__image,self.__layer,
self.__state,self.__cnt,self.__masterPosition,
self.focusMotorPosition)
def layerUp(self) :
self.__layer += 1
self.__image.setLayer(self.__layer)
def layerDown(self) :
self.__layer -= 1
self.__image.setLayer(self.__layer)
def stateChange(self,flag) :
self.__state = flag
if flag:
self.__image.show()
else:
self.__image.hide()
def image(self) :
return self.__image
class _MasterCheckItem(qt.QCheckListItem) :
def __init__(self,parent,name) :
qt.QCheckListItem.__init__(self,parent,name,qt.QCheckListItem.RadioButton)
self.setRenameEnabled(0,True)
self.setOpen(True)
def layerUp(self,item) :
pass
def layerDown(self,item):
pass
def stateChange(self,flag) :
item = self.firstChild()
while item:
item.setState(flag and qt.QCheckListItem.On or qt.QCheckListItem.Off)
item = item.nextSibling()
class _LiveImagePlug(QubStdData2ImagePlug) :
def __init__(self,cnt) :
QubStdData2ImagePlug.__init__(self)
self.__image = QubMosaicImage(motX = 0,motY = 0)
self.__image.setLayer(4096)
self.__cnt = cnt
self.__imageAlreadySend = False
def setImage(self,imagezoomed,fullimage) :
self.__image.setImage(fullimage)
return False
def show(self) :
self.__image.show()
def hide(self) :
self.__image.hide()
def addImage(self) :
if not self.__imageAlreadySend:
self.__cnt.mosaicView.addImage(self.__image)
self.__imageAlreadySend = True
def setPixelCalibration(self,xSize,ySize) :
self.__image.setCalibration(xSize,ySize)
def setBeamPosition(self,x,y) :
if x and y :
self.__image.setRefPos(x,y)
def move(self,x,y) :
self.__image.move(x,y)
def setHMotorPosition(self,position) :
_,vPos = self.__image.position()
self.__image.move(position,vPos)
def setVMotorPosition(self,position) :
hPos,_ = self.__image.position()
self.__image.move(hPos,position)
from Qub.Widget.QubAction import QubImageAction
class _MouseOrMotorPosition(QubImageAction):
def __init__(self,autoConnect = True,mouseFlag = False,**keys) :
QubImageAction.__init__(self,autoConnect = autoConnect,**keys)
self.__mouseFlag = mouseFlag
def addStatusWidget(self,parent) :
if self._widget is None:
self._widget = qt.QWidget(parent)
hlayout = qt.QHBoxLayout(self._widget)
self._xLabel = qt.QLabel("X:", self._widget)
self._xLabel.setSizePolicy(qt.QSizePolicy.Fixed,qt.QSizePolicy.Fixed)
hlayout.addWidget(self._xLabel)
self._xValue = qt.QLabel("x", self._widget)
self._xValue.setSizePolicy(qt.QSizePolicy.Fixed,qt.QSizePolicy.Fixed)
font = self._xValue.font()
font.setBold(True)
self._xValue.setFont(font)
hlayout.addWidget(self._xValue)
hlayout.addSpacing(5)
self._yLabel = qt.QLabel("Y:", self._widget)
self._yLabel.setSizePolicy(qt.QSizePolicy.Fixed,qt.QSizePolicy.Fixed)
hlayout.addWidget(self._yLabel)
self._yValue = qt.QLabel("x", self._widget)
self._yValue.setSizePolicy(qt.QSizePolicy.Fixed,qt.QSizePolicy.Fixed)
self._yValue.setFont(font)
hlayout.addWidget(self._yValue)
hlayout.addStretch()
return self._widget
def setMotxName(self,name) :
if self.__mouseFlag:
self._xLabel.setText('Mouse %s :' % str(name))
else:
self._xLabel.setText(name)
def setXValue(self,pos) :
self._xValue.setText('%.2f' % pos)
def setMotyName(self,name) :
if self.__mouseFlag:
self._yLabel.setText('Mouse %s :' % str(name))
else:
self._yLabel.setText(name)
def setYValue(self,pos) :
self._yValue.setText('%.2f' % pos)