The thread system not being sufficient remodulation of it
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import time
|
||||
from controller.MainController import MainController
|
||||
from model.WebPicDownloader import WebPicDownloader
|
||||
from util.AsyncTask import AsyncTask
|
||||
|
||||
|
||||
@@ -16,7 +18,7 @@ class HomeController:
|
||||
# Variables
|
||||
__main_controller = None
|
||||
__view = None
|
||||
__webpic = None
|
||||
__webpic: WebPicDownloader = None
|
||||
__download_task = None
|
||||
|
||||
# Constructor
|
||||
@@ -43,7 +45,9 @@ class HomeController:
|
||||
* :view: -> The view that this controller manage.
|
||||
"""
|
||||
self.__view = view
|
||||
self.__webpic.set_messenger_callback(view.add_log)
|
||||
self.__webpic.set_messenger_callback(self.on_webpic_messenger)
|
||||
self.__webpic.set_success_callback(self.on_webpic_success)
|
||||
self.__webpic.set_failure_callback(self.on_webpic_failure)
|
||||
# END View method
|
||||
|
||||
# START View events
|
||||
@@ -65,29 +69,41 @@ class HomeController:
|
||||
* :name: -> The name of the folder in which put pictures.
|
||||
"""
|
||||
if url.strip() and name.strip():
|
||||
self.__download_task = AsyncTask(
|
||||
rcallback=self.__async_task_start,
|
||||
rargs=(url, name),
|
||||
qcallback=self.__async_task_stop
|
||||
)
|
||||
self.__download_task.start()
|
||||
self.__webpic.start_downloading(url, name)
|
||||
else:
|
||||
self.__view.show_error_message("Opss, the url or folder name are not valid!")
|
||||
# END View events
|
||||
|
||||
# START Webpic events
|
||||
def on_webpic_messenger(self, message: str) -> None:
|
||||
"""
|
||||
"""
|
||||
self.__view.add_log(message)
|
||||
|
||||
def on_webpic_success(self) -> None:
|
||||
"""
|
||||
"""
|
||||
self.__view.show_success_message("The download has been successfully completed.")
|
||||
|
||||
def on_webpic_failure(self) -> None:
|
||||
"""
|
||||
"""
|
||||
self.__view.show_error_message("A critical error preventing the download occurred, check the logs.")
|
||||
# END Webpic events
|
||||
|
||||
# START Controller methods
|
||||
def on_quit(self) -> bool:
|
||||
"""
|
||||
[event function for controller]
|
||||
=> Call this event when a request to exit is thrown.
|
||||
"""
|
||||
if self.__download_task and self.__download_task.is_alive():
|
||||
if self.__webpic.is_alive():
|
||||
if self.__main_controller.show_question_dialog(
|
||||
"Are you sure?",
|
||||
"Do you really want to quit while the download is running?\nThis will stop the download."
|
||||
):
|
||||
self.__download_task.stop()
|
||||
self.__download_task.join()
|
||||
self.__webpic.stop_downloading()
|
||||
time.sleep(4)
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user