forked from julienGautier77/camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathROSAHighFlux.py
executable file
·802 lines (646 loc) · 34.2 KB
/
ROSAHighFlux.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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 24 10:59:16 2020
a Python user interface for camera allied vison, ImgingSource, Balser
install aliiedVision SDK (https://www.alliedvision.com/en/products/software.html)
on conda prompt :
for allied vision camera :
pip install pymba (https://github.com/morefigs/pymba.git )
# Encrease timeout :
#change in File "C:\ProgramData\Anaconda3\lib\site-packages\pymba\camera.py
# def acquire_frame(self, timeout_ms: Optional[int] = 200000000) -> Frame:
for Basler camera :
pip install pypylon: https://github.com/basler/pypylon
pip install qdarkstyle (https://github.com/ColinDuquesnoy/QDarkStyleSheet.git)
pip install pyqtgraph (https://github.com/pyqtgraph/pyqtgraph.git)
Change in pyqtgraph in ImgageItem.py line 462 :
if bins == 'auto':
if stepData.dtype.kind in "ui":
mn = stepData.min()
mx = stepData.max()
if mn==mx: # add to avoid / by zero !!!
mx=mx+0.01
step = np.ceil((mx-mn) / 500.)
bins = np.arange(mn, mx+1.01*step, step, dtype=np.int)
if len(bins) == 0:
bins = [mn, mx]
else:
bins = 500
pip install visu
@author: juliengautier
version : 2019.4
"""
__author__='julien Gautier'
__version__='2020.04'
from PyQt5.QtWidgets import QApplication,QVBoxLayout,QHBoxLayout,QWidget
from PyQt5.QtWidgets import QComboBox,QSlider,QLabel,QSpinBox,QToolButton,QMenu,QInputDialog,QDockWidget
from pyqtgraph.Qt import QtCore
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
from PyQt5 import QtGui
import sys,time
import pathlib,os
import qdarkstyle
import numpy as np
import __init__
__version__=__init__.__version__
version=str(__version__)
class CAMERA(QWidget):
datareceived=QtCore.pyqtSignal(bool) # signal emited when receive image
def __init__(self,cam='choose',confFile='confCamera.ini',**kwds):
'''
Parameters
----------
cam : TYPE str, optional
DESCRIPTION.
cam='choose' : generate a input dialog box which the list of all the camera connected (allied,basler,imagingSource)
cam='cam1' : open the camera by the ID and type save in the confFile.ini
ncam='menu': generate a input dialog box with a menu with all the camera name present in the .ini file
cam='firstGuppy' open the first allied vision camera
cam='firstBasler' open the first Basler camera
cam='firstImgSource' open the first ImagingSource camera
The default is 'choose'.
confFile : TYPE str, optional
DESCRIPTION.
confFile= path to file.initr
The default is 'confCamera.ini'.
**kwds:
affLight : TYPE boolean, optional
DESCRIPTION.
affLight=False all the option are show for the visualisation
affLight= True only few option (save open cross)
The default is True.
multi add time sleep to access QApplication.processEvents()
+ all kwds of VISU class
'''
super(CAMERA, self).__init__()
p = pathlib.Path(__file__)
self.nbcam=cam
self.kwds=kwds
if "affLight" in kwds:
self.light=kwds["affLight"]
else:
self.light=True
if "multi" in kwds:
self.multi=kwds["multi"]
else:
self.multi=False
if "separate" in kwds:
self.separate=kwds["separate"]
else:
self.separate=True
if "aff" in kwds: # affi of Visu
self.aff=kwds["aff"]
else:
self.aff="right"
# self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) # qdarkstyle : black windows style
self.confPath=str(p.parent / confFile) # ini file path
self.conf=QtCore.QSettings(str(p.parent / self.confPath), QtCore.QSettings.IniFormat) # ini file
self.kwds["confpath"]=self.confPath
sepa=os.sep
self.icon=str(p.parent) + sepa+'icons'+sepa
self.setWindowIcon(QIcon(self.icon+'LOA.png'))
self.iconPlay=self.icon+'Play.png'
self.iconSnap=self.icon+'Snap.png'
self.iconStop=self.icon+'Stop.png'
self.iconPlay=pathlib.Path(self.iconPlay)
self.iconPlay=pathlib.PurePosixPath(self.iconPlay)
self.iconStop=pathlib.Path(self.iconStop)
self.iconStop=pathlib.PurePosixPath(self.iconStop)
self.iconSnap=pathlib.Path(self.iconSnap)
self.iconSnap=pathlib.PurePosixPath(self.iconSnap)
self.nbShot=1
self.isConnected=False
self.version=str(__version__)
self.openCam()
self.setup()
self.setCamPara()
#self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
def openID(self):
'''
open a camera by id camera typ and ID must be known and saved in the ini file
'''
self.ccdName=self.conf.value(self.nbcam+"/nameCDD")
self.cameraType=self.conf.value(self.nbcam+"/camType")
self.camID=self.conf.value(self.nbcam+"/camId")
if self.cameraType=="guppy" :
try :
import guppyCam
print('ici')
self.CAM=guppyCam.GUPPY(cam=self.nbcam,conf=self.conf)
print('ici2')
self.CAM.openCamByID(self.camID)
print('ici3')
self.isConnected=self.CAM.isConnected
except :
print("no allied vision camera detected or vimba is not installed")
pass
elif self.cameraType=="basler":
try:
import baslerCam
self.CAM=baslerCam.BASLER(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openCamByID(self.camID)
self.isConnected=self.CAM.isConnected
except:
print("no basler camera detected or pypylon is not installed")
pass
elif self.cameraType=="imgSource":
try :
import ImgSourceCamCallBack
self.CAM=ImgSourceCamCallBack.IMGSOURCE(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openCamByID(self.camID)
# print('openID',self.camID)
self.isConnected=self.CAM.isConnected
except:
print("no imaging source camera detected or Tisgrabber is not installed")
pass
elif self.cameraType=="pixelink":
try :
import pixelinkCam
self.CAM=pixelinkCam.PIXELINK(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openCamByID(self.camID)
self.isConnected=self.CAM.isConnected
except:
print("no imaging source camera detected or Tisgrabber is not installed")
pass
else:
print('no camera')
self.isConnected=False
self.ccdName="no camera"
self.cameraType=""
self.camID=""
self.nbcam='camDefault'
def openCam(self):
'''open a camera with different way
'''
if self.nbcam=="choose": # create menu widget with all camera present
self.nbcam='camDefault'
try :
import guppyCam
self.itemsGuppy=guppyCam.camAvailable()
# print(self.itemsGuppy)
self.lenGuppy=len(self.itemsGuppy)
except:
print('No allied vision camera connected')
self.itemsGuppy=[]
self.lenGuppy=0
pass
try :
import baslerCam
self.itemsBasler=baslerCam.camAvailable()
self.lenBasler=len(self.itemsBasler)
except:
print('No Basler camera connected')
self.itemsBasler=[]
self.lenBasler=0
pass
try :
import ImgSourceCamCallBack
self.itemsImgSource=ImgSourceCamCallBack.camAvailable()
self.lenImgSource=len(self.itemsImgSource)
except:
print('No ImagingSource camera connected')
self.itemsImgSource=[]
self.lenImgSource=0
pass
try :
import pixelinkCam
self.itemsPixelink=pixelinkCam.PIXELINK.camAvailable()
self.lenImgPixelink=len(self.itemsPixelink)
except:
print('No pixelink camera connected')
self.itemsPixelink=[]
self.lenPixelink=0
pass
items=self.itemsGuppy+list(self.itemsBasler)+self.itemsImgSource+self.itemsPixelink
item, ok = QInputDialog.getItem(self, "Select a camera","List of avaible camera", items, 0, False,flags=QtCore.Qt.WindowStaysOnTopHint)
if ok and item:
indexItem = items.index(item)
if indexItem<self.lenGuppy:
indexItem=indexItem
self.cameraType="guppy"
self.camID=guppyCam.getCamID(indexItem)
self.CAM=guppyCam.GUPPY(cam=self.nbcam,conf=self.conf)
self.CAM.openCamByID(self.camID)
self.isConnected=self.CAM.isConnected
self.ccdName=self.camID
elif indexItem>=self.lenGuppy and indexItem<self.lenBasler+self.lenGuppy:
indexItem=indexItem-self.lenGuppy
self.cameraType="basler"
self.camID=baslerCam.getCamID(indexItem)
self.CAM=baslerCam.BASLER(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openCamByID(self.camID)
self.isConnected=self.CAM.isConnected
self.ccdName=self.camID
elif indexItem>=self.lenBasler+self.lenGuppy and indexItem<self.lenBasler+self.lenGuppy+self.lenImgSource:
indexItem=indexItem-self.lenGuppy-self.lenBasler
self.cameraType="imgSource"
self.camID=ImgSourceCamCallBack.getCamID(indexItem)
self.camID=self.camID.decode()
self.CAM=ImgSourceCamCallBack.IMGSOURCE(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openCamByID(self.camID)
self.isConnected=self.CAM.isConnected
self.ccdName=self.camID
elif indexItem>=self.lenBasler+self.lenGuppy+ self.lenImgSource and indexItem<self.lenBasler+self.lenGuppy+self.lenImgSource+self.lenPixelink:
indexItem=indexItem-self.lenGuppy-self.lenBasler-self.lenImgSource
self.cameraType="pixelink"
self.camID=pixelinkCam.getCamID(indexItem)
self.CAM=pixelinkCam.PIXELINK(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openCamByID(self.camID)
self.isConnected=self.CAM.isConnected
self.ccdName=self.camID
else:
self.isconnected=False
print('No camera choosen')
self.ccdName="no camera"
self.nbcam='camDefault'
else :
self.isconnected=False
print('No camera choosen')
self.ccdName="no camera"
self.cameraType=""
self.camID=""
self.nbcam='camDefault'
elif self.nbcam==None:
self.isconnected=False
print('No camera')
self.ccdName="no camera"
self.cameraType=""
self.camID=""
self.nbcam='camDefault'
elif self.nbcam=="firstGuppy": # open the first guppy cam in the list
self.nbcam='camDefault'
self.cameraType="guppy"
self.ccdName='First guppy Cam'
import guppyCam
self.CAM=guppyCam.GUPPY(cam=self.nbcam,conf=self.conf)
self.CAM.openFirstCam()
self.isConnected=self.CAM.isConnected
elif self.nbcam=="firstBasler": # open the first basler cam in the list
self.ccdName='First basler Cam'
self.nbcam='camDefault'
self.cameraType="basler"
import baslerCam
self.CAM=baslerCam.BASLER(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openFirstCam()
self.isConnected=self.CAM.isConnected
elif self.nbcam=="firstImgSource": # open the first imgSource cam in the list
self.ccdName='First ImSource Cam'
self.nbcam='camDefault'
self.cameraType="imgSource"
import ImgSourceCamCallBack
self.CAM=ImgSourceCamCallBack.IMGSOURCE(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openFirstCam()
self.isConnected=self.CAM.isConnected
elif self.nbcam=="firstPixelink": # open the first pixelink cam in the list
self.ccdName='First Pixelink Cam'
self.nbcam='camDefault'
self.cameraType="pixelink"
import pixelinkCam
self.CAM=pixelinkCam.PIXELINK(cam=self.nbcam,conf=self.conf,**self.kwds)
self.CAM.openFirstCam()
self.isConnected=self.CAM.isConnected
elif self.nbcam=='menu': # Qdialog with a menu with all the camera name present in the inifile
self.groupsName=[]
self.groups=self.conf.childGroups()
for groups in self.groups:
self.groupsName.append(self.conf.value(groups+"/nameCDD"))
item, ok = QInputDialog.getItem(self, "Select a camera","List of avaible camera", self.groupsName, 0, False,flags=QtCore.Qt.WindowStaysOnTopHint)
if ok and item:
indexItem = self.groupsName.index(item)
self.nbcam=self.groups[indexItem]
self.openID()
else : #open the camera by ID : nbcam return ID of the ini file
try :
self.openID()
except :
self.isConnected=False
def setCamPara(self):
'''set min max gain and exp value of cam in the widget
'''
if self.isConnected==True: # if camera is connected we address min and max value and value to the shutter and gain box
# print('camshutter',self.CAM.camParameter["exposureTime"])
if self.CAM.camParameter["expMax"] >1500: # we limit exposure time at 1500ms
self.hSliderShutter.setMaximum(1500)
self.shutterBox.setMaximum(1500)
else :
self.hSliderShutter.setMaximum(self.CAM.camParameter["expMax"])
self.shutterBox.setMaximum(self.CAM.camParameter["expMax"])
self.hSliderShutter.setValue(int(self.CAM.camParameter["exposureTime"]))
self.shutterBox.setValue(int(self.CAM.camParameter["exposureTime"]))
self.hSliderShutter.setMinimum(int(self.CAM.camParameter["expMin"]+1))
self.shutterBox.setMinimum(int(self.CAM.camParameter["expMin"]+1))
self.hSliderGain.setMinimum(int(self.CAM.camParameter["gainMin"]))
self.hSliderGain.setMaximum(int(self.CAM.camParameter["gainMax"]))
self.hSliderGain.setValue(int(self.CAM.camParameter["gain"]))
self.gainBox.setMinimum(int(self.CAM.camParameter["gainMin"]))
self.gainBox.setMaximum(int(self.CAM.camParameter["gainMax"]))
self.gainBox.setValue(int(self.CAM.camParameter["gain"]))
self.actionButton()
if self.isConnected==False:
self.setWindowTitle('Visualization No camera connected ' + 'v. '+ self.version)
self.runButton.setEnabled(False)
self.snapButton.setEnabled(False)
self.trigg.setEnabled(False)
self.hSliderShutter.setEnabled(False)
self.shutterBox.setEnabled(False)
self.gainBox.setEnabled(False)
self.hSliderGain.setEnabled(False)
self.runButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: gray ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconPlay,self.iconPlay))
self.snapButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: gray ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconSnap,self.iconSnap))
def setup(self):
""" user interface definition
"""
self.setWindowTitle('Visualization '+ self.cameraType+" " + self.ccdName+' v.'+ self.version)
hbox1=QHBoxLayout() # horizontal layout pour run snap stop
self.sizebuttonMax=30
self.sizebuttonMin=30
self.runButton=QToolButton(self)
self.runButton.setMaximumWidth(self.sizebuttonMax)
self.runButton.setMinimumWidth(self.sizebuttonMax)
self.runButton.setMaximumHeight(self.sizebuttonMax)
self.runButton.setMinimumHeight(self.sizebuttonMax)
self.runButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: transparent ;border-color: green;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"% (self.iconPlay,self.iconPlay) )
self.snapButton=QToolButton(self)
self.snapButton.setPopupMode(0)
menu=QMenu()
#menu.addAction('acq',self.oneImage)
menu.addAction('set nb of shot',self.nbShotAction)
self.snapButton.setMenu(menu)
self.snapButton.setMaximumWidth(self.sizebuttonMax)
self.snapButton.setMinimumWidth(self.sizebuttonMax)
self.snapButton.setMaximumHeight(self.sizebuttonMax)
self.snapButton.setMinimumHeight(self.sizebuttonMax)
self.snapButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: transparent ;border-color: green;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"% (self.iconSnap,self.iconSnap) )
self.stopButton=QToolButton(self)
self.stopButton.setMaximumWidth(self.sizebuttonMax)
self.stopButton.setMinimumWidth(self.sizebuttonMax)
self.stopButton.setMaximumHeight(self.sizebuttonMax)
self.stopButton.setMinimumHeight(self.sizebuttonMax)
self.stopButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: gray ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"% (self.iconStop,self.iconStop) )
self.stopButton.setEnabled(False)
hbox1.addWidget(self.runButton)
hbox1.addWidget(self.snapButton)
hbox1.addWidget(self.stopButton)
hbox1.setSizeConstraint(QtGui.QLayout.SetFixedSize)
hbox1.setContentsMargins(0, 10, 0, 10)
self.widgetControl=QWidget(self)
self.widgetControl.setLayout(hbox1)
self.dockControl=QDockWidget(self)
self.dockControl.setWidget(self.widgetControl)
self.dockControl.resize(80,80)
self.trigg=QComboBox()
self.trigg.setMaximumWidth(80)
self.trigg.addItem('OFF')
self.trigg.addItem('ON')
self.trigg.setStyleSheet('font :bold 10pt;color: white')
self.labelTrigger=QLabel('Trigger')
self.labelTrigger.setMaximumWidth(70)
self.labelTrigger.setStyleSheet('font :bold 10pt')
self.itrig=self.trigg.currentIndex()
hbox2=QHBoxLayout()
hbox2.setSizeConstraint(QtGui.QLayout.SetFixedSize)
hbox2.setContentsMargins(5, 15, 0, 0)
hbox2.addWidget(self.labelTrigger)
hbox2.addWidget(self.trigg)
self.widgetTrig=QWidget(self)
self.widgetTrig.setLayout(hbox2)
self.dockTrig=QDockWidget(self)
self.dockTrig.setWidget(self.widgetTrig)
self.labelExp=QLabel('Exposure (ms)')
self.labelExp.setStyleSheet('font :bold 10pt')
self.labelExp.setMaximumWidth(140)
self.labelExp.setAlignment(Qt.AlignCenter)
self.hSliderShutter=QSlider(Qt.Horizontal)
self.hSliderShutter.setMaximumWidth(80)
self.shutterBox=QSpinBox()
self.shutterBox.setStyleSheet('font :bold 8pt')
self.shutterBox.setMaximumWidth(120)
hboxShutter=QHBoxLayout()
hboxShutter.setContentsMargins(5, 0, 0, 0)
hboxShutter.setSpacing(10)
vboxShutter=QVBoxLayout()
vboxShutter.setSpacing(0)
vboxShutter.addWidget(self.labelExp)#,Qt.AlignLef)
hboxShutter.addWidget(self.hSliderShutter)
hboxShutter.addWidget(self.shutterBox)
vboxShutter.addLayout(hboxShutter)
vboxShutter.setSizeConstraint(QtGui.QLayout.SetFixedSize)
vboxShutter.setContentsMargins(5, 5, 0, 0)
self.widgetShutter=QWidget(self)
self.widgetShutter.setLayout(vboxShutter)
self.dockShutter=QDockWidget(self)
self.dockShutter.setWidget(self.widgetShutter)
self.labelGain=QLabel('Gain')
self.labelGain.setStyleSheet('font :bold 10pt')
self.labelGain.setMaximumWidth(120)
self.labelGain.setAlignment(Qt.AlignCenter)
self.hSliderGain=QSlider(Qt.Horizontal)
self.hSliderGain.setMaximumWidth(80)
self.gainBox=QSpinBox()
self.gainBox.setMaximumWidth(60)
self.gainBox.setStyleSheet('font :bold 8pt')
self.gainBox.setMaximumWidth(120)
hboxGain=QHBoxLayout()
hboxGain.setContentsMargins(5, 0, 0, 0)
hboxGain.setSpacing(10)
vboxGain=QVBoxLayout()
vboxGain.setSpacing(0)
vboxGain.addWidget(self.labelGain)
hboxGain.addWidget(self.hSliderGain)
hboxGain.addWidget(self.gainBox)
vboxGain.addLayout(hboxGain)
vboxGain.setSizeConstraint(QtGui.QLayout.SetFixedSize)
vboxGain.setContentsMargins(5, 5, 0, 0)
self.widgetGain=QWidget(self)
self.widgetGain.setLayout(vboxGain)
self.dockGain=QDockWidget(self)
self.dockGain.setWidget(self.widgetGain)
# self.TrigSoft=QPushButton('Trig Soft',self)
# self.TrigSoft.setMaximumWidth(100)
# self.vbox1.addWidget(self.TrigSoft)
# self.vbox1.addStretch(1)
# self.cameraWidget.setLayout(self.vbox1)
# self.cameraWidget.setMinimumSize(150,200)
# self.cameraWidget.setMaximumSize(200,900)
hMainLayout=QHBoxLayout()
if self.light==False:
#from visu.visual2 import SEE
from visu import SEE2
self.visualisation=SEE2(name=self.nbcam,**self.kwds) ## Widget for visualisation and tools self.confVisu permet d'avoir plusieurs camera et donc plusieurs fichier ini de visualisation
self.visualisation.setWindowTitle('Visualization '+ self.cameraType+" " + self.ccdName+' v.'+ self.version)
if self.separate==True:
print('ici')
self.vbox2=QVBoxLayout()
self.vbox2.addWidget(self.visualisation)
if self.aff=='left':
hMainLayout.addLayout(self.vbox2)
hMainLayout.addWidget(self.cameraWidget)
else :
hMainLayout.addWidget(self.cameraWidget)
hMainLayout.addLayout(self.vbox2)
else:
self.dockControl.setTitleBarWidget(QWidget()) # to avoid tittle
#self.dockControl.setFeatures(QDockWidget.DockWidgetMovable)
self.visualisation.addDockWidget(Qt.TopDockWidgetArea,self.dockControl)
self.dockTrig.setTitleBarWidget(QWidget())
self.visualisation.addDockWidget(Qt.TopDockWidgetArea,self.dockTrig)
self.dockShutter.setTitleBarWidget(QWidget())
self.visualisation.addDockWidget(Qt.TopDockWidgetArea,self.dockShutter)
self.dockGain.setTitleBarWidget(QWidget())
self.visualisation.addDockWidget(Qt.TopDockWidgetArea,self.dockGain)
hMainLayout.addWidget(self.visualisation)
else:
from visu import SEELIGHT
self.visualisation=SEELIGHT(confpath=self.confPath,name=self.nbcam,**self.kwds)
self.visualisation.hbox0.addWidget(self.cameraWidget)
hMainLayout.addWidget(self.visualisation)
self.setLayout(hMainLayout)
self.setContentsMargins(0, 0, 0, 0)
#self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # set window on the top
#self.activateWindow()
#self.raise_()
#self.showNormal()
def actionButton(self):
'''action when button are pressed
'''
self.runButton.clicked.connect(self.acquireMultiImage)
self.snapButton.clicked.connect(self.acquireOneImage)
self.stopButton.clicked.connect(self.stopAcq)
self.shutterBox.editingFinished.connect(self.shutter)
self.hSliderShutter.sliderReleased.connect(self.mSliderShutter)
self.gainBox.editingFinished.connect(self.gain)
self.hSliderGain.sliderReleased.connect(self.mSliderGain)
self.trigg.currentIndexChanged.connect(self.trigger)
self.CAM.newData.connect(self.Display)#,QtCore.Qt.DirectConnection)
# self.TrigSoft.clicked.connect(self.softTrigger)
def oneImage(self):
#self.nbShot=1
self.acquireOneImage()
def nbShotAction(self):
'''
number of snapShot
'''
nbShot, ok=QInputDialog.getInt(self,'Number of SnapShot ','Enter the number of snapShot ')
if ok:
self.nbShot=int(nbShot)
if self.nbShot<=0:
self.nbShot=1
def wait(self,seconds):
time_end=time.time()+seconds
while time.time()<time_end:
QtGui.QApplication.processEvents()
def Display(self,data):
'''Display data with visualisation module
'''
if self.multi==True:
self.wait(0.1)
self.data=data#np.rot90(data,1)
self.visualisation.newDataReceived(self.data)
self.imageReceived=True
self.datareceived.emit(True)
if self.CAM.camIsRunnig==False:
self.stopAcq()
def shutter (self):
'''
set exposure time
'''
sh=self.shutterBox.value() #
self.hSliderShutter.setValue(sh) # set value of slider
time.sleep(0.1)
self.CAM.setExposure(sh) # Set shutter CCD in ms
self.conf.setValue(self.nbcam+"/shutter",float(sh))
self.CAM.camParameter["exposureTime"]=sh
self.conf.sync()
def mSliderShutter(self): # for shutter slider
sh=self.hSliderShutter.value()
self.shutterBox.setValue(sh) #
self.CAM.setExposure(sh) # Set shutter CCD in ms
self.conf.setValue(self.nbcam+"/shutter",float(sh))
self.CAM.camParameter["exposureTime"]=sh
# self.conf.sync()
def gain (self):
'''
set gain
'''
g=self.gainBox.value() #
self.hSliderGain.setValue(g) # set slider value
time.sleep(0.1)
self.CAM.setGain(g)
self.conf.setValue(self.nbcam+"/gain",float(g))
self.conf.sync()
def mSliderGain(self):
'''
set slider
'''
g=self.hSliderGain.value()
self.gainBox.setValue(g) # set valeur de la box
time.sleep(0.1)
self.CAM.setGain(g)
self.conf.setValue(self.nbcam+"/gain",float(g))
self.conf.sync()
def trigger(self):
''' select trigger mode
trigger on
trigger off
'''
self.itrig=self.trigg.currentIndex()
if self.itrig==1:
self.CAM.setTrigger("on")
else :
self.CAM.setTrigger("off")
def acquireOneImage(self):
'''Start on acquisition
'''
self.imageReceived=False
self.runButton.setEnabled(False)
self.runButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: gray ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconPlay,self.iconPlay))
self.snapButton.setEnabled(False)
self.snapButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: gray ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color:gray}"%(self.iconSnap,self.iconSnap))
self.stopButton.setEnabled(True)
self.stopButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: transparent ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconStop,self.iconStop) )
self.trigg.setEnabled(False)
self.CAM.startOneAcq(self.nbShot)
def acquireMultiImage(self):
'''
start the acquisition thread
'''
self.runButton.setEnabled(False)
self.runButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: gray ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconPlay,self.iconPlay))
self.snapButton.setEnabled(False)
self.snapButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: gray ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconSnap,self.iconSnap))
self.stopButton.setEnabled(True)
self.stopButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: transparent ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconStop,self.iconStop) )
self.trigg.setEnabled(False)
self.CAM.startAcq() # start mutli image acquisition thread
def stopAcq(self):
'''Stop acquisition
'''
if self.isConnected==True:
self.CAM.stopAcq()
self.runButton.setEnabled(True)
self.runButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: transparent ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconPlay,self.iconPlay))
self.snapButton.setEnabled(True)
self.snapButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: transparent ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconSnap,self.iconSnap))
self.stopButton.setEnabled(False)
self.stopButton.setStyleSheet("QToolButton:!pressed{border-image: url(%s);background-color: gray ;border-color: gray;}""QToolButton:pressed{image: url(%s);background-color: gray ;border-color: gray}"%(self.iconStop,self.iconStop) )
self.trigg.setEnabled(True)
def close(self):
if self.isConnected==True:
self.CAM.closeCamera()
def closeEvent(self,event):
''' closing window event (cross button)
'''
if self.isConnected==True:
self.stopAcq()
time.sleep(0.1)
self.close()
if __name__ == "__main__":
appli = QApplication(sys.argv)
appli.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
pathVisu='C:/Users/loa/Desktop/Python/camera/confCamera.ini'
e = CAMERA(cam='cam10',fft='off',meas='on',affLight=False,aff='left',separate=False,multi=False,confpath=pathVisu)
e.show()
# x= CAMERA(cam="cam2",fft='off',meas='on',affLight=True,multi=False)
# x.show()
appli.exec_()