This repository has been archived on 2023-11-29. You can view files and clone it, but cannot push or open issues or pull requests.
WebPicDownloader/view/MainWindow.py

68 lines
1.8 KiB
Python

import tkinter as tk
from tracemalloc import Frame
from controller.MainController import MainController
from controller.Frames import Frames
class MainWindow(tk.Tk):
"""
View - MainWindow
dec...
@author Jérémi Nihart / EndMove
@link https://git.endmove.eu/EndMove/WebPicDownloader
@version 1.0.0
@since 2022-08-30
"""
# Variables
__controller: MainController = None
__views: dict = None
__current_view = None
# Constructor
def __init__(self, controller: MainController):
super().__init__()
# 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)
# START App methods
def add_view(self, frame, view):
"""
[function for app]
:frame: -> the frame id of the view to add.
"""
self.__views[frame] = view
# END App methods
# START Controller methods
def show_frame(self, frame):
"""
[function for app & controller]
: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
else:
raise ValueError("Unable to find the requested Frame")
# END Controller methods