From 5f8c2e9761f6df8247fcb617be8efd2bfd8059be Mon Sep 17 00:00:00 2001 From: Beto <100471939@alumnos.uc3m.es> Date: Sat, 21 Oct 2023 12:17:43 +0200 Subject: [PATCH] Comentarios y refactor de la interfaz --- src/app.py | 11 +++++------ src/screens/home_screen.py | 7 ++++++- src/screens/loading_screen.py | 27 --------------------------- src/screens/register_toplevel.py | 5 +++-- src/screens/user_screen.py | 8 +++++++- 5 files changed, 21 insertions(+), 37 deletions(-) diff --git a/src/app.py b/src/app.py index 9982f63..5b29e4d 100644 --- a/src/app.py +++ b/src/app.py @@ -9,15 +9,12 @@ class App: def __init__(self): self.root = tk.Tk() self.api = Client() - self.root.title("La pinga de la ponga") self.root.geometry("700x400") self.root.grid_rowconfigure(0, weight=1) self.root.grid_columnconfigure(0, weight=1) - self.user = None - - self.loading_progress = 0 + # Create the frames and position them in the grid self.frames = {} for fr in (HomeScreen, UserScreen, LoadingScreen): frame = fr(self) @@ -26,19 +23,21 @@ def __init__(self): self.current_screen = HomeScreen self.showHomeScreen() + # Initiate the app self.root.mainloop() def resetProgress(self): - self.loading_progress = 0 + """Resets the progress bar to 0""" self.frames[LoadingScreen].progress_bar["value"] = 0 self.frames[LoadingScreen].update() def updateProgress(self, progress): - self.loading_progress = progress + """Updates the progress bar to the given value""" self.frames[LoadingScreen].progress_bar["value"] = progress self.frames[LoadingScreen].update() def updateStatus(self, status): + """Updates the loading status label to the given value""" self.frames[LoadingScreen].update_status(status) def showScreen(self, name): diff --git a/src/screens/home_screen.py b/src/screens/home_screen.py index 207363e..1ded7df 100644 --- a/src/screens/home_screen.py +++ b/src/screens/home_screen.py @@ -6,6 +6,10 @@ import platform class HomeScreen(tk.Frame): + """ + This class represents the home frame shown in the main app. It contains a grid of + images that all users have uploaded to the server. + """ def __init__(self, app): super().__init__(app.root, bg="#212121") self.pack(fill=tk.BOTH, expand=True) @@ -69,7 +73,7 @@ def create_main_menu(self): self.user_menu.add_command(label="Register", command=self.register) - # DEVELOPER OPTIONS +# DEVELOPER OPTIONS ################################################## # clear server # self.main_menu.add_command(label="CLEAN SERVER", command=self.clean_server) # admin mode @@ -86,6 +90,7 @@ def admin_mode(self): def clean_server(self): self.app.api.server.clear_server() self.initiate_main_display() +##################################################################### def show_images(self): self.images = [] diff --git a/src/screens/loading_screen.py b/src/screens/loading_screen.py index ca7a0b0..03c1c95 100644 --- a/src/screens/loading_screen.py +++ b/src/screens/loading_screen.py @@ -36,30 +36,3 @@ def update_status(self, status): self.status_label.place(relx=0.5, rely=0.7, anchor=tk.CENTER) self.update_idletasks() self.update() - -if __name__ == '__main__': - class appTest: - def __init__(self): - self.root = tk.Tk() - self.root.geometry("700x400") - self.root.grid_rowconfigure(0, weight=1) - self.root.grid_columnconfigure(0, weight=1) - self.frames = {} - for fr in (LoadingScreen,): - frame = fr(self) - self.frames[fr] = frame - frame.grid(row=0, column=0, sticky=tk.NSEW) - self.current_screen: tk.Frame = LoadingScreen - self.showLoadingScreen() - self.root.mainloop() - - def showScreen(self, name): - frame = self.frames[name] - self.current_screen = frame - frame.tkraise() - - def showLoadingScreen(self): - self.frames[LoadingScreen].initiate_main_display() - self.showScreen(LoadingScreen) - - appTest() \ No newline at end of file diff --git a/src/screens/register_toplevel.py b/src/screens/register_toplevel.py index 60dfd6b..d4c14cb 100644 --- a/src/screens/register_toplevel.py +++ b/src/screens/register_toplevel.py @@ -34,11 +34,12 @@ def __init__(self, app): def register(self): user = self.username_entry.get() password = self.password_entry.get() + password2 = self.password_entry_r.get() try: - if self.password_entry.get() != self.password_entry_r.get(): + if password2 != password: messagebox.showerror("Error", "Passwords don't match") else: - self.app.api.register(self.username_entry.get(), self.password_entry.get()) + self.app.api.register(user, password) messagebox.showinfo("Success", "User registered successfully") self.destroy() except Exception as e: diff --git a/src/screens/user_screen.py b/src/screens/user_screen.py index 6945333..d91889b 100644 --- a/src/screens/user_screen.py +++ b/src/screens/user_screen.py @@ -1,10 +1,15 @@ import tkinter as tk -from PIL import Image, ImageTk import platform + +from PIL import Image, ImageTk from packages.server.ImgPackage import ImgPackage from .image_selector_toplevel import ImageSelectorWindow class UserScreen(tk.Frame): + """ + This class represents the user frame shown in the main app. It contains a grid of + images that the user has uploaded to the server. + """ def __init__(self, app): super().__init__(app.root, background="#212121") self.app = app @@ -84,6 +89,7 @@ def logout(self): def show_images(self): self.images = [] self.app.updateStatus("Decrypting images...") + # We get the images from the api. We also get the progress of the decryption for progress, i in self.app.api.get_images(): self.images.append(i) self.app.updateProgress(progress)