Skip to content

Commit 7d0074f

Browse files
Merge pull request #72 from DiamondLightSource/countdown
Countdown
2 parents daa75fd + edf5f66 commit 7d0074f

File tree

4 files changed

+78
-12
lines changed

4 files changed

+78
-12
lines changed

dls_barcode/gui/countdown_box.py

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
RED = "; color: red"
77
BLACK = "; color: black"
8-
BASIC_STYLE_SHEET = "font-size: 14pt"
8+
BASIC_STYLE_SHEET = "font-size: 20pt"
99

1010

1111
class MessageBox(QGroupBox):

dls_barcode/main_manager.py

Lines changed: 6 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,21 +51,25 @@ 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)
5858
self._camera_switch = CameraSwitch(self._camera_scanner, self._config.top_camera_timeout)
5959
self._restart_live_capture_from_side()
60+
self._ui.resetCountdown()
6061

6162
def _camera_capture_alive(self):
6263
return self._camera_scanner is not None and self._camera_switch is not None
6364

6465
def _restart_live_capture_from_top(self):
6566
self._camera_switch.restart_live_capture_from_top()
67+
self._ui.startCountdown(self._config.top_camera_timeout.value())
6668

6769
def _restart_live_capture_from_side(self):
6870
self._reset_msg_timer()
6971
self._camera_switch.restart_live_capture_from_side()
72+
self._ui.resetCountdown()
7073

7174
def _read_message_queue(self):
7275
if self._message_queue.empty():

0 commit comments

Comments
 (0)