From 3ab5d180d2c351fdacc6741459dcc66bab50276a Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Sat, 5 Nov 2016 13:38:00 +0200 Subject: [PATCH] Pause button change functionality --- youtube_dl_gui/mainframe.py | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index 2b96db0..f3db285 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -419,22 +419,24 @@ class MainFrame(wx.Frame): self._status_bar_write(msg) def _update_pause_button(self, event): - selected_row = self._status_list.get_selected() + selected_rows = self._status_list.get_all_selected() + + label = "Pause" + bitmap = self._bitmaps["pause"] - if selected_row != -1: - object_id = self._status_list.GetItemData(selected_row) + for row in selected_rows: + object_id = self._status_list.GetItemData(row) download_item = self._download_list.get_item(object_id) if download_item.stage == "Paused": - self._buttons["pause"].SetLabel("Resume") - self._buttons["pause"].SetBitmap(self._bitmaps["resume"], wx.TOP) - elif download_item.stage == "Queued": - self._buttons["pause"].SetLabel("Pause") - self._buttons["pause"].SetBitmap(self._bitmaps["pause"], wx.TOP) - else: - if self._buttons["pause"].GetLabel() == "Resume": - self._buttons["pause"].SetLabel("Pause") - self._buttons["pause"].SetBitmap(self._bitmaps["pause"], wx.TOP) + # If we find one or more items in Paused + # state set the button functionality to resume + label = "Resume" + bitmap = self._bitmaps["resume"] + break + + self._buttons["pause"].SetLabel(label) + self._buttons["pause"].SetBitmap(bitmap, wx.TOP) def _update_videoformat_combobox(self): self._videoformat_combobox.Clear() @@ -618,14 +620,18 @@ class MainFrame(wx.Frame): if not selected_rows: self._create_popup("No row selected", self.ERROR_LABEL, wx.OK | wx.ICON_EXCLAMATION) else: + #REFACTOR Use DoubleStageButton for this and check stage + if self._buttons["pause"].GetLabel() == "Pause": + new_state = "Paused" + else: + new_state = "Queued" + for selected_row in selected_rows: object_id = self._status_list.GetItemData(selected_row) download_item = self._download_list.get_item(object_id) - if download_item.stage == "Queued": - self._download_list.change_stage(object_id, "Paused") - elif download_item.stage == "Paused": - self._download_list.change_stage(object_id, "Queued") + if download_item.stage == "Queued" or download_item.stage == "Paused": + self._download_list.change_stage(object_id, new_state) self._status_list._update_from_item(selected_row, download_item)