Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Commit

Permalink
Comentarios y refactor de la interfaz
Browse files Browse the repository at this point in the history
  • Loading branch information
seniorbeto committed Oct 21, 2023
1 parent 39da659 commit 5f8c2e9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 37 deletions.
11 changes: 5 additions & 6 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
7 changes: 6 additions & 1 deletion src/screens/home_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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 = []
Expand Down
27 changes: 0 additions & 27 deletions src/screens/loading_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 3 additions & 2 deletions src/screens/register_toplevel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion src/screens/user_screen.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 5f8c2e9

Please sign in to comment.