Skip to content

Commit

Permalink
refactored callers of refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdversluis committed Jul 5, 2016
1 parent 9611f6e commit a636791
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Tribler/Main/vwxGUI/GuiUtility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
8 changes: 6 additions & 2 deletions Tribler/Main/vwxGUI/SearchGridManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions Tribler/Main/vwxGUI/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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':
Expand Down
8 changes: 6 additions & 2 deletions Tribler/Main/vwxGUI/list_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 8 additions & 5 deletions Tribler/Test/test_gui_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit a636791

Please sign in to comment.