Skip to content

Commit

Permalink
Merge pull request #122 from computerlyrik/add-deprecation-messages
Browse files Browse the repository at this point in the history
Add deprecation messages to CLI and GUI
  • Loading branch information
maresb authored May 12, 2024
2 parents 1e9d50a + 702ae23 commit b58e236
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 81 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pipx install labelle

Old versions of dymoprint can still be found on [PyPI](https://pypi.org/project/dymoprint/#history).

For more context on the deprecation, see [issue #114](https://github.com/computerlyrik/dymoprint/issues/114).

## Disclaimer

Dymoprint has never been and is not currently affiliated, associated, authorized, endorsed by, or in any way officially connected with DYMO, or any of its subsidiaries or its affiliates. The official DYMO website can be found at <https://www.dymo.com>. The name DYMO®, as well as related names, marks, emblems, and images, are registered trademarks of their respective owners. While dymoprint software is designed to support certain devices manufactured by DYMO, no past or present endorsement or partnership is implied.
164 changes: 84 additions & 80 deletions src/dymoprint/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .constants import (
AVAILABLE_BARCODES,
DEFAULT_MARGIN_PX,
DEPRECATION_MESSAGE_ANSI,
PIXELS_PER_MM,
USE_QR,
e_qrcode,
Expand Down Expand Up @@ -163,103 +164,106 @@ def mm_to_payload_px(mm, margin):


def main():
args = parse_args()
render_engine = DymoRenderEngine(args.t)
try:
args = parse_args()
render_engine = DymoRenderEngine(args.t)

# read config file
FONT_FILENAME = font_filename(args.s)
# read config file
FONT_FILENAME = font_filename(args.s)

labeltext = args.text
labeltext = args.text

if args.u is not None:
if os.path.isfile(args.u):
FONT_FILENAME = args.u
else:
die("Error: file '%s' not found." % args.u)
if args.u is not None:
if os.path.isfile(args.u):
FONT_FILENAME = args.u
else:
die("Error: file '%s' not found." % args.u)

# check if barcode, qrcode or text should be printed, use frames only on text
if args.qr and not USE_QR:
die("Error: %s" % e_qrcode)
# check if barcode, qrcode or text should be printed, use frames only on text
if args.qr and not USE_QR:
die("Error: %s" % e_qrcode)

if args.barcode and args.qr:
die("Error: can not print both QR and Barcode on the same label (yet)")
if args.barcode and args.qr:
die("Error: can not print both QR and Barcode on the same label (yet)")

if args.fixed_length is not None and (
args.min_length != 0 or args.max_length is not None
):
die("Error: can't specify min/max and fixed length at the same time")
if args.fixed_length is not None and (
args.min_length != 0 or args.max_length is not None
):
die("Error: can't specify min/max and fixed length at the same time")

if args.max_length is not None and args.max_length < args.min_length:
die("Error: maximum length is less than minimum length")
if args.max_length is not None and args.max_length < args.min_length:
die("Error: maximum length is less than minimum length")

bitmaps = []
bitmaps = []

if args.test_pattern:
bitmaps.append(render_engine.render_test(args.test_pattern))
if args.test_pattern:
bitmaps.append(render_engine.render_test(args.test_pattern))

if args.qr:
bitmaps.append(render_engine.render_qr(labeltext.pop(0)))
if args.qr:
bitmaps.append(render_engine.render_qr(labeltext.pop(0)))

elif args.barcode:
bitmaps.append(render_engine.render_barcode(labeltext.pop(0), args.barcode))
elif args.barcode:
bitmaps.append(render_engine.render_barcode(labeltext.pop(0), args.barcode))

elif args.barcode_text:
bitmaps.append(
render_engine.render_barcode_with_text(
labeltext.pop(0), args.barcode_text, FONT_FILENAME, args.f
elif args.barcode_text:
bitmaps.append(
render_engine.render_barcode_with_text(
labeltext.pop(0), args.barcode_text, FONT_FILENAME, args.f
)
)
)

if labeltext:
bitmaps.append(
render_engine.render_text(
text_lines=labeltext,
font_file_name=FONT_FILENAME,
frame_width_px=args.f,
font_size_ratio=int(args.scale) / 100.0,
align=args.a,
if labeltext:
bitmaps.append(
render_engine.render_text(
text_lines=labeltext,
font_file_name=FONT_FILENAME,
frame_width_px=args.f,
font_size_ratio=int(args.scale) / 100.0,
align=args.a,
)
)
)

if args.picture:
bitmaps.append(render_engine.render_picture(args.picture))
if args.picture:
bitmaps.append(render_engine.render_picture(args.picture))

margin = args.m
justify = args.j

if args.fixed_length is not None:
min_label_mm_len = args.fixed_length
max_label_mm_len = args.fixed_length
else:
min_label_mm_len = args.min_length
max_label_mm_len = args.max_length

min_payload_len_px = max(0, mm_to_payload_px(min_label_mm_len, margin))
max_payload_len_px = (
mm_to_payload_px(max_label_mm_len, margin)
if max_label_mm_len is not None
else None
)
margin = args.m
justify = args.j

label_bitmap = render_engine.merge_render(
bitmaps=bitmaps,
min_payload_len_px=min_payload_len_px,
max_payload_len_px=max_payload_len_px,
justify=justify,
)
if args.fixed_length is not None:
min_label_mm_len = args.fixed_length
max_label_mm_len = args.fixed_length
else:
min_label_mm_len = args.min_length
max_label_mm_len = args.max_length

min_payload_len_px = max(0, mm_to_payload_px(min_label_mm_len, margin))
max_payload_len_px = (
mm_to_payload_px(max_label_mm_len, margin)
if max_label_mm_len is not None
else None
)

# print or show the label
if args.preview or args.preview_inverted or args.imagemagick:
print("Demo mode: showing label..")
# fix size, adding print borders
label_image = Image.new(
"L", (margin + label_bitmap.width + margin, label_bitmap.height)
label_bitmap = render_engine.merge_render(
bitmaps=bitmaps,
min_payload_len_px=min_payload_len_px,
max_payload_len_px=max_payload_len_px,
justify=justify,
)
label_image.paste(label_bitmap, (margin, 0))
if args.preview or args.preview_inverted:
label_rotated = label_bitmap.transpose(Image.ROTATE_270)
print(image_to_unicode(label_rotated, invert=args.preview_inverted))
if args.imagemagick:
ImageOps.invert(label_image).show()
else:
print_label(label_bitmap, margin_px=args.m, tape_size_mm=args.t)

# print or show the label
if args.preview or args.preview_inverted or args.imagemagick:
print("Demo mode: showing label..")
# fix size, adding print borders
label_image = Image.new(
"L", (margin + label_bitmap.width + margin, label_bitmap.height)
)
label_image.paste(label_bitmap, (margin, 0))
if args.preview or args.preview_inverted:
label_rotated = label_bitmap.transpose(Image.ROTATE_270)
print(image_to_unicode(label_rotated, invert=args.preview_inverted))
if args.imagemagick:
ImageOps.invert(label_image).show()
else:
print_label(label_bitmap, margin_px=args.m, tape_size_mm=args.t)
finally:
print(DEPRECATION_MESSAGE_ANSI)
29 changes: 29 additions & 0 deletions src/dymoprint/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,32 @@
"upc",
"upca",
]

ANSI_RED = "\033[91m"
ANSI_GREEN = "\033[92m"
ANSI_RESET = "\033[0m"
DEPRECATION_MESSAGE_ANSI = (
f"\n{ANSI_RED}WARNING: dymoprint is deprecated. To remove this message, either "
f"upgrade to Labelle or downgrade to a particular version of dymoprint less "
f"than v3.{ANSI_GREEN}\n"
f"\n"
f" pipx uninstall dymoprint\n"
f" pipx install labelle\n"
f"{ANSI_RED}\n"
f"For more info, see <https://github.com/labelle-org/labelle> and "
f"<https://github.com/computerlyrik/dymoprint/issues/114>.{ANSI_RESET}\n"
f"\n"
)
DEPRECATION_MESSAGE_POPUP = (
"WARNING: dymoprint is deprecated. To remove this message, either "
"upgrade to Labelle or downgrade to a particular version of dymoprint less "
"than v3."
"<pre style='background-color: #f4f4f4; padding: 5px;'>"
"pipx uninstall dymoprint\n"
"pipx install labelle"
"</pre>"
"For more info, see <a href='https://github.com/labelle-org/labelle'>"
"https://github.com/labelle-org/labelle</a> and "
"<a href='https://github.com/computerlyrik/dymoprint/issues/114'>"
"https://github.com/computerlyrik/dymoprint/issues/114</a>."
)
13 changes: 12 additions & 1 deletion src/dymoprint/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@
)
from usb.core import USBError

from .constants import DEFAULT_MARGIN_PX, ICON_DIR
from .constants import DEFAULT_MARGIN_PX, DEPRECATION_MESSAGE_POPUP, ICON_DIR
from .dymo_print_engines import DymoRenderEngine, print_label
from .q_dymo_labels_list import QDymoLabelList


class DeprecationPopup(QMessageBox):
def __init__(self):
super().__init__()
self.setWindowTitle("Deprecation Warning")
self.setText(DEPRECATION_MESSAGE_POPUP)
self.setIcon(QMessageBox.Icon.Warning)


class DymoPrintWindow(QWidget):
label_bitmap: Optional[Image.Image]

def __init__(self):
super().__init__()
popup = DeprecationPopup()
popup.exec()

self.render_engine = DymoRenderEngine(12)
self.label_bitmap = None

Expand Down

0 comments on commit b58e236

Please sign in to comment.