Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ drop = [
line-length = 88
extend-exclude = ["_vendor"]
src = ["src"]
target-version = "py38"

[tool.ruff.lint]
select = [
Expand Down
56 changes: 28 additions & 28 deletions src/labelle/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import logging
import sys
from pathlib import Path
from typing import Annotated, List, NoReturn, Optional
from typing import Annotated, NoReturn

import typer
from rich.console import Console
Expand Down Expand Up @@ -109,7 +109,7 @@ def list_devices() -> NoReturn:
def default(
ctx: typer.Context,
version: Annotated[
Optional[bool],
bool | None,
typer.Option(
"--version",
callback=version_callback,
Expand All @@ -118,7 +118,7 @@ def default(
),
] = None,
device_pattern: Annotated[
Optional[List[str]],
list[str] | None,
typer.Option(
"--device",
help=(
Expand All @@ -129,7 +129,7 @@ def default(
),
] = None,
text: Annotated[
Optional[List[str]],
list[str] | None,
typer.Argument(
help="Text, each parameter gives a new line",
rich_help_panel="Elements",
Expand Down Expand Up @@ -160,25 +160,25 @@ def default(
),
] = Direction.LEFT,
sample_pattern: Annotated[
Optional[int],
int | None,
typer.Option(help="Prints test pattern of a desired dot height [px]"),
] = None,
min_length: Annotated[
Optional[float],
float | None,
typer.Option(
help="Minimum label length [mm], add whitespace if smaller",
rich_help_panel="Label Dimensions",
),
] = None,
max_length: Annotated[
Optional[float],
float | None,
typer.Option(
help="Maximum label length [mm], error if the label won't fit",
rich_help_panel="Label Dimensions",
),
] = None,
fixed_length: Annotated[
Optional[float],
float | None,
typer.Option(
help="Fixed label length [mm], set both minimum and maximum length",
rich_help_panel="Label Dimensions",
Expand All @@ -189,13 +189,13 @@ def default(
typer.Option(help="Destination of the label render"),
] = Output.PRINTER,
font: Annotated[
Optional[str],
str | None,
typer.Option(
help="User font. Overrides --style parameter", rich_help_panel="Design"
),
] = None,
qr_content: Annotated[
Optional[str],
str | None,
typer.Option(
"--qr", callback=qr_callback, help="QR code", rich_help_panel="Elements"
),
Expand All @@ -205,7 +205,7 @@ def default(
typer.Option(help="Read batch commands from stdin", rich_help_panel="Elements"),
] = False,
barcode_content: Annotated[
Optional[str],
str | None,
typer.Option("--barcode", help="Barcode", rich_help_panel="Elements"),
] = None,
barcode_type: Annotated[
Expand All @@ -216,13 +216,13 @@ def default(
),
] = DEFAULT_BARCODE_TYPE,
barcode_with_text_content: Annotated[
Optional[str],
str | None,
typer.Option(
"--barcode-with-text", help="Barcode with text", rich_help_panel="Elements"
),
] = None,
picture: Annotated[
Optional[Path], typer.Option(help="Picture", rich_help_panel="Elements")
Path | None, typer.Option(help="Picture", rich_help_panel="Elements")
] = None,
margin_px: Annotated[
float,
Expand All @@ -235,7 +235,7 @@ def default(
typer.Option(help="Scaling font factor, [0,100] [%]", rich_help_panel="Design"),
] = 90,
tape_size_mm: Annotated[
Optional[int],
int | None,
typer.Option(help="Tape size [mm]", rich_help_panel="Device Configuration"),
] = None,
# Old dymoprint arguments
Expand Down Expand Up @@ -281,94 +281,94 @@ def default(
),
] = False,
old_style: Annotated[
Optional[str],
str | None,
typer.Option(
"-s",
help="DEPRECATED",
hidden=True,
),
] = None,
old_align: Annotated[
Optional[str],
str | None,
typer.Option(
"-a",
help="DEPRECATED",
hidden=True,
),
] = None,
old_font: Annotated[
Optional[str],
str | None,
typer.Option(
"-u",
help="DEPRECATED",
hidden=True,
),
] = None,
old_barcode: Annotated[
Optional[str],
str | None,
typer.Option(
"-c",
help="DEPRECATED",
hidden=True,
),
] = None,
barcode_text: Annotated[
Optional[str],
str | None,
typer.Option(
"--barcode-text",
help="DEPRECATED",
hidden=True,
),
] = None,
old_picture: Annotated[
Optional[str],
str | None,
typer.Option(
"-p",
help="DEPRECATED",
hidden=True,
),
] = None,
old_margin: Annotated[
Optional[int],
int | None,
typer.Option(
"-m",
help="DEPRECATED",
hidden=True,
),
] = None,
scale: Annotated[
Optional[float],
float | None,
typer.Option(
help="DEPRECATED",
hidden=True,
),
] = None,
old_tape_size: Annotated[
Optional[int],
int | None,
typer.Option(
"-t",
help="DEPRECATED",
hidden=True,
),
] = None,
old_min_length: Annotated[
Optional[float],
float | None,
typer.Option(
"-l",
help="DEPRECATED",
hidden=True,
),
] = None,
old_justify: Annotated[
Optional[str],
str | None,
typer.Option(
"-j",
help="DEPRECATED",
hidden=True,
),
] = None,
test_pattern: Annotated[
Optional[int],
int | None,
typer.Option(
help="DEPRECATED",
hidden=True,
Expand Down Expand Up @@ -504,9 +504,9 @@ def render_text(lines):
render_engines.append(PictureRenderEngine(picture))

if batch:
accumulator: List[str] = []
accumulator: list[str] = []
accumulator_type: str = "empty"
accumulator_options: List[str] = []
accumulator_options: list[str] = []

def flush_all():
nonlocal accumulator
Expand Down
3 changes: 1 addition & 2 deletions src/labelle/gui/gui.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import sys
from typing import Optional

from PIL import Image
from PyQt6 import QtCore
Expand All @@ -26,7 +25,7 @@


class LabelleWindow(QWidget):
_label_bitmap_to_print: Optional[Image.Image]
_label_bitmap_to_print: Image.Image | None
_device_manager: DeviceManager
_dymo_labeler: DymoLabeler
_render_context: RenderContext
Expand Down
5 changes: 2 additions & 3 deletions src/labelle/gui/q_actions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import Optional

from PyQt6 import QtCore
from PyQt6.QtCore import QSize, Qt
Expand All @@ -12,12 +11,12 @@
class QActions(QWidget):
_error_label: QLabel
_is_enabled: bool
_last_error: Optional[str]
_last_error: str | None
_print_button: QPushButton

print_label_signal = QtCore.pyqtSignal(name="printLabel")

def __init__(self, parent: Optional[QWidget] = None):
def __init__(self, parent: QWidget | None = None):
super().__init__(parent)
self._error_label = QLabel()
self._is_enabled = False
Expand Down
19 changes: 9 additions & 10 deletions src/labelle/gui/q_labels_list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import List, Optional

from PIL import Image
from PyQt6 import QtCore
Expand Down Expand Up @@ -74,10 +73,10 @@ class QLabelList(QListWidget):
renderPrintPayloadSignal = QtCore.pyqtSignal(
Image.Image, name="renderPrintPayloadSignal"
)
render_context: Optional[RenderContext]
dymo_labeler: Optional[DymoLabeler]
render_context: RenderContext | None
dymo_labeler: DymoLabeler | None
h_margin_mm: float
min_label_width_mm: Optional[float]
min_label_width_mm: float | None
justify: Direction

def __init__(self, parent=None):
Expand Down Expand Up @@ -142,7 +141,7 @@ def update_params(

@property
def _payload_render_engine(self):
render_engines: List[RenderEngine] = []
render_engines: list[RenderEngine] = []
for i in range(self.count()):
item = self.item(i)
item_widget = self.itemWidget(self.item(i))
Expand Down Expand Up @@ -206,11 +205,11 @@ def contextMenuEvent(self, event) -> None:
"""
assert self.render_context is not None
contextMenu = QMenu(self)
add_text: Optional[QAction] = contextMenu.addAction("Add Text")
add_qr: Optional[QAction] = contextMenu.addAction("Add QR")
add_barcode: Optional[QAction] = contextMenu.addAction("Add Barcode")
add_img: Optional[QAction] = contextMenu.addAction("Add Image")
delete: Optional[QAction] = contextMenu.addAction("Delete")
add_text: QAction | None = contextMenu.addAction("Add Text")
add_qr: QAction | None = contextMenu.addAction("Add QR")
add_barcode: QAction | None = contextMenu.addAction("Add Barcode")
add_img: QAction | None = contextMenu.addAction("Add Image")
delete: QAction | None = contextMenu.addAction("Delete")
menu_click = contextMenu.exec(event.globalPos())

if menu_click == add_text:
Expand Down
3 changes: 1 addition & 2 deletions src/labelle/gui/q_render.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import Optional

from PIL import Image, ImageQt
from PyQt6.QtGui import QPixmap
Expand All @@ -9,7 +8,7 @@


class QRender(QLabel):
def __init__(self, parent: Optional[QWidget] = None) -> None:
def __init__(self, parent: QWidget | None = None) -> None:
super().__init__(parent)
self._init_elements()

Expand Down
7 changes: 3 additions & 4 deletions src/labelle/lib/barcode_to_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# this notice are preserved.
# === END LICENSE STATEMENT ===

from typing import List, Tuple, Union

from PIL import Image, ImageDraw

Expand All @@ -17,7 +16,7 @@ def _mm2px(mm: float, dpi: float = 25.4) -> float:
return (mm * dpi) / 25.4


def _list_of_runs(line: BinaryString) -> List[int]:
def _list_of_runs(line: BinaryString) -> list[int]:
# Pack line to list give better gfx result, otherwise in can
# result in aliasing gaps
# '11010111' -> [2, -1, 1, -1, 3]
Expand All @@ -43,7 +42,7 @@ def _calculate_size(
module_height: float,
vertical_margin: float,
dpi: float = 25.4,
) -> Tuple[int, int]:
) -> tuple[int, int]:
width = 2 * quiet_zone + modules_per_line * module_width
height = vertical_margin * 2 + module_height
return int(_mm2px(width, dpi)), int(_mm2px(height, dpi))
Expand Down Expand Up @@ -99,7 +98,7 @@ def _paint_module(
xpos: float,
ypos: float,
width: float,
color: Union[int, str],
color: int | str,
dpi: float,
module_height: float,
draw: ImageDraw.ImageDraw,
Expand Down
4 changes: 2 additions & 2 deletions src/labelle/lib/barcode_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# this notice are preserved.
# === END LICENSE STATEMENT ===

from typing import List, NamedTuple, NewType
from typing import NamedTuple, NewType

from barcode.writer import BaseWriter

Expand Down Expand Up @@ -39,7 +39,7 @@ def __init__(self) -> None:
finish=_noop,
)

def render(self, code: List[str]) -> BarcodeResult:
def render(self, code: list[str]) -> BarcodeResult:
"""Extract the barcode string from the code and render it into an image."""
if len(code) != 1:
raise ValueError("Barcode expected to have only one line")
Expand Down
Loading