Browse Source

Add change_stage method to DownloadList and use that to update the items stage

doc-issue-template
MrS0m30n3 8 years ago
parent
commit
fd2229dc12
3 changed files with 24 additions and 3 deletions
  1. 16
      tests/test_dlist.py
  2. 7
      youtube_dl_gui/downloadmanager.py
  3. 4
      youtube_dl_gui/mainframe.py

16
tests/test_dlist.py

@ -220,6 +220,22 @@ class TestClear(unittest.TestCase):
self.assertEqual(len(dlist), 0)
class TestChangeStage(unittest.TestCase):
"""Test case for the DownloadList change_stage method."""
def setUp(self):
self.mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(3)]
self.dlist = DownloadList(self.mocks)
def test_change_stage(self):
self.dlist.change_stage(0, "Active")
self.assertEqual(self.mocks[0].stage, "Active")
def test_change_stage_id_not_exist(self):
self.assertRaises(KeyError, self.dlist.change_stage, 3, "Active")
class TestSynchronizeDecorator(unittest.TestCase):
def test_synchronize(self):

7
youtube_dl_gui/downloadmanager.py

@ -286,6 +286,11 @@ class DownloadList(object):
"""Returns a list with all the items."""
return [self._items_dict[object_id] for object_id in self._items_list]
@synchronized(_SYNC_LOCK)
def change_stage(self, object_id, new_stage):
"""Change the stage of the item with the given object_id."""
self._items_dict[object_id].stage = new_stage
@synchronized(_SYNC_LOCK)
def __len__(self):
return len(self._items_list)
@ -354,7 +359,7 @@ class DownloadManager(Thread):
for worker in self._workers:
if worker.available():
worker.download(item.url, item.options, item.object_id)
item.stage = "Active" #TODO Add change_stage method to download list
self.download_list.change_stage(item.object_id, "Active")
break
else:
if self._jobs_done():

4
youtube_dl_gui/mainframe.py

@ -422,9 +422,9 @@ class MainFrame(wx.Frame):
download_item = self._download_list.get_item(object_id)
if download_item.stage == "Queued":
download_item.stage = "Paused"
self._download_list.change_stage(object_id, "Paused")
elif download_item.stage == "Paused":
download_item.stage = "Queued"
self._download_list.change_stage(object_id, "Queued")
self._update_pause_button(None)
self._status_list._update_from_item(selected_row, download_item)

Loading…
Cancel
Save