Trying ro fix multi-threading issue
This commit is contained in:
@@ -76,13 +76,22 @@ class HomeController:
|
||||
# END View events
|
||||
|
||||
# START Controller methods
|
||||
def on_quit(self) -> None:
|
||||
def on_quit(self) -> bool:
|
||||
"""
|
||||
[event function for controller]
|
||||
=> Call this event when a request to exit is thrown.
|
||||
"""
|
||||
self.__download_task.stop()
|
||||
print("Quit... homecontroller END")
|
||||
if self.__download_task and self.__download_task.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()
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
print("Quit... homecontroller END") # REMOVE
|
||||
# END Controller methods
|
||||
|
||||
# START Task methods
|
||||
@@ -96,7 +105,7 @@ class HomeController:
|
||||
* :url: -> Url for webpic.
|
||||
* :name: -> Working dir name for webpic.
|
||||
"""
|
||||
print("start callback called")
|
||||
print("start callback called") # REMOVE
|
||||
self.__view.clear_logs()
|
||||
if self.__webpic.download(url, name):
|
||||
self.__view.show_success_message("The download has been successfully completed.")
|
||||
@@ -110,6 +119,6 @@ class HomeController:
|
||||
function will keep its controller context. In short it's as if the thread was
|
||||
launched in the controller and the execution never left it.
|
||||
"""
|
||||
print("stop callback called")
|
||||
print("stop callback called") # REMOVE
|
||||
self.__webpic.stop()
|
||||
# END Task methods
|
||||
@@ -1,3 +1,6 @@
|
||||
import os
|
||||
|
||||
|
||||
class MainController:
|
||||
"""
|
||||
Controller - MainController
|
||||
@@ -19,7 +22,7 @@ class MainController:
|
||||
"""
|
||||
Constructor
|
||||
|
||||
:config: -> The application configuration (a dictionary).
|
||||
* :config: -> The application configuration (a dictionary).
|
||||
"""
|
||||
# Setup variables
|
||||
self.__config = config
|
||||
@@ -31,17 +34,17 @@ class MainController:
|
||||
[function for view]
|
||||
=> Allow to define the controller view.
|
||||
|
||||
:view: -> The view that this controller manage.
|
||||
* :view: -> The view that this controller manage and setup it.
|
||||
"""
|
||||
self.__view = view
|
||||
view.set_window_title(self.get_config('app_name'))
|
||||
|
||||
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
|
||||
os.startfile(self.get_config('app_folder'))
|
||||
|
||||
def on_quite(self) -> None:
|
||||
"""
|
||||
@@ -77,7 +80,7 @@ class MainController:
|
||||
[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.
|
||||
* :frame: -> The frame we want to display on the window instead of the current frame.
|
||||
"""
|
||||
self.__view.show_frame(frame)
|
||||
|
||||
@@ -86,16 +89,34 @@ class MainController:
|
||||
[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.
|
||||
* :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")
|
||||
|
||||
def show_question_dialog(self, title: str='title', message: str='question?', icon: str='question') -> bool:
|
||||
"""
|
||||
[function for controller]
|
||||
=> Ask a question to the user and block until he answers with yes or no.
|
||||
|
||||
* :title: ->
|
||||
* :message: ->
|
||||
* :icon: ->
|
||||
"""
|
||||
return self.__view.show_question_dialog(title, message, icon)
|
||||
# END Controller methods
|
||||
|
||||
# START Controller events
|
||||
def subscribe_to_quite_event(self, callback) -> None:
|
||||
# TODO
|
||||
"""
|
||||
[function for controller]
|
||||
=> Subscription function allowing to be warned if a request to quit occurs.
|
||||
In the case where the callback function returns False the process continues
|
||||
but if the callback returns True the process is aborted.
|
||||
|
||||
* :callback: -> Callback function that will be called when a request to exit occurs.
|
||||
"""
|
||||
self.__quite_event_subscribers.append(callback)
|
||||
# END Controller events
|
||||
|
||||
Reference in New Issue
Block a user