44from PIL import Image
55
66from labelle .lib .barcode_writer import BarcodeImageWriter
7- from labelle .lib .constants import DEFAULT_BARCODE_TYPE
7+ from labelle .lib .constants import DEFAULT_BARCODE_TYPE , BarcodeType
88from labelle .lib .render_engines .render_context import RenderContext
99from labelle .lib .render_engines .render_engine import (
1010 RenderEngine ,
1111 RenderEngineException ,
1212)
1313
14+ if DEFAULT_BARCODE_TYPE != BarcodeType .CODE128 :
15+ # Ensure that we fail fast if the default barcode type is adjusted
16+ # and the code below hasn't been updated.
17+ raise RuntimeError (
18+ "The conditional below assumes that the default barcode type is CODE128. "
19+ "Different barcodes have different quirks, so we should manually test the "
20+ "new default to ensure a good user experience in the GUI when the initial "
21+ "value is an empty string."
22+ )
23+
1424
1525class BarcodeRenderError (RenderEngineException ):
1626 def __init__ (self ) -> None :
@@ -25,7 +35,10 @@ def __init__(self, content: str, barcode_type: str | None) -> None:
2535 self .barcode_type = barcode_type or DEFAULT_BARCODE_TYPE
2636
2737 def render (self , context : RenderContext ) -> Image .Image :
28- if self .barcode_type == "code128" and self .content == "" :
38+ if (
39+ self .barcode_type == DEFAULT_BARCODE_TYPE == BarcodeType .CODE128
40+ and self .content == ""
41+ ):
2942 # An exception is raised on the empty string. Since this is
3043 # the default code, we really don't want to trigger a popup
3144 # in the GUI before the user entered a barcode.
0 commit comments