From a63679160ccea53f8d5c39bc809eff949800ecf0 Mon Sep 17 00:00:00 2001 From: Laurens Versluis Date: Tue, 5 Jul 2016 14:28:26 +0200 Subject: [PATCH] refactored callers of refresh --- Tribler/Main/vwxGUI/GuiUtility.py | 2 +- Tribler/Main/vwxGUI/SearchGridManager.py | 8 ++++++-- Tribler/Main/vwxGUI/list.py | 9 ++++++--- Tribler/Main/vwxGUI/list_details.py | 8 ++++++-- Tribler/Test/test_gui_dialogs.py | 13 ++++++++----- 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Tribler/Main/vwxGUI/GuiUtility.py b/Tribler/Main/vwxGUI/GuiUtility.py index 2db5fe335c1..a3a6cdbafd4 100644 --- a/Tribler/Main/vwxGUI/GuiUtility.py +++ b/Tribler/Main/vwxGUI/GuiUtility.py @@ -592,7 +592,7 @@ def subscribe_latestupdate_sort(a, b): manager = self.frame.channellist.GetManager() yield manager.SetCategory('searchresults') - manager.refresh(data) + yield manager.refresh(data) self.ShowPage('channels') diff --git a/Tribler/Main/vwxGUI/SearchGridManager.py b/Tribler/Main/vwxGUI/SearchGridManager.py index 6bc756f1e2c..138b9877864 100644 --- a/Tribler/Main/vwxGUI/SearchGridManager.py +++ b/Tribler/Main/vwxGUI/SearchGridManager.py @@ -509,9 +509,11 @@ def gotDispersyRemoteHits(self, subject, changetype, objectID, search_results): else: self._logger.debug("TorrentSearchGridManager: gotRemoteHist: not scheduling refresh") + @inlineCallbacks + # TODO (Laurens): Refactor callers because deferred. def refreshGrid(self, remote=False): if self.gridmgr: - self.gridmgr.refresh(remote) + yield self.gridmgr.refresh(remote) def getThumbnailTorrents(self, is_collected=True, limit=20): result = [] @@ -888,9 +890,11 @@ def exists(self, infohashes): def set_gridmgr(self, gridmgr): self.gridmgr = gridmgr + @inlineCallbacks + # TODO (Laurens): Refactor callers because deferred. def refreshGrid(self): if self.gridmgr is not None: - self.gridmgr.refresh() + yield self.gridmgr.refresh() class ChannelManager(object): diff --git a/Tribler/Main/vwxGUI/list.py b/Tribler/Main/vwxGUI/list.py index 5d9ebbc5c80..734dd130189 100644 --- a/Tribler/Main/vwxGUI/list.py +++ b/Tribler/Main/vwxGUI/list.py @@ -397,19 +397,23 @@ def Reset(self): self.dirtyset.clear() self.prev_refresh_if = 0 + @inlineCallbacks + # TODO (Laurens): Refactor callers because deferred. def do_or_schedule_refresh(self, force_refresh=False): if self.list.isReady and (self.list.ShouldGuiUpdate() or force_refresh): diff = time() - self.prev_refresh_if if diff > 5 or force_refresh: self.prev_refresh_if = time() - self.refresh() + yield self.refresh() else: self.dirtyset.add('COMPLETE_REFRESH') self.list.dirty = True + @inlineCallbacks + # TODO (Laurens): Refactor callers because deferred. def refreshDirty(self): if self.category != 'searchresults' and 'COMPLETE_REFRESH' in self.dirtyset or len(self.dirtyset) > 5: - self.refresh() + yield self.refresh() else: if 'COMPLETE_REFRESH' in self.dirtyset: self.dirtyset.remove('COMPLETE_REFRESH') @@ -419,7 +423,6 @@ def refreshDirty(self): self.dirtyset.clear() @inlineCallbacks - # TODO (Laurens): Refactor callers because deferred. def refresh(self, search_results=None): self._logger.debug("ChannelManager complete refresh") if self.category != 'searchresults': diff --git a/Tribler/Main/vwxGUI/list_details.py b/Tribler/Main/vwxGUI/list_details.py index 5aaac17f4d2..32d79ddc5fa 100644 --- a/Tribler/Main/vwxGUI/list_details.py +++ b/Tribler/Main/vwxGUI/list_details.py @@ -627,19 +627,23 @@ def updateEditTab(self): self.editButton.Enable(self.canEdit) self.notebook.ShowPage(self.notebook.GetIndexFromText('Edit'), self.canEdit) + @inlineCallbacks + # TODO (Laurens): Refactor callers because deferred. def updateCommentsTab(self): if self.canComment: commentManager = self.commentList.GetManager() commentManager.SetIds(self.torrent.channel, channeltorrent=self.torrent) - commentManager.refresh() + yield commentManager.refresh() self.notebook.ShowPage(self.notebook.GetIndexFromText('Comments'), self.canComment) + @inlineCallbacks + # TODO (Laurens): Refactor callers because deferred. def updateModificationsTab(self): show_modifications = self.canEdit or bool(self.torrent.get('description', '')) if show_modifications: modificationManager = self.modificationList.GetManager() modificationManager.SetIds(self.torrent) - modificationManager.refresh() + yield modificationManager.refresh() self.notebook.ShowPage(self.notebook.GetIndexFromText('Modifications'), show_modifications) def updateTrackersTab(self): diff --git a/Tribler/Test/test_gui_dialogs.py b/Tribler/Test/test_gui_dialogs.py index a158ec7e08e..c9a1c543682 100644 --- a/Tribler/Test/test_gui_dialogs.py +++ b/Tribler/Test/test_gui_dialogs.py @@ -9,7 +9,7 @@ # Import WX after selecting the version -from twisted.internet.defer import inlineCallbacks +from twisted.internet.defer import inlineCallbacks, returnValue from Tribler.Test.test_as_server import TestGuiAsServer, TESTS_DATA_DIR, wx from Tribler.Test.test_libtorrent_download import TORRENT_VIDEO_FILE @@ -212,15 +212,18 @@ def do_search(): self.guiUtility.dosearch(u'mp3') self.callLater(10, do_favorite) + @inlineCallbacks + # TODO (Laurens): Refactor callers because deferred. def wait_for_channel(): def has_connections_or_channel(): if self.frame.SRstatusbar.GetChannelConnections() > 10: - return True + returnValue(True) if self.frame.channellist.GetItems(): - return True + returnValue(True) - self.frame.channellist.GetManager().refresh() - return False + manager = self.frame.channellist.GetManager() + yield manager.refresh() + returnValue(False) self.CallConditional(300, has_connections_or_channel, do_search, 'did not connect to more than 10 peers within 300s')