Skip to content

Commit

Permalink
refactor: rename avery labels to LabelSheet
Browse files Browse the repository at this point in the history
  • Loading branch information
margau committed Feb 10, 2025
1 parent ee23137 commit 5434099
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
# pylint: disable=invalid-name,too-many-instance-attributes
"""This module is used to generate label PDFs for Avery labels and other label types."""
"""This module is used to generate label PDFs for label sheets and other label types."""
from dataclasses import dataclass, KW_ONLY
from collections.abc import Iterator
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import LETTER, A4
from reportlab.lib.units import mm, inch


# Usage:
# label = AveryLabels.AveryLabel(5160)
# label.open( "labels5160.pdf" )
# label.render( RenderAddress, 30 )
# label.close()
#
# 'render' can either pass a callable, which receives the canvas object
# (with X,Y=0,0 at the lower right) or a string "form" name of a form
# previously created with canv.beginForm().


@dataclass
class LabelInfo:
"""Class for modeling label info"""
class LabelSheetInfo:
"""Class for modeling label sheet info"""

_: KW_ONLY
labels_horizontal: int
Expand All @@ -31,16 +19,16 @@ class LabelInfo:
pagesize: tuple[float, float]


labelInfo: dict[str, LabelInfo] = {
"averyL4731": LabelInfo(
labelSheetInfo: dict[str, LabelSheetInfo] = {
"averyL4731": LabelSheetInfo(
labels_horizontal=7,
labels_vertical=27,
label_size=(25.4 * mm, 10 * mm),
gutter_size=(2.5 * mm, 0),
margin=(9 * mm, 13.5 * mm),
pagesize=A4,
),
"averyL4732": LabelInfo(
"averyL4732": LabelSheetInfo(
labels_horizontal=5,
labels_vertical=16,
label_size=(35.6 * mm, 16.9 * mm),
Expand All @@ -49,15 +37,15 @@ class LabelInfo:
pagesize=A4,
),
# 2.6 x 1 address labels
"avery5160": LabelInfo(
"avery5160": LabelSheetInfo(
labels_horizontal=3,
labels_vertical=10,
label_size=(187, 72),
gutter_size=(11, 0),
margin=(14, 36),
pagesize=LETTER,
),
"avery5161": LabelInfo(
"avery5161": LabelSheetInfo(
labels_horizontal=2,
labels_vertical=10,
label_size=(288, 72),
Expand All @@ -66,7 +54,7 @@ class LabelInfo:
pagesize=LETTER,
),
# 4 x 2 address labels
"avery5163": LabelInfo(
"avery5163": LabelSheetInfo(
labels_horizontal=2,
labels_vertical=5,
label_size=(288, 144),
Expand All @@ -75,7 +63,7 @@ class LabelInfo:
pagesize=LETTER,
),
# 1.75 x 0.5 return address labels
"avery5167": LabelInfo(
"avery5167": LabelSheetInfo(
labels_horizontal=4,
labels_vertical=20,
label_size=(1.75 * inch, 0.5 * inch),
Expand All @@ -84,7 +72,7 @@ class LabelInfo:
pagesize=LETTER,
),
# 3.5 x 2 business cards
"avery5371": LabelInfo(
"avery5371": LabelSheetInfo(
labels_horizontal=2,
labels_vertical=5,
label_size=(252, 144),
Expand All @@ -93,7 +81,7 @@ class LabelInfo:
pagesize=LETTER,
),
# Herma 4201, 64 removable labels
"herma4201": LabelInfo(
"herma4201": LabelSheetInfo(
labels_horizontal=4,
labels_vertical=16,
label_size=(45.7 * mm, 16.9 * mm),
Expand All @@ -102,15 +90,15 @@ class LabelInfo:
pagesize=A4,
),
# HERMA No. 10003 labels (former article No. 4345)
"herma10003": LabelInfo(
"herma10003": LabelSheetInfo(
labels_horizontal=5,
labels_vertical=16,
label_size=(35.56 * mm, 16.93 * mm),
gutter_size=(2.54 * mm, 0),
margin=(11.02 * mm, 13.06 * mm),
pagesize=A4,
),
"herma4346": LabelInfo(
"herma4346": LabelSheetInfo(
labels_horizontal=4,
labels_vertical=12,
label_size=(45.72*mm, 21.167*mm),
Expand All @@ -124,12 +112,12 @@ class LabelInfo:
BUSINESS_CARDS = 5371


class AveryLabel:
class LabelSheet:
""" class for creating the pdfs """
def __init__(self, label, debug,
topDown=True, start_pos=None,
**kwargs):
data = labelInfo[label]
data = labelSheetInfo[label]
self.across = data.labels_horizontal
self.down = data.labels_vertical
self.size = data.label_size
Expand Down
7 changes: 3 additions & 4 deletions paperless_asn_qr_codes/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# pylint: disable=global-statement,global-variable-undefined,global-variable-not-assigned,used-before-assignment
""" Main module for the paperless ASN QR code generator, fills the labels with content """
import argparse
import re

from reportlab.lib.units import mm
from reportlab_qrcode import QRCodeImage

from paperless_asn_qr_codes import avery_labels
from paperless_asn_qr_codes import LabelSheet

def render(c, _, y):
""" Render the QR code and ASN number on the label """
Expand All @@ -32,7 +31,7 @@ def _start_position(arg):
raise argparse.ArgumentTypeError("invalid value")

# prepare a sorted list of all formats
available_formats = list(avery_labels.labelInfo.keys())
available_formats = list(LabelSheet.labelSheetInfo.keys())
available_formats.sort()

parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -94,7 +93,7 @@ def _start_position(arg):
global digits
startASN = int(args.start_asn)
digits = int(args.digits)
label = avery_labels.AveryLabel(
label = LabelSheet.LabelSheet(
args.format, args.border, topDown=args.row_wise, start_pos=args.start_position
)
label.open(args.output_file)
Expand Down

0 comments on commit 5434099

Please sign in to comment.