Fixing bugs & start creating interface

This commit is contained in:
Jérémi N ‘EndMove’ 2022-08-31 12:07:43 +02:00
parent dce1b2f9a5
commit 16794bf488
Signed by: EndMove
GPG Key ID: 65C4A02E1F5371A4
10 changed files with 145 additions and 38 deletions

4
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,4 @@
{
"todo-tree.tree.showBadges": true,
"todo-tree.tree.showCountsInTree": true
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

@ -15,4 +15,4 @@ class Frames(Enum):
@since 2022-08-30 @since 2022-08-30
""" """
Home = 1 # Home view Home = 1 # Home view
Info = 2 # Info & copyright view Info = 2 # Info & copyright view

View File

@ -37,7 +37,15 @@ class HomeController:
:frame: -> The frame we want to launch. :frame: -> The frame we want to launch.
""" """
self.__main_controller.change_frame(frame) #self.__main_controller.change_frame(frame)
self.__view.add_log("Salut comment vas tu ? 1")
self.__view.add_log("Salut comment vas tu ? 2")
self.__view.add_log("Salut comment vas tu ? 3")
self.__view.add_log("Salut comment vas tu ? 4")
self.__view.add_log("Salut comment vas tu ? 5")
self.__view.add_log("Salut comment vas tu ? 6")
self.__view.add_log("Salut comment vas tu ? 7")
self.__view.add_log("Salut comment vas tu ? 8")
def on_download_started(self, url: str, name: str) -> None: def on_download_started(self, url: str, name: str) -> None:
""" """
@ -47,4 +55,4 @@ class HomeController:
:name: -> The name of the folder in which put pictures. :name: -> The name of the folder in which put pictures.
""" """
pass pass
# END View events # END View events

View File

@ -38,4 +38,4 @@ class InfoController:
:frame: -> The frame we want to launch. :frame: -> The frame we want to launch.
""" """
self.__main_controller.change_frame(frame) self.__main_controller.change_frame(frame)
# END View events # END View events

View File

@ -20,18 +20,29 @@ class MainController:
def set_view(self, view) -> None: def set_view(self, view) -> None:
""" """
[function for view] [function for view]
=> Allow to define the controller view.
:view: -> The view that this controller manage. :view: -> The view that this controller manage.
""" """
self.__view = view self.__view = view
# END view methods
def on_check_for_update(self) -> None:
"""
[event function for view]
=> Event launched when a check for available updates is requested.
"""
# TODO write the function
print("on_check_for_update")
pass
# END View methods
# START Controller methods # START Controller methods
def change_frame(self, frame) -> None: def change_frame(self, frame) -> None:
""" """
[function for controller] [function for controller]
=> Allows you to request a frame change in the main window.
:frame: -> The frame we want to display on the window instead of the current frame. :frame: -> The frame we want to display on the window instead of the current frame.
""" """
self.__view.show_frame(frame) self.__view.show_frame(frame)
# END Controller methods # END Controller methods

View File

@ -35,4 +35,4 @@ if __name__ == '__main__':
main_window.show_frame(Frames.Home) main_window.show_frame(Frames.Home)
# Start main windows looping (launch program) # Start main windows looping (launch program)
main_window.mainloop() main_window.mainloop()

View File

@ -1,5 +1,6 @@
import tkinter as tk import tkinter as tk
from tkinter import ttk from tkinter import ttk
from tkinter import scrolledtext as st
from controller.Frames import Frames from controller.Frames import Frames
from controller.HomeController import HomeController from controller.HomeController import HomeController
@ -21,23 +22,26 @@ class HomeView(ttk.Frame):
def __init__(self, parent, controller: HomeController): def __init__(self, parent, controller: HomeController):
super().__init__(parent) super().__init__(parent)
# Init view
self.__init_content()
# create widgets # create widgets
# label # label
self.label = ttk.Label(self, text='Email:') # self.label = ttk.Label(self, text='Email:')
self.label.grid(row=1, column=0) # self.label.grid(row=1, column=0)
# email entry # email entry
self.email_var = tk.StringVar() # self.email_var = tk.StringVar()
self.email_entry = ttk.Entry(self, textvariable=self.email_var, width=30) # self.email_entry = ttk.Entry(self, textvariable=self.email_var, width=30)
self.email_entry.grid(row=1, column=1, sticky=tk.NSEW) # self.email_entry.grid(row=1, column=1, sticky=tk.NSEW)
# save button # save button
self.save_button = ttk.Button(self, text='Save', command=self.event_btn) # self.save_button = ttk.Button(self, text='Save', command=self.event_btn)
self.save_button.grid(row=1, column=3, padx=10) # self.save_button.grid(row=1, column=3, padx=10)
# message # message
self.message_label = ttk.Label(self, text='coucou toi :D JE SUIS SUPER MAN héhéh', foreground='red') # self.message_label = ttk.Label(self, text='coucou toi :D JE SUIS SUPER MAN héhéh', foreground='red')
self.message_label.grid(row=2, column=1, sticky=tk.W) # self.message_label.grid(row=2, column=1, sticky=tk.W)
# place this frame # place this frame
# self.grid(row=0, column=0, padx=5, pady=5) # self.grid(row=0, column=0, padx=5, pady=5)
@ -46,7 +50,57 @@ class HomeView(ttk.Frame):
# Save and setup main controller # Save and setup main controller
self.__controller = controller self.__controller = controller
controller.set_view(self) controller.set_view(self)
# START Internal function
def __init_content(self) -> None:
"""
[internal function]
=> Initialize the view content.
"""
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=3)
def event_btn(self) -> None: # Website link
self.web_label = ttk.Label(self, text="Website URL:")
self.web_label.grid(column=0, row=0, sticky=tk.W, padx=5, pady=5)
self.web_entry = ttk.Entry(self, width=50) # show="-"
self.web_entry.grid(column=1, row=0, sticky=tk.E, padx=5, pady=5, ipadx=2, ipady=2)
# Download name
self.name_label = ttk.Label(self, text="Download Name:")
self.name_label.grid(column=0, row=1, sticky=tk.W, padx=5, pady=5)
self.name_entry = ttk.Entry(self, width=50)
self.name_entry.grid(column=1, row=1, sticky=tk.E, padx=5, pady=5, ipadx=2, ipady=2)
# Logs area
self.log_area = st.ScrolledText(self, wrap=tk.WORD, state = tk.DISABLED, width=40, height=8)#, font=("Times New Roman", 15))
self.log_area.grid(column=0, row=3, sticky=tk.EW, columnspan=2, pady=10, padx=10)
# Download button
self.download_button = ttk.Button(self, text="Start downloading", command=self.event_btn)
self.download_button.grid(column=1, row=4, sticky=tk.E, padx=5, pady=5, ipadx=5, ipady=2)
# END Internal function
# START Controller methods
def add_log(self, line: str) -> None:
"""
[function for controller]
TODO desc
"""
print("ADD: ", line)
self.log_area.configure(state=tk.NORMAL)
self.log_area.insert(tk.END, f"{line}\n")
self.log_area.configure(state=tk.DISABLED)
def clear_log(self) -> None:
"""
[function for controller]
TODO desc
"""
self.log_area.delete(0, tk.END)
# END Controller methods
def event_btn(self) -> None:# TODO remove
print("you clicked ! And now you are on info page ... :D") print("you clicked ! And now you are on info page ... :D")
self.__controller.on_change_view(Frames.Info) self.__controller.on_change_view(Frames.Info)

