-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Device dependent margins/config #54
Changes from 3 commits
d73626d
06f61ea
3aecdc7
1872e40
1b279b3
2353512
dcc6234
040f2c2
f907b8b
d64c977
a7def5e
d8dcb3d
4fc8b68
1d36049
d8b3b6d
13fa9b9
424ec34
d342a04
1786928
16d82e8
e239867
b390217
0bdf8fd
a4ed930
fdf3538
0fa7ad5
7246473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,13 @@ | |
import array | ||
import logging | ||
import math | ||
from typing import Any | ||
|
||
import usb | ||
from PIL import Image | ||
from usb.core import NoBackendError, USBError | ||
|
||
from labelle.lib.constants import ESC, SYN | ||
from labelle.lib.constants import ESC, SUPPORTED_DEVICE_ID, SYN | ||
from labelle.lib.devices.usb_device import UsbDevice, UsbDeviceError | ||
from labelle.lib.utils import mm_to_px | ||
|
||
|
@@ -240,23 +241,81 @@ class DymoLabeler: | |
|
||
LABELER_DISTANCE_BETWEEN_PRINT_HEAD_AND_CUTTER_MM = 8.1 | ||
LABELER_PRINT_HEAD_HEIGHT_MM = 8.2 | ||
SUPPORTED_TAPE_SIZES_MM = (19, 12, 9, 6) | ||
DEFAULT_TAPE_SIZE_MM = 12 | ||
|
||
# Default supported tape sizes | ||
labeler_supported_tape_sizes: list | ||
|
||
# Default printer head size in dots | ||
labeler_print_head_width_pixels: int | ||
|
||
# Default printer margins (for each tape size) | ||
# { tapeSizeMm : (firstVisiblePixel, lastVisiblePixel) } | ||
labeler_label_vertical_margins: dict[int, Any] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering what "first" and "last" mean here regarding visible pixels. I don't know offhand which pixel ordering is being used, so it would be helpful to be more explicit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is outdated btw |
||
|
||
def __init__( | ||
self, | ||
tape_size_mm: int | None = None, | ||
device: UsbDevice | None = None, | ||
): | ||
if tape_size_mm is None: | ||
tape_size_mm = self.DEFAULT_TAPE_SIZE_MM | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this still relevant? Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really happy about this either, but the whole software kind of relies on it (also with the GUI) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed it, it now takes the highest supported size if not set. |
||
if tape_size_mm not in self.SUPPORTED_TAPE_SIZES_MM: | ||
|
||
self._device = device | ||
|
||
# --- Set options based on printer type --- | ||
if self._device is not None: | ||
if self._device.id_product == SUPPORTED_DEVICE_ID.LABELMANAGER_PC: | ||
self.labeler_print_head_width_pixels = 128 | ||
self.labeler_supported_tape_sizes = [19, 12, 9, 6] | ||
self.labeler_label_vertical_margins = { | ||
6: (11, 51), | ||
9: (1, 62), | ||
12: (0, 63), | ||
19: (0, 0), | ||
} | ||
|
||
elif self._device.id_product == SUPPORTED_DEVICE_ID.LABELMANAGER_PC_II: | ||
self.labeler_print_head_width_pixels = 128 | ||
self.labeler_supported_tape_sizes = [24, 19, 12, 9, 6] | ||
self.labeler_label_vertical_margins = { | ||
6: (11, 51), | ||
9: (1, 62), | ||
12: (0, 63), | ||
19: (0, 0), | ||
24: (0, 0), | ||
} | ||
|
||
else: | ||
# Defaults (For most printers) | ||
self.labeler_print_head_width_pixels = 64 | ||
self.labeler_supported_tape_sizes = [12, 9, 6] | ||
self.labeler_label_vertical_margins = { | ||
6: (11, 51), | ||
9: (1, 62), | ||
12: (0, 63), | ||
} | ||
else: | ||
# Simulator (supports everything) | ||
self.labeler_print_head_width_pixels = 128 | ||
self.labeler_supported_tape_sizes = [24, 19, 12, 9, 6] | ||
self.labeler_label_vertical_margins = { | ||
6: (11, 51), | ||
9: (1, 62), | ||
12: (0, 63), | ||
19: (0, 0), | ||
24: (0, 0), | ||
} | ||
|
||
# --- End set options based on printer type --- | ||
|
||
# Check if selected tape size is supported by printer | ||
if tape_size_mm not in self.labeler_supported_tape_sizes: | ||
raise ValueError( | ||
f"Unsupported tape size {tape_size_mm}mm. " | ||
f"Supported sizes: {self.SUPPORTED_TAPE_SIZES_MM}" | ||
f"Supported sizes: {self.labeler_supported_tape_sizes}" | ||
) | ||
self.tape_size_mm = tape_size_mm | ||
self._device = device | ||
|
||
@property | ||
def height_px(self): | ||
|
@@ -277,6 +336,7 @@ def minimum_horizontal_margin_mm(self): | |
|
||
@property | ||
def labeler_margin_px(self) -> tuple[float, float]: | ||
# ToDo: Use preset margins here instead of this calculation | ||
vertical_margin_mm = max( | ||
0, (self.tape_size_mm - self.LABELER_PRINT_HEAD_HEIGHT_MM) / 2 | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really needed? In case the list is constant, it would be better as a convention to prefer tuple over list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The amount of supported tape sizes varies from printer to printer. I got an error that I tried to change the "tuple" size. A quick google search gave this as a solution. If there is a better solution please elaborate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, tuples are "immutable" so you should always generate a new one instead of modifying an old one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed (It didn´t complain this time)
Edit:
Sorry, had to revert this: