Complete label printer redesign: file monitoring, SVG templates, sharp print quality
- Redesigned GUI for automatic file monitoring workflow - Changed label format to 35x25mm landscape - Implemented SVG template support with variable substitution - Added configuration auto-save/load (conf/app.conf) - Added system tray minimize functionality - Fixed print quality: landscape orientation, vector fonts, 600 DPI - Auto-clear file after print to prevent duplicates - All popups auto-dismiss after 2-3 seconds - Semicolon separator for data format (article;nr_art;serial) - SumatraPDF integration with noscale settings - Printer configured for outline fonts (sharp output) - Reorganized documentation into documentation/ folder
This commit is contained in:
159
test_svg_template.py
Normal file
159
test_svg_template.py
Normal file
@@ -0,0 +1,159 @@
|
||||
"""
|
||||
Test SVG template functionality
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Import the PDF generator
|
||||
from print_label_pdf import PDFLabelGenerator
|
||||
|
||||
def test_svg_template():
|
||||
"""Test SVG template with sample data"""
|
||||
print("=== Testing SVG Template Functionality ===\n")
|
||||
|
||||
# Check if template exists
|
||||
template_path = os.path.join('conf', 'label_template.svg')
|
||||
if not os.path.exists(template_path):
|
||||
print(f"❌ Template not found: {template_path}")
|
||||
return False
|
||||
|
||||
print(f"✓ Template found: {template_path}")
|
||||
|
||||
# Sample data
|
||||
test_data = {
|
||||
'Article': 'COM-2024-001',
|
||||
'NrArt': 'ART-12345',
|
||||
'Serial': 'SN-20260212-001'
|
||||
}
|
||||
|
||||
print(f"✓ Test data: {test_data}")
|
||||
|
||||
# Create generator
|
||||
generator = PDFLabelGenerator()
|
||||
print("✓ PDF generator initialized")
|
||||
|
||||
# Test SVG template method
|
||||
print("\n--- Testing SVG Template Method ---")
|
||||
try:
|
||||
pdf_output = 'test_label_svg.pdf'
|
||||
result = generator.create_label_from_svg_template(
|
||||
template_path,
|
||||
test_data,
|
||||
filename=pdf_output
|
||||
)
|
||||
|
||||
if result and os.path.exists(pdf_output):
|
||||
file_size = os.path.getsize(pdf_output)
|
||||
print(f"✓ SVG template PDF created: {pdf_output} ({file_size} bytes)")
|
||||
return True
|
||||
else:
|
||||
print("❌ SVG template PDF creation failed")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
def test_programmatic_layout():
|
||||
"""Test programmatic layout (fallback)"""
|
||||
print("\n--- Testing Programmatic Layout (Fallback) ---")
|
||||
|
||||
generator = PDFLabelGenerator()
|
||||
|
||||
try:
|
||||
pdf_output = 'test_label_programmatic.pdf'
|
||||
result = generator.create_label_pdf(
|
||||
comanda='COM-2024-001',
|
||||
article='ART-12345',
|
||||
serial='SN-20260212-001',
|
||||
filename=pdf_output,
|
||||
image_path=os.path.join('conf', 'accepted.png')
|
||||
)
|
||||
|
||||
if result and os.path.exists(pdf_output):
|
||||
file_size = os.path.getsize(pdf_output)
|
||||
print(f"✓ Programmatic layout PDF created: {pdf_output} ({file_size} bytes)")
|
||||
return True
|
||||
else:
|
||||
print("❌ Programmatic layout PDF creation failed")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
def test_wrapper_functions():
|
||||
"""Test convenience wrapper functions"""
|
||||
print("\n--- Testing Wrapper Functions ---")
|
||||
|
||||
from print_label_pdf import create_label_pdf_simple, create_label_pdf_file
|
||||
|
||||
# Test data string
|
||||
test_string = "COM-2024-001;ART-12345;SN-20260212-001"
|
||||
|
||||
try:
|
||||
# Test create_label_pdf_simple (returns bytes)
|
||||
print("Testing create_label_pdf_simple()...")
|
||||
pdf_bytes = create_label_pdf_simple(test_string)
|
||||
if pdf_bytes:
|
||||
print(f"✓ create_label_pdf_simple returned {len(pdf_bytes)} bytes")
|
||||
else:
|
||||
print("❌ create_label_pdf_simple failed")
|
||||
return False
|
||||
|
||||
# Test create_label_pdf_file (returns filename)
|
||||
print("Testing create_label_pdf_file()...")
|
||||
pdf_file = create_label_pdf_file(test_string, filename='test_label_wrapper.pdf')
|
||||
if pdf_file and os.path.exists(pdf_file):
|
||||
file_size = os.path.getsize(pdf_file)
|
||||
print(f"✓ create_label_pdf_file created: {pdf_file} ({file_size} bytes)")
|
||||
return True
|
||||
else:
|
||||
print("❌ create_label_pdf_file failed")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ Error: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("SVG Template Test Suite\n")
|
||||
print("=" * 50)
|
||||
|
||||
results = []
|
||||
|
||||
# Test 1: SVG template
|
||||
results.append(("SVG Template", test_svg_template()))
|
||||
|
||||
# Test 2: Programmatic layout
|
||||
results.append(("Programmatic Layout", test_programmatic_layout()))
|
||||
|
||||
# Test 3: Wrapper functions
|
||||
results.append(("Wrapper Functions", test_wrapper_functions()))
|
||||
|
||||
# Summary
|
||||
print("\n" + "=" * 50)
|
||||
print("SUMMARY")
|
||||
print("=" * 50)
|
||||
|
||||
for test_name, passed in results:
|
||||
status = "✓ PASS" if passed else "❌ FAIL"
|
||||
print(f"{status}: {test_name}")
|
||||
|
||||
total = len(results)
|
||||
passed = sum(1 for _, p in results if p)
|
||||
|
||||
print(f"\nTotal: {passed}/{total} tests passed")
|
||||
|
||||
if passed == total:
|
||||
print("\n🎉 All tests passed!")
|
||||
sys.exit(0)
|
||||
else:
|
||||
print("\n⚠ Some tests failed")
|
||||
sys.exit(1)
|
||||
Reference in New Issue
Block a user