init
This commit is contained in:
38
config.py
Normal file
38
config.py
Normal file
@@ -0,0 +1,38 @@
|
||||
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
|
||||
Reference in New Issue
Block a user