Ann top menu event + manage on quit event request
This commit is contained in:
parent
5c6609ff0a
commit
7bc1157ffb
@ -2,7 +2,7 @@ class MainController:
|
||||
"""
|
||||
Controller - MainController
|
||||
|
||||
desc...
|
||||
TODO desc...
|
||||
|
||||
@author Jérémi Nihart / EndMove
|
||||
@link https://git.endmove.eu/EndMove/WebPicDownloader
|
||||
@ -10,11 +10,17 @@ class MainController:
|
||||
@since 2022-08-30
|
||||
"""
|
||||
# Variables
|
||||
__config: dict = None
|
||||
__view = None
|
||||
|
||||
# Constructor
|
||||
def __init__(self) -> None:
|
||||
pass
|
||||
def __init__(self, config: dict) -> None:
|
||||
"""
|
||||
Constructor
|
||||
|
||||
:config: -> The application configuration (a dictionary).
|
||||
"""
|
||||
self.__config = config
|
||||
|
||||
# START View methods
|
||||
def set_view(self, view) -> None:
|
||||
@ -26,6 +32,22 @@ class MainController:
|
||||
"""
|
||||
self.__view = view
|
||||
|
||||
def on_open_folder(self) -> None:
|
||||
"""
|
||||
[event function for view]
|
||||
=> Event launch when you ask to open the current folder.
|
||||
"""
|
||||
# TODO on_open_folder
|
||||
pass
|
||||
|
||||
def on_quite(self) -> None:
|
||||
"""
|
||||
[event function for view]
|
||||
=> Event launch when you ask to quit the program.
|
||||
"""
|
||||
print("You asked to quit...") # TODO remove
|
||||
self.__view.close_window() # End the program
|
||||
|
||||
def on_check_for_update(self) -> None:
|
||||
"""
|
||||
[event function for view]
|
||||
@ -33,6 +55,13 @@ class MainController:
|
||||
"""
|
||||
# TODO write the function
|
||||
print("on_check_for_update")
|
||||
|
||||
def on_about(self) -> None:
|
||||
"""
|
||||
[event function for view]
|
||||
=> Event launched when a request for more information arise.
|
||||
"""
|
||||
# TODO on_about
|
||||
pass
|
||||
# END View methods
|
||||
|
||||
@ -45,4 +74,16 @@ class MainController:
|
||||
:frame: -> The frame we want to display on the window instead of the current frame.
|
||||
"""
|
||||
self.__view.show_frame(frame)
|
||||
|
||||
def get_config(self, name: str) -> str|int:
|
||||
"""
|
||||
[function for controller]
|
||||
=> Allows controllers to access the application's configuration.
|
||||
|
||||
:name: -> The name of the configuration parameter for which we want to access the configured value.
|
||||
"""
|
||||
if self.__config.get(name):
|
||||
return self.__config.get(name)
|
||||
else:
|
||||
raise ValueError("Unable to find a configuration with this name")
|
||||
# END Controller methods
|
||||
|
13
main.py
13
main.py
@ -1,3 +1,4 @@
|
||||
import os
|
||||
from controller.HomeController import HomeController
|
||||
from controller.InfoController import InfoController
|
||||
from controller.MainController import MainController
|
||||
@ -8,6 +9,13 @@ from view.InfoView import InfoView
|
||||
from view.MainWindow import MainWindow
|
||||
|
||||
|
||||
def get_config() -> dict:
|
||||
return {
|
||||
'app_name': "WebPicDownloader",
|
||||
'app_folder': os.getcwd(),
|
||||
'app_version': "1.0.0"
|
||||
}
|
||||
|
||||
if __name__ == '__main__':
|
||||
"""
|
||||
WebPicDownloader is a program developed and maintened by EndMove under Apache 2.0 License. Stealing code is a crime !
|
||||
@ -18,11 +26,14 @@ if __name__ == '__main__':
|
||||
@version 1.0.0
|
||||
@since 2022-08-30
|
||||
"""
|
||||
# configuration
|
||||
config = get_config()
|
||||
|
||||
# Create utli/model
|
||||
webpic = WebPicDownloader()
|
||||
|
||||
# Create app controllers
|
||||
main_controller = MainController()
|
||||
main_controller = MainController(config)
|
||||
home_controller = HomeController(main_controller, webpic)
|
||||
info_controller = InfoController(main_controller)
|
||||
|
||||
|
@ -19,7 +19,7 @@ class MainWindow(tk.Tk):
|
||||
__frame_id: int = None
|
||||
|
||||
# Constructor
|
||||
def __init__(self, controller: MainController):
|
||||
def __init__(self, controller: MainController) -> None:
|
||||
super().__init__()
|
||||
|
||||
# Init view repository
|
||||
@ -29,12 +29,13 @@ class MainWindow(tk.Tk):
|
||||
self.__controller = controller
|
||||
controller.set_view(self)
|
||||
|
||||
# Init view components
|
||||
# Init view components & more
|
||||
self.__init_window()
|
||||
self.__init_top_menu()
|
||||
self.__init_bind_protocol()
|
||||
|
||||
# START Internal methods
|
||||
def __init_window(self):
|
||||
def __init_window(self) -> None:
|
||||
"""
|
||||
[internal function]
|
||||
=> Initialize window parameters
|
||||
@ -44,7 +45,7 @@ class MainWindow(tk.Tk):
|
||||
self.resizable(False, False)
|
||||
self.config(bg='#f7ef38')
|
||||
|
||||
def __init_top_menu(self):
|
||||
def __init_top_menu(self) -> None:
|
||||
"""
|
||||
[internal function]
|
||||
=> Initialize top menu of the window.
|
||||
@ -52,21 +53,24 @@ class MainWindow(tk.Tk):
|
||||
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_command(label="Open folder", command=self.__controller.on_open_folder)
|
||||
col1_menu.add_separator()
|
||||
col1_menu.add_command(label="Quit", command=self.alert)
|
||||
col1_menu.add_command(label="Quit", command=self.__controller.on_quite)
|
||||
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)
|
||||
col2_menu.add_command(label="About", command=self.__controller.on_about)
|
||||
main_menu.add_cascade(label="Help", menu=col2_menu)
|
||||
|
||||
self.config(menu=main_menu)
|
||||
|
||||
def alert(self):
|
||||
# TODO remove
|
||||
print("You clicked")
|
||||
def __init_bind_protocol(self) -> None:
|
||||
"""
|
||||
[internal function]
|
||||
=> Initialize the function bindding on events of the main window.
|
||||
"""
|
||||
self.protocol("WM_DELETE_WINDOW", self.__controller.on_quite)
|
||||
# END Internal methods
|
||||
|
||||
# START App methods
|
||||
@ -95,4 +99,11 @@ class MainWindow(tk.Tk):
|
||||
self.__frame_id = frame
|
||||
else:
|
||||
raise ValueError("Unable to find the requested Frame")
|
||||
|
||||
def close_window(self) -> None:
|
||||
"""
|
||||
[function for app & controller]
|
||||
TODO
|
||||
"""
|
||||
self.destroy()
|
||||
# END Controller methods
|
||||
|
Reference in New Issue
Block a user