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

99 lines
2.8 KiB
Python

import tkinter as tk
from controller.MainController import MainController
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
__frame_id: int = None
# Constructor
def __init__(self, controller: MainController):
super().__init__()
# Init view repository
self.__views = {}
# 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):
"""
[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]
=> 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.
"""
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