39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
import json
|
|
import printer
|
|
|
|
|
|
class PrinterConfig:
|
|
editables = {"printer_address", "printer_port"}
|
|
required_params = {"printer_address"}
|
|
|
|
def __init__(self):
|
|
self.printer_address = None
|
|
self.printer_port = 9100
|
|
self.printer_profile = "RP-F10-80mm"
|
|
self.__printer = None
|
|
|
|
def save(self):
|
|
with open("config.json", "w", encoding="utf-8") as ofd:
|
|
json.dump(self.__dict__, ofd, ensure_ascii=False)
|
|
|
|
def load(self):
|
|
with open("config.json", "r", encoding="utf-8") as ifd:
|
|
self.__dict__ = json.load(ifd)
|
|
|
|
@property
|
|
def complete(self):
|
|
for param in self.required_params:
|
|
if getattr(self, param) is None:
|
|
return False
|
|
return True
|
|
|
|
@property
|
|
def printer(self):
|
|
if self.__printer is None:
|
|
self.__printer = printer.Printer(
|
|
address=self.printer_address,
|
|
port=self.printer_port,
|
|
profile=self.printer_profile,
|
|
)
|
|
return self.printer
|