15
15
from PyQt6 .QtCore import QTimer
16
16
from dataclasses import asdict
17
17
18
- from config .config import ffmpeg_config , paths_config
19
- from .utility import CameraSettingsConfig , find_all_cameras , load_saved_setups , load_camera_dict , init_camera_api , get_valid_supported_encoder_formats
20
- from .preview_dialog import CameraPreviewDialog
18
+ from config .config import ffmpeg_config , paths_config , default_camera_config
19
+ from .utility import (
20
+ CameraSettingsConfig ,
21
+ find_all_cameras ,
22
+ load_saved_setups ,
23
+ load_camera_dict ,
24
+ init_camera_api ,
25
+ get_valid_supported_encoder_formats ,
26
+ )
27
+ from .preview_dialog import CameraPreviewWidget
21
28
22
29
23
30
class CamerasTab (QWidget ):
@@ -61,6 +68,11 @@ def tab_selected(self):
61
68
def tab_deselected (self ):
62
69
"""Called when tab deselected."""
63
70
self .refresh_timer .stop ()
71
+ # Deinitialise all camera apis on tab being deselected
72
+ for unique_id in self .setups :
73
+ if self .GUI .preview_showing :
74
+ self .setups [unique_id ].close_preview_camera ()
75
+ self .setups [unique_id ].camera_api .stop_capturing ()
64
76
65
77
def get_saved_setups (self , unique_id : str = None , name : str = None ) -> CameraSettingsConfig :
66
78
"""Get a saved Setup_info object from a name or unique_id from self.saved_setups."""
@@ -117,11 +129,11 @@ def refresh(self):
117
129
setups_table = self .camera_table ,
118
130
name = None ,
119
131
unique_id = unique_id ,
120
- fps = "30" ,
121
- pxl_fmt = "Mono8" ,
122
- downsampling_factor = 1 ,
123
- exposure_time = 15000 ,
124
- gain = 0 ,
132
+ fps = default_camera_config [ "fps" ] ,
133
+ pxl_fmt = default_camera_config [ "pxl_fmt" ] ,
134
+ downsampling_factor = default_camera_config [ "downsampling_factor" ] ,
135
+ exposure_time = default_camera_config [ "exposure_time" ] ,
136
+ gain = default_camera_config [ "gain" ] ,
125
137
)
126
138
127
139
self .update_saved_setups (self .setups [unique_id ])
@@ -196,7 +208,17 @@ def remove(self, unique_id):
196
208
class Camera_table_item :
197
209
"""Class representing single camera in the Camera Tab table."""
198
210
199
- def __init__ (self , setups_table , name , unique_id , fps , exposure_time , gain , pxl_fmt , downsampling_factor ):
211
+ def __init__ (
212
+ self ,
213
+ setups_table ,
214
+ name ,
215
+ unique_id ,
216
+ fps ,
217
+ exposure_time ,
218
+ gain ,
219
+ pxl_fmt ,
220
+ downsampling_factor ,
221
+ ):
200
222
self .setups_table = setups_table
201
223
self .setups_tab = setups_table .setups_tab
202
224
self .GUI = self .setups_tab .GUI
@@ -211,6 +233,7 @@ def __init__(self, setups_table, name, unique_id, fps, exposure_time, gain, pxl_
211
233
self .label = self .label if self .label is not None else self .unique_id
212
234
self .GUI .preview_showing = False
213
235
self .camera_api = init_camera_api (_id = self .unique_id )
236
+
214
237
# Name edit
215
238
self .name_edit = QLineEdit ()
216
239
if self .label :
@@ -232,6 +255,7 @@ def __init__(self, setups_table, name, unique_id, fps, exposure_time, gain, pxl_
232
255
self .fps = str (self .fps [0 ])
233
256
self .fps_edit .setValue (int (self .fps ))
234
257
self .fps_edit .valueChanged .connect (self .camera_fps_changed )
258
+ self .fps_edit .setEnabled (False )
235
259
236
260
# Exposure time edit
237
261
self .exposure_time_edit = QSpinBox ()
@@ -241,6 +265,8 @@ def __init__(self, setups_table, name, unique_id, fps, exposure_time, gain, pxl_
241
265
if self .exposure_time :
242
266
self .exposure_time_edit .setValue (int (self .exposure_time ))
243
267
self .exposure_time_edit .valueChanged .connect (self .camera_exposure_time_changed )
268
+ self .exposure_time_edit .setEnabled (False )
269
+
244
270
# Gain edit
245
271
self .gain_edit = QSpinBox ()
246
272
self .gain_edit .setRange (* self .camera_api .get_gain_range ())
@@ -290,7 +316,7 @@ def camera_fps_changed(self):
290
316
self .setups_tab .update_saved_setups (setup = self )
291
317
if self .GUI .preview_showing is True :
292
318
self .setups_tab .camera_preview .camera_api .set_frame_rate (self .fps )
293
- # reset the range of the exposure time
319
+
294
320
self .exposure_time_edit .setRange (* self .camera_api .get_exposure_time_range ())
295
321
296
322
def camera_pxl_fmt_changed (self ):
@@ -325,13 +351,23 @@ def camera_downsampling_factor(self):
325
351
def open_preview_camera (self ):
326
352
"""Button to preview the camera in the row"""
327
353
if self .GUI .preview_showing :
328
- self .setups_tab .camera_preview .close ()
329
- self .GUI .preview_showing = False
330
- self .setups_tab .camera_preview = CameraPreviewDialog (gui = self .GUI , unique_id = self .unique_id )
354
+ self .close_preview_camera ()
355
+ self .setups_tab .camera_preview = CameraPreviewWidget (
356
+ gui = self .GUI , camera_table_item = self , unique_id = self .unique_id
357
+ ) # camera_api=self.camera_api)
331
358
self .setups_tab .page_layout .addWidget (self .setups_tab .camera_preview )
332
359
self .GUI .preview_showing = True
333
- # refresh timer off
334
-
360
+
361
+ self .fps_edit .setEnabled (self .GUI .preview_showing )
362
+ self .exposure_time_edit .setEnabled (self .GUI .preview_showing )
363
+
364
+ def close_preview_camera (self ):
365
+ self .setups_tab .camera_preview .close ()
366
+ self .GUI .preview_showing = False
367
+
368
+ self .fps_edit .setEnabled (self .GUI .preview_showing )
369
+ self .exposure_time_edit .setEnabled (self .GUI .preview_showing )
370
+
335
371
def getCameraSettingsConfig (self ):
336
372
"""Get the camera settings config datastruct from the setups table."""
337
373
return CameraSettingsConfig (
0 commit comments