Created
March 22, 2020 17:50
-
-
Save owencsmith/075bb15127439fd392bdbddfe3155747 to your computer and use it in GitHub Desktop.
The file containing the code for my MQP's user interface for a cup cleaning system.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from guizero import App, Window, PushButton, TextBox, Text, Box | |
import tkinter | |
import sched, time | |
from ArduinoComm import Communication | |
def making_account(): | |
""" | |
Hides the possible preceding screens and shows the create account screen | |
""" | |
welcome_screen_box.hide() | |
login_screen_box.hide() | |
new_account.show() | |
def return_to_window(): | |
""" | |
Returns the program to the welcome screen from account log in and create account screens | |
""" | |
welcome_screen_box.show() | |
new_account.hide() | |
login_screen_box.hide() | |
def user_login(): | |
""" | |
Reveals the user login screen and hides the preceding welcome screen | |
""" | |
welcome_screen_box.hide() | |
login_screen_box.show() | |
login_username.focus() | |
def check_credentials(): | |
""" | |
Checks the login credentials from the login screen | |
""" | |
if login_username.value not in user_dict or user_dict[login_username.value] != login_password.value: | |
invalid_credentials() | |
else: | |
valid_credentials() | |
def invalid_credentials(self): | |
""" | |
Warns that the user has not entered valid login credentials | |
""" | |
invalid_warning.show() | |
login_username.focus() | |
def valid_credentials(): | |
""" | |
After a successful login attempt removes warnings, clears fields, and transitions to the home screen | |
""" | |
invalid_warning.hide() | |
login_screen_box.hide() | |
create_account_button.hide() | |
login_username.clear() | |
login_password.clear() | |
home_screen.show() | |
def dispense_cup(): | |
""" | |
Transitions from home screen to a user receiving a cup. Tells the second Arduino to make the magic happen | |
""" | |
# try | |
# catch | |
# ard2.writeNumber(0) | |
rc_confirmed_box.hide() | |
home_screen.hide() | |
got_my_cup.show() | |
def begin_return(): | |
""" | |
Transitions from home screen to a user returning a cup. | |
""" | |
home_screen.hide() | |
returned_cup_box.show() | |
def finish_return(): | |
""" | |
Tells the first Arduino to make the magic happen | |
""" | |
returned_cup_box.hide() | |
ard1.writeNumber(1) | |
rc_confirmed_box.show() | |
def create_attempt(): | |
if new_username_text.value != "" and new_username_text.value not in user_dict: | |
user_dict[new_username_text.value] = new_password_text.value | |
has_account.hide() | |
new_account.hide() | |
user_login() | |
else: | |
has_account.show() | |
def thank_you_screen(): | |
got_my_cup.hide() | |
rc_confirmed_box.hide() | |
# deposited_cup.hide() | |
thank_you.show() | |
thank_you.after(5000, go_to_home, ()) | |
def go_to_home(): | |
thank_you.hide() | |
thank_you.cancel(go_to_home) | |
welcome_screen_box.show() | |
title_box.show() | |
user_dict = { | |
"asdf": "asdf" | |
} | |
s = sched.scheduler(time.time, time.sleep) | |
ard1 = Communication(0x08) | |
# ard2 = Communication(0x02) | |
# region App Setup | |
app = app = App(title="") | |
app.bg = "#1B1A1A" # light gray "#576574" # magenta "#6F1E51" | |
app.text_size = "14" | |
app.text_color = "white" | |
app.font = "Arial" | |
app.full_screen = True | |
app_width = app.width | |
app_height = app.height | |
app_button_color = "#2C2C2B" # dark gray"#222f3e" # very berry"#B53471" | |
# endregion | |
# region To Create Account Screen | |
title_box = Box(app, width="fill", align="top") | |
create_account_button = PushButton(title_box, padx=5, pady=5, text="Create Account", command=making_account, | |
align="left") | |
create_account_button.bg = app_button_color | |
create_account_button.text_size = 15 | |
# endregion | |
# region Initial Welcome Screen | |
welcome_screen_box = Box(app, width="fill", align="top", height="fill") | |
header = Text(welcome_screen_box, text="Reusable Cup Machine") | |
header.text_size = create_account_button.text_size * 6 | |
login = PushButton(welcome_screen_box, padx=35, pady=30, text="Login", command=user_login) | |
login.bg = app_button_color | |
login.text_size = create_account_button.text_size * 10 | |
login.tk.pack(fill="none", expand=True) | |
# endregion | |
# region User Login Screen | |
login_screen_box = Box(app, width="fill", align="top") | |
login_title = Text(login_screen_box, text="Login Screen") | |
login_title.size = 40 | |
# endregion | |
# region Invalid Login Attempt Warning | |
invalid_warning = Box(login_screen_box, width="fill") | |
invalid_text = Text(invalid_warning, text="Provided Credentials Could Not Be Determined to Be Authentic") | |
invalid_text.text_size = 9 | |
try_again = Text(invalid_warning, text="Please Try Again") | |
try_again.text_size = 9 | |
invalid_warning.text_color = "red" | |
invalid_warning.hide() | |
# endregion | |
# region Username and Password Input | |
username = Text(login_screen_box, text="Username:") | |
login_username = TextBox(login_screen_box) | |
login_username.text_color = "black" | |
login_username.bg = "white" | |
password = Text(login_screen_box, text="Password:") | |
login_password = TextBox(login_screen_box, hide_text=True) | |
login_password.text_color = "black" | |
login_password.bg = "white" | |
login_attempt_button = PushButton(login_screen_box, padx=35, pady=30, text="Next", command=check_credentials) | |
login_attempt_button.bg = app_button_color | |
login_screen_box.hide() | |
# endregion | |
# region Home Screen After Login | |
home_screen = Box(app, width="fill") | |
return_cup = PushButton(home_screen, text="Return Cup", command=begin_return) | |
return_cup.text_size = create_account_button.text_size * 5 | |
return_cup.bg = app_button_color | |
get_cup = PushButton(home_screen, text="Get Cup", command=dispense_cup) | |
get_cup.text_size = return_cup.text_size | |
get_cup.bg = app_button_color | |
home_screen.hide() | |
# endregion | |
# region Create Account Screen | |
new_account = Box(app, width="fill") | |
has_account = Text(new_account, size=10, text="Username already exists!", color="red") | |
has_account.hide() | |
new_username = Text(new_account, size=10, text="Username:") | |
new_username_text = TextBox(new_account) | |
new_username_text.bg = "white" | |
new_username_text.text_color = "black" | |
new_password = Text(new_account, size=10, text="Password:") | |
new_password_text = TextBox(new_account, hide_text=True) | |
new_password_text.bg = "white" | |
new_password_text.text_color = "black" | |
na_sub_box = Box(new_account, layout="grid") | |
exit_create = PushButton(na_sub_box, text="Close", command=return_to_window, grid=[0, 0]) | |
exit_create.bg = app_button_color | |
attempt_create = PushButton(na_sub_box, text="Create", align="left", grid=[1, 0], command=create_attempt) | |
attempt_create.bg = app_button_color | |
new_account.hide() | |
# endregion | |
# region Return Cup Starting Info | |
returned_cup_box = Box(app, width="fill") | |
rc_info_text = Text(returned_cup_box, size=36, text="Place Your Cup in the Ring", align="center") | |
rc_confirm_button = PushButton(returned_cup_box, text="Placed the Cup", command=finish_return, width=int(app_width / 3), | |
height=int(app_height / 3), align="center") | |
rc_confirm_button.text_size = login_title.text_size * 3 | |
returned_cup_box.hide() | |
# endregion | |
# region Return Cup Confirmed Info | |
rc_confirmed_box = Box(app, width="fill") | |
rcc_info_text = Text(rc_confirmed_box, size=36, text="Would You Like To \n Get a New Cup?", align="center") | |
rcc_sidebyside = Box(rc_confirmed_box, layout="grid", align="center") | |
rcc_yes = PushButton(rcc_sidebyside, grid=[0, 0], text="Yes", command=dispense_cup, align="center") | |
rcc_no = PushButton(rcc_sidebyside, grid=[1, 0], text="No", command=thank_you_screen, align="center") | |
rc_confirmed_box.hide() | |
# endregion | |
# region Dispense Cup Info | |
got_my_cup = Box(app, width="fill") | |
dc_info_text = Text(got_my_cup, size=36, text="Retrieve Your Cup\nFrom Below", align="center") | |
dc_confirm_button = PushButton(got_my_cup, text="Got My Cup", command=thank_you_screen, width=int(app_width / 3), | |
height=int(app_height / 3), align="center") | |
dc_confirm_button.text_size = login_title.text_size * 3 | |
got_my_cup.hide() | |
# endregion | |
# region Thank You | |
thank_you = Box(app, width="fill") | |
ty_text = PushButton(thank_you, width=app_width, height=app_height, text="Thank\nYou", command=go_to_home, | |
align="center") | |
ty_text.text_size = login_title.text_size * 5 | |
ty_text.tk.config(highlightthickness=0) | |
thank_you.hide() | |
# endregion | |
app.display() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment