backup before major refactor...
This commit is contained in:
140
kiosk.py
140
kiosk.py
@ -197,6 +197,7 @@ class GlobalVars:
|
||||
info_text = None
|
||||
BUTTON_FONT = None
|
||||
TEXT_FONT = None
|
||||
last_print_printer = None # "sticker" or "ribbon" - for re-print functionality
|
||||
|
||||
|
||||
class DrawingMixin:
|
||||
@ -1276,8 +1277,140 @@ class Screen10(tk.Frame):
|
||||
container = tk.Frame(self, bg=BG_COLOR)
|
||||
container.pack(expand=True)
|
||||
|
||||
RoundedLabel(container, text="Thank you!", bg='white', font=('Georgia', 48)).pack()
|
||||
tk.Button(container, text="Done", command=lambda: master.switch_frame(Screen0), height=3, width=30, bg='peach puff', font=GlobalVars.BUTTON_FONT).pack(pady=10)
|
||||
RoundedLabel(container, text="Thank you!", bg='white', font=('Georgia', 48)).pack(pady=(0, 20))
|
||||
|
||||
# Video player frame
|
||||
self.video_frame = tk.Frame(container, width=640, height=400, bg='black')
|
||||
self.video_frame.pack(pady=20)
|
||||
self.video_frame.pack_propagate(False)
|
||||
|
||||
# Video label for displaying frames
|
||||
self.video_label = tk.Label(self.video_frame, bg='black')
|
||||
self.video_label.pack(fill='both', expand=True)
|
||||
|
||||
# Determine which video to play
|
||||
self.video_file = self._get_video_file()
|
||||
self.cap = None
|
||||
self.running = False
|
||||
self.photo = None # Keep reference to prevent garbage collection
|
||||
|
||||
if self.video_file and os.path.exists(self.video_file):
|
||||
self.cap = cv2.VideoCapture(self.video_file)
|
||||
self.running = True
|
||||
self._update_frame()
|
||||
|
||||
# Button container for side-by-side layout
|
||||
button_frame = tk.Frame(container, bg=BG_COLOR)
|
||||
button_frame.pack(pady=10)
|
||||
|
||||
tk.Button(button_frame, text="Done", command=self._cleanup_and_done,
|
||||
height=2, width=20, bg='peach puff', font=GlobalVars.BUTTON_FONT).pack(side='left', padx=10)
|
||||
tk.Button(button_frame, text="tap here if print failed", command=self._cleanup_and_failed,
|
||||
height=2, width=20, bg='light gray', font=GlobalVars.BUTTON_FONT).pack(side='left', padx=10)
|
||||
|
||||
def _get_video_file(self):
|
||||
"""Determine which video to play based on print type and config."""
|
||||
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
if GlobalVars.print_type == "sticker":
|
||||
return os.path.join(base_path, "sticker.mp4")
|
||||
elif GlobalVars.print_type == "ribbon":
|
||||
has_cutter = CONFIG.get("ribbon", {}).get("has_cutter", False)
|
||||
if has_cutter:
|
||||
return os.path.join(base_path, "ribbon-no-cut.mp4")
|
||||
else:
|
||||
return os.path.join(base_path, "ribbon-cut.mp4")
|
||||
return None
|
||||
|
||||
def _update_frame(self):
|
||||
"""Update video frame using OpenCV."""
|
||||
if not self.running or self.cap is None:
|
||||
return
|
||||
|
||||
ret, frame = self.cap.read()
|
||||
if not ret:
|
||||
# Loop: reset to beginning
|
||||
self.cap.set(cv2.CAP_PROP_POS_FRAMES, 0)
|
||||
ret, frame = self.cap.read()
|
||||
if not ret:
|
||||
return
|
||||
|
||||
# Convert BGR to RGB
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
||||
|
||||
# Get original dimensions
|
||||
h, w = frame.shape[:2]
|
||||
target_w, target_h = 640, 400 # Larger video area
|
||||
|
||||
# Calculate scale to fit while preserving aspect ratio
|
||||
scale = min(target_w / w, target_h / h)
|
||||
new_w, new_h = int(w * scale), int(h * scale)
|
||||
|
||||
# Resize preserving aspect ratio
|
||||
frame = cv2.resize(frame, (new_w, new_h))
|
||||
|
||||
# Create black background and center the frame (letterboxing)
|
||||
canvas = np.zeros((target_h, target_w, 3), dtype=np.uint8)
|
||||
x_offset = (target_w - new_w) // 2
|
||||
y_offset = (target_h - new_h) // 2
|
||||
canvas[y_offset:y_offset+new_h, x_offset:x_offset+new_w] = frame
|
||||
frame = canvas
|
||||
|
||||
# Convert to PIL Image then to PhotoImage
|
||||
img = Image.fromarray(frame)
|
||||
self.photo = ImageTk.PhotoImage(image=img)
|
||||
self.video_label.config(image=self.photo)
|
||||
|
||||
# Schedule next frame update (~30fps = 33ms)
|
||||
if self.running:
|
||||
self.after(33, self._update_frame)
|
||||
|
||||
def _cleanup_and_done(self):
|
||||
"""Stop video and go to home screen."""
|
||||
self.running = False
|
||||
if self.cap:
|
||||
self.cap.release()
|
||||
self.master.switch_frame(Screen0)
|
||||
|
||||
def _cleanup_and_failed(self):
|
||||
"""Stop video and go to print failed screen."""
|
||||
self.running = False
|
||||
if self.cap:
|
||||
self.cap.release()
|
||||
self.master.switch_frame(PrintFailedScreen)
|
||||
|
||||
|
||||
# Print failed screen with re-print option
|
||||
class PrintFailedScreen(tk.Frame):
|
||||
def __init__(self, master):
|
||||
tk.Frame.__init__(self, master, bg=BG_COLOR)
|
||||
|
||||
# Center content
|
||||
container = tk.Frame(self, bg=BG_COLOR)
|
||||
container.pack(expand=True)
|
||||
|
||||
RoundedLabel(container, text="Print didn't work?", bg='white', font=('Georgia', 36)).pack(pady=30)
|
||||
|
||||
# Re-print button
|
||||
tk.Button(container, text="Re-print", command=self._reprint,
|
||||
height=3, width=30, bg='peach puff', font=GlobalVars.BUTTON_FONT).pack(pady=10)
|
||||
|
||||
# Done button
|
||||
tk.Button(container, text="Done", command=lambda: master.switch_frame(Screen0),
|
||||
height=3, width=30, bg='light gray', font=GlobalVars.BUTTON_FONT).pack(pady=10)
|
||||
|
||||
def _reprint(self):
|
||||
"""Re-send the last print job."""
|
||||
if GlobalVars.last_print_printer and os.path.exists("to_print.zpl"):
|
||||
try:
|
||||
printer_name = CONFIG["printers"][GlobalVars.last_print_printer]
|
||||
subprocess.Popen(f'lp -d {printer_name} -o raw to_print.zpl',
|
||||
shell=True, stdout=subprocess.PIPE)
|
||||
except:
|
||||
print('traceback.format_exc():\n%s' % traceback.format_exc())
|
||||
# Go back to thank you screen
|
||||
self.master.switch_frame(Screen10)
|
||||
|
||||
|
||||
# Sticker or tag?
|
||||
class Screen11(tk.Frame):
|
||||
@ -1657,6 +1790,7 @@ class Screen13(tk.Frame):
|
||||
|
||||
# print to sticker printer
|
||||
if GlobalVars.print_type == "sticker":
|
||||
GlobalVars.last_print_printer = "sticker"
|
||||
try:
|
||||
result = subprocess.Popen(f'lp -d {CONFIG["printers"]["sticker"]} -o raw to_print.zpl', shell=True, stdout=subprocess.PIPE, )
|
||||
except:
|
||||
@ -1664,6 +1798,7 @@ class Screen13(tk.Frame):
|
||||
exit()
|
||||
# or print to tag printer:
|
||||
if GlobalVars.print_type == "ribbon":
|
||||
GlobalVars.last_print_printer = "ribbon"
|
||||
try:
|
||||
result = subprocess.Popen(f'lp -d {CONFIG["printers"]["ribbon"]} -o raw to_print.zpl', shell=True, stdout=subprocess.PIPE, )
|
||||
except:
|
||||
@ -2161,6 +2296,7 @@ class NoQRPrintScreen(tk.Frame):
|
||||
file.write(zpl_code)
|
||||
|
||||
# Print to ribbon printer
|
||||
GlobalVars.last_print_printer = "ribbon"
|
||||
try:
|
||||
result = subprocess.Popen(f'lp -d {CONFIG["printers"]["ribbon"]} -o raw to_print.zpl', shell=True, stdout=subprocess.PIPE)
|
||||
except:
|
||||
|
||||
BIN
ribbon-cut.mp4
Normal file
BIN
ribbon-cut.mp4
Normal file
Binary file not shown.
0
ribbon-no-cut.mp4
Normal file
0
ribbon-no-cut.mp4
Normal file
BIN
sticker.mp4
Normal file
BIN
sticker.mp4
Normal file
Binary file not shown.
Reference in New Issue
Block a user