changed menu layout

This commit is contained in:
Spekulaas 2023-10-25 13:47:05 +02:00
parent 7900493ec5
commit 826999e229
2 changed files with 115 additions and 45 deletions

View File

@ -18,20 +18,33 @@ class MenuHelper:
self.db = db
self.start_menu = {}
self.user_menu = {}
self.user_main_menu = {}
self.user_blockchain_menu = {}
self.user_settings_menu = {}
self.start_menu[0] = "Exit"
self.start_menu[1] = "Explore the Blockchain"
self.start_menu[2] = "Login"
self.start_menu[3] = "Sign up"
self.user_menu[0] = "Log out"
self.user_menu[1] = "Explore the Blockchain"
self.user_menu[2] = "Transfer coins"
self.user_menu[3] = "Cancel transaction"
self.user_menu[4] = "Check balance"
self.user_menu[5] = "Check the pool"
self.user_menu[6] = "Mine a block"
self.user_main_menu[0] = "Exit"
self.user_main_menu[1] = "User Settings"
self.user_main_menu[2] = "Blockchain"
self.user_main_menu[3] = "Log out"
self.user_blockchain_menu[0] = "Back"
self.user_blockchain_menu[1] = "Explore the Blockchain"
self.user_blockchain_menu[2] = "Transfer coins"
self.user_blockchain_menu[3] = "Cancel transaction"
self.user_blockchain_menu[4] = "Check balance"
self.user_blockchain_menu[5] = "Check the pool"
self.user_blockchain_menu[6] = "Mine a block"
self.user_settings_menu[0] = "Back"
self.user_settings_menu[1] = "View account info"
self.user_settings_menu[2] = "Change username"
self.user_settings_menu[3] = "Change password"
self.user_settings_menu[3] = "DELETE ACCOUNT"
self.opened_logs = False
@ -41,15 +54,10 @@ class MenuHelper:
def runStartMenu(self):
while(True):
self.printMenu(self.start_menu)
# make input an interger
try:
choice = int(input())
except:
self.clearScreen()
print("Wrong input, try again")
choice = self.getMenuInput(self.start_menu)
if choice == None:
continue
self.clearScreen()
# check if choice is in menu
match self.start_menu[choice]:
@ -58,7 +66,7 @@ class MenuHelper:
exit()
case "Explore the Blockchain":
pass
print("TODO")
case "Login":
user = User(self.db)
@ -80,43 +88,105 @@ class MenuHelper:
case _:
print("Wrong input, try again")
def runUserMenu(self, user):
while(True):
self.printMenu(self.user_menu)
# make input an interger
try:
choice = int(input())
except:
self.clearScreen()
print("Wrong input, try again")
def runUserMainMenu(self, user):
while(user):
choice = self.getMenuInput(self.user_main_menu)
if choice == None:
continue
self.clearScreen()
# check if choice is in menu
match self.user_menu[choice]:
match self.user_main_menu[choice]:
case "Exit":
print('Exiting system')
exit()
case "Log out":
user.logout()
user = None
case "Explore the Blockchain":
pass
case "User Settings":
print(user.private_key)
case "Transfer coins":
pass
case "Cancel transaction":
pass
case "Check balance":
pass
case "Check the pool":
pass
case "Mine a block":
pass
case "Blockchain":
self.runUserBlockchainMenu(user)
case _:
print("Wrong input, try again")
def runUserBlockchainMenu(self, user):
while(user):
choice = self.getMenuInput(self.user_blockchain_menu)
if choice == None:
continue
# check if choice is in menu
match self.user_blockchain_menu[choice]:
case "Back":
return
case "Explore the Blockchain":
print(user.private_key)
case "Transfer coins":
input("Enter the username of the receiver: ")
print("TODO")
case "Cancel transaction":
print("TODO")
case "Check balance":
print("TODO")
case "Check the pool":
print("TODO")
case "Mine a block":
print("TODO")
case _:
print("Wrong input, try again")
def runUserSettingsMenu(self, user):
while(user):
choice = self.getMenuInput(self.user_settings_menu)
if choice == None:
continue
# check if choice is in menu
match self.user_settings_menu[choice]:
case "Back":
return
case "View account info":
print(user.private_key)
case "Change username":
print("TODO")
case "Change password":
print("TODO")
case "DELETE ACCOUNT":
print("TODO")
case _:
print("Wrong input, try again")
def getMenuInput(self, menu):
self.printMenu(menu)
# make input an interger
try:
choice = int(input())
except:
self.clearScreen()
print("Wrong input, try again")
return None
self.clearScreen()
return choice
def clearScreen(self):
os.system('cls' if os.name == 'nt' else 'clear')

View File

@ -22,4 +22,4 @@ if __name__ == "__main__":
user = menu.runStartMenu()
if user:
menu.runUserMenu(user)
menu.runUserMainMenu(user)