forked from julienGautier77/camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmulticamLoop.py
190 lines (142 loc) · 5.7 KB
/
multicamLoop.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
# -*- coding: utf-8 -*-
"""
Created on Mon May 4 14:58:50 2020
@author: LOA
"""
from PyQt5.QtWidgets import QGridLayout,QVBoxLayout,QWidget,QApplication,QGroupBox,QTabWidget,QMainWindow
from PyQt5.QtWidgets import QSizePolicy,QDockWidget
from pyqtgraph.Qt import QtCore
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIcon
import sys,time
import pathlib,os
import qdarkstyle
import camera2
from PyQt5 import QtGui
class MULTICAM(QWidget):
"""
Qwidget for opening many camera in a same window
"""
def __init__(self,names=['cam1','cam2'],**kwds):
super(MULTICAM, self).__init__()
self.kwds=kwds
self.numerOfCam=len(names)
if self.numerOfCam%2 != 0: # if cam number is not odd we add one
names.append('cam=None')
self.numerOfCam=len(names)
self.names=names
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # set window on the top
self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
p = pathlib.Path(__file__)
sepa=os.sep
self.icon=str(p.parent) + sepa + 'icons' +sepa
self.setWindowIcon(QIcon(self.icon+'LOA.png'))
self.cam=[]
i=1
for cams in self.names:
if i%2!= 0:
self.cam.append(camera2.CAMERA(cam=cams,aff='left',**self.kwds))
else :
self.cam.append(camera2.CAMERA(cam=cams,aff='right',**self.kwds))
i+=1
self.setup()
self.actionButton()
def setup(self):
grid_layout = QGridLayout()
grid_layout.setVerticalSpacing(1)
grid_layout.setHorizontalSpacing(1)
self.dock=[]
for i in range(0,self.numerOfCam):
self.dock.append(QDockWidget(self))
self.dock[i].setWindowTitle(self.cam[i].ccdName)
self.dock[i].setStyleSheet("QDockWidget::title { color: purple;}")
self.dock[i].setWidget(self.cam[i])
self.dock[i].setFeatures(QDockWidget.DockWidgetFloatable)
# self.dock0.setWindowState(Qt::WindowFullScreen)
z=0
for i in range(0,int(self.numerOfCam/2)):
for j in range(0,int(self.numerOfCam/2)):
if z<self.numerOfCam:
grid_layout.addWidget(self.dock[z], i, j)
z+=1
grid_layout.setContentsMargins(0,0,0,0)
self.horizontalGroupBox=QGroupBox()
self.horizontalGroupBox.setLayout(grid_layout)
self.horizontalGroupBox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
windowLayout=QVBoxLayout()
windowLayout.addWidget(self.horizontalGroupBox)
# windowLayout.addWidget(self.resetButton)
windowLayout.setContentsMargins(1,1,1,1)
self.setContentsMargins(1,1,1,1)
self.setLayout(windowLayout)
def actionButton(self):
for dock in self.dock:
dock.topLevelChanged.connect(lambda :self.DockChanged(dock))
def DockChanged(self,dock):
self.wait(0.01)
dock.setFloating(True)
dock.showMaximized()
print('ici')
# dock.showFullScreen()
def wait(self,seconds):
time_end=time.time()+seconds
while time.time()<time_end:
QtGui.QApplication.processEvents()
def stopRun(self):
for cam in self.cam:
cam.stopAcq()
def closeAll(self):
for cam in self.cam:
cam.close()
def closeEvent(self,event):
self.stopRun()
self.closeAll()
# sys.exit(0)
event.accept()
class MainWindows(QWidget):
## Main class 3 tabs : 12 cameras
def __init__(self):
super().__init__()
self.left=100
self.top=30
self.width=1200
self.height=300
self.setGeometry(self.left,self.top,self.width,self.height)
self.setWindowTitle('Lolita Alignment' )
self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
p = pathlib.Path(__file__)
sepa=os.sep
self.icon=str(p.parent) + sepa + 'icons' +sepa
self.setWindowIcon(QIcon(self.icon+'LOA.png'))
self.setup()
self.actionButton()
def setup(self):
self.layout=QVBoxLayout(self)
self.layout.setContentsMargins(1,1,1,1)
self.setContentsMargins(1,1,1,1)
self.tabs=QTabWidget()
self.tabs.setContentsMargins(1,1,1,1)
self.tab0=MULTICAM(names=['cam0','cam1','cam2','cam3'])
self.tab1=MULTICAM(names=['cam6','cam7','cam4','cam5'])
# self.tab2=App4Cam()
self.tabs.addTab(self.tab0,' Lolita centers ')
self.tabs.addTab(self.tab1,' P3 & misc. ')
#self.tabs.addTab(self.tab2,' P3 ')
self.layout.addWidget(self.tabs)
self.setLayout(self.layout)
def changeTab(self):
# print('tab change', 'tab is',self.tabs.currentIndex())
self.tab=[self.tab0,self.tab1]
self.tab0.stopRun()
self.tab1.stopRun()
#self.tab2.stopRun()
def actionButton(self):
self.tabs.currentChanged.connect(self.changeTab)
def closeEvent(self,event):
event.accept()
if __name__=='__main__':
app=QApplication(sys.argv)
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
multiTab=MainWindows()
multiTab.show()
sys.exit(app.exec_() )