Added propagation of the program stop event
This commit is contained in:
parent
69db2dbbee
commit
7002439532
@ -26,9 +26,13 @@ class HomeController:
|
|||||||
:controller: -> The main application cpntroller.
|
:controller: -> The main application cpntroller.
|
||||||
:webpic: -> The webpicdownloader instance.
|
:webpic: -> The webpicdownloader instance.
|
||||||
"""
|
"""
|
||||||
|
# Setub variables
|
||||||
self.__main_controller = controller
|
self.__main_controller = controller
|
||||||
self.__webpic = webpic
|
self.__webpic = webpic
|
||||||
|
|
||||||
|
# Subscribe to events
|
||||||
|
controller.subscribe_to_quite_event(self.on_quit)
|
||||||
|
|
||||||
# START View methods
|
# START View methods
|
||||||
def set_view(self, view) -> None:
|
def set_view(self, view) -> None:
|
||||||
"""
|
"""
|
||||||
@ -49,10 +53,7 @@ class HomeController:
|
|||||||
|
|
||||||
:frame: -> The frame we want to launch.
|
:frame: -> The frame we want to launch.
|
||||||
"""
|
"""
|
||||||
#self.__main_controller.change_frame(frame)
|
self.__main_controller.change_frame(frame)
|
||||||
self.__view.add_log("Salut comment vas tu ? 1")
|
|
||||||
self.__view.add_log("Salut comment vas tu ? 2")
|
|
||||||
self.__view.show_success_message("Super tu as réussi la quête !")
|
|
||||||
|
|
||||||
def on_download_requested(self, url: str, name: str) -> None:
|
def on_download_requested(self, url: str, name: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -72,11 +73,16 @@ class HomeController:
|
|||||||
|
|
||||||
# Verify variable and start AsyncTask
|
# Verify variable and start AsyncTask
|
||||||
if url.strip() and name.strip() :
|
if url.strip() and name.strip() :
|
||||||
AsyncTask(download_task).start()
|
AsyncTask(download_task)
|
||||||
else:
|
else:
|
||||||
self.__view.show_error_message("Opss, the url or folder name are not valid!")
|
self.__view.show_error_message("Opss, the url or folder name are not valid!")
|
||||||
# END View events
|
# END View events
|
||||||
|
|
||||||
# START Controller methods
|
# START Controller methods
|
||||||
|
def on_quit(self) -> None:
|
||||||
|
"""
|
||||||
|
[event function for controller]
|
||||||
|
=> Call this event when a request to exit is thrown.
|
||||||
|
"""
|
||||||
|
print("Quit... homecontroller")
|
||||||
# END Controller methods
|
# END Controller methods
|
@ -12,6 +12,7 @@ class MainController:
|
|||||||
# Variables
|
# Variables
|
||||||
__config: dict = None
|
__config: dict = None
|
||||||
__view = None
|
__view = None
|
||||||
|
__quite_event_subscribers: list = None
|
||||||
|
|
||||||
# Constructor
|
# Constructor
|
||||||
def __init__(self, config: dict) -> None:
|
def __init__(self, config: dict) -> None:
|
||||||
@ -20,7 +21,9 @@ class MainController:
|
|||||||
|
|
||||||
:config: -> The application configuration (a dictionary).
|
:config: -> The application configuration (a dictionary).
|
||||||
"""
|
"""
|
||||||
|
# Setup variables
|
||||||
self.__config = config
|
self.__config = config
|
||||||
|
self.__quite_event_subscribers = []
|
||||||
|
|
||||||
# START View methods
|
# START View methods
|
||||||
def set_view(self, view) -> None:
|
def set_view(self, view) -> None:
|
||||||
@ -38,14 +41,16 @@ class MainController:
|
|||||||
=> Event launch when you ask to open the current folder.
|
=> Event launch when you ask to open the current folder.
|
||||||
"""
|
"""
|
||||||
# TODO on_open_folder
|
# TODO on_open_folder
|
||||||
pass
|
print("on_open_folder") # TODO remove
|
||||||
|
|
||||||
def on_quite(self) -> None:
|
def on_quite(self) -> None:
|
||||||
"""
|
"""
|
||||||
[event function for view]
|
[event function for view]
|
||||||
=> Event launch when you ask to quit the program.
|
=> Event launch when you ask to quit the program.
|
||||||
"""
|
"""
|
||||||
print("You asked to quit...") # TODO remove
|
for callback in self.__quite_event_subscribers:
|
||||||
|
callback()
|
||||||
|
print("on_quite") # TODO remove
|
||||||
self.__view.close_window() # End the program
|
self.__view.close_window() # End the program
|
||||||
|
|
||||||
def on_check_for_update(self) -> None:
|
def on_check_for_update(self) -> None:
|
||||||
@ -62,7 +67,7 @@ class MainController:
|
|||||||
=> Event launched when a request for more information arise.
|
=> Event launched when a request for more information arise.
|
||||||
"""
|
"""
|
||||||
# TODO on_about
|
# TODO on_about
|
||||||
pass
|
print("on_about")
|
||||||
# END View methods
|
# END View methods
|
||||||
|
|
||||||
# START Controller methods
|
# START Controller methods
|
||||||
@ -87,3 +92,9 @@ class MainController:
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Unable to find a configuration with this name")
|
raise ValueError("Unable to find a configuration with this name")
|
||||||
# END Controller methods
|
# END Controller methods
|
||||||
|
|
||||||
|
# START Controller events
|
||||||
|
def subscribe_to_quite_event(self, callback) -> None:
|
||||||
|
# TODO
|
||||||
|
self.__quite_event_subscribers.append(callback)
|
||||||
|
# END Controller events
|
||||||
|
@ -14,6 +14,7 @@ class AsyncTask(threading.Thread):
|
|||||||
@since 2022-09-01
|
@since 2022-09-01
|
||||||
"""
|
"""
|
||||||
# Variables
|
# Variables
|
||||||
|
__stop = None
|
||||||
__callback = None
|
__callback = None
|
||||||
__args: list = None
|
__args: list = None
|
||||||
|
|
||||||
@ -30,6 +31,7 @@ class AsyncTask(threading.Thread):
|
|||||||
:args: -> Argument to pass to the function when executing it.
|
:args: -> Argument to pass to the function when executing it.
|
||||||
"""
|
"""
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.__stop = threading.Event()
|
||||||
self.__callback = callback
|
self.__callback = callback
|
||||||
self.__args = args
|
self.__args = args
|
||||||
|
|
||||||
@ -38,3 +40,7 @@ class AsyncTask(threading.Thread):
|
|||||||
[!] : This function should not be used! Start the task with {AsyncTask.start()}!
|
[!] : This function should not be used! Start the task with {AsyncTask.start()}!
|
||||||
"""
|
"""
|
||||||
self.__callback(*self.__args)
|
self.__callback(*self.__args)
|
||||||
|
|
||||||
|
def stop(self) -> None:
|
||||||
|
# TODO
|
||||||
|
self.__stop.set()
|
@ -2,7 +2,6 @@ import tkinter as tk
|
|||||||
import tkinter.font as tfont
|
import tkinter.font as tfont
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
from tkinter import scrolledtext as tst
|
from tkinter import scrolledtext as tst
|
||||||
from controller.Frames import Frames
|
|
||||||
from controller.HomeController import HomeController
|
from controller.HomeController import HomeController
|
||||||
|
|
||||||
class HomeView(ttk.Frame):
|
class HomeView(ttk.Frame):
|
||||||
|
Reference in New Issue
Block a user