-
Notifications
You must be signed in to change notification settings - Fork 9
/
CameraBrick.py
702 lines (583 loc) · 30.4 KB
/
CameraBrick.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
"""
[Name] CameraBrick
[Description]
The Camera brick can display image from camera. You can connect
external action and some drawing vector.
[Properties]
----------------------------------------------------------------------
| name | type | description
----------------------------------------------------------------------
| camera | string | name of camera hardware object
| zoom list | string | a list of posible zoom separate
| | | with comma for the sub view display
| init zoom | integer | the init zoom for the sub view display
| swap rgb | boolean | swap the bgr chanel to rgb
| fix width | integer | fix the width of the camera display
| fix height | integer | fix the height of the camera display
| action : print | boolean | show print action
| action : save image | boolean | show save image action
| action : update | boolean | show update action
| action : startCamera | boolean | Starts the camera (set live mode)
| action : brightness contrast | boolean | show brightness contrast action
| action : beam | boolean | show beam action
| action : scale | boolean | show scale action
| action : change foreground color | boolean | show change foreground color action
| action : measure | boolean | show measure action
| action : measure (place) | combo | display measure action in the toolbar or in contextmenu
| action : zoom window | boolean | show zoom window action
| action : zoom fit or fill | boolean | show zoom fit or fill action
| action : zoom list | boolean | show zoom list action
| action : x,y coordinates | boolean | show x,y coordinates
| action : save image (place) | combo | display save action in the toolbar or
| | | in contextmenu
| action : save image (default path) | string | change the default save path
| action : save image (show always configure) | boolean | on save action click : if true shows
| | | the configure save panel ELSE save an image on click.
| action : default color | combo | chose the default vector color (requier
| | | to have <b>change foreground color<\b> activated
----------------------------------------------------------------------
[Signals]
---------------------------------------------------------------
| name | arguments | description
---------------------------------------------------------------
| BeamPositionChanged | x,y position on image | emitted when beam position changed
---------------------------------------------------------------
[Slots]
----------------------------------------------------------------------
| name | arguments | description
-------------------------------------------------------------------
| changeBeamPosition | x,y position on image | usualy emitted by the CameraBeamBrick
| | | when the zoom changed
| changePixelScale | xSize,ySize in pixelsize in meter | usualy emitted by the CameraCalibrationBrick
| | | when the zoom changed
| getView | a Dictionary | returns a dictionnary whith 2 key : 'view'
| | | (QubPixmapDisplayView Object) to add external
| | | action and 'drawing' (QubPixmapDisplay
| | | Object) to add external drawing
| getImage | a Dictionary | return the last image in a dictionnary key 'image'
----------------------------------------------------------------------
"""
__category__ = "Camera"
from BlissFramework.BaseComponents import BlissWidget
import logging
import os
import time
import qt
from Qub.Widget.QubAction import QubToggleAction
from Qub.Widget.QubActionSet import QubZoomRectangle
from Qub.Widget.QubActionSet import QubZoomListAction
from Qub.Widget.QubActionSet import QubZoomAction
from Qub.Widget.QubActionSet import QubBeamAction
from Qub.Widget.QubActionSet import QubPositionAction
from Qub.Widget.QubActionSet import QubPrintPreviewAction
from Qub.Widget.QubActionSet import QubScaleAction
from Qub.Widget.QubActionSet import QubOpenDialogAction
from Qub.Widget.QubActionSet import QubForegroundColorAction
from Qub.Widget.QubActionSet import QubInfoAction
from Qub.Widget.QubActionSet import QubSaveImageAction
from Qub.Objects.QubPixmapDisplayView import QubPixmapDisplayView
from Qub.Objects.QubPixmapDisplay import QubPixmapZoomPlug
from Qub.Objects.QubImage2Pixmap import QubImage2Pixmap
from Qub.Objects.QubStdData2Image import QubStdData2Image,QubStdData2ImagePlug
from Qub.Print.QubPrintPreview import QubPrintPreview
from Qub.Widget.QubDialog import QubSaveImageDialog,QubMeasureListDialog,QubBrightnessContrastDialog
from widgets.grid_dialog import GridDialog
DISABLED_JPEG = file(os.path.join(os.path.dirname(__file__), "disabled.jpeg"), "r").read()
DISABLED_WIDTH = 659
DISABLED_HEIGHT = 493
###
### Brick to display a video of the sample
###
class CameraBrick(BlissWidget):
def __init__(self, *args):
BlissWidget.__init__(self, *args)
self.camera = None
self.update_disabled = False
self.__cameraName = None
self.__zoomList = [1.5,2,2.5,3,3.5,4]
self.__initZoom = 2
self.__fixWidth = -1
self.__fixHeight = -1
self.__swapRgb = True
####### PRINT #######
self.__printWidget = QubPrintPreview(self)
self.__printWidget.resize(400,500)
printer = qt.QPrinter()
printer.setOutputToFile(1)
printer.setOutputFileName('/tmp/print_file.ps')
self.__printWidget.setPrinter(printer)
self.__printWidget.update()
self.__beamAction = None
self.__scaleAction = None
self.__chosenActions = {}
self.__wholeActions = []
self.__measureDialog = None
####### PRINT ACTION #######
printAction = QubPrintPreviewAction(name="print",group="admin",withVectorMenu=True)
printAction.previewConnect(self.__printWidget)
self.__wholeActions.append(printAction)
####### SAVE IMAGE #######
self.__saveAction = QubSaveImageAction(parent=self, label='Save falcon image',
name="save", group="admin")
self.__saveAction.setConnectCallBack(self._save_dialog_new)
self.__wholeActions.append(self.__saveAction)
self.__defaultSavePath = '/tmp'
####### UPDATE #######
update = QubToggleAction(name="update",group="image",initState=True)
self.connect(update,qt.PYSIGNAL("StateChanged"),self.__cameraUpdate)
self.__wholeActions.append(update)
####### Start Camera ######
startCamera = QubToggleAction(name="startCamera", group="image", iconName = 'bright-cont', initState=True)
self.connect(startCamera, qt.PYSIGNAL("StateChanged"), self.__cameraStart)
self.__wholeActions.append(startCamera)
####### BRIGHTNESS/CONTRAST #######
self.__brightcount = QubOpenDialogAction(name="bright-cont",
iconName = 'bright-cont', group="image")
self.__brightcount.setDialog(QubBrightnessContrastDialog(self))
self.__wholeActions.append(self.__brightcount)
###### Grid TOOL ######
self.__gridToolAction = QubOpenDialogAction(parent=self, name='grid_tool',
iconName='rectangle', label='Grid tool',
group="Tools") #place="contextmenu")
self.__gridDialog = GridDialog(self, "Grid Dialog", flags = qt.Qt.WStyle_StaysOnTop)
self.__gridToolAction.setConnectCallBack(self._grid_dialog_connect_hdlr)
self.__wholeActions.append(self.__gridToolAction)
self.__previous_pos_dict = {}
self.__beamWidth = 0
self.__beamHeight = 0
####### BEAM ACTION #######
self.__beamAction = QubBeamAction(name="beam", group="Tools")
self.__wholeActions.append(self.__beamAction)
self.connect(self.__beamAction,qt.PYSIGNAL("BeamSelected"),
self.beamSelection)
####### SCALE #######
self.__scaleAction = QubScaleAction(name='scale',group='Tools')
self.__wholeActions.append(self.__scaleAction)
self.__wholeActions.extend(self.__creatStdActions())
####### ACTION INFO #######
actionInfo = QubInfoAction(name="actionInfo", group="image",place="statusbar")
self.__wholeActions.append(actionInfo)
####### CHANGE FOREGROUND COLOR #######
self.__fcoloraction = QubForegroundColorAction(name="color", group="image")
self.__wholeActions.append(self.__fcoloraction)
####### MEASURE #######
self.__measureAction = QubOpenDialogAction(parent=self, name='measure',
iconName='measure', label='Measure',
group="Tools")
self.__measureAction.setConnectCallBack(self._measure_dialog_new)
self.__wholeActions.append(self.__measureAction)
# ###### POSITION TOOL ######
# self.__posToolAction = QubOpenDialogAction(parent=self, name='pos_tool',
# iconName='circle', label='Position tool',
# group="Tools")
# self.__posToolAction.setConnectCallBack(self._line_dialog_new)
# self.__wholeActions.append(self.__posToolAction)
####### ZOOM LIST #######
zoomActionList = QubZoomListAction(place = "toolbar",
initZoom = 1,zoomValList = [0.1,0.25,0.5,0.75,1,1.5,2],
show = 1,group = "zoom")
self.__wholeActions.append(zoomActionList)
####### ZOOM Action #######
self.__zoomFitOrFill = QubZoomAction(place = "toolbar",group = "zoom")
self.__wholeActions.append(self.__zoomFitOrFill)
####### LINK ZOOM ACTION #######
self.__zoomFitOrFill.setList(zoomActionList)
zoomActionList.setActionZoomMode(self.__zoomFitOrFill)
####### ZOOM WINDOW #######
self.__zoomAction = QubZoomRectangle(label='Zoom Crop',place="toolbar", show=1, group="zoom")
self.connect(self.__zoomAction,qt.PYSIGNAL("Actif"),self.__hide_show_zoom)
self.__wholeActions.append(self.__zoomAction)
self.__splitter = qt.QSplitter(qt.Qt.Horizontal,self)
self.__splitter.show()
self.__mainVideo = QubPixmapDisplayView(self.__splitter)
self.__mainVideo.show()
self.__mainVideo.setScrollbarMode('Auto')
self.__mainPlug = _MainVideoPlug(self.__mainVideo,self.__zoomAction)
actions = self.__creatStdActions()
####### ZOOM LIST #######
self.__zoomActionList = QubZoomListAction(place = "toolbar",keepROI = True,
initZoom = self.__initZoom,zoomValList = self.__zoomList,
show = 1,group = "zoom")
actions.insert(0,self.__zoomActionList)
####### ZOOM Action #######
zoomFitOrFill = QubZoomAction(place = "toolbar",keepROI = True,group = "zoom")
zoomFitOrFill.setList(self.__zoomActionList)
self.__zoomActionList.setActionZoomMode(zoomFitOrFill)
actions.append(zoomFitOrFill)
self.__zoomVideo = QubPixmapDisplayView(self.__splitter,None,actions)
self.__zoomVideo.hide()
self.__zoomPlug = _ZoomPlug(self.__zoomVideo)
self.__zoomPlug.zoom().setZoom(2,2)
self.__cbk = _rectangleZoom(self.__zoomAction,self.__zoomPlug)
layout = qt.QHBoxLayout(self,0,0,"layout")
layout.addWidget(self.__splitter)
self.__image2Pixmap = QubImage2Pixmap()
self.__image2Pixmap.plug(self.__mainPlug)
self.__zoomPlug.setPoller(self.__image2Pixmap)
self.__jpegDecompress = QubStdData2Image()
self.__jpegDecompress.setSwapRGB(True)
self.__jpeg2image = None
####### PROPERTY #######
self.addProperty('camera','string','')
self.addProperty('zoom list','string',','.join([str(x) for x in self.__zoomList]))
self.addProperty('init zoom','integer',self.__initZoom)
self.addProperty('swap rgb','boolean',True)
self.addProperty('fix : width','integer',-1)
self.addProperty('fix : height','integer',-1)
self.addProperty('action : print','boolean',True)
self.addProperty('action : save image','boolean',True)
self.addProperty('action : update','boolean',True)
self.addProperty('action : startCamera','boolean',True)
self.addProperty('action : brightness contrast','boolean',True)
self.addProperty('action : beam','boolean',True)
self.addProperty('action : scale','boolean',True)
self.addProperty('action : change foreground color','boolean',True)
self.addProperty('action : measure','boolean',True)
self.addProperty('action : measure (place)', 'combo', ('toolbar','contextmenu'),'toolbar')
self.addProperty('action : zoom window','boolean',True)
self.addProperty('action : zoom fit or fill','boolean',True)
self.addProperty('action : zoom list','boolean',True)
self.addProperty('action : x,y coordinates','boolean',True)
self.addProperty('action : default color','combo',('black','red','green'),'black')
self.addProperty('action : save image (place)',"combo",('toolbar','contextmenu'),'toolbar')
self.addProperty('action : save image (default path)',"string",'/tmp')
self.addProperty('action : save image (show always configure)',"boolean",True)
self.addProperty("diffractometer", "string", "")
self.diffractometerHwobj = None
####### SIGNAL #######
self.defineSignal("BeamPositionChanged", ())
####### SLOT #######
self.defineSlot("changeBeamPosition", ())
self.defineSlot("changePixelScale",())
self.defineSlot('getView',())
self.defineSlot('getImage',())
####### LINK VIEW AND SUB VIEW #######
mainView = self.__mainVideo.view()
zoomView = self.__zoomVideo.view()
mainView.addEventMgrLink(zoomView,
mainView.canvas(),zoomView.canvas(),
mainView.matrix(),zoomView.matrix())
self.imageReceivedConnected = None
def safeConnect(self):
if not self.imageReceivedConnected and self.camera is not None:
#print "CONNECTING 0"
self.camera.connect('imageReceived', self.__imageReceived)
#self.connect(self.camera,qt.PYSIGNAL('imageReceived'),self.__imageReceived)
self.imageReceivedConnected = False
def safeDisconnect(self):
if self.imageReceivedConnected and self.camera is not None:
#print "DISCONNECTING 3"
self.camera.disconnect('imageReceived', self.__imageReceived)
#self.disconnect(self.camera,qt.PYSIGNAL('imageReceived'),self.__imageReceived)
self.imageReceivedConnected = False
def disable_update(self):
#self.__imageReceived(DISABLED_JPEG,DISABLED_WIDTH,DISABLED_HEIGHT)
self.update_disabled = True
def enable_update(self):
self.update_disabled = False
def __imageReceived(self,image,width,height,force_update=False):
if self.update_disabled:
return
if not force_update:
if not self.isVisible():
return
if isinstance(image,qt.QImage):
if self.__swapRgb:
image = image.swapRGB()
self.__jpeg2image.setImage(image,image)
else:
self.__jpegDecompress.putData(image,width,height)
def propertyChanged(self,property,oldValue,newValue):
if property=='camera':
#if self.camera is not None and not self.isRunning():
# self.safeDisconnect()
self.safeDisconnect()
self.camera = self.getHardwareObject(newValue)
self.__hwoName = newValue
if self.camera is not None:
try:
self.__tangoName = self.camera.tangoname
except:
self.__tangoName = ""
try:
camera_role=self.camera.getDeviceByRole('camera')
if camera_role is not None:
self.camera=camera_role
except AttributeError:
pass
self.__brightcount.setCamera(self.camera)
elif property == 'zoom list' :
zoomList = [float(x) for x in newValue.split(',')]
if zoomList != self.__zoomList :
self.__zoomList = zoomList
self.__zoomActionList.changeZoomList(zoomList,self.__initZoom)
elif property == 'init zoom' :
if newValue != self.__initZoom :
self.__initZoom = newValue
self.__zoomActionList.changeZoomList(self.__zoomList,newValue)
elif property == 'swap rgb' :
self.__jpegDecompress.setSwapRGB(newValue)
self.__swapRgb = newValue
elif property == 'action : print' : self.__chosenActions['print'] = newValue
elif property == 'action : save image' : self.__chosenActions['save'] = newValue
elif property == 'action : update' : self.__chosenActions['update'] = newValue
elif property == 'action : startCamera' : self.__chosenActions['startCamera'] = newValue
elif property == 'action : brightness contrast' : self.__chosenActions['bright-cont'] = newValue
elif property == 'action : beam' : self.__chosenActions['beam'] = newValue
elif property == 'action : scale' : self.__chosenActions['scale'] = newValue
elif property == 'action : change foreground color' : self.__chosenActions['color'] = newValue
elif property == 'action : measure' : self.__chosenActions['measure'] = newValue
elif property == 'action : zoom window' : self.__chosenActions['zoomrect'] = newValue
elif property == 'action : zoom fit or fill' : self.__chosenActions['Zoom tools'] = newValue
elif property == 'action : zoom list' : self.__chosenActions['zoomlist'] = newValue
elif property == 'action : x,y coordinates' : self.__chosenActions['position'] = newValue
elif property == 'action : default color' : self.__chosenDefaultColor = newValue
elif property == 'action : save image (place)' :
self.__saveAction.setPlace(newValue,True)
elif property == 'action : measure (place)':
self.__measureAction.setPlace(newValue, True)
elif property == 'action : save image (default path)' :
self.__defaultSavePath = newValue
elif property == 'action : save image (show always configure)' :
self.__saveAction.setConfigureOnClick(newValue)
elif property == 'fix : width' : self.__fixWidth = newValue
elif property == 'fix : height': self.__fixHeight = newValue
elif property == "diffractometer":
self.diffractometerHwobj = self.getHardwareObject(newValue)
if self.diffractometerHwobj is not None:
self.__previous_pos_dict = self.diffractometerHwobj.getPositions()
self.diffractometerHwobj.connect("minidiffStateChanged",
self.diffractometerChanged)
if self.diffractometerHwobj.zoomMotor is not None:
zoom = self.diffractometerHwobj.zoomMotor.getPosition()
xSize,ySize = self.diffractometerHwobj.getCalibrationData(zoom)
#xSize,ySize = self.__scaleAction.xPixelSize(), self.__scaleAction.yPixelSize()
self.diffractometerHwobj.getBeamInfo(self.__getBeamInfo)
beam_pos_x = self.diffractometerHwobj.getBeamPosX()
beam_pos_y = self.diffractometerHwobj.getBeamPosY()
self.__gridDialog.set_x_pixel_size(xSize)
self.__gridDialog.set_y_pixel_size(ySize)
self.__gridDialog.set_beam_position(beam_pos_x, beam_pos_y,
self.__beamWidth, self.__beamHeight)
def run(self) :
chosenActions = []
for action in self.__wholeActions :
if self.__chosenActions.get(action.name(), True) :
chosenActions.append(action)
self.__mainVideo.addAction(chosenActions)
if not self.__chosenActions.get('update', False) :
self.__cameraUpdate(True)
if not self.__chosenActions.get('startCamera', False) :
self.__cameraStart(True)
if self.__fixWidth != -1 and self.__fixHeight != -1 :
self.__mainVideo.view().setFixedSize(self.__fixWidth + 4,self.__fixHeight + 4)
self.__startIdle = qt.QTimer(self)
qt.QObject.connect(self.__startIdle,qt.SIGNAL('timeout()'),self.__idleRun)
self.__startIdle.start(0)
def __idleRun(self) :
self.__startIdle.stop()
self.__fcoloraction.setColor(self.__chosenDefaultColor)
self.__mainVideo.view().setForegroundColor(qt.QColor(self.__chosenDefaultColor))
def stop(self) :
self.safeDisconnect()
def beamSelection(self,x,y) :
self.emit(qt.PYSIGNAL("BeamPositionChanged"), (x,y))
self.changeBeamPosition(x,y)
def changeBeamPosition(self, x, y, beam_width=None, beam_height=None):
self.__beamAction.setBeamPosition(x, y)
try:
if not beam_width:
beam_width = self.__beamWidth
if not beam_height:
beam_height = self.__beamHeight
self.__gridDialog.set_beam_position(x, y, beam_width, beam_height)
except:
pass
def changePixelScale(self,sizex,sizey) :
self.__scaleAction.setXPixelSize(sizex)
self.__scaleAction.setYPixelSize(sizey)
if self.__measureDialog :
self.__measureDialog.setXPixelSize(sizex)
self.__measureDialog.setYPixelSize(sizey)
self.__gridDialog.set_x_pixel_size(sizex)
self.__gridDialog.set_y_pixel_size(sizey)
def getView(self,key):
try:
key['drawing'] = self.__mainVideo.view()
key['view'] = self.__mainVideo
key['hwname'] = self.__hwoName
key['dsname'] = self.__tangoName
except:
pass
def getImage(self,key) :
if self.__jpeg2image is not None :
try:
key['image'] = self.__jpeg2image.getLastImage()
except:
pass
def __creatStdActions(self) :
actions = []
####### MOUSE POSITION #######
posaction = QubPositionAction(name="position", group="image",place="statusbar")
actions.append(posaction)
return actions
def __cameraUpdate(self,onoff) :
if onoff :
self.__jpeg2image = _Jpeg2ImagePlug(self.__image2Pixmap)
self.__jpegDecompress.plug(self.__jpeg2image)
if self.camera is not None:
imageInfo = self.camera.imageType()
else:
imageInfo = None
imType = self.__jpegDecompress.STANDARD
if imageInfo :
if imageInfo.type() == 'bayer': imType = self.__jpegDecompress.BAYER_RG
elif imageInfo.type() == 'raw': imType = self.__jpegDecompress.RAW
self.__jpegDecompress.setImageType(imType)
self.safeConnect()
else:
self.safeDisconnect()
self.__jpeg2image.setEnd()
def __cameraStart(self, onoff) :
if onoff :
print "********************************************************Set the camera ON"
if self.camera is not None:
self.camera.setLive(True)
else:
print "camera is none"
else:
print "****************************************************Set the camera off"
if self.camera is not None:
print "camera :"
print self.camera
self.camera.setLive(False)
else:
print "camera is none"
def __hide_show_zoom(self,actif) :
if actif :
if self.__chosenActions['Zoom tools'] :
self.__zoomFitOrFill.setState(True)
else:
self.__mainVideo.setScrollbarMode('Fit2Screen')
self.__zoomPlug.start()
self.__zoomVideo.show()
splitterWidth = self.__splitter.width()
self.__splitter.setSizes([splitterWidth/3,splitterWidth - splitterWidth/3])
else:
if self.__chosenActions['Zoom tools'] :
self.__zoomFitOrFill.setState(False)
else:
self.__mainVideo.setScrollbarMode('Auto')
self.__zoomPlug.stop()
self.__zoomVideo.hide()
def _measure_dialog_new(self,openDialogAction,aQubImage) :
try :
self.__measureDialog = QubMeasureListDialog(self,
canvas=aQubImage.canvas(),
matrix=aQubImage.matrix(),
eventMgr=aQubImage)
xSize,ySize = self.__scaleAction.xPixelSize(),self.__scaleAction.yPixelSize()
self.__measureDialog.setXPixelSize(xSize)
self.__measureDialog.setYPixelSize(ySize)
self.__measureDialog.connect(aQubImage, qt.PYSIGNAL("ForegroundColorChanged"),
self.__measureDialog.setDefaultColor)
openDialogAction.setDialog(self.__measureDialog)
except:
import traceback
traceback.print_exc()
def _grid_dialog_connect_hdlr(self,openDialogAction, aQubImage) :
try :
self.__gridDialog.set_qub_event_mgr(aQubImage)
openDialogAction.setDialog(self.__gridDialog)
except:
import traceback
traceback.print_exc()
def __getBeamInfo(self, ret):
self.__beamWidth = float(ret["size_x"])
self.__beamHeight = float(ret["size_y"])
#self.__beamShape = ret["shape"]
def _save_dialog_new(self,openDialogAction,aQubImage) :
saveDialog = QubSaveImageDialog(self,matrix=aQubImage.matrix(),canvas=aQubImage.canvas())
saveDialog.setImage2Pixmap(self.__image2Pixmap)
saveDialog.setSavePath(self.__defaultSavePath)
openDialogAction.setDialog(saveDialog)
def instanceMirrorChanged(self,mirror):
#print "INSTANCEMIRRORCHANGED",mirror,BlissWidget.isInstanceMirrorAllow()
return
if BlissWidget.isInstanceModeSlave():
if BlissWidget.isInstanceMirrorAllow():
self.safeConnect()
else:
self.safeDisconnect()
def diffractometerChanged(self, *args):
"""
Handles diffractometer change events, connected to the signal
minidiffStateChanged of the diffractometer hardware object.
"""
if self.diffractometerHwobj.isReady():
pos_dict = self.diffractometerHwobj.getPositions()
p1 = self.diffractometerHwobj.motor_positions_to_screen(self.__previous_pos_dict)
p2 = (self.diffractometerHwobj.getBeamPosX(), self.diffractometerHwobj.getBeamPosY())
dx = p2[0] - p1[0]
dy = p2[1] - p1[1]
if dy != 0:
self.__gridDialog.move_grid_ver(-dy)
if dx != 0:
self.__gridDialog.move_grid_hor(-dx)
#print dx, dy
self.__previous_pos_dict = pos_dict
class _MainVideoPlug(QubPixmapZoomPlug) :
def __init__(self,receiver,zoomAction) :
QubPixmapZoomPlug.__init__(self,receiver)
self.__firstPixmap = True
self.__zoomAction = zoomAction
def setPixmap(self,pixmap,image) :
if self.__firstPixmap : # INIT
self.__firstPixmap = False
width,height = image.width() / 2,image.height() / 2
self.__zoomAction.initSelection(width / 2,height / 2,width,height)
self._receiver.setPixmap(pixmap, image)
return False
class _ZoomPlug(QubPixmapZoomPlug) :
def __init__(self,receiver) :
QubPixmapZoomPlug.__init__(self,receiver)
self.__actif = True
self.__inPoll = False
def setPixmap(self,pixmap,image) :
if self.__actif :
QubPixmapZoomPlug.setPixmap(self,pixmap,image)
else :
self.__inPoll = False
return not self.__actif
def setPoller(self,poller) :
self.__poller = poller
def start(self) :
self.__actif = True
if not self.__inPoll :
self.__poller.plug(self)
self.__inPoll = True
def stop(self) :
self.__actif = False
class _Jpeg2ImagePlug(QubStdData2ImagePlug) :
def __init__(self,receiver) :
QubStdData2ImagePlug.__init__(self)
self.__receiver = receiver
def setImage(self,imagezoomed,fullimage) :
self.__lastImage = fullimage
self.__receiver.putImage(imagezoomed,fullimage)
return False
def getLastImage(self) :
return self.__lastImage
class _rectangleZoom :
def __init__(self,action,plug) :
self.__plug = plug
self.__action = action
qt.QObject.connect(action,qt.PYSIGNAL('RectangleSelected'),self.__cbk)
def __del__(self) :
qt.QObject.disconnect(self.__action,qt.PYSIGNAL('RectangleSelected'),self.__cbk)
def __cbk(self,drawingMgr) :
rect = drawingMgr.rect()
zoomClass = self.__plug.zoom()
zoom = zoomClass.zoom()
zoomClass.setRoiNZoom(rect.x(),rect.y(),
rect.width(),rect.height(),*zoom)