fixing multi frame switching

This commit is contained in:
Jérémi N ‘EndMove’ 2022-08-30 13:51:50 +02:00
parent e85b021383
commit 746b40fa18
Signed by: EndMove
GPG Key ID: 65C4A02E1F5371A4
6 changed files with 43 additions and 16 deletions

View File

@ -2,5 +2,5 @@ from enum import Enum
class Frames(Enum): class Frames(Enum):
Home = 1 Home = 1 # Home view
Info = 2 Info = 2 # Info & copyright view

View File

@ -1,4 +1,3 @@
from controller.Frames import Frames
class MainController: class MainController:
@ -8,20 +7,24 @@ class MainController:
desc... desc...
""" """
# Variables # Variables
view = None __view = None
# Constructor # Constructor
def __init__(self) -> None: def __init__(self) -> None:
pass pass
def change_frame(self, frame: Frames.value) -> None: def change_frame(self, frame) -> None:
""" """
[function for controller] [function for controller]
:frame: -> The frame to be displayed on the screen.
""" """
pass pass
def set_view(self, view) -> None: def set_view(self, view) -> None:
""" """
[function for view] [function for view]
:view: -> The view that this controller manage.
""" """
self.view = view self.__view = view

View File

@ -27,6 +27,7 @@
# # set the controller to view # # set the controller to view
# view.set_controller(controller) # view.set_controller(controller)
from controller.Frames import Frames
from controller.MainController import MainController from controller.MainController import MainController
from view.MainWindow import MainWindow from view.MainWindow import MainWindow
from view.View import View from view.View import View
@ -37,6 +38,7 @@ if __name__ == '__main__':
app = MainWindow(controller) app = MainWindow(controller)
app.set_view(View(app)) app.add_view(Frames.Home, View(app))
app.show_frame(Frames.Home)
app.mainloop() app.mainloop()

1
version.txt Normal file
View File

@ -0,0 +1 @@
1.0.0

View File

@ -23,6 +23,8 @@ class View(ttk.Frame):
self.message_label = ttk.Label(self, text='', foreground='red') self.message_label = ttk.Label(self, text='', foreground='red')
self.message_label.grid(row=2, column=1, sticky=tk.W) self.message_label.grid(row=2, column=1, sticky=tk.W)
self.grid(row=0, column=0, padx=10, pady=10)
# set the controller # set the controller
self.controller = None self.controller = None

View File

@ -8,24 +8,43 @@ class MainWindow(tk.Tk):
dec... dec...
""" """
# Variables # Variables
controller: MainController __controller: MainController = None
__views: dict = None
# Constructor # Constructor
def __init__(self, controller: MainController): def __init__(self, controller: MainController):
super().__init__() super().__init__()
# Init view repository
self.__views = {}
# Init main window # Init main window
self.title('Tkinter MVC Demo') self.title('Tkinter app')
self.geometry('450x250')
self.resizable(False, False)
# Save and setup main controller # Save and setup main controller
self.controller = controller self.__controller = controller
controller.set_view(self) controller.set_view(self)
def set_view(self, view): def add_view(self, frame, view):
self.view = view """
self.view.grid(row=0, column=0, padx=10, pady=10) [function for app]
:frame: -> the frame id of the view to add.
"""
self.__views[frame] = view
# Section Interface
def show_frame(self, frame): def show_frame(self, frame):
pass """
# End Section Interface [function for app & controller]
:frame: -> the frame if of the view to display.
"""
print(self.__views)
if self.__views.get(frame):
self.__views.get(frame).tkraise()
#self.view = self.__views.get(frame)
#self.view.grid(row=0, column=0)
else:
raise ValueError("Unable to find the requested Frame")