Adds a LabelPrintingMixin plugin class

- Enables the implementation of custom label printing plugins
- Will be available directly from the "print labels" dialog box
This commit is contained in:
Oliver 2022-03-24 12:51:27 +11:00
parent 170c4dfd4c
commit 69e9d1625a
2 changed files with 56 additions and 1 deletions

View File

@ -393,6 +393,59 @@ class AppMixin:
return True
class LabelPrintingMixin:
"""
Mixin which enables direct printing of stock labels.
Each plugin should provide a PRINTER_NAME attribute,
and also implement the print_label() function
"""
class MixinMeta:
"""
Meta options for this mixin
"""
MIXIN_NAME = 'Label printing'
def __init__(self):
super().__init__()
self.add_mixin('labels', 'has_label_printing', __class__)
@property
def has_label_printing(self):
if not bool(self.PRINTER_NAME):
raise ValueError("PRINTER_NAME must be defined")
return True
PRINTER_NAME = "LabelPrinter"
def get_printer_name(self):
return self.PRINTER_NAME
def print_labels(self, labels, **kwargs):
"""
Print multiple labels.
Default implementation is to call print_label() for each label,
but it can be overridden if desired.
"""
for label in labels:
self.print_label(label, **kwargs)
def print_label(self, label, **kwargs):
"""
Callback to print a single label
Arguments:
label: A black-and-white pillow Image object
"""
# Unimplemented (to be implemented by the particular plugin class)
...
class APICallMixin:
"""
Mixin that enables easier API calls for a plugin

View File

@ -2,7 +2,8 @@
Utility class to enable simpler imports
"""
from ..builtin.integration.mixins import APICallMixin, AppMixin, SettingsMixin, EventMixin, ScheduleMixin, UrlsMixin, NavigationMixin
from ..builtin.integration.mixins import APICallMixin, AppMixin, LabelPrintingMixin, SettingsMixin, EventMixin, ScheduleMixin, UrlsMixin, NavigationMixin
from ..builtin.action.mixins import ActionMixin
from ..builtin.barcode.mixins import BarcodeMixin
@ -10,6 +11,7 @@ __all__ = [
'APICallMixin',
'AppMixin',
'EventMixin',
'LabelPrintingMixin',
'NavigationMixin',
'ScheduleMixin',
'SettingsMixin',