View File

@ -50,4 +50,4 @@ class InfoView(ttk.Frame):
def event_btn(self) -> None: def event_btn(self) -> None:
print("you clicked on the button that is on the info view!") print("you clicked on the button that is on the info view!")
print("got redirected to the home view :D") print("got redirected to the home view :D")
self.__controller.on_change_view(Frames.Home) self.__controller.on_change_view(Frames.Home)

View File

@ -1,7 +1,5 @@
import tkinter as tk import tkinter as tk
from tracemalloc import Frame
from controller.MainController import MainController from controller.MainController import MainController
from controller.Frames import Frames
class MainWindow(tk.Tk): class MainWindow(tk.Tk):
@ -18,7 +16,7 @@ class MainWindow(tk.Tk):
# Variables # Variables
__controller: MainController = None __controller: MainController = None
__views: dict = None __views: dict = None
__current_view = None __frame_id: int = None
# Constructor # Constructor
def __init__(self, controller: MainController): def __init__(self, controller: MainController):
@ -27,19 +25,50 @@ class MainWindow(tk.Tk):
# Init view repository # Init view repository
self.__views = {} self.__views = {}
# Init main window
self.title('Tkinter app')
self.geometry('450x250')
self.resizable(False, False)
self.config(bg='#f7ef38')
self.rowconfigure(0, weight=1)
self.columnconfigure(0, weight=1)
# Save and setup main controller # Save and setup main controller
self.__controller = controller self.__controller = controller
controller.set_view(self) controller.set_view(self)
# Init view components
self.__init_window()
self.__init_top_menu()
# START Internal methods
def __init_window(self):
"""
[internal function]
=> Initialize window parameters
"""
self.title('Tkinter app')
# self.geometry('450x250')
self.resizable(False, False)
self.config(bg='#f7ef38')
def __init_top_menu(self):
"""
[internal function]
=> Initialize top menu of the window.
"""
main_menu = tk.Menu(self)
col1_menu = tk.Menu(main_menu, tearoff=0)
col1_menu.add_command(label="Open folder", command=self.alert)
col1_menu.add_separator()
col1_menu.add_command(label="Quit", command=self.alert)
main_menu.add_cascade(label="File", menu=col1_menu)
col2_menu = tk.Menu(main_menu, tearoff=0)
col2_menu.add_command(label="Check for update", command=self.__controller.on_check_for_update)
col2_menu.add_command(label="About", command=self.alert)
main_menu.add_cascade(label="Help", menu=col2_menu)
self.config(menu=main_menu)
def alert(self):
# TODO remove
print("You clicked")
# END Internal methods
# START App methods # START App methods
def add_view(self, frame, view): def add_view(self, frame, view):
""" """
@ -54,15 +83,16 @@ class MainWindow(tk.Tk):
def show_frame(self, frame): def show_frame(self, frame):
""" """
[function for app & controller] [function for app & controller]
=> Allows to display the selected frame provided that it
has been previously added to the frame dictionary.
:frame: -> the frame if of the view to display. :frame: -> the frame if of the view to display.
""" """
new_view = self.__views.get(frame) if self.__views.get(frame):
if new_view: if self.__frame_id:
if self.__current_view: self.__views.get(self.__frame_id).pack_forget()
self.__current_view.pack_forget() self.__views.get(frame).pack(fill=tk.BOTH, expand=False)
new_view.pack(fill=tk.BOTH, expand=False) self.__frame_id = frame
self.__current_view = new_view
else: else:
raise ValueError("Unable to find the requested Frame") raise ValueError("Unable to find the requested Frame")
# END Controller methods # END Controller methods