Change the way cuts are managed, rewrite lock mechanism, add support for

multiple printers
This commit is contained in:
n07070 committed 2026-11-28 00:54:15 +01:00
1 parent aa1f9d1532
commit 52205be6af
8 files changed
+439 -322

No files matched your search

+21 -17
View File
@@ -33,6 +33,7 @@ class TaskType(Enum):
IMAGE = "image"
CUT = "cut"
QR = "qr"
REMOVE = "remove"
class PrintTask(ABC):
@@ -40,10 +41,12 @@ class PrintTask(ABC):
A print task holds information about what we are looking to print.
"""
def __init__(self, task_type: TaskType):
def __init__(self, task_type: TaskType, do_cut=False):
self.task_id = self._generate_id()
self.task_type = task_type
self.status = "pending" # pending, processing, completed, failed
self.log = ""
self.do_cut = do_cut
@abstractmethod
def get_print_data(self):
@@ -59,25 +62,25 @@ class TextTask(PrintTask):
This tasks represents a texte content, and it's signature.
"""
def __init__(self, content, signature):
super().__init__(TaskType.TEXT)
def __init__(self, content, signature="", do_cut=False):
super().__init__(TaskType.TEXT, do_cut)
self.content = content
self.signature = signature
def get_print_data(self):
return {"txt": self.content, "sign": self.signature}
return {"txt": self.content, "sign": self.signature, "do_cut": self.do_cut}
class QRTask(TextTask):
"""This task prints a QR-Code, the signature is ignore and is always the content itself"""
def __init__(self, content):
super().__init__(content, signature="")
def __init__(self, content, do_cut):
super().__init__(content, signature="", do_cut=False)
self.content = content
self.signature = content
def get_print_data(self):
return {"txt": self.content, "sign": self.signature}
return {"txt": self.content, "sign": self.signature, "do_cut": self.do_cut}
class ImageTask(PrintTask):
@@ -85,8 +88,8 @@ class ImageTask(PrintTask):
This tasks represents a image content ( in the form of it's path ), and it's signature.
"""
def __init__(self, image_path, signature, process, task_id):
super().__init__(TaskType.IMAGE)
def __init__(self, image_path, signature, process, task_id, do_cut):
super().__init__(TaskType.IMAGE, do_cut)
self.task_id = self._generate_id() if not task_id else task_id
self.image_path = image_path
self.signature = signature
@@ -94,18 +97,19 @@ class ImageTask(PrintTask):
def get_print_data(self):
# Return image data in printer-compatible format
return {"img": self.image_path, "sign": self.signature, "process": self.process}
return {"img": self.image_path, "sign": self.signature, "process": self.process, "do_cut": self.do_cut}
class CutTask(PrintTask):
class RemoveTask(PrintTask):
"""
This class activates the cutter on the printer if it exists
This class is used to clear images and leftovers after a print
"""
def __init__(self):
super().__init__(TaskType.CUT)
def __init__(self, task_id, image_path):
super().__init__(TaskType.REMOVE)
self.task_id = self._generate_id() if not task_id else task_id
self.image_path = image_path
# There is no print data,
# the task existence in itself is indication of what to do
def get_print_data(self):
return None
# Return image data in printer-compatible format
return {"img": self.image_path}