BonPrinter v1.2.0
Thermal Printer tool
Loading...
Searching...
No Matches
Model Class Reference

Holds the data of the application. More...

Public Member Functions

None __init__ (self, "MainWindow" ui, LogConfig log_config)
str|None get_last_path (self)
 Get last path to open dialog.
None set_last_path (self, str path)
 Set last path and save in persistent storage.
None update_enable_report_status (self, Optional[bool] b_enable_report=None)
 Update report enable status.
None update_output_path (self, str s_output_path)
 Update output path.
None update_show_price_status (self, Optional[bool] b_show_price=None)
 Update Show price status.

Public Attributes

 b_enable_report = read_print_report_settings()
bool b_show_price = read_show_price_settings()
Authentication c_auth = Authentication(ui)
Calculator c_calc = Calculator()
config.Config c_config = config.Config(ui)
language.Language c_language = language.Language(ui)
monitor.MonitorScale c_monitor = monitor.MonitorScale(ui)
printer.Printer c_printer = printer.Printer(ui)
report.Report c_report = report.Report(ui)
sound.Sound c_sound = sound.Sound(ui)
 log_config = log_config
 notepad_worker = OpenNotepadWorker()
str|None s_last_path = read_last_dir()
str s_output_path = read_output_path_settings()
 ui = ui

Detailed Description

Holds the data of the application.

Parameters
ui: main window object
log_config: log configuration of the application

Definition at line 36 of file model.py.

Constructor & Destructor Documentation

◆ __init__()

None __init__ ( self,
"MainWindow" ui,
LogConfig log_config )

Definition at line 43 of file model.py.

43 def __init__(self, ui: "MainWindow", log_config: LogConfig) -> None:
44 self.ui = ui
45 self.ui.model = self # set model before function return to get language for status messages before
46 self.log_config = log_config
47 self.s_output_path: str = read_output_path_settings()
48 self.b_enable_report = read_print_report_settings()
49 self.b_show_price: bool = read_show_price_settings()
50 self.s_last_path: str | None = read_last_dir()
51 self.c_auth: Authentication = Authentication(ui)
52 self.c_calc: Calculator = Calculator()
53 self.c_config: config.Config = config.Config(ui) # init before printer and report
54 self.c_report: report.Report = report.Report(ui)
55 self.c_sound: sound.Sound = sound.Sound(ui)
56 self.c_monitor: monitor.MonitorScale = monitor.MonitorScale(ui)
57 self.c_language: language.Language = language.Language(ui)
58 self.update_output_path(self.s_output_path) # update after set language. call to create output if not exist
59 self.notepad_worker = OpenNotepadWorker()
60
61 # printer
62 self.c_printer: printer.Printer = printer.Printer(ui)
63 self.c_printer.set_header(self.c_config.get_header1(),
64 self.c_config.get_header2())
65 self.c_printer.start() # start printer thread
66

Member Function Documentation

◆ get_last_path()

str | None get_last_path ( self)

Get last path to open dialog.

Returns
last path

Definition at line 131 of file model.py.

131 def get_last_path(self) -> str | None:
132 """!
133 @brief Get last path to open dialog
134 @return last path
135 """
136 path = self.s_output_path
137 if self.s_last_path:
138 if os.path.exists(self.s_last_path):
139 path = self.s_last_path
140 else:
141 self.s_last_path = None
142 return path
143

◆ set_last_path()

None set_last_path ( self,
str path )

Set last path and save in persistent storage.

Parameters
path: path to set as last path

Definition at line 144 of file model.py.

144 def set_last_path(self, path: str) -> None:
145 """!
146 @brief Set last path and save in persistent storage
147 @param path : path to set as last path
148 """
149 self.s_last_path = path
150 write_last_dir(path)

◆ update_enable_report_status()

None update_enable_report_status ( self,
Optional[bool] b_enable_report = None )

Update report enable status.

Parameters
b_enable_report: [True] enable print report; [False] disable print report; [None] toggle print report

Definition at line 67 of file model.py.

