From e0e8eb81f9261fe81b332b116f1389af18299037 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Fri, 4 Nov 2016 23:15:31 +0200 Subject: [PATCH] Down button add support for multiple items selection --- youtube_dl_gui/mainframe.py | 41 ++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index 5d30491..6b158a4 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -571,17 +571,25 @@ class MainFrame(wx.Frame): print self._download_list._items_list def _on_arrow_down(self, event): - selected_row = self._status_list.get_selected() + index = self._status_list.get_next_selected(reverse=True) - if selected_row == -1: + if index == -1: self._create_popup("No row selected", self.ERROR_LABEL, wx.OK | wx.ICON_EXCLAMATION) else: - object_id = self._status_list.GetItemData(selected_row) - download_item = self._download_list.get_item(object_id) + while index >= 0: + object_id = self._status_list.GetItemData(index) + download_item = self._download_list.get_item(object_id) + + new_index = index + 1 + if new_index >= self._status_list.GetItemCount(): + new_index = self._status_list.GetItemCount() - 1 - if self._download_list.move_down(object_id): - self._status_list.move_item_down(selected_row) - self._status_list._update_from_item(selected_row + 1, download_item) + if not self._status_list.IsSelected(new_index): + self._download_list.move_down(object_id) + self._status_list.move_item_down(index) + self._status_list._update_from_item(new_index, download_item) + + index = self._status_list.get_next_selected(index, True) print self._download_list._items_list @@ -1216,6 +1224,25 @@ class ListCtrl(wx.ListCtrl, ListCtrlAutoWidthMixin): for index in xrange(self._list_index): self.Select(index, on=0) + def get_next_selected(self, start=-1, reverse=False): + if start == -1: + start = self._list_index - 1 if reverse else 0 + else: + # start from next item + if reverse: + start -= 1 + else: + start += 1 + + end = -1 if reverse else self._list_index + step = -1 if reverse else 1 + + for index in xrange(start, end, step): + if self.IsSelected(index): + return index + + return -1 + def get_items(self): """Returns a list of items inside the ListCtrl.