Skip to content

Commit

Permalink
Merge pull request #4 from computerlyrik/mypy
Browse files Browse the repository at this point in the history
Make mypy pass
  • Loading branch information
tomers authored Jan 20, 2024
2 parents cd70115 + ec3cd80 commit 9aa2738
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,9 @@ ignore = [
"ISC002", # multi-line-implicit-string-concatenation
]
target-version = "py38"

[tool.mypy]
exclude = ["_vendor"]
ignore_missing_imports = true
check_untyped_defs = true
install_types = true
4 changes: 2 additions & 2 deletions src/dymoprint/gui/q_dymo_label_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class BaseDymoLabelWidget(QWidget):
Abstract method to be implemented by subclasses for rendering the label.
"""

render_engine: DymoRenderEngine

itemRenderSignal = QtCore.pyqtSignal(name="itemRenderSignal")

def content_changed(self):
Expand Down Expand Up @@ -90,7 +92,6 @@ class TextDymoLabelWidget(BaseDymoLabelWidget):
itemRenderSignal: A signal emitted when the content of the label changes.
"""

render_engine: DymoRenderEngine
align: QComboBox
label: QPlainTextEdit
font_style: FontStyle
Expand Down Expand Up @@ -245,7 +246,6 @@ class BarcodeDymoLabelWidget(BaseDymoLabelWidget):
and barcode type.
"""

render_engine: DymoRenderEngine
label: QLineEdit
barcode_type_label: QLabel
barcode_type: QComboBox
Expand Down
24 changes: 16 additions & 8 deletions src/dymoprint/gui/q_dymo_labels_list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from typing import Optional

from PIL import Image
from PyQt6 import QtCore
from PyQt6.QtGui import QAction
from PyQt6.QtWidgets import QAbstractItemView, QListWidget, QListWidgetItem, QMenu

from dymoprint.gui.q_dymo_label_widgets import (
Expand All @@ -8,6 +11,7 @@
QrDymoLabelWidget,
TextDymoLabelWidget,
)
from dymoprint.lib.dymo_print_engines import DymoRenderEngine


class QDymoLabelList(QListWidget):
Expand Down Expand Up @@ -38,6 +42,8 @@ class QDymoLabelList(QListWidget):
"""

renderSignal = QtCore.pyqtSignal(Image.Image, name="renderSignal")
render_engine: DymoRenderEngine
itemWidget: TextDymoLabelWidget

def __init__(
self, render_engine, min_payload_len_px=0, justify="center", parent=None
Expand Down Expand Up @@ -66,7 +72,9 @@ def dropEvent(self, e) -> None:
super().dropEvent(e)
self.render_label()

def update_params(self, render_engine, min_payload_len_px=0, justify="center"):
def update_params(
self, render_engine: DymoRenderEngine, min_payload_len_px=0, justify="center"
):
"""Update the render engine used for rendering the label.
Args:
Expand Down Expand Up @@ -109,11 +117,11 @@ def contextMenuEvent(self, event):
event (QContextMenuEvent): The context menu event.
"""
contextMenu = QMenu(self)
add_text = contextMenu.addAction("Add Text")
add_qr = contextMenu.addAction("Add QR")
add_barcode = contextMenu.addAction("Add Barcode")
add_img = contextMenu.addAction("Add Image")
delete = contextMenu.addAction("Delete")
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")
menu_click = contextMenu.exec(event.globalPos())

if menu_click == add_text:
Expand Down Expand Up @@ -149,8 +157,8 @@ def contextMenuEvent(self, event):
item_widget.itemRenderSignal.connect(self.render_label)
if menu_click == delete:
try:
item = self.itemAt(event.pos())
self.takeItem(self.indexFromItem(item).row()) # self.update()
item_to_delete = self.itemAt(event.pos())
self.takeItem(self.indexFromItem(item_to_delete).row()) # self.update()
except Exception as e: # noqa: BLE001
print(f"No item selected {e}")
self.render_label()
6 changes: 4 additions & 2 deletions src/dymoprint/lib/barcode_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ def _init(self, code):
self._draw = ImageDraw.Draw(self._image)

def _paint_module(self, xpos, ypos, width, color):
size = [
size = (
(mm2px(xpos, self.dpi), mm2px(ypos, self.dpi)),
(
mm2px(xpos + width, self.dpi),
mm2px(ypos + self.module_height, self.dpi),
),
]
)
assert self._draw is not None
self._draw.rectangle(size, outline=color, fill=color)

def _finish(self):
# although Image mode set to "1", draw function writes white as 255
assert self._image is not None
self._image = self._image.point(lambda x: 1 if x > 0 else 0, mode="1")
return self._image

Expand Down

0 comments on commit 9aa2738

Please sign in to comment.