2022-08-30 12:28:59 +02:00
|
|
|
class MainController:
|
|
|
|
"""
|
2022-08-30 21:12:04 +02:00
|
|
|
Controller - MainController
|
2022-08-30 12:28:59 +02:00
|
|
|
|
2022-09-01 18:05:58 +02:00
|
|
|
TODO desc...
|
2022-08-30 21:12:04 +02:00
|
|
|
|
|
|
|
@author Jérémi Nihart / EndMove
|
|
|
|
@link https://git.endmove.eu/EndMove/WebPicDownloader
|
|
|
|
@version 1.0.0
|
|
|
|
@since 2022-08-30
|
2022-08-30 12:28:59 +02:00
|
|
|
"""
|
|
|
|
# Variables
|
2022-09-01 18:05:58 +02:00
|
|
|
__config: dict = None
|
2022-08-30 13:51:50 +02:00
|
|
|
__view = None
|
2022-09-01 22:07:14 +02:00
|
|
|
__quite_event_subscribers: list = None
|
2022-08-30 12:28:59 +02:00
|
|
|
|
|
|
|
# Constructor
|
2022-09-01 18:05:58 +02:00
|
|
|
def __init__(self, config: dict) -> None:
|
|
|
|
"""
|
|
|
|
Constructor
|
|
|
|
|
|
|
|
:config: -> The application configuration (a dictionary).
|
|
|
|
"""
|
2022-09-01 22:07:14 +02:00
|
|
|
# Setup variables
|
2022-09-01 18:05:58 +02:00
|
|
|
self.__config = config
|
2022-09-01 22:07:14 +02:00
|
|
|
self.__quite_event_subscribers = []
|
2022-08-30 12:28:59 +02:00
|
|
|
|
2022-08-30 21:12:04 +02:00
|
|
|
# START View methods
|
|
|
|
def set_view(self, view) -> None:
|
2022-08-30 12:28:59 +02:00
|
|
|
"""
|
2022-08-30 21:12:04 +02:00
|
|
|
[function for view]
|
2022-08-31 12:07:43 +02:00
|
|
|
=> Allow to define the controller view.
|
2022-08-30 13:51:50 +02:00
|
|
|
|
2022-08-30 21:12:04 +02:00
|
|
|
:view: -> The view that this controller manage.
|
2022-08-30 12:28:59 +02:00
|
|
|
"""
|
2022-08-30 21:12:04 +02:00
|
|
|
self.__view = view
|
2022-08-31 12:07:43 +02:00
|
|
|
|
2022-09-01 18:05:58 +02:00
|
|
|
def on_open_folder(self) -> None:
|
|
|
|
"""
|
|
|
|
[event function for view]
|
|
|
|
=> Event launch when you ask to open the current folder.
|
|
|
|
"""
|
|
|
|
# TODO on_open_folder
|
2022-09-01 22:07:14 +02:00
|
|
|
print("on_open_folder") # TODO remove
|
2022-09-01 18:05:58 +02:00
|
|
|
|
|
|
|
def on_quite(self) -> None:
|
|
|
|
"""
|
|
|
|
[event function for view]
|
|
|
|
=> Event launch when you ask to quit the program.
|
|
|
|
"""
|
2022-09-01 22:07:14 +02:00
|
|
|
for callback in self.__quite_event_subscribers:
|
|
|
|
callback()
|
|
|
|
print("on_quite") # TODO remove
|
2022-09-01 18:05:58 +02:00
|
|
|
self.__view.close_window() # End the program
|
|
|
|
|
2022-08-31 12:07:43 +02:00
|
|
|
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")
|
2022-09-01 18:05:58 +02:00
|
|
|
|
|
|
|
def on_about(self) -> None:
|
|
|
|
"""
|
|
|
|
[event function for view]
|
|
|
|
=> Event launched when a request for more information arise.
|
|
|
|
"""
|
|
|
|
# TODO on_about
|
2022-09-01 22:07:14 +02:00
|
|
|
print("on_about")
|
2022-08-31 12:07:43 +02:00
|
|
|
# END View methods
|
2022-08-30 12:28:59 +02:00
|
|
|
|
2022-08-30 21:12:04 +02:00
|
|
|
# START Controller methods
|
|
|
|
def change_frame(self, frame) -> None:
|
2022-08-30 12:28:59 +02:00
|
|
|
"""
|
2022-08-30 21:12:04 +02:00
|
|
|
[function for controller]
|
2022-08-31 12:07:43 +02:00
|
|
|
=> Allows you to request a frame change in the main window.
|
2022-08-30 13:51:50 +02:00
|
|
|
|
2022-08-30 21:12:04 +02:00
|
|
|
:frame: -> The frame we want to display on the window instead of the current frame.
|
2022-08-30 12:28:59 +02:00
|
|
|
"""
|
2022-08-30 21:12:04 +02:00
|
|
|
self.__view.show_frame(frame)
|
2022-09-01 18:05:58 +02:00
|
|
|
|
|
|
|
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")
|
2022-08-31 12:07:43 +02:00
|
|
|
# END Controller methods
|
2022-09-01 22:07:14 +02:00
|
|
|
|
|
|
|
# START Controller events
|
|
|
|
def subscribe_to_quite_event(self, callback) -> None:
|
|
|
|
# TODO
|
|
|
|
self.__quite_event_subscribers.append(callback)
|
|
|
|
# END Controller events
|