66
77from dls_barcode .config import BarcodeConfig , BarcodeConfigDialog
88from dls_barcode .camera import CameraScanner , CameraSwitch , NoNewBarcodeMessage
9+ from dls_barcode .gui .scan_button import ScanButton
910from dls_util import Beeper
1011from dls_util .file import FileManager
1112from .barcode_table import BarcodeTable
1213from .image_frame import ImageFrame
1314from .record_table import ScanRecordTable
1415from .message_box import MessageBox
1516from .message_factory import MessageFactory
17+ from .menu_bar import MenuBar
1618
17-
18- RESULT_TIMER_PERIOD = 1000 # ms
19- VIEW_TIMER_PERIOD = 1 # ms
20- MESSAGE_TIMER_PERIOD = 1 # ms
19+ RESULT_TIMER_PERIOD = 1000 # ms
20+ VIEW_TIMER_PERIOD = 1 # ms
21+ MESSAGE_TIMER_PERIOD = 1 # ms
2122
2223
2324class DiamondBarcodeMainWindow (QtGui .QMainWindow ):
@@ -33,6 +34,7 @@ def __init__(self, config_file, version):
3334 self ._record_table = None
3435 self ._barcode_table = None
3536 self ._image_frame = None
37+ self ._scan_button = None
3638
3739 # Scan elements
3840 self ._camera_scanner = None
@@ -71,29 +73,35 @@ def _init_ui(self):
7173 self .setWindowTitle ('Diamond Puck Barcode Scanner' )
7274 self .setWindowIcon (self ._window_icon )
7375
74- self .init_menu_bar ()
76+ self ._menu_bar = MenuBar (self .menuBar (), self ._version , self ._cleanup , self ._on_options_action_clicked ,
77+ self ._on_about_action_clicked , self ._exit_icon , self ._config_icon , self ._about_icon )
7578
7679 # Barcode table - lists all the barcodes in a record
7780 self ._barcode_table = BarcodeTable (self ._config )
7881
82+ # Scan button - start/stop scan
83+ self ._scan_button = ScanButton ('Start/stop scan' , self ._stop_capture_icon , self ._start_capture_icon ,
84+ self ._on_scan_action_clicked )
85+
7986 # Image frame - displays image of the currently selected scan record
80- self ._image_frame = ImageFrame (500 , 500 , "Plate Image" )
87+ self ._image_frame = ImageFrame ("Plate Image" )
8188
8289 # Scan record table - lists all the records in the store
83- self ._record_table = ScanRecordTable (self ._barcode_table , self ._image_frame , self ._config , self .on_record_table_clicked )
90+ self ._record_table = ScanRecordTable (self ._barcode_table , self ._image_frame , self ._config , self ._cleanup )
8491
8592 # Message display
8693 self ._message_box = MessageBox ()
87- self ._message_box .setFixedHeight (64 )
88-
89- # Open options first to make sure the cameras are set up correctly.
90- # Start live capture of the side as soon as the dialog box is closed
91- self ._open_options_dialog ()
9294
9395 # Create layout
96+
9497 hbox = QtGui .QHBoxLayout ()
9598 hbox .setSpacing (10 )
96- hbox .addWidget (self ._record_table )
99+
100+ table_vbox = QtGui .QVBoxLayout ()
101+ table_vbox .addWidget (self ._record_table )
102+ table_vbox .addWidget (self ._scan_button )
103+
104+ hbox .addLayout (table_vbox )
97105 hbox .addWidget (self ._barcode_table )
98106
99107 img_vbox = QtGui .QVBoxLayout ()
@@ -113,74 +121,26 @@ def _init_ui(self):
113121 def _init_icons (self ):
114122 self ._window_icon = QtGui .QIcon ("..\\ resources\\ icons\\ qr_code_32.png" )
115123 self ._start_capture_icon = self .style ().standardIcon (QtGui .QStyle .SP_MediaPlay )
124+ self ._stop_capture_icon = self .style ().standardIcon (QtGui .QStyle .SP_MediaStop )
116125 self ._exit_icon = self .style ().standardIcon (QtGui .QStyle .SP_DialogCloseButton )
117126 self ._config_icon = self .style ().standardIcon (QtGui .QStyle .SP_FileDialogDetailedView )
118127 self ._about_icon = self .style ().standardIcon (QtGui .QStyle .SP_FileDialogInfoView )
119128
120- def init_menu_bar (self ):
121- """Create and populate the menu bar.
122- """
123- # Continuous scanner mode
124- live_action = QtGui .QAction (self ._start_capture_icon , '&Camera Capture' , self )
125- live_action .setShortcut ('Ctrl+W' )
126- live_action .setStatusTip ('Capture continuously from camera' )
127- live_action .triggered .connect (self ._on_scan_action_clicked )
128-
129- # Exit Application
130- exit_action = QtGui .QAction (self ._exit_icon , '&Exit' , self )
131- exit_action .setShortcut ('Ctrl+Q' )
132- exit_action .setStatusTip ('Exit application' )
133- exit_action .triggered .connect (self ._cleanup )
134- exit_action .triggered .connect (QtGui .qApp .quit )
135-
136- # Open options dialog
137- options_action = QtGui .QAction (self ._config_icon , '&Config' , self )
138- options_action .setShortcut ('Ctrl+O' )
139- options_action .setStatusTip ('Open Options Dialog' )
140- options_action .triggered .connect (self ._on_options_action_clicked )
141-
142- # Show version number
143- about_action = QtGui .QAction (self ._about_icon , "About" , self )
144- about_action .triggered .connect (self ._on_about_action_clicked )
145-
146- # Create menu bar
147- menu_bar = self .menuBar ()
148- file_menu = menu_bar .addMenu ('&File' )
149- file_menu .addAction (exit_action )
150-
151- scan_menu = menu_bar .addMenu ('&Scan' )
152- scan_menu .addAction (live_action )
153-
154- option_menu = menu_bar .addMenu ('&Options' )
155- option_menu .addAction (options_action )
156-
157- help_menu = menu_bar .addMenu ('?' )
158- help_menu .addAction (about_action )
159-
160129 def _on_about_action_clicked (self ):
161130 QtGui .QMessageBox .about (self , 'About' , "Version: " + self ._version )
162131
163132 def _on_scan_action_clicked (self ):
164133 print ("MAIN: Scan menu clicked" )
165134 if not self ._camera_capture_alive ():
166135 self ._initialise_scanner ()
167-
168- self ._restart_live_capture_from_side ()
136+ self ._restart_live_capture_from_side ()
137+ else :
138+ self ._cleanup ()
169139
170140 def _on_options_action_clicked (self ):
171- result_ok = self ._open_options_dialog ()
172- if not result_ok :
173- return
174-
175- self ._cleanup ()
176- self ._initialise_scanner ()
177- self ._restart_live_capture_from_side ()
178-
179- def _open_options_dialog (self ):
180- dialog = BarcodeConfigDialog (self ._config , self ._before_test_camera )
141+ dialog = BarcodeConfigDialog (self ._config , self ._cleanup )
181142 dialog .setWindowIcon (self ._config_icon )
182- result_ok = dialog .exec_ ()
183- return result_ok
143+ dialog .exec_ ()
184144
185145 def closeEvent (self , event ):
186146 """This overrides the method from the base class.
@@ -195,19 +155,12 @@ def _cleanup(self):
195155 self ._camera_scanner .kill ()
196156 self ._camera_scanner = None
197157 self ._camera_switch = None
158+ self ._scan_button .setStartLayout ()
198159
199160 def _initialise_scanner (self ):
200161 self ._camera_scanner = CameraScanner (self ._result_queue , self ._view_queue , self ._message_queue , self ._config )
201162 self ._camera_switch = CameraSwitch (self ._camera_scanner , self ._config .top_camera_timeout )
202163
203- def on_record_table_clicked (self ):
204- if self ._camera_capture_alive ():
205- self ._camera_switch .stop_live_capture ()
206-
207- def _before_test_camera (self ):
208- # We need to stop the cameras otherwise the Test Camera button won't be able to open them
209- self ._cleanup ()
210-
211164 def _camera_capture_alive (self ):
212165 return self ._camera_scanner is not None and self ._camera_switch is not None
213166
@@ -242,17 +195,17 @@ def _read_message_queue(self):
242195 self ._message_box .display (MessageFactory .from_scanner_message (scanner_msg ))
243196
244197 def _reset_msg_timer (self ):
245- self ._duplicate_record_msg_timer = None
198+ self ._record_msg_timer = None
246199
247200 def _start_msg_timer (self ):
248- self ._duplicate_record_msg_timer = time .time ()
201+ self ._record_msg_timer = time .time ()
249202
250203 def _msg_timer_is_running (self ):
251- return self ._duplicate_record_msg_timer is not None
204+ return self ._record_msg_timer is not None
252205
253206 def _has_msg_timer_timeout (self ):
254207 timeout = 2 * RESULT_TIMER_PERIOD / 1000
255- return self ._msg_timer_is_running () and time .time () - self ._duplicate_record_msg_timer > timeout
208+ return self ._msg_timer_is_running () and time .time () - self ._record_msg_timer > timeout
256209
257210 def _read_result_queue (self ):
258211 """ Called every second; read any new results from the scan results queue, store them and display them.
@@ -314,4 +267,4 @@ def _restart_live_capture_from_top(self):
314267 def _restart_live_capture_from_side (self ):
315268 self ._reset_msg_timer ()
316269 self ._camera_switch .restart_live_capture_from_side ()
317-
270+ self . _scan_button . setStopLayout ()
0 commit comments