-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
192 lines (152 loc) · 6.84 KB
/
main.py
File metadata and controls
192 lines (152 loc) · 6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import tkinter as tk
from tkinter import messagebox
import os
import sys
from gui.loginpage import open_login_window
from gui.pospage import POSDashboard
from gui.kitchenpage import KitchenDashboard
from gui.adminpage import AdminDashboard
from backend.order import clear_all_orders
THEME_COLOR = "#800000"
TEXT_COLOR = "#FFFFFF"
FONT_HEADER = ("Segoe UI", 42, "bold")
FONT_SUB = ("Segoe UI", 16)
FONT_CARD_TITLE = ("Segoe UI", 20, "bold")
FONT_BTN = ("Segoe UI", 11, "bold")
class SmartChefApp(tk.Tk):
def __init__(self):
super().__init__()
self.title("SmartChef System")
self.resizable(True, True)
self.minsize(1000, 700)
icon_path = ("assets/SC.png")
if os.path.exists(icon_path):
try:
icon_img = tk.PhotoImage(file=icon_path)
self.iconphoto(True, icon_img)
except Exception as e:
print(f"Error loading app icon: {e}")
self.maximize_me()
self.protocol("WM_DELETE_WINDOW", self.on_closing)
self.dashboards = {}
self.preload_dashboards()
self.canvas = tk.Canvas(self, bg=THEME_COLOR, highlightthickness=0)
self.canvas.pack(fill="both", expand=True)
self.bg_image_obj = None
self.bg_id = None
self.load_background()
self.title_id = self.canvas.create_text(0, 0, text="Welcome to SmartChef",
font=FONT_HEADER, fill=TEXT_COLOR, anchor="center")
self.subtitle_id = self.canvas.create_text(0, 0, text="Select your role to continue",
font=FONT_SUB, fill="#DDDDDD", anchor="center")
self.card_manager = self.create_card_frame("Manager", "assets/Manager.png", scale=4)
self.card_waiter = self.create_card_frame("Waiter", "assets/Waiter.png", scale=4)
self.card_chef = self.create_card_frame("Chef", "assets/Chef.png", scale=2)
self.bind("<Configure>", self.resize_layout)
def maximize_me(self):
self.after(10, self._attempt_maximize)
def _attempt_maximize(self):
try:
self.state('zoomed')
return
except tk.TclError:
pass
try:
self.attributes('-zoomed', True)
return
except tk.TclError:
pass
self.geometry("1280x800")
def on_closing(self):
try:
print("Cleaning up orders...")
clear_all_orders()
except Exception as e:
print(f"Error during cleanup: {e}")
finally:
self.destroy()
def preload_dashboards(self):
print("Preloading dashboards...")
pos = POSDashboard(self)
pos.withdraw()
pos.protocol("WM_DELETE_WINDOW", lambda: self.hide_dashboard(pos))
self.dashboards["Waiter"] = pos
kitchen = KitchenDashboard(self)
kitchen.withdraw()
kitchen.protocol("WM_DELETE_WINDOW", lambda: self.hide_dashboard(kitchen))
self.dashboards["Chef"] = kitchen
admin = AdminDashboard(self)
admin.withdraw()
admin.protocol("WM_DELETE_WINDOW", lambda: self.hide_dashboard(admin))
self.dashboards["Manager"] = admin
def hide_dashboard(self, window):
window.withdraw()
self.lift()
self.focus_force()
def load_background(self):
bg_path = ("assets/BG.png")
if os.path.exists(bg_path):
try:
self.bg_image_obj = tk.PhotoImage(file=bg_path)
self.bg_id = self.canvas.create_image(0, 0, image=self.bg_image_obj, anchor="nw")
self.canvas.tag_lower(self.bg_id)
except Exception as e:
print(f"Error loading background: {e}")
def resize_layout(self, event):
w = self.winfo_width()
h = self.winfo_height()
self.canvas.coords(self.title_id, w/2, h * 0.15)
self.canvas.coords(self.subtitle_id, w/2, h * 0.22)
card_y = h * 0.60
col_1 = w * 0.25
col_2 = w * 0.50
col_3 = w * 0.75
self.card_manager.place(x=col_1, y=card_y, anchor="center", width=280, height=380)
self.card_waiter.place(x=col_2, y=card_y, anchor="center", width=280, height=380)
self.card_chef.place(x=col_3, y=card_y, anchor="center", width=280, height=380)
def create_card_frame(self, role, relative_icon_path, scale=4):
card = tk.Frame(self, bg="white", padx=20, pady=30, relief="raised", bd=2)
full_path = (relative_icon_path)
if os.path.exists(full_path):
try:
original_image = tk.PhotoImage(file=full_path)
photo = original_image.subsample(scale, scale)
if not hasattr(self, "card_icons"):
self.card_icons = []
self.card_icons.append(photo)
self.card_icons.append(original_image)
icon_lbl = tk.Label(card, image=photo, bg="white")
icon_lbl.pack(pady=(10, 20))
except Exception as e:
print(f"Image load error for {role}: {e}")
tk.Label(card, text=role[0], font=("Segoe UI", 60), bg="white").pack(pady=20)
else:
tk.Label(card, text=role[0], font=("Segoe UI", 60, "bold"),
bg="white", fg=THEME_COLOR).pack(pady=(10, 20))
tk.Label(card, text=role, font=FONT_CARD_TITLE, bg="white", fg="#333").pack(pady=(0, 5))
tk.Frame(card, bg=THEME_COLOR, height=3, width=60).pack(pady=(0, 25))
btn = tk.Button(card, text="LOGIN", font=FONT_BTN,
bg=THEME_COLOR, fg="white",
activebackground="#A52A2A", activeforeground="white",
relief="flat", cursor="hand2", width=18, pady=8,
command=lambda: self.open_login(role))
btn.pack(side="bottom", pady=10)
btn.bind("<Enter>", lambda e: btn.config(bg="#A52A2A"))
btn.bind("<Leave>", lambda e: btn.config(bg=THEME_COLOR))
return card
def open_login(self, role):
target_dashboard = self.dashboards.get(role)
open_login_window(self, role, target_dashboard)
if target_dashboard.state() != "withdrawn":
def force_lift():
target_dashboard.lift()
target_dashboard.focus_force()
try:
target_dashboard.attributes("-topmost", True)
target_dashboard.after(200, lambda: target_dashboard.attributes("-topmost", False))
except Exception:
pass
self.after(200, force_lift)
if __name__ == "__main__":
app = SmartChefApp()
app.mainloop()