diff --git a/src/scripts/print_labels_mod43.py b/src/scripts/print_labels_mod43.py
index f4dff02..ff0b900 100644
--- a/src/scripts/print_labels_mod43.py
+++ b/src/scripts/print_labels_mod43.py
@@ -22,7 +22,7 @@ barcode_prefix = f"#{PN} ###*1IT ECE"
barcode_suffix = "*="
-barcode_format = "{barcode_prefix}{SN7}{check}{barcode_suffix}"
+barcode_format = f"#{PN} ###*1IT ECE{SN7}{M43:X:Y}*="
module_data_format ="1IT ECE{SN7}"
def main():
diff --git a/src/ui/print_step_editor/print_step_editor.py b/src/ui/print_step_editor/print_step_editor.py
index ae357a7..fc6eb6e 100644
--- a/src/ui/print_step_editor/print_step_editor.py
+++ b/src/ui/print_step_editor/print_step_editor.py
@@ -13,6 +13,4 @@ class Print_Step_Editor(Editor):
"labeltxt_5": self.labeltxt_5,
"extra_label": self.extra_label,
"barcode": self.barcode,
- "prefix_mod_43": self.prefix_43,
- "suffix_mod_43": self.suffix_43,
})
diff --git a/src/ui/print_step_editor/print_step_editor.ui b/src/ui/print_step_editor/print_step_editor.ui
index 14771fc..5c27b66 100644
--- a/src/ui/print_step_editor/print_step_editor.ui
+++ b/src/ui/print_step_editor/print_step_editor.ui
@@ -6,8 +6,8 @@
0
0
- 846
- 686
+ 750
+ 332
@@ -243,33 +243,6 @@
- -
-
-
- -
-
-
- -
-
-
- PREFIX
-
-
-
- -
-
-
- SUFFIX
-
-
-
- -
-
-
- MOD 43
-
-
-
diff --git a/src/ui/test/test.py b/src/ui/test/test.py
index 3d319c9..1c16a5b 100755
--- a/src/ui/test/test.py
+++ b/src/ui/test/test.py
@@ -70,6 +70,10 @@ class Test(Widget):
else:
self.flag_label.setVisible(False)
+ # Initialize barcode formatting variables
+ self.barcode_prefix = ""
+ self.barcode_suffix = "*="
+
self.active_errors = [] # List to hold current errors (type: tuples of (message, is_error))
self.current_error_index = 0 # Keeps track of the current error index during alternation
@@ -843,12 +847,8 @@ class Test(Widget):
recipe = archived.test_data.get("recipe", {})
# Define barcode format variables
- part_number = recipe.get("part_number", "-")
- # Use prefix_mod_43 from print step editor if available, otherwise use default
- self.barcode_prefix = self.print_step.spec.get("prefix_mod_43", f"#{part_number} ###*1IT ECE")
- self.module_data_format = f"1IT ECE{archived.id:0>7}"
+ self.module_data_format = "1IT ECE{SN7}"
# Use suffix_mod_43 from print step editor if available, otherwise use default
- self.barcode_suffix = self.print_step.spec.get("suffix_mod_43", "*=")
self.barcode_format = self.print_step.spec.get("barcode")
leak_test_1 = archived.test_data.get("leak_1", {})
leak_test_1_step = leak_test_1.get("step", {})
@@ -954,16 +954,9 @@ class Test(Widget):
label_brother = context.get("RECIPE_TO_PRINT", "-") + context.get("DD","-") + context.get("MO","-") + context.get("YY","-") + context.get("SN5","-")
barcode = str(label_brother)
- formatted_module_data = self.module_data_format.format(**context)
- check = self.calculate_modulo43_checksum(formatted_module_data)
- context.update(
- {
- "barcode_prefix": self.barcode_prefix,
- "check": check,
- "barcode_suffix": self.barcode_suffix,
- }
- )
- formatted_barcode = self.barcode_format.format(**context)
+ # Process any {M43:X:Y} patterns in the barcode format
+ processed_barcode_format = self.process_m43_patterns(self.barcode_format, context)
+ formatted_barcode = processed_barcode_format.format(**context)
context['BCODE'] = formatted_barcode
self.printed_barcode = formatted_barcode
if self.archived is not None:
@@ -1118,6 +1111,61 @@ class Test(Widget):
else: # No args provided
self.flag_label.setVisible(False) # Hide label
+ def process_m43_patterns(self, barcode_format, context):
+ """
+ Process any {M43:X:Y} patterns in the barcode format string.
+
+ The pattern {M43:X:Y} is replaced with the modulo 43 check digit calculated
+ for the substring of the formatted barcode starting at position X and
+ containing Y characters.
+
+ Args:
+ barcode_format: The barcode format string that may contain {M43:X:Y} patterns.
+ context: The context dictionary used for formatting.
+
+ Returns:
+ The processed barcode format string with {M43:X:Y} patterns replaced by
+ placeholders that will be filled with the calculated check digits.
+ """
+ import re
+
+ # Create a temporary copy of the barcode format for processing
+ processed_format = barcode_format
+
+ # Find all {M43:X:Y} patterns in the barcode format
+ pattern = r'\{M43:(\d+):(\d+)\}'
+ matches = re.finditer(pattern, barcode_format)
+
+ # Process each match
+ for i, match in enumerate(matches):
+ # Extract X and Y values
+ x = int(match.group(1))
+ y = int(match.group(2))
+
+ # Create a placeholder for this check digit
+ placeholder = f"{{m43_check_{i}}}"
+
+ # Replace the {M43:X:Y} pattern with the placeholder
+ processed_format = processed_format.replace(match.group(0), placeholder)
+
+ # Format the barcode without the M43 patterns to get the base string
+ base_format = re.sub(pattern, "", barcode_format)
+ base_string = base_format.format(**context)
+
+ # Extract the substring for checksum calculation
+ if x < len(base_string) and x + y <= len(base_string):
+ substring = base_string[x:x+y]
+ # Calculate the check digit
+ check_digit = self.calculate_modulo43_checksum(substring)
+ # Add the check digit to the context
+ context[f"m43_check_{i}"] = check_digit
+ else:
+ # Handle out-of-range indices
+ self.log.warning(f"M43 pattern with X={x}, Y={y} is out of range for string of length {len(base_string)}")
+ context[f"m43_check_{i}"] = "?"
+
+ return processed_format
+
def calculate_modulo43_checksum(self,data_sequence: str) -> str:
"""
Calculates the Modulo 43 checksum for a given data sequence.