From 7756d71b324358ac5f173d5c4fd48a91cedc24d4 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Mon, 24 Jun 2019 12:45:09 -0500 Subject: [PATCH] Added a progress bar for downloads in the application. Fixed a problem with format in Tidal --- src/controller/mainController.py | 5 +++++ src/controller/player.py | 1 + src/extractors/tidal.py | 1 + src/utils.py | 1 + src/wxUI/mainWindow.py | 2 ++ 5 files changed, 10 insertions(+) diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 68f03c7..b7dc2c7 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -88,8 +88,13 @@ class Controller(object): pub.subscribe(self.change_status, "change_status") pub.subscribe(self.on_download_finished, "download_finished") pub.subscribe(self.on_notify, "notify") + pub.subscribe(self.on_update_progress, "update-progress") # Event functions. These functions will call other functions in a thread and are bound to widget events. + + def on_update_progress(self, value): + wx.CallAfter(self.window.progressbar.SetValue, value) + def on_settings(self, *args, **kwargs): settings = configuration.configuration() self.reload_extractors() diff --git a/src/controller/player.py b/src/controller/player.py index 102edb3..5af6589 100644 --- a/src/controller/player.py +++ b/src/controller/player.py @@ -149,6 +149,7 @@ class audioPlayer(object): while True: state = media.get_state() pub.sendMessage("change_status", status=_("Downloading {0} ({1}%).").format(item.title, int(transcoder.get_position()*100))) + pub.sendMessage("update-progress", value=int(transcoder.get_position()*100)) if str(state) == 'State.Ended': break elif str(state) == 'state.error': diff --git a/src/extractors/tidal.py b/src/extractors/tidal.py index 2239ea1..d04caad 100644 --- a/src/extractors/tidal.py +++ b/src/extractors/tidal.py @@ -38,6 +38,7 @@ class interface(base.baseInterface): self.file_extension = "flac" else: self.file_extension = "mp3" + return self.file_extension def transcoder_enabled(self): if config.app["services"]["tidal"]["quality"] == "lossless": diff --git a/src/utils.py b/src/utils.py index 2094a6b..ac280fd 100644 --- a/src/utils.py +++ b/src/utils.py @@ -68,6 +68,7 @@ def download_file(url, local_filename): done = int(100 * dl / total_length) msg = _(u"Downloading {0} ({1}%).").format(os.path.basename(local_filename), done) pub.sendMessage("change_status", status=msg) + pub.sendMessage("update-progress", value=done) pub.sendMessage("download_finished", file=os.path.basename(local_filename)) log.debug("Download finished successfully") return local_filename diff --git a/src/wxUI/mainWindow.py b/src/wxUI/mainWindow.py index ef3f1eb..45806f0 100644 --- a/src/wxUI/mainWindow.py +++ b/src/wxUI/mainWindow.py @@ -74,6 +74,8 @@ class mainWindow(wx.Frame): box2.Add(self.next) self.sizer.Add(box1, 0, wx.GROW) self.sizer.Add(box2, 1, wx.GROW) + self.progressbar = wx.Gauge(self.panel, wx.NewId(), range=100, style=wx.GA_HORIZONTAL) + self.sizer.Add(self.progressbar, 0, wx.ALL, 5) self.panel.SetSizerAndFit(self.sizer) # self.SetClientSize(self.sizer.CalcMin()) # self.Layout()