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
@@ -65,35 +67,39 @@ def __init__(self, config_file, version):
6567 def _init_ui (self ):
6668 """ Create the basic elements of the user interface.
6769 """
68- self ._init_icons ( )
70+ self ._window_icon = QtGui . QIcon ( ".. \\ resources \\ icons \\ qr_code_32.png" )
6971
7072 self .setGeometry (100 , 100 , 1020 , 650 )
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 , self . _on_about_action_clicked )
7577
7678 # Barcode table - lists all the barcodes in a record
7779 self ._barcode_table = BarcodeTable (self ._config )
7880
81+ # Scan button - start/stop scan
82+ self ._scan_button = ScanButton ('Start/stop scan' , self ._on_scan_action_clicked )
83+
7984 # Image frame - displays image of the currently selected scan record
80- self ._image_frame = ImageFrame (500 , 500 , "Plate Image" )
85+ self ._image_frame = ImageFrame ("Plate Image" )
8186
8287 # 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 )
88+ self ._record_table = ScanRecordTable (self ._barcode_table , self ._image_frame , self ._config , self ._to_run_on_table_clicked )
8489
8590 # Message display
8691 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 ()
9292
9393 # Create layout
94+
9495 hbox = QtGui .QHBoxLayout ()
9596 hbox .setSpacing (10 )
96- hbox .addWidget (self ._record_table )
97+
98+ table_vbox = QtGui .QVBoxLayout ()
99+ table_vbox .addWidget (self ._record_table )
100+ table_vbox .addWidget (self ._scan_button )
101+
102+ hbox .addLayout (table_vbox )
97103 hbox .addWidget (self ._barcode_table )
98104
99105 img_vbox = QtGui .QVBoxLayout ()
@@ -110,52 +116,9 @@ def _init_ui(self):
110116
111117 self .show ()
112118
113- def _init_icons (self ):
114- self ._window_icon = QtGui .QIcon ("..\\ resources\\ icons\\ qr_code_32.png" )
115- self ._start_capture_icon = self .style ().standardIcon (QtGui .QStyle .SP_MediaPlay )
116- self ._exit_icon = self .style ().standardIcon (QtGui .QStyle .SP_DialogCloseButton )
117- self ._config_icon = self .style ().standardIcon (QtGui .QStyle .SP_FileDialogDetailedView )
118- self ._about_icon = self .style ().standardIcon (QtGui .QStyle .SP_FileDialogInfoView )
119-
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 )
119+ def _to_run_on_table_clicked (self ):
120+ self ._cleanup ()
121+ self ._scan_button .setStartLayout ()
159122
160123 def _on_about_action_clicked (self ):
161124 QtGui .QMessageBox .about (self , 'About' , "Version: " + self ._version )
@@ -164,23 +127,16 @@ def _on_scan_action_clicked(self):
164127 print ("MAIN: Scan menu clicked" )
165128 if not self ._camera_capture_alive ():
166129 self ._initialise_scanner ()
167-
168- self ._restart_live_capture_from_side ()
130+ self ._restart_live_capture_from_side ()
131+ self ._scan_button .setDelayedStopLayout ()
132+ else :
133+ self ._cleanup ()
134+ self ._scan_button .setStartLayout ()
169135
170136 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 )
181- dialog .setWindowIcon (self ._config_icon )
182- result_ok = dialog .exec_ ()
183- return result_ok
137+ dialog = BarcodeConfigDialog (self ._config , self ._cleanup )
138+ self ._scan_button .setStartLayout ()
139+ dialog .exec_ ()
184140
185141 def closeEvent (self , event ):
186142 """This overrides the method from the base class.
@@ -200,14 +156,6 @@ def _initialise_scanner(self):
200156 self ._camera_scanner = CameraScanner (self ._result_queue , self ._view_queue , self ._message_queue , self ._config )
201157 self ._camera_switch = CameraSwitch (self ._camera_scanner , self ._config .top_camera_timeout )
202158
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-
211159 def _camera_capture_alive (self ):
212160 return self ._camera_scanner is not None and self ._camera_switch is not None
213161
@@ -242,17 +190,17 @@ def _read_message_queue(self):
242190 self ._message_box .display (MessageFactory .from_scanner_message (scanner_msg ))
243191
244192 def _reset_msg_timer (self ):
245- self ._duplicate_record_msg_timer = None
193+ self ._record_msg_timer = None
246194
247195 def _start_msg_timer (self ):
248- self ._duplicate_record_msg_timer = time .time ()
196+ self ._record_msg_timer = time .time ()
249197
250198 def _msg_timer_is_running (self ):
251- return self ._duplicate_record_msg_timer is not None
199+ return self ._record_msg_timer is not None
252200
253201 def _has_msg_timer_timeout (self ):
254202 timeout = 2 * RESULT_TIMER_PERIOD / 1000
255- return self ._msg_timer_is_running () and time .time () - self ._duplicate_record_msg_timer > timeout
203+ return self ._msg_timer_is_running () and time .time () - self ._record_msg_timer > timeout
256204
257205 def _read_result_queue (self ):
258206 """ Called every second; read any new results from the scan results queue, store them and display them.
@@ -315,3 +263,5 @@ def _restart_live_capture_from_side(self):
315263 self ._reset_msg_timer ()
316264 self ._camera_switch .restart_live_capture_from_side ()
317265
266+
267+
0 commit comments