Skip to content

Commit 97b6c3a

Browse files
committed
I04_1-156: moved some overlays to utils
1 parent 87761c9 commit 97b6c3a

File tree

7 files changed

+44
-29
lines changed

7 files changed

+44
-29
lines changed

dls_barcode/camera/camera_scanner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
import queue
66

77
# TODO: tidy up
8-
from dls_util.image import Image, Color
8+
from dls_util.image import Image
99
from dls_util import Beeper
1010
from dls_util.message import MessageType, Message
1111
from dls_barcode.scan import GeometryScanner, SlotScanner, OpenScanner
1212
from dls_barcode.datamatrix import DataMatrix
13-
from .overlay import PlateOverlay, TextOverlay
1413
from .capture_worker import CaptureWorker
1514
from .camera_position import CameraPosition
1615
from .stream_action import StreamAction
1716
from .capture_command import CaptureCommand
17+
from .plate_overlay import PlateOverlay
1818

1919
Q_LIMIT = 1
2020
SCANNED_TAG = "Scan Complete"

dls_barcode/camera/capture_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import time
22
import queue
33

4-
from .overlay import Overlay
4+
from dls_util.image import Overlay
55
from .stream_action import StreamAction
66
from dls_util.image import Image
77
from dls_util.cv import CameraStream
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from dls_util.image import Overlay, Image, Color
2+
3+
4+
class PlateOverlay(Overlay):
5+
""" Represents an overlay that can be drawn on top of an image. Used to draw the outline of a plate
6+
on the continuous scanner camera image to highlight to the user which barcodes on the plate have
7+
already been scanned.
8+
"""
9+
def __init__(self, plate, options, lifetime=2):
10+
Overlay.__init__(self, lifetime)
11+
12+
self._plate = plate
13+
self._options = options
14+
15+
def draw_on_image(self, img):
16+
""" Draw the plate highlight to the image.
17+
"""
18+
image = Image(img)
19+
20+
# If the overlay has not expired, draw on the plate highlight and/or the status message
21+
if not self.has_expired():
22+
self._plate.draw_plate(image, Color.Blue())
23+
self._plate.draw_pins(image, self._options)

dls_barcode/gui/main_window.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from dls_barcode.camera import CameraScanner, CameraSwitch
88
from dls_util import Beeper
99
from dls_util.file import FileManager
10+
from dls_util.message import MessageType, Message
1011
from .barcode_table import BarcodeTable
1112
from .image_frame import ImageFrame
1213
from .record_table import ScanRecordTable
@@ -190,7 +191,6 @@ def _read_view_queue(self):
190191
except queue.Empty:
191192
pass
192193

193-
# todo: refactor this uglyness (above too)
194194
def _read_message_queue(self):
195195
if not self._message_queue.empty():
196196
try:
@@ -230,6 +230,7 @@ def _read_side_scan(self):
230230
def _read_top_scan(self):
231231
if self._result_queue.empty():
232232
if self._camera_switch.is_top_scan_timeout():
233+
self._message_display.display_message(Message(MessageType.INFO, "Scan timeout"))
233234
print("\n*** Scan timeout ***")
234235
self._camera_switch.restart_live_capture_from_side()
235236
return

dls_util/image/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from .color import Color
22
from .image import Image
3+
from .overlay import Overlay
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
import time
22

33
from dls_util.image import Image, Color
4+
from dls_util.object_with_lifetime import ObjectWithLifetime
45

56

6-
class Overlay:
7+
class Overlay(ObjectWithLifetime):
78
""" Abstract base class. Represents an overlay that can be drawn on top of an image. Has a specified lifetime
89
so that the overlay will only be displayed for a short time.
910
"""
1011
def __init__(self, lifetime):
11-
self._lifetime = lifetime
12-
self._start_time = time.time()
12+
ObjectWithLifetime.__init__(self, lifetime)
1313

1414
def draw_on_image(self, img):
1515
pass
1616

17-
def has_expired(self):
18-
return (time.time() - self._start_time) > self._lifetime
19-
2017

2118
class TextOverlay(Overlay):
2219
""" Represents an overlay that can be drawn on top of an image. Used to write status text messages.
@@ -40,24 +37,5 @@ def draw_on_image(self, img):
4037
centered=True, scale=2, thickness=3)
4138

4239

43-
class PlateOverlay(Overlay):
44-
""" Represents an overlay that can be drawn on top of an image. Used to draw the outline of a plate
45-
on the continuous scanner camera image to highlight to the user which barcodes on the plate have
46-
already been scanned.
47-
"""
48-
def __init__(self, plate, options, lifetime=2):
49-
Overlay.__init__(self, lifetime)
50-
51-
self._plate = plate
52-
self._options = options
53-
54-
def draw_on_image(self, img):
55-
""" Draw the plate highlight to the image.
56-
"""
57-
image = Image(img)
5840

59-
# If the overlay has not expired, draw on the plate highlight and/or the status message
60-
if not self.has_expired():
61-
self._plate.draw_plate(image, Color.Blue())
62-
self._plate.draw_pins(image, self._options)
6341

dls_util/object_with_lifetime.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import time
2+
3+
4+
class ObjectWithLifetime:
5+
""" Abstract base class. Has a specified lifetime.
6+
"""
7+
def __init__(self, lifetime):
8+
self._lifetime = lifetime
9+
self._start_time = time.time()
10+
11+
def has_expired(self):
12+
return (time.time() - self._start_time) > self._lifetime

0 commit comments

Comments
 (0)