Skip to content

Commit fd6b4fc

Browse files
Merge pull request #76 from DiamondLightSource/I04-413_scan_completed_test
I04 413 scan completed test
2 parents 6859ce5 + fd5e0ed commit fd6b4fc

File tree

8 files changed

+104
-18
lines changed

8 files changed

+104
-18
lines changed

dls_barcode/camera/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .camera_switch import CameraSwitch
22
from .camera_scanner import CameraScanner
3-
from .scanner_message import NoNewBarcodeMessage, ScanErrorMessage
3+
from .scanner_message import NoNewBarcodeMessage, ScanErrorMessage, NoNewPuckBarcodeMessage

dls_barcode/camera/scanner_message.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ class NoNewBarcodeMessage:
22
pass
33

44

5+
class NoNewPuckBarcodeMessage:
6+
pass
7+
8+
59
class ScanErrorMessage:
610
def __init__(self, content):
711
self._content = content

dls_barcode/camera/scanner_worker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from dls_barcode.datamatrix import DataMatrix
77
from .camera_position import CameraPosition
88
from .plate_overlay import PlateOverlay
9-
from .scanner_message import NoNewBarcodeMessage, ScanErrorMessage
9+
from .scanner_message import NoNewBarcodeMessage, ScanErrorMessage, NoNewPuckBarcodeMessage
1010

1111
NO_PUCK_TIME = 2
1212

