mirror of
https://github.com/Ircama/epson_print_conf.git
synced 2024-10-18 01:00:36 -04:00
Fix calendar on Linux and other stuff
This commit is contained in:
parent
263398f865
commit
178369e9f5
1 changed files with 103 additions and 72 deletions
175
ui.py
175
ui.py
|
@ -1,3 +1,4 @@
|
||||||
|
import sys
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
@ -124,6 +125,19 @@ class ToolTip:
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
class BugFixedDateEntry(DateEntry):
|
||||||
|
"""
|
||||||
|
Fixes a bug on the calendar that does not accept mouse selection with Linux
|
||||||
|
"""
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
def drop_down(self):
|
||||||
|
super().drop_down()
|
||||||
|
if self._top_cal is not None and not self._calendar.winfo_ismapped():
|
||||||
|
self._top_cal.lift()
|
||||||
|
|
||||||
|
|
||||||
class EpsonPrinterUI(tk.Tk):
|
class EpsonPrinterUI(tk.Tk):
|
||||||
def __init__(self, conf_dict={}, replace_conf=False):
|
def __init__(self, conf_dict={}, replace_conf=False):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
@ -287,13 +301,13 @@ class EpsonPrinterUI(tk.Tk):
|
||||||
ti_received_frame.columnconfigure(2, weight=0) # Button column on the right
|
ti_received_frame.columnconfigure(2, weight=0) # Button column on the right
|
||||||
|
|
||||||
# TI Received Time Calendar Widget
|
# TI Received Time Calendar Widget
|
||||||
self.date_entry = DateEntry(
|
self.date_entry = BugFixedDateEntry(
|
||||||
ti_received_frame, date_pattern="yyyy-mm-dd"
|
ti_received_frame, date_pattern="yyyy-mm-dd"
|
||||||
)
|
)
|
||||||
self.date_entry.grid(
|
self.date_entry.grid(
|
||||||
row=0, column=1, padx=PADX, pady=PADY, sticky=(tk.W, tk.E)
|
row=0, column=1, padx=PADX, pady=PADY, sticky=(tk.W, tk.E)
|
||||||
)
|
)
|
||||||
self.date_entry.delete(0, "end")
|
self.date_entry.delete(0, "end") # blank the field removing the current date
|
||||||
ToolTip(self.date_entry, "Enter a valid date with format YYYY-MM-DD.")
|
ToolTip(self.date_entry, "Enter a valid date with format YYYY-MM-DD.")
|
||||||
|
|
||||||
# TI Received Time Buttons
|
# TI Received Time Buttons
|
||||||
|
@ -467,6 +481,14 @@ class EpsonPrinterUI(tk.Tk):
|
||||||
model=model,
|
model=model,
|
||||||
hostname=ip_address
|
hostname=ip_address
|
||||||
)
|
)
|
||||||
|
if not printer.parm.get("stats", {}).get("Power off timer"):
|
||||||
|
self.status_text.insert(
|
||||||
|
tk.END,
|
||||||
|
f"[ERROR]: Missing 'Power off timer' in configuration\n",
|
||||||
|
)
|
||||||
|
self.config(cursor="")
|
||||||
|
self.update_idletasks()
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
po_timer = printer.stats()["stats"]["Power off timer"]
|
po_timer = printer.stats()["stats"]["Power off timer"]
|
||||||
self.status_text.insert(
|
self.status_text.insert(
|
||||||
|
@ -474,10 +496,7 @@ class EpsonPrinterUI(tk.Tk):
|
||||||
)
|
)
|
||||||
self.po_timer_var.set(po_timer)
|
self.po_timer_var.set(po_timer)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.status_text.insert(
|
self.status_text.insert(tk.END, f"[ERROR] {e}\n")
|
||||||
tk.END,
|
|
||||||
f"[ERROR] {e}: Missing 'Power off timer' in configuration\n",
|
|
||||||
)
|
|
||||||
finally:
|
finally:
|
||||||
self.config(cursor="")
|
self.config(cursor="")
|
||||||
self.update_idletasks()
|
self.update_idletasks()
|
||||||
|
@ -504,35 +523,39 @@ class EpsonPrinterUI(tk.Tk):
|
||||||
model=model,
|
model=model,
|
||||||
hostname=ip_address
|
hostname=ip_address
|
||||||
)
|
)
|
||||||
try:
|
if not printer.parm.get("stats", {}).get("Power off timer"):
|
||||||
po_timer = printer.stats()["stats"]["Power off timer"]
|
|
||||||
po_timer = self.po_timer_var.get()
|
|
||||||
self.config(cursor="")
|
|
||||||
self.update_idletasks()
|
|
||||||
if not po_timer.isnumeric():
|
|
||||||
self.status_text.insert(
|
|
||||||
tk.END, "[ERROR] Please Use a valid value for minutes.\n"
|
|
||||||
)
|
|
||||||
return
|
|
||||||
self.status_text.insert(
|
|
||||||
tk.END, f"[INFO] Set Power off timer: {po_timer} minutes.\n"
|
|
||||||
)
|
|
||||||
response = messagebox.askyesno(
|
|
||||||
"Confirm Action", "Are you sure you want to proceed?"
|
|
||||||
)
|
|
||||||
if response:
|
|
||||||
printer.write_poweroff_timer(int(po_timer))
|
|
||||||
else:
|
|
||||||
self.status_text.insert(
|
|
||||||
tk.END, f"[WARNING] Set Power off timer aborted.\n"
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
self.config(cursor="")
|
|
||||||
self.update_idletasks()
|
|
||||||
self.status_text.insert(
|
self.status_text.insert(
|
||||||
tk.END,
|
tk.END,
|
||||||
f"[ERROR] {e}: Cannot set 'Power off timer'; missing configuration\n",
|
f"[ERROR]: Missing 'Power off timer' in configuration\n",
|
||||||
)
|
)
|
||||||
|
self.config(cursor="")
|
||||||
|
self.update_idletasks()
|
||||||
|
return
|
||||||
|
po_timer = self.po_timer_var.get()
|
||||||
|
self.config(cursor="")
|
||||||
|
self.update_idletasks()
|
||||||
|
if not po_timer.isnumeric():
|
||||||
|
self.status_text.insert(
|
||||||
|
tk.END, "[ERROR] Please Use a valid value for minutes.\n"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
self.status_text.insert(
|
||||||
|
tk.END, f"[INFO] Set Power off timer: {po_timer} minutes.\n"
|
||||||
|
)
|
||||||
|
response = messagebox.askyesno(
|
||||||
|
"Confirm Action", "Are you sure you want to proceed?"
|
||||||
|
)
|
||||||
|
if response:
|
||||||
|
try:
|
||||||
|
printer.write_poweroff_timer(int(po_timer))
|
||||||
|
except Exception as e:
|
||||||
|
self.status_text.insert(tk.END, f"[ERROR] {e}\n")
|
||||||
|
else:
|
||||||
|
self.status_text.insert(
|
||||||
|
tk.END, f"[WARNING] Set Power off timer aborted.\n"
|
||||||
|
)
|
||||||
|
self.config(cursor="")
|
||||||
|
self.update_idletasks()
|
||||||
|
|
||||||
def get_ti_date(self, cursor=True):
|
def get_ti_date(self, cursor=True):
|
||||||
if cursor:
|
if cursor:
|
||||||
|
@ -556,6 +579,14 @@ class EpsonPrinterUI(tk.Tk):
|
||||||
model=model,
|
model=model,
|
||||||
hostname=ip_address
|
hostname=ip_address
|
||||||
)
|
)
|
||||||
|
if not printer.parm.get("stats", {}).get("First TI received time"):
|
||||||
|
self.status_text.insert(
|
||||||
|
tk.END,
|
||||||
|
f"[ERROR]: Missing 'First TI received time' in configuration\n",
|
||||||
|
)
|
||||||
|
self.config(cursor="")
|
||||||
|
self.update_idletasks()
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
date_string = datetime.strptime(
|
date_string = datetime.strptime(
|
||||||
printer.stats()["stats"]["First TI received time"], "%d %b %Y"
|
printer.stats()["stats"]["First TI received time"], "%d %b %Y"
|
||||||
|
@ -566,10 +597,7 @@ class EpsonPrinterUI(tk.Tk):
|
||||||
)
|
)
|
||||||
self.date_entry.set_date(date_string)
|
self.date_entry.set_date(date_string)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.status_text.insert(
|
self.status_text.insert(tk.END, f"[ERROR] {e}\n")
|
||||||
tk.END,
|
|
||||||
f"[ERROR] {e}: Missing 'First TI received time' in configuration\n",
|
|
||||||
)
|
|
||||||
finally:
|
finally:
|
||||||
self.config(cursor="")
|
self.config(cursor="")
|
||||||
self.update_idletasks()
|
self.update_idletasks()
|
||||||
|
@ -596,35 +624,36 @@ class EpsonPrinterUI(tk.Tk):
|
||||||
model=model,
|
model=model,
|
||||||
hostname=ip_address
|
hostname=ip_address
|
||||||
)
|
)
|
||||||
try:
|
if not printer.parm.get("stats", {}).get("First TI received time"):
|
||||||
date_string = datetime.strptime(
|
|
||||||
printer.stats()["stats"]["First TI received time"], "%d %b %Y"
|
|
||||||
).strftime("%y-%m-%d")
|
|
||||||
date_string = self.date_entry.get_date()
|
|
||||||
self.status_text.insert(
|
self.status_text.insert(
|
||||||
tk.END,
|
tk.END,
|
||||||
f"[INFO] Set 'First TI received time' (YYYY-MM-DD) to: {date_string.strftime('%Y-%m-%d')}.\n",
|
f"[ERROR]: Missing 'First TI received time' in configuration\n",
|
||||||
)
|
)
|
||||||
response = messagebox.askyesno(
|
self.config(cursor="")
|
||||||
"Confirm Action", "Are you sure you want to proceed?"
|
self.update_idletasks()
|
||||||
)
|
return
|
||||||
if response:
|
date_string = self.date_entry.get_date()
|
||||||
|
self.status_text.insert(
|
||||||
|
tk.END,
|
||||||
|
f"[INFO] Set 'First TI received time' (YYYY-MM-DD) to: {date_string.strftime('%Y-%m-%d')}.\n",
|
||||||
|
)
|
||||||
|
response = messagebox.askyesno(
|
||||||
|
"Confirm Action", "Are you sure you want to proceed?"
|
||||||
|
)
|
||||||
|
if response:
|
||||||
|
try:
|
||||||
printer.write_first_ti_received_time(
|
printer.write_first_ti_received_time(
|
||||||
date_string.year, date_string.month, date_string.day
|
date_string.year, date_string.month, date_string.day
|
||||||
)
|
)
|
||||||
else:
|
except Exception as e:
|
||||||
self.status_text.insert(
|
self.status_text.insert(tk.END, f"[ERROR] {e}\n")
|
||||||
tk.END,
|
else:
|
||||||
f"[WARNING] Change of 'First TI received time' aborted.\n",
|
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
self.status_text.insert(
|
self.status_text.insert(
|
||||||
tk.END,
|
tk.END,
|
||||||
f"[ERROR] {e}: Cannot set 'First TI received time'; missing configuration\n",
|
f"[WARNING] Change of 'First TI received time' aborted.\n",
|
||||||
)
|
)
|
||||||
finally:
|
self.config(cursor="")
|
||||||
self.config(cursor="")
|
self.update_idletasks()
|
||||||
self.update_idletasks()
|
|
||||||
|
|
||||||
def validate_number_input(self, new_value):
|
def validate_number_input(self, new_value):
|
||||||
# This function will be called with the new input value
|
# This function will be called with the new input value
|
||||||
|
@ -711,25 +740,23 @@ class EpsonPrinterUI(tk.Tk):
|
||||||
model=model,
|
model=model,
|
||||||
hostname=ip_address
|
hostname=ip_address
|
||||||
)
|
)
|
||||||
try:
|
response = messagebox.askyesno(
|
||||||
printer.stats() # query the printer first
|
"Confirm Action", "Are you sure you want to proceed?"
|
||||||
response = messagebox.askyesno(
|
)
|
||||||
"Confirm Action", "Are you sure you want to proceed?"
|
if response:
|
||||||
)
|
try:
|
||||||
if response:
|
|
||||||
printer.reset_waste_ink_levels()
|
printer.reset_waste_ink_levels()
|
||||||
self.status_text.insert(
|
self.status_text.insert(
|
||||||
tk.END, "[INFO] Waste ink levels have been reset.\n"
|
tk.END, "[INFO] Waste ink levels have been reset.\n"
|
||||||
)
|
)
|
||||||
else:
|
except Exception as e:
|
||||||
self.status_text.insert(
|
self.status_text.insert(tk.END, f"[ERROR] {e}\n")
|
||||||
tk.END, f"[WARNING] Waste ink levels reset aborted.\n"
|
else:
|
||||||
)
|
self.status_text.insert(
|
||||||
except Exception as e:
|
tk.END, f"[WARNING] Waste ink levels reset aborted.\n"
|
||||||
self.status_text.insert(tk.END, f"[ERROR] {e}\n")
|
)
|
||||||
finally:
|
self.config(cursor="")
|
||||||
self.config(cursor="")
|
self.update_idletasks()
|
||||||
self.update_idletasks()
|
|
||||||
|
|
||||||
def start_detect_printers(self):
|
def start_detect_printers(self):
|
||||||
self.show_status_text_view()
|
self.show_status_text_view()
|
||||||
|
@ -916,4 +943,8 @@ if __name__ == "__main__":
|
||||||
conf_dict = pickle.load(args.pickle[0])
|
conf_dict = pickle.load(args.pickle[0])
|
||||||
|
|
||||||
app = EpsonPrinterUI(conf_dict=conf_dict, replace_conf=args.override)
|
app = EpsonPrinterUI(conf_dict=conf_dict, replace_conf=args.override)
|
||||||
app.mainloop()
|
try:
|
||||||
|
app.mainloop()
|
||||||
|
except:
|
||||||
|
print("\nInterrupted.")
|
||||||
|
sys.exit(0)
|
||||||
|
|
Loading…
Reference in a new issue