data init idk other stuff

This commit is contained in:
2025-04-18 15:19:57 -04:00
parent 8f35cedb4a
commit 03b43ce3ab
28 changed files with 3378 additions and 810 deletions

View File

@@ -142,13 +142,14 @@ class LabelPrinterService:
logger.error(f"Unexpected error in _send_print_request: {e}")
return False
async def print_file(self, file_path: Union[str, Path, FileInDB], label_size: Literal["dk1201", "dk1241"], label_type: Optional[Literal["address_label", "packing_slip", "set_label"]] = None) -> bool:
async def print_file(self, file_path: Union[str, Path, FileInDB], label_size: Literal["dk1201", "dk1241"], label_type: Optional[Literal["address_label", "packing_slip", "set_label", "return_label", "pirate_ship_label"]] = None, copies: Optional[int] = None) -> bool:
"""Print a PDF or PNG file to the label printer.
Args:
file_path: Path to the PDF or PNG file, or a FileInDB object
label_size: Size of label to use ("dk1201" or "dk1241")
label_type: Type of label to use ("address_label" or "packing_slip" or "set_label")
copies: Optional number of copies to print. If None, prints once.
Returns:
bool: True if print was successful, False otherwise
@@ -206,7 +207,7 @@ class LabelPrinterService:
resized_image = resized_image.resize((991, 306), Image.Resampling.LANCZOS)
# if file path contains address_label, rotate image 90 degrees
if label_type == "address_label" or label_type == "set_label":
if label_type == "address_label" or label_type == "set_label" or label_type == "return_label":
rotate = "90"
cut = False
else:
@@ -240,16 +241,30 @@ class LabelPrinterService:
with open(cache_path, "wb") as f:
f.write(converted_image)
# Send to API
if not await self._send_print_request(cache_path):
logger.error(f"Failed to print page {i+1}")
return False
# Wait for printer to be ready before processing next page
if i < len(images) - 1: # Don't wait after the last page
if not await self._wait_for_printer_ready():
logger.error("Printer not ready for next page")
if copies:
# Send to API for each copy
for copy in range(copies):
logger.info(f"Printing copy {copy + 1} of {copies}")
if not await self._send_print_request(cache_path):
logger.error(f"Failed to print page {i+1}, copy {copy + 1}")
return False
# Wait for printer to be ready before next copy or page
if copy < copies - 1 or i < len(images) - 1:
if not await self._wait_for_printer_ready():
logger.error("Printer not ready for next copy/page")
return False
else:
# Send to API once (original behavior)
if not await self._send_print_request(cache_path):
logger.error(f"Failed to print page {i+1}")
return False
# Wait for printer to be ready before processing next page
if i < len(images) - 1: # Don't wait after the last page
if not await self._wait_for_printer_ready():
logger.error("Printer not ready for next page")
return False
return True