fixing bugs with the textarea and background task
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
from controller.MainController import MainController
|
||||
from util.AsyncTask import AsyncTask
|
||||
|
||||
|
||||
class HomeController:
|
||||
@@ -20,6 +20,12 @@ class HomeController:
|
||||
|
||||
# Constructor
|
||||
def __init__(self, controller: MainController, webpic) -> None:
|
||||
"""
|
||||
Constructor
|
||||
|
||||
:controller: -> The main application cpntroller.
|
||||
:webpic: -> The webpicdownloader instance.
|
||||
"""
|
||||
self.__main_controller = controller
|
||||
self.__webpic = webpic
|
||||
|
||||
@@ -27,6 +33,7 @@ class HomeController:
|
||||
def set_view(self, view) -> None:
|
||||
"""
|
||||
[function for view]
|
||||
=> Define the view of this controller.
|
||||
|
||||
:view: -> The view that this controller manage.
|
||||
"""
|
||||
@@ -38,6 +45,7 @@ class HomeController:
|
||||
def on_change_view(self, frame) -> None:
|
||||
"""
|
||||
[event function for view]
|
||||
=> Call this event method when the user requests to change the window.
|
||||
|
||||
:frame: -> The frame we want to launch.
|
||||
"""
|
||||
@@ -49,19 +57,22 @@ class HomeController:
|
||||
def on_download_requested(self, url: str, name: str) -> None:
|
||||
"""
|
||||
[event function for view]
|
||||
=> Call this event method when the user requests to download
|
||||
|
||||
:url: -> The url of the website to use for pic-download.\n
|
||||
:name: -> The name of the folder in which put pictures.
|
||||
"""
|
||||
if url.strip() and name.strip() :
|
||||
# TODO use webpic here to download files
|
||||
print(f"url : {url} -- name : {name}")
|
||||
|
||||
self.__view.clear_logs() # BUG this process must be asynchrone ...
|
||||
# Define the download task function (to call in a AsyncTask)
|
||||
def download_task():
|
||||
self.__view.clear_logs()
|
||||
if self.__webpic.download(url, name):
|
||||
self.__view.show_success_message("The download has been successfully completed.")
|
||||
else:
|
||||
self.__view.show_error_message("A critical error preventing the download occurred, check the logs.")
|
||||
|
||||
# Verify variable and start AsyncTask
|
||||
if url.strip() and name.strip() :
|
||||
AsyncTask(download_task).start()
|
||||
else:
|
||||
self.__view.show_error_message("Opss, the url or folder name are not valid!")
|
||||
# END View events
|
||||
|
||||
Reference in New Issue
Block a user