Skip to content

Commit 65fcf51

Browse files
authored
Merge pull request #23 from maresb/fix-gui-barcode
Fix barcodes in GUI
2 parents d18c36e + d61d379 commit 65fcf51

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/labelle/gui/q_label_widgets.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def render_engine_impl(self):
380380
font_file_name=self.font_style.currentData(),
381381
frame_width_px=self.frame_width_px.value(),
382382
font_size_ratio=self.font_size.value() / 100.0,
383-
align=self.align.currentText(),
383+
align=Direction(self.align.currentText()),
384384
)
385385
else:
386386
render_engine = BarcodeRenderEngine(

src/labelle/lib/constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
class BarcodeType(str, Enum):
7474
CODE128 = "code128"
7575
CODE39 = "code39"
76-
CODEBAR = "codebar"
76+
CODABAR = "codabar"
7777
EAN = "ean"
7878
EAN13 = "ean13"
7979
EAN13_GUARD = "ean13-guard"

src/labelle/lib/render_engines/barcode.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,15 @@ def __init__(self, content: str, barcode_type: str | None):
2525
self.barcode_type = barcode_type or DEFAULT_BARCODE_TYPE
2626

2727
def render(self, context: RenderContext) -> Image.Image:
28-
code = barcode_module.get(
29-
self.barcode_type, self.content, writer=BarcodeImageWriter()
30-
)
28+
if self.barcode_type == "code128" and self.content == "":
29+
# An exception is raised on the empty string. Since this is
30+
# the default code, we really don't want to trigger a popup
31+
# in the GUI before the user entered a barcode.
32+
self.content = " "
3133
try:
34+
code = barcode_module.get(
35+
self.barcode_type, self.content, writer=BarcodeImageWriter()
36+
)
3237
bitmap = code.render(
3338
{
3439
"font_size": 0,

0 commit comments

Comments
 (0)