def admin_login(container, buttonframe): util_funcs.clear_frame(container) password = tk.StringVar() global notif_admin notif_admin = tk.StringVar() login_label = tk.Label(container, text="Log in as admin", font=("Open Sans", 40, 'bold')) login_label.place(relx=0.3, rely=0.1, relwidth=0.42, relheight=0.1) password_label = tk.Label(container, text="Password", font=("Open Sans", 15)) password_label.place(relx=0.445, rely=0.25, relwidth=0.11, relheight=0.04) password_entry = tk.Entry(container, textvariable=password, show="*", font=("Open Sans", 15)) password_entry.place(relx=0.425, rely=0.3, relwidth=0.15, relheight=0.04) login_button = ttk.Button(container, text="Login", command=partial(check_creds_login, container, buttonframe, uname=None, pass1=password, mode='admin'), width=20) login_button.place(relx=0.5, rely=0.4, anchor="center") notif_label = tk.Label(container, textvariable=notif_admin, font=("Open Sans", 14, 'bold')) notif_label.place(relx=0.5, rely=0.48, anchor="center") util_funcs.set_colors(container)
def customer_profile(container, username): util_funcs.clear_frame(container) tk.Label(container, text="").pack() tk.Label(container, text="").pack() try: pending = database.pull_orders('customer', username, 'PENDING') delivered = database.pull_orders('customer', username, 'DELIVERED') except Error: error = tk.PhotoImage(file="src/icons/error.png").subsample(4, 4) error_label = tk.Label(container, image=error) error_label.image = error error_label.pack(anchor='center') tk.Label(container, text="Sorry, there was en error.", font=("Open Sans", 30)).pack(anchor='center') else: profile = tk.Label(container, text=f"Profile of {username}", font=("Open Sans", 40, 'bold'), fg="#982121") profile.place(relx=0.5, rely=0.08, anchor='center') pending_button = ttk.Button(container, text="Pending orders", command=partial(call_pending, container, pending), width=20) pending_button.place(relx=0.5, rely=0.2, anchor='center') delivered_button = ttk.Button(container, text="Delivered orders", command=partial(call_delivered, container, delivered), width=20) delivered_button.place(relx=0.5, rely=0.3, anchor='center')
def deliver_pizza(container): order = admin.deliver_pizza() if order: try: database.deliver(order) except Error: notif_order.set("Delivery failed") else: util_funcs.clear_frame(container) orders(container) if admin.orders: notif_order.set("Order delivered")
def check_creds_login(container, buttonframe, uname, pass1, mode): password = pass1.get() if mode == 'customer': username = uname.get() if not username or not password: notif_customer.set('Please fill in all fields.') return try: user = database.query(username, 'password') stored = user hashed = bcrypt.hashpw(password.encode('utf-8'), stored) if hmac.compare_digest(hashed, stored): util_funcs.clear_frame(container) util_funcs.clear_frame(buttonframe) customer.create_page(container, buttonframe, username) return notif_customer.set('Invalid credentials') return except Error: notif_customer.set('Invalid credentials') elif mode == 'admin': if not pass1.get(): notif_admin.set('Please enter admin password') return try: user = database.query('admin', 'password') hashed = bcrypt.hashpw(password.encode('utf-8'), user) if hmac.compare_digest(hashed, user): util_funcs.clear_frame(container) util_funcs.clear_frame(buttonframe) admin.create_page(container, buttonframe) return notif_admin.set('Wrong password') except Error: notif_admin.set('Try again')
def register(container): util_funcs.clear_frame(container) global notif_register username = tk.StringVar() password = tk.StringVar() password2 = tk.StringVar() notif_register = tk.StringVar() register_label = tk.Label(container, text="Register a user", font=("Open Sans", 40, 'bold')) register_label.place(relx=0.3, rely=0.1, relwidth=0.4, relheight=0.1) username_label = tk.Label(container, text="Username", font=("Open Sans", 15)) username_label.place(relx=0.445, rely=0.25, relwidth=0.11, relheight=0.04) username_entry = tk.Entry(container, textvariable=username, font=("Open Sans", 15)) username_entry.place(relx=0.425, rely=0.30, relwidth=0.16, relheight=0.04) password_label = tk.Label(container, text="Password", font=("Open Sans", 15)) password_label.place(relx=0.45, rely=0.35, relwidth=0.1, relheight=0.04) password_entry = tk.Entry(container, textvariable=password, font=("Open Sans", 15), show="*") password_entry.place(relx=0.425, rely=0.4, relwidth=0.16, relheight=0.04) confirm_label = tk.Label(container, text="Confirm password", font=("Open Sans", 15)) confirm_label.place(relx=0.405, rely=0.45, relwidth=0.19, relheight=0.04) confirm_entry = tk.Entry(container, textvariable=password2, show="*", font=("Open Sans", 15)) confirm_entry.place(relx=0.425, rely=0.5, relwidth=0.16, relheight=0.04) register_button = ttk.Button(container, text="Register", command=partial(check_creds_register, container, username, password, password2), width=20) register_button.place(relx=0.5, rely=0.6, anchor="center") notif_label = tk.Label(container, textvariable=notif_register, font=("Open Sans", 14, 'bold')) notif_label.place(relx=0.5, rely=0.68, anchor="center") util_funcs.set_colors(container)
def admin_profile(container): util_funcs.clear_frame(container) tk.Label(container, text="").pack() label = tk.Label(container, text="Profile of admin", font=("Open Sans", 40, 'bold'), fg="#982121") label.pack(side="top", anchor="center") tk.Label(container, text="").pack() temp_container = tk.Frame(container) temp_container.pack(side='top') scrollbar = tk.Scrollbar(temp_container, bd=1, relief='sunken') listbox = tk.Listbox(temp_container, bg=container.cget("background"), width=50, height=15, font=("Open Sans", 16, 'bold'), fg="#982121") listbox.config(yscrollcommand=scrollbar.set) scrollbar.config(command=listbox.yview) user_list = database.pull_users() for user in user_list: if user[0] != 'admin': listbox.insert('end', f"{user[0]} => budget: {user[1]}") scrollbar.pack(side='right', fill='y') listbox.configure(justify='center') listbox.pack(side="top", anchor="center") global notif_profile name = tk.StringVar() notif_profile = tk.StringVar() amount = tk.IntVar() amount.set(100) name_lebel = tk.Label(container, text="Name", font=("Open Sans", 16), fg="#982121") amount_label = tk.Label(container, text="Amount", font=("Open Sans", 16), fg="#982121") name_entry = tk.Entry(container, textvariable=name, font=("Open Sans", 15), fg="#982121") amount_entry = tk.Entry(container, textvariable=amount, font=("Open Sans", 15), fg="#982121") add_button = ttk.Button(container, text="Update budget", command=partial(util, container, name, amount), width=20) tk.Label(container, text="").pack() name_lebel.pack() name_entry.pack() tk.Label(container, text="").pack() amount_label.pack() amount_entry.pack() tk.Label(container, text="").pack() add_button.pack() tk.Label(container, text="").pack() tk.Label(container, textvariable=notif_profile, font=("Open Sans", 16), fg="#982121").pack()
def default_pizzas(container, username): util_funcs.clear_frame(container) label = tk.Label(container, text="Our default pizzas", font=("Open Sans", 40, 'bold'), fg="#982121") label.place(relx=0.5, rely=0.07, anchor="center") buttons = ['Supreme', 'Pepperoni', 'Margarita'] num = 0 for pizza in buttons: button = ttk.Button(container, text=pizza, command=partial(pizza_menu, container, pizza, username), width=20) button.place(relx=0.5, rely=0.2 + num * 0.14, anchor="center") num += 1
def customer_login(container, buttonframe): util_funcs.clear_frame(container) global notif_customer username = tk.StringVar() password = tk.StringVar() notif_customer = tk.StringVar() login_label = tk.Label(container, text="Log in", font=("Open Sans", 40, 'bold')) login_label.place(relx=0.3, rely=0.1, relwidth=0.4, relheight=0.1) username_label = tk.Label(container, text="Username", font=("Open Sans", 15)) username_label.place(relx=0.445, rely=0.25, relwidth=0.11, relheight=0.04) username_entry = tk.Entry(container, textvariable=username, font=("Open Sans", 15)) username_entry.place(relx=0.425, rely=0.3, relwidth=0.15, relheight=0.04) password_label = tk.Label(container, text="Password", font=("Open Sans", 15)) password_label.place(relx=0.45, rely=0.35, relwidth=0.1, relheight=0.04) password_entry = tk.Entry(container, textvariable=password, show="*", font=("Open Sans", 15)) password_entry.place(relx=0.425, rely=0.4, relwidth=0.15, relheight=0.04) login_button = ttk.Button(container, text="Login", command=partial(check_creds_login, container, buttonframe, username, password, mode='customer'), width=20) login_button.place(relx=0.5, rely=0.5, anchor="center") notif_label = tk.Label(container, textvariable=notif_customer, font=("Open Sans", 14, 'bold')) notif_label.place(relx=0.5, rely=0.58, anchor="center") util_funcs.set_colors(container)
def orders(container): util_funcs.clear_frame(container) tk.Label(container, text="").pack() tk.Label(container, text="").pack() tk.Label(container, text="").pack() global notif_order global deliver_button notif_order = tk.StringVar() if admin.orders: temp_container = tk.Frame(container) temp_container.pack(side="top") pending = admin.pull_orders() util_funcs.pending_orders(temp_container, pending) deliver_button = ttk.Button(container, text="Deliver a pizza", command=partial(deliver_pizza, container), width=20) tk.Label(container, text="").pack(side="top") deliver_button.pack(side="top") tk.Label(container, text="").pack() notif_label = tk.Label(container, textvariable=notif_order, font=("Open Sans", 16), fg="#982121") notif_label.pack(side="top", anchor="center") else: notif_label = tk.Label(container, textvariable=notif_order, font=("Open Sans", 16), fg="#982121") notif_label.pack(side="top", anchor="center") notif_order.set("There is no order waiting")
def call_pending(container, pending): util_funcs.clear_frame(container) temp_container = tk.Frame(container) temp_container.pack() util_funcs.pending_orders(temp_container, pending)
def call_delivered(container, delivered): util_funcs.clear_frame(container) temp_container = tk.Frame(container) temp_container.pack() util_funcs.delivered_orders(temp_container, delivered)
def pizza_menu(container, name, username): util_funcs.clear_frame(container) pizza = pizza_builder.PizzaBuilder(name) global status_pizza global notif_pizza global cost_pizza label = "Create your own pizza" if name == 'Custom' else name budget_image = tk.PhotoImage(file="src/icons/budget.png").subsample(4, 4) name_label = tk.Label(container, text=label, font=("Open Sans", 40, 'bold')) name_label.place(relx=0.5, rely=0.07, anchor="center") budget_icon = tk.Label(container, image=budget_image) budget_icon.image = budget_image budget_icon.place(relx=0.83, rely=0.15, anchor='center') budget_label = tk.Label(container, text="Budget:", font=("Open Sans", 14)) budget_money = tk.Label(container, textvariable=budget, font=("Open Sans", 14)) budget_label.place(relx=0.8, rely=0.3, anchor="center") budget_money.place(relx=0.86, rely=0.3, anchor="center") ingredients = pizza.default create_buttons(container, pizza, 'add', ingredients) create_buttons(container, pizza, 'remove', ingredients) status_pizza = tk.StringVar() set_status(pizza) cost_pizza = tk.DoubleVar() cost_pizza.set(pizza.get_price()) status_label = tk.Label(container, textvariable=status_pizza, font=("Open Sans", 16)) status_label.place(relx=0.6, rely=0.2, anchor='n') price_word = tk.Label(container, text="Cost:", font=("Open Sans", 18)) price_word.place(relx=0.58, rely=0.67, anchor='center') price_label = tk.Label(container, textvariable=cost_pizza, font=("Open Sans", 18, 'bold')) price_label.place(relx=0.62, rely=0.67, anchor='center') order_button = ttk.Button(container, text="Order", command=partial(order, container, pizza, username), width=20) order_button.place(relx=0.6, rely=0.76, anchor='center') notif_pizza = tk.StringVar() notif_label = tk.Label(container, textvariable=notif_pizza, font=("Open Sans", 18)) notif_label.place(relx=0.83, rely=0.76, anchor='center') pizza_image = pizzas[name] pizza_label = tk.Label(container, image=pizza_image) pizza_label.image = pizza_image pizza_label.place(relx=0.83, rely=0.55, anchor='center') util_funcs.set_colors(container)
def logout(container, buttonframe): util_funcs.clear_frame(container) util_funcs.clear_frame(buttonframe) create_page(container, buttonframe)