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/controller/MainController.py

102 lines
3.0 KiB
Python

class MainController:
"""
Controller - MainController
TODO desc...
@author Jérémi Nihart / EndMove
@link https://git.endmove.eu/EndMove/WebPicDownloader
@version 1.0.0
@since 2022-08-30
"""
# Variables
__config: dict = None
__view = None
__quite_event_subscribers: list = None
# Constructor
def __init__(self, config: dict) -> None:
"""
Constructor
:config: -> The application configuration (a dictionary).
"""
# Setup variables
self.__config = config
self.__quite_event_subscribers = []
# START View methods
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
def on_open_folder(self) -> None:
"""
[event function for view]
=> Event launch when you ask to open the current folder.
"""
# TODO on_open_folder
print("on_open_folder") # TODO remove
def on_quite(self) -> None:
"""
[event function for view]
=> Event launch when you ask to quit the program. This event is propagated
to the subscribers, they can eventually cancel the event
"""
for callback in self.__quite_event_subscribers:
if callback():
return
self.__view.close_window() # End the program
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")
def on_about(self) -> None:
"""
[event function for view]
=> Event launched when a request for more information arise.
"""
# TODO on_about
print("on_about")
# 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.
"""
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
# START Controller events
def subscribe_to_quite_event(self, callback) -> None:
# TODO
self.__quite_event_subscribers.append(callback)
# END Controller events