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

@ -37,7 +37,15 @@ class HomeController:
: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:
"""

View File

@ -20,16 +20,27 @@ class MainController:
def set_view(self, view) -> None:
"""
[function for view]
=> Allow to define the controller view.
:view: -> The view that this controller manage.
"""
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
def change_frame(self, frame) -> None:
"""
[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.
"""

View File

@ -1,5 +1,6 @@
import tkinter as tk
from tkinter import ttk
from tkinter import scrolledtext as st
from controller.Frames import Frames
from controller.HomeController import HomeController
@ -21,23 +22,26 @@ class HomeView(ttk.Frame):
def __init__(self, parent, controller: HomeController):
super().__init__(parent)
# Init view
self.__init_content()
# create widgets
# label
self.label = ttk.Label(self, text='Email:')
self.label.grid(row=1, column=0)
# self.label = ttk.Label(self, text='Email:')
# self.label.grid(row=1, column=0)
# email entry
self.email_var = tk.StringVar()
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_var = tk.StringVar()
# self.email_entry = ttk.Entry(self, textvariable=self.email_var, width=30)
# self.email_entry.grid(row=1, column=1, sticky=tk.NSEW)
# save button
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 = ttk.Button(self, text='Save', command=self.event_btn)
# self.save_button.grid(row=1, column=3, padx=10)
# message
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 = 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)
# place this frame
# self.grid(row=0, column=0, padx=5, pady=5)
@ -47,6 +51,56 @@ class HomeView(ttk.Frame):
self.__controller = controller
controller.set_view(self)
def event_btn(self) -> None:
# START Internal function
def __init_content(self) -> None:
"""
[internal function]
=> Initialize the view content.
"""
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=3)
# 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")
self.__controller.on_change_view(Frames.Info)

View File

@ -1,7 +1,5 @@
import tkinter as tk
from tracemalloc import Frame
from controller.MainController import MainController
from controller.Frames import Frames
class MainWindow(tk.Tk):
@ -18,7 +16,7 @@ class MainWindow(tk.Tk):
# Variables
__controller: MainController = None
__views: dict = None
__current_view = None
__frame_id: int = None
# Constructor
def __init__(self, controller: MainController):
@ -27,19 +25,50 @@ class MainWindow(tk.Tk):
# Init view repository
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
self.__controller = controller
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
def add_view(self, frame, view):
"""
@ -54,15 +83,16 @@ class MainWindow(tk.Tk):
def show_frame(self, frame):
"""
[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.
"""
new_view = self.__views.get(frame)
if new_view:
if self.__current_view:
self.__current_view.pack_forget()
new_view.pack(fill=tk.BOTH, expand=False)
self.__current_view = new_view
if self.__views.get(frame):
if self.__frame_id:
self.__views.get(self.__frame_id).pack_forget()
self.__views.get(frame).pack(fill=tk.BOTH, expand=False)
self.__frame_id = frame
else:
raise ValueError("Unable to find the requested Frame")
# END Controller methods