67 def update_enable_report_status(self, b_enable_report: Optional[bool] = None) -> None:
68 """!
69 @brief Update report enable status.
70 @param b_enable_report : [True] enable print report; [False] disable print report; [None] toggle print report
71 """
72 if b_enable_report is None:
73 b_enable_report = not self.b_show_price
74 self.b_enable_report = b_enable_report
75 write_print_report_settings(self.b_show_price)
76 if self.b_enable_report:
77 s_statusbar_text = ["Enable Print Report", "Druckbericht aktiviert"]
78 else:
79 s_statusbar_text = ["Disable Print Report", "Druckbericht deaktiviert"]
80 self.ui.set_status(s_statusbar_text)
81 self.ui.update_screen()
82

◆ update_output_path()

None update_output_path ( self,
str s_output_path )

Update output path.

Parameters
s_output_path: new output path to set

Definition at line 99 of file model.py.

99 def update_output_path(self, s_output_path: str) -> None:
100 """!
101 @brief Update output path
102 @param s_output_path : new output path to set
103 """
104 if not os.path.exists(s_output_path):
105 self.ui.set_status([f"Path not exist: {s_output_path}",
106 f"Pfad existiert nicht: {s_output_path}"], True)
107 if not os.path.exists(S_DEFAULT_OUTPUT_PATH):
108 log.debug("Create default output folder")
109 os.mkdir(S_DEFAULT_OUTPUT_PATH)
110 s_output_path = S_DEFAULT_OUTPUT_PATH
111
112 try: # test write access
113 s_test_file = s_output_path + "/" + S_WRITE_TEST_FILE_NAME
114 with open(s_test_file, mode="w", encoding="utf-8") as file:
115 file.write("Write Access Test")
116 os.remove(s_test_file)
117 except BaseException:
118 b_access = False
119 else:
120 b_access = True
121
122 if b_access:
123 self.s_output_path = s_output_path
124 write_output_path_settings(self.s_output_path)
125 self.ui.set_status([f"Output path changed to: {s_output_path}",
126 f"Ausgangsverzeichnis geƤndert zu: {s_output_path}"])
127 else:
128 self.ui.set_status([f"No Write access to path: {s_output_path}",
129 f"Kein Schreibzugriff auf das Verzeichnis: {s_output_path}"], True)
130

◆ update_show_price_status()

None update_show_price_status ( self,
Optional[bool] b_show_price = None )

Update Show price status.

Parameters
b_show_price: [True] show price below article name; [False] show not; [None] toggle actual setting

Definition at line 83 of file model.py.

83 def update_show_price_status(self, b_show_price: Optional[bool] = None) -> None:
84 """!
85 @brief Update Show price status.
86 @param b_show_price : [True] show price below article name; [False] show not; [None] toggle actual setting
87 """
88 if b_show_price is None:
89 b_show_price = not self.b_show_price
90 self.b_show_price = b_show_price
91 write_show_price_settings(self.b_show_price)
92 if self.b_show_price:
93 s_statusbar_text = ["Show Price", "Preis anzeigen"]
94 else:
95 s_statusbar_text = ["Hide Price", "Preis verbergen"]
96 self.ui.set_status(s_statusbar_text)
97 self.ui.update_screen()
98

Member Data Documentation

◆ b_enable_report

b_enable_report = read_print_report_settings()

Definition at line 48 of file model.py.

◆ b_show_price

b_show_price = read_show_price_settings()

Definition at line 49 of file model.py.

◆ c_auth

Definition at line 51 of file model.py.

◆ c_calc

Calculator c_calc = Calculator()

Definition at line 52 of file model.py.

◆ c_config

Definition at line 53 of file model.py.

◆ c_language

Definition at line 57 of file model.py.

◆ c_monitor

Definition at line 56 of file model.py.

◆ c_printer

Definition at line 62 of file model.py.

◆ c_report

Definition at line 54 of file model.py.

◆ c_sound

Definition at line 55 of file model.py.

◆ log_config

log_config = log_config

Definition at line 46 of file model.py.

◆ notepad_worker

notepad_worker = OpenNotepadWorker()

Definition at line 59 of file model.py.

◆ s_last_path

s_last_path = read_last_dir()

Definition at line 50 of file model.py.

◆ s_output_path

s_output_path = read_output_path_settings()

Definition at line 47 of file model.py.

◆ ui

ui = ui

Definition at line 44 of file model.py.


The documentation for this class was generated from the following file: