Skip to content

Commit

Permalink
Merge pull request #3 from computerlyrik/add-device-detection-error
Browse files Browse the repository at this point in the history
Add and catch DeviceDetectionError
  • Loading branch information
tomers authored Jan 20, 2024
2 parents 9aa2738 + 3a26d89 commit d207208
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/dymoprint/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from usb.core import NoBackendError, USBError

from dymoprint.lib.constants import DEFAULT_MARGIN_PX, ICON_DIR
from dymoprint.lib.detect import detect_device
from dymoprint.lib.detect import DeviceDetectionError, detect_device
from dymoprint.lib.dymo_print_engines import DymoRenderEngine, print_label

from .q_dymo_labels_list import QDymoLabelList
Expand Down Expand Up @@ -194,7 +194,7 @@ def check_status(self):
try:
self.detected_device = detect_device()
is_enabled = True
except (NoBackendError, USBError) as e:
except (DeviceDetectionError, NoBackendError, USBError) as e:
self.error_label.setText(f"Error: {e}")
self.detected_device = None
self.error_label.setVisible(not is_enabled)
Expand Down
6 changes: 5 additions & 1 deletion src/dymoprint/lib/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def device_info(dev: usb.core.Device) -> str:
return res


class DeviceDetectionError(RuntimeError):
pass


def detect_device() -> DetectedDevice:
dymo_devs = list(usb.core.find(idVendor=DEV_VENDOR, find_all=True))
if len(dymo_devs) == 0:
Expand All @@ -57,7 +61,7 @@ def detect_device() -> DetectedDevice:
f"- Vendor ID: {hex(dev.idVendor):6} "
f"Product ID: {hex(dev.idProduct)}"
)
die("Unable to open device.")
raise DeviceDetectionError("No Dymo devices found.")
if len(dymo_devs) > 1:
print("Found multiple Dymo devices:")
for dev in dymo_devs:
Expand Down

0 comments on commit d207208

Please sign in to comment.