Browse Source

DownloadList add index method

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
0a8dbec082
3 changed files with 23 additions and 2 deletions
  1. 15
      tests/test_dlist.py
  2. 7
      youtube_dl_gui/downloadmanager.py
  3. 3
      youtube_dl_gui/mainframe.py

15
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):

7
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)

3
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)

Loading…
Cancel
Save