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
8 changes: 5 additions & 3 deletions src/labelle/lib/devices/device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from usb.core import NoBackendError, USBError

from labelle.lib.constants import (
SUPPORTED_DEVICE_ID,
SUPPORTED_PRODUCTS,
UNCONFIRMED_MESSAGE,
)
Expand Down Expand Up @@ -82,8 +81,11 @@ def find_and_select_device(self, patterns: list[str] | None = None) -> UsbDevice
LOG.debug(dev.device_info)
dev = devices[0]
if dev.is_supported:
msg = f"Recognized device as \
{SUPPORTED_PRODUCTS[SUPPORTED_DEVICE_ID(dev.id_product)]}"
foundDeviceConfig: DeviceConfig | None = get_device_config_by_id(
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you really need to declare the type of foundDeviceConfig (I guess you meant found_device_config :-) )?
If the function declares its return type, then I think it should be fine not to declare here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this was an ugly workaround. Will be obsolete when I fix the other function.
And yes of course I meant snake_case 😉

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

dev.id_product
)
if foundDeviceConfig is not None:
msg = f"Recognized device as {foundDeviceConfig.name}"
Copy link
Contributor

Choose a reason for hiding this comment

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

What is msg if found_device_config is 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.

I was not sure how to proceed than. Just print nothing?
Is there a quick syntax to "add if not null, otherwise leave empty"

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:
msg = f"Unrecognized device: {hex(dev.id_product)}. {UNCONFIRMED_MESSAGE}"
LOG.debug(msg)
Expand Down
13 changes: 9 additions & 4 deletions src/labelle/lib/devices/usb_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,15 @@ def _is_supported_vendor(dev: usb.core.Device) -> bool:

@property
def is_supported(self) -> bool:
return (
self._is_supported_vendor(self._dev)
and self.id_product in SUPPORTED_PRODUCTS
)
# If vendor matches
if self._is_supported_vendor(self._dev) is True:
# if one item in our supported products matches the device id
for device in SUPPORTED_PRODUCTS:
if device.matches_device_id(self.id_product) is True:
return True

# no matches found
return False

@staticmethod
def supported_devices() -> set[UsbDevice]:
Expand Down