@@ -67,7 +67,10 @@ def _process_frame(self, frame, config, overlay_queue, result_queue, message_que
6767
elif scan_result.any_valid_barcodes():
6868
# We have read valid barcodes but they are not new, so the scanner didn't even output a plate
6969
self._last_puck_time = time.time()
70-
message_queue.put(NoNewBarcodeMessage()) #important used in the message logic
70+
if scan_result.geometry() is not None:
71+
message_queue.put(NoNewBarcodeMessage()) #important used in the message logic
72+
else:
73+
message_queue.put(NoNewPuckBarcodeMessage())
7174
elif scan_result.error() is not None and (time.time() - self._last_puck_time > NO_PUCK_TIME):
7275
#TODO use log
7376
message_queue.put(ScanErrorMessage(scan_result.error()))

dls_barcode/gui/main_window.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from PyQt5 import QtWidgets, QtGui
22

33
from dls_barcode.config import BarcodeConfigDialog
4+
from dls_barcode.gui.progress_bar import ProgressBox
45
from dls_barcode.gui.scan_button import ScanButton
56
from .barcode_table import BarcodeTable
67
from .countdown_box import CountdownBox
@@ -60,7 +61,8 @@ def _init_ui(self):
6061
self._message_box = MessageBox()
6162

6263
# Count down display
63-
self._countdown_box = CountdownBox()
64+
#self._countdown_box = CountdownBox()
65+
self._countdown_box = ProgressBox()
6466

6567
# Create layout
6668

@@ -135,6 +137,9 @@ def closeEvent(self, event):
135137
def displayScanCompleteMessage(self):
136138
self._message_box.display(MessageFactory.scan_completed_message())
137139

140+
def displayPuckScanCompleteMessage(self):
141+
self._message_box.display(MessageFactory.puck_scan_completed_message())
142+
138143
def displayScanErrorMessage(self, scanner_msg):
139144
self._message_box.display(MessageFactory.from_scanner_message(scanner_msg))
140145

@@ -155,3 +160,6 @@ def startCountdown(self, count):
155160

156161
def resetCountdown(self):
157162
self._countdown_box.reset_countdown()
163+
164+
def scanCompleted(self):
165+
self._countdown_box.scan_completed()

dls_barcode/gui/message_factory.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ def scan_timeout_message():
1717

1818
@staticmethod
1919
def scan_completed_message():
20-
return Message(MessageType.INFO, "Scan completed")
20+
return Message(MessageType.INFO, "Scan completed")
21+
22+
@staticmethod
23+
def puck_scan_completed_message():
24+
return Message(MessageType.INFO, "Scan completed!")

dls_barcode/gui/progress_bar.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from PyQt5 import QtCore
2+
from PyQt5.QtWidgets import QLabel, QGroupBox, QVBoxLayout, QProgressBar
3+
4+
BLACK = "; color: black"
5+
BASIC_STYLE_SHEET = "font-size: 20pt"
6+
7+
8+
class ProgressBox(QGroupBox):
9+
"""GUI component. Displays countdown for the user."""
10+
11+
def __init__(self):
12+
super(ProgressBox, self).__init__()
13+
14+
self.setTitle("Scan Completed")
15+
self.setMaximumHeight(100)
16+
self.setMaximumWidth(200)
17+
self._timer = None
18+
self._init_ui()
19+
self.count = 0
20+
21+
def _init_ui(self):
22+
self.pbar = QProgressBar(self)
23+
self.pbar.setGeometry(30, 40, 200, 25)
24+
vbox = QVBoxLayout()
25+
vbox.addWidget(self.pbar)
26+
vbox.addStretch()
27+
self.setLayout(vbox)
28+
29+
def start_countdown(self, count):
30+
self.count = 0
31+
self.pbar.setValue(self.count)
32+
self.max = count
33+
self._timer = QtCore.QTimer()
34+
self._timer.timeout.connect(self.display)
35+
self._timer.start(1000)
36+
37+
def reset_countdown(self):
38+
if self._timer is not None:
39+
self._timer.stop()
40+
self._timer = None
41+
self.count = 0
42+
self.pbar.setValue(self.count)
43+
44+
def display(self):
45+
if self.count <= self.max:
46+
self.count = self.count + 1
47+
self.pbar.setValue(100 * (self.count / self.max))
48+
49+
def scan_completed(self):
50+
self.count = 100
51+
self.pbar.setValue(self.count)

dls_barcode/main_manager.py

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
from PyQt5 import QtCore
77

8-
from dls_barcode.camera import CameraScanner, CameraSwitch, NoNewBarcodeMessage, ScanErrorMessage
8+
from dls_barcode.camera import CameraScanner, CameraSwitch, ScanErrorMessage, NoNewPuckBarcodeMessage
9+
910
from dls_util import Beeper
1011

1112
RESULT_TIMER_PERIOD = 1000 # ms
@@ -23,6 +24,7 @@ def __init__(self, ui, config):
2324
# Scan elements
2425
self._camera_scanner = None
2526
self._camera_switch = None
27+
self._scan_completed_message_flag = False
2628

2729
# Queue that holds new results generated in continuous scanning mode
2830
self._result_queue = multiprocessing.Queue()
@@ -62,7 +64,6 @@ def initialise_scanner(self):
6264
self._camera_switch = CameraSwitch(self._camera_scanner, self._config.top_camera_timeout)
6365

6466
self._restart_live_capture_from_side()
65-
self._ui.resetCountdown()
6667

6768
def _camera_capture_alive(self):
6869
return self._camera_scanner is not None and self._camera_switch is not None
@@ -78,7 +79,6 @@ def _restart_live_capture_from_side(self):
7879
log.debug("5) starting live capture form side")
7980
self._reset_msg_timer()
8081
self._camera_switch.restart_live_capture_from_side()
81-
self._ui.resetCountdown()
8282

8383
def _read_message_queue(self):
8484
if self._message_queue.empty():
@@ -93,11 +93,13 @@ def _read_message_queue(self):
9393
if not self._msg_timer_is_running():
9494
# The result queue is read at a slower rate - use a timer to give it time to process a new barcode
9595
self._start_msg_timer()
96-
elif self._has_msg_timer_timeout() and isinstance(scanner_msg, NoNewBarcodeMessage):
97-
self._ui.displayScanCompleteMessage()
96+
elif self._has_msg_timer_timeout() and isinstance(scanner_msg, NoNewPuckBarcodeMessage):
97+
self._ui.displayPuckScanCompleteMessage()
98+
self._ui.scanCompleted()
9899
elif isinstance(scanner_msg, ScanErrorMessage):
99100
self._ui.displayScanErrorMessage(scanner_msg)
100101
self._reset_msg_timer()
102+
self._ui.resetCountdown()
101103
else:
102104
self._reset_msg_timer()
103105

@@ -137,6 +139,7 @@ def _read_result_queue(self):
137139
self._read_top_scan()
138140

139141
def _read_side_scan(self):
142+
self._scan_completed_message_flag = False
140143
if self._result_queue.empty():
141144
return
142145

@@ -156,14 +159,21 @@ def _read_side_scan(self):
156159
self._restart_live_capture_from_top()
157160

158161
def _read_top_scan(self):
159-
if self._result_queue.empty():
160-
if self._camera_switch.is_top_scan_timeout():
162+
if self._camera_switch.is_top_scan_timeout():
163+
log = logging.getLogger(".".join([__name__]))
164+
extra = ({"timeout_value": 1})
165+
log = logging.LoggerAdapter(log, extra)
166+
log.info("scan timeout", extra)
167+
if self._scan_completed_message_flag:
168+
self._ui.displayScanCompleteMessage()
169+
self._ui.scanCompleted()
170+
else:
161171
self._ui.displayScanTimeoutMessage()
162-
log = logging.getLogger(".".join([__name__]))
163-
extra = ({"timeout_value": 1})
164-
log = logging.LoggerAdapter(log, extra)
165-
log.info("scan timeout", extra)
166-
self._restart_live_capture_from_side()
172+
self._ui.resetCountdown()
173+
self._restart_live_capture_from_side()
174+
return
175+
176+
if self._result_queue.empty():
167177
return
168178

169179
# Get the result
@@ -173,6 +183,7 @@ def _read_top_scan(self):
173183
self._ui.addRecordFrame(self._latest_holder_barcode, plate, self._latest_holder_image, pins_image)
174184

175185
if not plate.is_full_valid():
186+
self._scan_completed_message_flag = True
176187
return
177188

178189
# Barcodes successfully read
@@ -181,4 +192,7 @@ def _read_top_scan(self):
181192
extra = ({"scan_time": self._camera_switch.get_scan_time(), "timeout_value": 0})
182193
log = logging.LoggerAdapter(log, extra)
183194
log.info("Scan Completed", extra)
195+
self._ui.displayScanCompleteMessage()
196+
self._ui.scanCompleted()
197+
self._scan_completed_message_flag = True
184198
self._restart_live_capture_from_side()

docs/release-notes/release-notes-dev.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ Changes merged into master
55
--------------------------
66
| Jira Task | GitHub Issue | Type | Description |
77
|-----------|--------------|------|-------------|
8-
|I04_1-I04_1-415||Patch|Puck scanner - record backup functionality change|
8+
|I04_1-415 | | Patch|Puck scanner - record backup functionality change|
9+
|I04_1-413 | |Patch|Puck scanner - 'Scan completed' delay|
10+
911

1012
Change Types:
1113
* Major - Backward incompatible change

0 commit comments

Comments
 (0)