From 9e935e07c02b01a5913e08d2f981463768ed2e09 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Sun, 25 Sep 2016 23:28:57 +0300 Subject: [PATCH] Add wx.Timer --- youtube_dl_gui/downloadmanager.py | 2 -- youtube_dl_gui/mainframe.py | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/youtube_dl_gui/downloadmanager.py b/youtube_dl_gui/downloadmanager.py index 5ed9274..50846c1 100644 --- a/youtube_dl_gui/downloadmanager.py +++ b/youtube_dl_gui/downloadmanager.py @@ -366,8 +366,6 @@ class DownloadManager(Thread): time.sleep(self.WAIT_TIME) - self._talk_to_gui("report_active") #TODO Use wx.Timer for this - # Close all the workers for worker in self._workers: worker.close() diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index b85e83c..e51b480 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -194,6 +194,9 @@ class MainFrame(wx.Frame): # Get video formats self._video_formats = read_formats() + # Set the Timer + self._app_timer = wx.Timer(self) + # Set the app icon app_icon_path = get_icon_file() if app_icon_path is not None: @@ -280,6 +283,7 @@ class MainFrame(wx.Frame): self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._update_pause_button, self._status_list) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self._update_pause_button, self._status_list) self.Bind(wx.EVT_CLOSE, self._on_close) + self.Bind(wx.EVT_TIMER, self._on_timer, self._app_timer) # Set threads wxCallAfter handlers self._set_publisher(self._update_handler, UPDATE_PUB_TOPIC) @@ -301,6 +305,10 @@ class MainFrame(wx.Frame): self._set_layout() + def _on_timer(self, event): + msg = self.URL_REPORT_MSG.format(self.download_manager.active()) + self._status_bar_write(msg) + def _update_pause_button(self, event): #TODO keep all icons in a data stracture instead of creating them each time #TODO create double stage buttons? @@ -726,17 +734,17 @@ class MainFrame(wx.Frame): self._print_stats() self._reset_widgets() self.download_manager = None + self._app_timer.Stop() self._after_download() elif data == 'closed': self._status_bar_write(self.CLOSED_MSG) self._reset_widgets() self.download_manager = None + self._app_timer.Stop() elif data == 'closing': self._status_bar_write(self.CLOSING_MSG) elif data == 'report_active': - # Report number of urls been downloaded - msg = self.URL_REPORT_MSG.format(self.download_manager.active()) - self._status_bar_write(msg) + pass def _update_handler(self, msg): """updatemanager.UpdateThread thread handler. @@ -769,6 +777,7 @@ class MainFrame(wx.Frame): self.ERROR_LABEL, wx.OK | wx.ICON_EXCLAMATION) else: + self._app_timer.Start(1000) self.download_manager = DownloadManager(self._download_list, self.opt_manager, self.log_manager) self._status_bar_write(self.DOWNLOAD_STARTED)