Skip to content
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

Merged
merged 27 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d73626d
Add "DYMO LabelMANAGER PC II" device ID
FaBjE Jun 15, 2024
06f61ea
Add 24mm tape type
FaBjE Jun 16, 2024
3aecdc7
device specific init WIP
FaBjE Jun 18, 2024
1872e40
Add DeviceConfig class for each printer
FaBjE Jun 20, 2024
1b279b3
Please mypy...
FaBjE Jun 20, 2024
2353512
Fix usb device recognition
FaBjE Jun 21, 2024
dcc6234
Calculate margins instead of using lookup table
FaBjE Jun 21, 2024
040f2c2
Force sending an "exact printhead width" bitmap to the printer
FaBjE Jun 21, 2024
f907b8b
Fix config not updated when device set
FaBjE Jun 21, 2024
d64c977
Tested on LabelManager PnP
FaBjE Jun 21, 2024
a7def5e
replace all camels with snakes
FaBjE Jun 22, 2024
d8dcb3d
Cleanup supported device list syntax
FaBjE Jun 23, 2024
4fc8b68
Convert device config to dataclass
FaBjE Jun 23, 2024
1d36049
Convert labeler device-config to property
FaBjE Jun 23, 2024
d8b3b6d
Move get_tape_print_size_and_margins_px to labeler class tape_print_p…
FaBjE Jun 23, 2024
13fa9b9
Revert GUI supported_tape_sizes type
FaBjE Jun 23, 2024
424ec34
Remove fixed default tapesize (take highest supported as default)
FaBjE Jun 23, 2024
d342a04
Shorten matches_device_id function
FaBjE Jun 23, 2024
1786928
Fix code convention in if statement
FaBjE Jun 23, 2024
16d82e8
Shorten if statement
FaBjE Jun 23, 2024
e239867
Shorten if statement
FaBjE Jun 23, 2024
b390217
Let get_device_config_by_id raise exception if not supported
FaBjE Jun 23, 2024
0bdf8fd
Remove var / shorten line
FaBjE Jun 23, 2024
a4ed930
fix comment
FaBjE Jun 23, 2024
fdf3538
Clear up comment block
FaBjE Jun 23, 2024
0fa7ad5
Fix wrong var name
FaBjE Jun 23, 2024
7246473
Remove constant DPI values and calculations
FaBjE Jun 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/labelle/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# either sysfs is unavailable or unusable by this script for some reason.
# Please beware that DEV_NODE must be set to None when not used, else you will
# be bitten by the NameError exception.
from enum import IntEnum
from enum import Enum, IntEnum
from pathlib import Path

import labelle.resources.fonts
Expand Down
2 changes: 1 addition & 1 deletion src/labelle/lib/devices/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def find_and_select_device(self, patterns: list[str] | None = None) -> UsbDevice
return dev


def get_device_config_by_id(idValue: int) -> DeviceConfig:
def get_device_config_by_id(idValue: int) -> DeviceConfig | None:
"""Get a labeler device config with USB ID.

:param idValue: USB ID value
Expand Down
11 changes: 6 additions & 5 deletions src/labelle/lib/devices/dymo_labeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def _raw_print_label(self, lines: list[list[int]]):

class DymoLabeler:
_device: UsbDevice | None
_deviceConfig: DeviceConfig | None
_deviceConfig: DeviceConfig
tape_size_mm: int

LABELER_DISTANCE_BETWEEN_PRINT_HEAD_AND_CUTTER_MM = 8.1
Expand All @@ -254,14 +254,15 @@ def __init__(

if self._device is not None:
# Retrieve device config
self._deviceConfig = get_device_config_by_id(self._device.id_product)
foundConfig = get_device_config_by_id(self._device.id_product)
if foundConfig is not None:
self._deviceConfig = foundConfig
else:
raise ValueError(f"Unsupported device type {self._device.id_product}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As before, style comment. Please use the following convention:

            if foundConfig is None:
                raise ValueError(f"Unsupported device type {self._device.id_product}")
            self._deviceConfig = foundConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you return None from the function and raise here, instead of raising in the function itself, and then you will not have to test returned value from the function (and change its type to also support None).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question...
Stupid answer: I learned about the raising exceptions later on.

will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

else:
# Use simulator config
self._deviceConfig = SIMULATOR_CONFIG

if self._deviceConfig is None:
raise ValueError(f"Unsupported device type {device.id_product}")

if tape_size_mm is None:
tape_size_mm = self.DEFAULT_TAPE_SIZE_MM
if tape_size_mm not in self._deviceConfig.supportedTapeSizes:
Expand Down