4
4
from PIL import Image
5
5
6
6
from 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
8
8
from labelle .lib .render_engines .render_context import RenderContext
9
9
from labelle .lib .render_engines .render_engine import (
10
10
RenderEngine ,
11
11
RenderEngineException ,
12
12
)
13
13
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
+
14
24
15
25
class BarcodeRenderError (RenderEngineException ):
16
26
def __init__ (self ) -> None :
@@ -25,7 +35,10 @@ def __init__(self, content: str, barcode_type: str | None) -> None:
25
35
self .barcode_type = barcode_type or DEFAULT_BARCODE_TYPE
26
36
27
37
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
+ ):
29
42
# An exception is raised on the empty string. Since this is
30
43
# the default code, we really don't want to trigger a popup
31
44
# in the GUI before the user entered a barcode.
0 commit comments