diff --git a/README.md b/README.md index 7134a51..e7dd306 100644 --- a/README.md +++ b/README.md @@ -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 . 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. diff --git a/src/dymoprint/command_line.py b/src/dymoprint/command_line.py index 10dd150..32bb01d 100755 --- a/src/dymoprint/command_line.py +++ b/src/dymoprint/command_line.py @@ -15,6 +15,7 @@ from .constants import ( AVAILABLE_BARCODES, DEFAULT_MARGIN_PX, + DEPRECATION_MESSAGE_ANSI, PIXELS_PER_MM, USE_QR, e_qrcode, @@ -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) diff --git a/src/dymoprint/constants.py b/src/dymoprint/constants.py index 794d0f7..52d95b5 100755 --- a/src/dymoprint/constants.py +++ b/src/dymoprint/constants.py @@ -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 and " + f".{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." + "
"
+    "pipx uninstall dymoprint\n"
+    "pipx install labelle"
+    "
" + "For more info, see " + "https://github.com/labelle-org/labelle and " + "" + "https://github.com/computerlyrik/dymoprint/issues/114." +) diff --git a/src/dymoprint/gui.py b/src/dymoprint/gui.py index bc2517a..7d794ba 100644 --- a/src/dymoprint/gui.py +++ b/src/dymoprint/gui.py @@ -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