diff --git a/tests/test_dlist.py b/tests/test_dlist.py index 8f55f6b..0e21072 100644 --- a/tests/test_dlist.py +++ b/tests/test_dlist.py @@ -236,6 +236,21 @@ class TestChangeStage(unittest.TestCase): self.assertRaises(KeyError, self.dlist.change_stage, 3, "Active") +class TestIndex(unittest.TestCase): + + """Test case for the DownloadList index method.""" + + def setUp(self): + self.mocks = [mock.Mock(object_id=i) for i in range(3)] + self.dlist = DownloadList(self.mocks) + + def test_index(self): + self.assertEqual(self.dlist.index(2), 2) + + def test_index_not_exist(self): + self.assertEqual(self.dlist.index(3), -1) + + class TestSynchronizeDecorator(unittest.TestCase): def test_synchronize(self): diff --git a/youtube_dl_gui/downloadmanager.py b/youtube_dl_gui/downloadmanager.py index 50846c1..7b2bfd0 100644 --- a/youtube_dl_gui/downloadmanager.py +++ b/youtube_dl_gui/downloadmanager.py @@ -291,6 +291,13 @@ class DownloadList(object): """Change the stage of the item with the given object_id.""" self._items_dict[object_id].stage = new_stage + @synchronized(_SYNC_LOCK) + def index(self, object_id): + """Get the zero based index of the item with the given object_id.""" + if object_id in self._items_list: + return self._items_list.index(object_id) + return -1 + @synchronized(_SYNC_LOCK) def __len__(self): return len(self._items_list) diff --git a/youtube_dl_gui/mainframe.py b/youtube_dl_gui/mainframe.py index aeda1cc..87a30b3 100644 --- a/youtube_dl_gui/mainframe.py +++ b/youtube_dl_gui/mainframe.py @@ -707,8 +707,7 @@ class MainFrame(wx.Frame): download_item = self._download_list.get_item(data["index"]) download_item.update_stats(data) - #TODO Add get index from object_id on download_list instead - row = self._download_list._items_list.index(data["index"]) + row = self._download_list.index(data["index"]) self._status_list._update_from_item(row, download_item)