Skip to content

Commit d588fc6

Browse files
committed
I04_1:399 add scan countdown to the gui
A new countdown box added to the gui next to the information box. It shows the time left to the timeout in seconds. It updates every second. It is cleared as soon as the scan is stopped. It starts with top camera scanner.
1 parent 4699501 commit d588fc6

File tree

3 files changed

+69
-11
lines changed

3 files changed

+69
-11
lines changed

dls_barcode/gui/countdown_box.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from PyQt5 import QtCore
2+
from PyQt5.QtWidgets import QLabel, QGroupBox, QVBoxLayout
3+
4+
BLACK = "; color: black"
5+
BASIC_STYLE_SHEET = "font-size: 25pt"
6+
7+
8+
class CountdownBox(QGroupBox):
9+
"""GUI component. Displays countdown for the user."""
10+
11+
def __init__(self):
12+
super(CountdownBox, self).__init__()
13+
14+
self.setTitle("Countdown")
15+
self.setMaximumHeight(100)
16+
self.setMaximumWidth(100)
17+
self._init_ui()
18+
self.count = None
19+
20+
def _init_ui(self):
21+
self._message_lbl = QLabel()
22+
self._message_lbl.setStyleSheet(BASIC_STYLE_SHEET + BLACK)
23+
self._message_lbl.setAlignment(QtCore.Qt.AlignCenter)
24+
vbox = QVBoxLayout()
25+
vbox.addWidget(self._message_lbl)
26+
vbox.addStretch()
27+
self.setLayout(vbox)
28+
29+
def start_countdown(self, count):
30+
self.count = count
31+
self._timer = QtCore.QTimer()
32+
self._timer.timeout.connect(self.display)
33+
self._timer.start(1000)
34+
35+
def reset_countdown(self):
36+
self._message_lbl.clear()
37+
self.count = None
38+
39+
def display(self):
40+
self._message_lbl.clear()
41+
if self.count is not None and self.count >= 0:
42+
self._message_lbl.setText(str(self.count))
43+
self.count = self.count - 1

dls_barcode/gui/main_window.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
import sys
21
from PyQt5 import QtWidgets, QtGui
32

43
from dls_barcode.config import BarcodeConfigDialog
5-
64
from dls_barcode.gui.scan_button import ScanButton
7-
85
from .barcode_table import BarcodeTable
6+
from .countdown_box import CountdownBox
97
from .image_frame import ImageFrame
10-
from .record_table import ScanRecordTable
8+
from .menu_bar import MenuBar
119
from .message_box import MessageBox
1210
from .message_factory import MessageFactory
13-
from .menu_bar import MenuBar
11+
from .record_table import ScanRecordTable
1412

1513

1614
class DiamondBarcodeMainWindow(QtWidgets.QMainWindow):
1715
""" Main GUI window for the Barcode Scanner App.
1816
"""
1917

2018
def __init__(self, config, version, flags, *args, **kwargs):
21-
#super(DiamondBarcodeMainWindow, self).__init__(None, None)
2219

2320
super().__init__(flags, *args, **kwargs)
2421
self._config = config
@@ -32,6 +29,7 @@ def __init__(self, config, version, flags, *args, **kwargs):
3229
self._barcode_table = None
3330
self._image_frame = None
3431
self._scan_button = None
32+
self._countdown_box = None
3533

3634
self._init_ui()
3735

@@ -61,6 +59,9 @@ def _init_ui(self):
6159
# Message display
6260
self._message_box = MessageBox()
6361

62+
# Count down display
63+
self._countdown_box = CountdownBox()
64+
6465
# Create layout
6566

6667
hbox = QtWidgets.QHBoxLayout()
@@ -75,7 +76,14 @@ def _init_ui(self):
7576

7677
img_vbox = QtWidgets.QVBoxLayout()
7778
img_vbox.addWidget(self._image_frame)
78-
img_vbox.addWidget(self._message_box)
79+
80+
msg_hbox = QtWidgets.QHBoxLayout()
81+
msg_hbox.setSpacing(10)
82+
msg_hbox.addWidget(self._message_box)
83+
msg_hbox.addWidget(self._countdown_box)
84+
85+
img_vbox.addLayout(msg_hbox)
86+
7987
hbox.addLayout(img_vbox)
8088

8189
vbox = QtWidgets.QVBoxLayout()
@@ -104,7 +112,6 @@ def _to_run_on_table_clicked(self):
104112
def _on_about_action_clicked(self):
105113
QtWidgets.QMessageBox.about(self, 'About', "Version: " + self._version)
106114

107-
108115
def _on_scan_action_clicked(self):
109116
print("MAIN: Scan menu clicked")
110117
if not self._camera_capture_alive():
@@ -142,3 +149,9 @@ def addRecordFrame(self, latest_holder_barcode, plate, latest_holder_image, pins
142149

143150
def isLatestHolderBarcode(self, holder_barcode):
144151
return self._record_table.is_latest_holder_barcode(holder_barcode)
152+
153+
def startCountdown(self, count):
154+
self._countdown_box.start_countdown(count)
155+
156+
def resetCountdown(self):
157+
self._countdown_box.reset_countdown()

dls_barcode/main_manager.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
21
import multiprocessing
32
import queue
43
import time
4+
55
from PyQt5 import QtCore
6-
from dls_barcode.camera import CameraScanner, CameraSwitch, NoNewBarcodeMessage, ScanErrorMessage
76

7+
from dls_barcode.camera import CameraScanner, CameraSwitch, NoNewBarcodeMessage, ScanErrorMessage
88
from dls_util import Beeper
99

1010
RESULT_TIMER_PERIOD = 1000 # ms
@@ -27,7 +27,6 @@ def __init__(self, ui, config):
2727
self._result_queue = multiprocessing.Queue()
2828
self._view_queue = multiprocessing.Queue()
2929
self._message_queue = multiprocessing.Queue()
30-
#self._reset_msg_timer()
3130
# initialise all actions
3231
self._ui.set_actions_triger(self._cleanup, self.initialise_scanner, self._camera_capture_alive)
3332

@@ -52,6 +51,7 @@ def _cleanup(self):
5251
self._camera_scanner.kill()
5352
self._camera_scanner = None
5453
self._camera_switch = None
54+
self._ui.resetCountdown()
5555

5656
def initialise_scanner(self):
5757
self._camera_scanner = CameraScanner(self._result_queue, self._view_queue, self._message_queue, self._config)
@@ -63,9 +63,11 @@ def _camera_capture_alive(self):
6363

6464
def _restart_live_capture_from_top(self):
6565
self._camera_switch.restart_live_capture_from_top()
66+
self._ui.startCountdown(self._config.top_camera_timeout.value())
6667

6768
def _restart_live_capture_from_side(self):
6869
self._reset_msg_timer()
70+
self._ui.resetCountdown()
6971
self._camera_switch.restart_live_capture_from_side()
7072

7173
def _read_message_queue(self):

0 commit comments

Comments
 (0)