Skip to content

Commit

Permalink
UI changes (#131)
Browse files Browse the repository at this point in the history
Began to remodel the UI using tabulate for better tables
  • Loading branch information
tylerlight071 authored Feb 9, 2024
2 parents 4b9f2c2 + 30412e4 commit baf4292
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 40 deletions.
25 changes: 17 additions & 8 deletions N_P_P.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from login import login
from client_database import client_database
from pymongo import MongoClient
from tabulate import tabulate

get_mongodb_uri()

Expand Down Expand Up @@ -37,8 +38,8 @@ def logout():

# Main menu
def display_menu(options):
for i, option in enumerate(options, 1):
print(f"{i}. {option}")
table_data = [[i, option] for i, option in enumerate(options, 1)]
print(tabulate(table_data, tablefmt='fancy_grid'))

def handle_option(option, functions):
try:
Expand All @@ -52,14 +53,19 @@ def handle_option(option, functions):
print(Fore.RED + "\nInvalid option. Please try again." + Style.RESET_ALL)
time.sleep(2)

from tabulate import tabulate

def main_menu():
options = [Fore.GREEN + "Login" + Style.RESET_ALL, Fore.YELLOW + "Exit" + Style.RESET_ALL]
functions = [login, exit]
while True:
clear_screen()
print(Fore.CYAN + "\n🐕 Welcome to Nexus Pet Portal! 🐈\n" + Style.RESET_ALL)
display_menu(options)
choice = input("\nPlease select an option: ")
welcome_table = [[Fore.CYAN + "🐕 Welcome to Nexus Pet Portal! 🐈" + Style.RESET_ALL]]
options_table = [[f"{i}. {option}"] for i, option in enumerate(options, 1)]
options_table.append(["Please select an option:"])
print(tabulate(welcome_table, tablefmt='fancy_grid'))
print(tabulate(options_table, tablefmt='fancy_grid'))
choice = input("\n> ")
user_details = handle_option(choice, functions)
if user_details is not None:
user_menu(user_details[0], user_details[1])
Expand All @@ -82,9 +88,12 @@ def user_menu(current_user, user_level):
functions.append(logout)
while True:
clear_screen()
print(Fore.CYAN + "\n📖 Main Menu 📖\n" + Style.RESET_ALL)
display_menu(options)
choice = input("\nPlease select an option: ")
menu_table = [[Fore.CYAN + "📖 Main Menu 📖" + Style.RESET_ALL]]
options_table = [[f"{i}. {option}"] for i, option in enumerate(options, 1)]
options_table.append(["Please select an option:"])
print(tabulate(menu_table, tablefmt='fancy_grid'))
print(tabulate(options_table, tablefmt='fancy_grid'))
choice = input("\n> ")
# Logout option
if choice == str(len(options)):
log_action(current_user, "Logged out")
Expand Down
3 changes: 2 additions & 1 deletion login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import getpass
import time
from colorama import Fore, Style
from tabulate import tabulate
from common_functions import clear_screen, log_action, hash_password, verify_password, get_mongodb_uri
from admin_dashboard import admin_dashboard
from pymongo import MongoClient
Expand Down Expand Up @@ -98,7 +99,7 @@ def login():
# Continuous loop for login
while attempts < MAX_ATTEMPTS:
# Display login prompt
print("\n👤 User Login 👤")
print(tabulate([["\n👤 User Login 👤"]], tablefmt='fancy_grid'))
username = input("\nEnter your username: ")
password = getpass.getpass("Enter your password: ")

Expand Down
51 changes: 49 additions & 2 deletions notifications.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@
import time
from tabulate import tabulate
from colorama import Fore, Style
from common_functions import clear_screen

def notifications():
print("\nThis is the notifications feature. It is currently under construction. Please come back later.")
time.sleep(2)
notifications = [
{"id": 1, "text": "Notification 1", "read": False},
{"id": 2, "text": "Notification 2", "read": False},
{"id": 3, "text": "Notification 3", "read": False},
]

while True:
clear_screen()

print("\nNotifications:")
table = [[notif['id'], notif['text'], 'Read' if notif['read'] else 'Unread'] for notif in notifications]
print(tabulate(table, headers=['ID', 'Text', 'Status'], tablefmt='pretty'))

print("\nOptions:")
print(Fore.CYAN + "1. Read a notification")
print(Fore.CYAN + "2. Delete a notification")
print(Fore.CYAN + "3. Clear read notifications")
print(Fore.CYAN + "4. Exit" + Style.RESET_ALL)

option = input("\nPlease select an option: ")

if option == '1':
clear_screen()
notif_id = int(input("\nEnter the ID of the notification you want to read: "))
for notification in notifications:
if notification['id'] == notif_id:
notification['read'] = True
print(Fore.GREEN + f"\n{notification['text']}" + Style.RESET_ALL)
break
else:
print(Fore.RED + "Notification not found." + Style.RESET_ALL)
elif option == '2':
clear_screen()
notif_id = int(input("\nEnter the ID of the notification you want to delete: "))
notifications = [notification for notification in notifications if notification['id'] != notif_id]
elif option == '3':
notifications = [notification for notification in notifications if not notification['read']]
elif option == '4':
break
else:
print(Fore.RED + "Invalid option. Please try again." + Style.RESET_ALL)
time.sleep(2)
clear_screen()

time.sleep(2)

8 changes: 8 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
altgraph==0.17.4
annotated-types==0.6.0
ansicon==1.89.0
anyio==4.2.0
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
asttokens==2.4.1
Babel==2.14.0
beautifulsoup4==4.12.2
blessed==1.20.0
blinker==1.7.0
bottle==0.12.25
bottle-websocket==0.2.9
Expand All @@ -26,6 +28,7 @@ deep-translator==1.11.4
distro==1.9.0
dlib==19.24.2
dnspython==2.5.0
editor==1.6.6
Eel==0.16.0
emoji==2.9.0
executing==2.0.1
Expand Down Expand Up @@ -54,6 +57,7 @@ ipython==8.17.2
itsdangerous==2.1.2
jedi==0.19.1
Jinja2==3.1.3
jinxed==1.2.1
langdetect==1.0.9
lz4==4.3.3
MarkupSafe==2.1.3
Expand Down Expand Up @@ -88,15 +92,18 @@ pypiwin32==223
pyttsx3==2.90
pywin32==306
pywin32-ctypes==0.2.2
readchar==4.0.5
requests==2.31.0
rsa==4.9
runs==1.2.2
setuptools==69.0.3
six==1.16.0
sniffio==1.3.0
sounddevice==0.4.6
soupsieve==2.5
SpeechRecognition==3.10.1
stack-data==0.6.3
tabulate==0.9.0
tkcalendar==1.6.1
tqdm==4.66.1
traitlets==5.13.0
Expand All @@ -108,5 +115,6 @@ wcwidth==0.2.9
Werkzeug==3.0.1
wheel==0.42.0
whichcraft==0.6.1
xmod==1.8.1
zope.event==5.0
zope.interface==6.1
7 changes: 4 additions & 3 deletions sudo_user_login.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import sys
import getpass
from tabulate import tabulate
from common_functions import clear_screen, verify_password, log_action
from colorama import Fore, Style

Expand All @@ -19,7 +20,7 @@ def login(self):
MAX_ATTEMPTS = 2

for attempts in range(MAX_ATTEMPTS):
print(Fore.LIGHTMAGENTA_EX + "\n👤 Sudo Login 👤" + Style.RESET_ALL)
print(tabulate([[Fore.LIGHTMAGENTA_EX + "👤 Sudo Login 👤" + Style.RESET_ALL]], tablefmt='fancy_grid'))
print(enter_credentials)

username, password = self.get_credentials()
Expand Down Expand Up @@ -106,7 +107,7 @@ class SudoUserLevel1(SudoUser):
def login(self):
for attempts in range(self.MAX_ATTEMPTS):
clear_screen()
print(Fore.LIGHTMAGENTA_EX + "\n👤 Sudo Login 👤" + Style.RESET_ALL)
print(tabulate([[Fore.LIGHTMAGENTA_EX + "👤 Sudo Login 👤" + Style.RESET_ALL]], tablefmt='fancy_grid'))
print(enter_credentials)

username, password = self.get_credentials()
Expand Down Expand Up @@ -151,7 +152,7 @@ class SudoAdmin(SudoUser):
def login(self):
for attempts in range(self.MAX_ATTEMPTS):
clear_screen()
print(Fore.LIGHTMAGENTA_EX + "\n👤 ADMIN Sudo Login 👤" + Style.RESET_ALL)
print(tabulate([[Fore.LIGHTMAGENTA_EX + "👤 ADMIN Sudo Login 👤" + Style.RESET_ALL]], tablefmt='fancy_grid'))
print(enter_credentials)

username, password = self.get_credentials()
Expand Down
30 changes: 14 additions & 16 deletions tables.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
from colorama import Fore, Style
from common_functions import clear_screen
from tabulate import tabulate

basic_animal_table = ("+-------------------------------------------------------------------------------------------+")
animal_table_with_index = ("+---------------------------------------------------------------------------------+")

# Function to print the table of animals
def print_animal_table(animals):

# Print table header
print("\n🐾 " + Fore.CYAN + "List of Animals" + Style.RESET_ALL + " 🐾")
print(basic_animal_table)
print("| " + Fore.YELLOW + "Name".ljust(20) + Style.RESET_ALL + "| " + Fore.YELLOW + "Species".ljust(8) + Style.RESET_ALL + "| " + Fore.YELLOW + "Breed".ljust(25) + Style.RESET_ALL + "| " + Fore.YELLOW + "Gender".ljust(15) + Style.RESET_ALL + "| " + Fore.YELLOW + "Age".ljust(1) + Style.RESET_ALL + " | " + Fore.YELLOW + "Adopted".ljust(7) + Style.RESET_ALL + " |")
print(basic_animal_table)
print("\n🐾 " + Fore.CYAN + "List of Animals" + Style.RESET_ALL + " 🐾\n")

# Print each animal's data row by row
# Prepare table data
table_data = []
for animal in animals:
name_column = f"| {animal['name'].ljust(20)}"
species_column = f"| {animal['species'].ljust(8)}"
breed_column = f"| {animal['breed'].ljust(25)}"
gender_column = f"| {animal['gender'].ljust(15)}"
age_column = f"| {str(animal['age']).ljust(3)}"
adopted_column = f"| {str(animal['adopted']).ljust(7)} |"
print(name_column + species_column + breed_column + gender_column + age_column + adopted_column)

# Print table footer
print(basic_animal_table)
row = [animal['name'], animal['species'], animal['breed'], animal['gender'], animal['age'], animal['adopted']]
table_data.append(row)

# Print table with tabulate
headers = [Fore.YELLOW + "Name", "Species", "Breed", "Gender", "Age", "Adopted" + Style.RESET_ALL]
print(tabulate(table_data, headers=headers, tablefmt='fancy_grid'))

# presto
# pretty
# psql

# Function to print the table of animals with index numbers
def print_animal_table_with_index(animals):
Expand Down
30 changes: 20 additions & 10 deletions view_animals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import time
import ctypes
from colorama import Fore, Style
from tabulate import tabulate
from common_functions import clear_screen, load_animal_data, log_action, get_mongodb_uri, sanitize_input
from view_animal_profile import view_animals_full
from sudo_user_login import SudoUserLevel1, SudoUser
Expand All @@ -8,6 +10,11 @@
from tables import print_animal_table
from pymongo import MongoClient

# Get console window
ctypes.windll.kernel32.GetConsoleWindow()
# Set console title
ctypes.windll.kernel32.SetConsoleTitleW("🐾 Nexus Pet Portal 🐾")

# Connect to MongoDB
uri = get_mongodb_uri()
client = MongoClient(uri)
Expand Down Expand Up @@ -287,9 +294,6 @@ def view_animals():
animals = load_animal_data(animals_collection)
current_user = SudoUserLevel1(users_collection.database).login()

# Load animal data
print_animal_table(animals)

while True:
print_options(current_user)
user_input = input(select_option)
Expand All @@ -310,16 +314,22 @@ def view_animals():

# Print options for the user
def print_options(current_user):
print(Fore.CYAN + "\n⚙️ Options ⚙️" + Style.RESET_ALL)
print("\n1. " + Fore.GREEN + "Search for animal" + Style.RESET_ALL)
print("2. " + Fore.GREEN + "Sort/Filter Animals" + Style.RESET_ALL)
options = [
["1. ", Fore.GREEN + "🔍 Search for animal" + Style.RESET_ALL],
["2. ", Fore.GREEN + "🔼 Sort/Filter Animals" + Style.RESET_ALL]
]

if current_user['level'] >= 2:
print("3. " + Fore.GREEN + "View animal profile" + Style.RESET_ALL)
print("4. " + Fore.GREEN + "Modify Database" + Style.RESET_ALL)
print("5. " + Fore.YELLOW + "Exit" + Style.RESET_ALL)
options.extend([
["3. ", Fore.GREEN + "🐾 View animal profile" + Style.RESET_ALL],
["4. ", Fore.GREEN + "📋 Modify Database" + Style.RESET_ALL],
["5. ", Fore.YELLOW + "← Back" + Style.RESET_ALL]
])
else:
print("3. " + Fore.YELLOW + "Exit" + Style.RESET_ALL)
options.append(["3. ", Fore.YELLOW + "Exit" + Style.RESET_ALL])

print(tabulate([[Fore.CYAN + "☰ Options ☰" + Style.RESET_ALL]], tablefmt='fancy_grid'))
print(tabulate(options, tablefmt='fancy_grid'))

# Search the database
def search_database(animals, current_user):
Expand Down

0 comments on commit baf4292

Please sign in to comment.