Skip to content

Commit

Permalink
Resize columns after refresh tasks ended
Browse files Browse the repository at this point in the history
  • Loading branch information
Insoleet committed Feb 11, 2016
1 parent dcdf8c1 commit 11b5073
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
5 changes: 0 additions & 5 deletions src/sakia/gui/community_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,10 @@ async def refresh_status(self):
if self.community:
text = ""

logging.debug("Here I am with {0}".format(self.community))
current_block_number = self.community.network.current_blockid.number
if current_block_number:
text += self.tr(" Block {0}").format(current_block_number)
try:
logging.debug("Before get _block {0}".format(self.community))
block = await self.community.get_block(current_block_number)
logging.debug("After get _block {0}".format(self.community))
text += " ({0})".format(QLocale.toString(
QLocale(),
QDateTime.fromTime_t(block['medianTime']),
Expand All @@ -250,7 +246,6 @@ async def refresh_status(self):
except ValueError as e:
logging.debug(str(e))

logging.debug("I can crash now {0}".format(self.community))
if len(self.community.network.synced_nodes) == 0:
self.button_membership.setEnabled(False)
self.button_certification.setEnabled(False)
Expand Down
6 changes: 4 additions & 2 deletions src/sakia/gui/network_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ def change_community(self, community):
community.network.nodes_changed.connect(self.refresh_nodes)

self.community = community
self.table_network.model().change_community(community)
refresh_task = self.table_network.model().change_community(community)
refresh_task.add_done_callback(lambda fut: self.table_network.resizeColumnsToContents())

@pyqtSlot()
def refresh_nodes(self):
logging.debug("Refresh nodes")
self.table_network.model().sourceModel().refresh_nodes()
refresh_task = self.table_network.model().sourceModel().refresh_nodes()
refresh_task.add_done_callback(lambda fut: self.table_network.resizeColumnsToContents())

def node_context_menu(self, point):
index = self.table_network.indexAt(point)
Expand Down
4 changes: 2 additions & 2 deletions src/sakia/gui/transactions_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ async def refresh_minimum_maximum(self):

def refresh(self):
if self.community:
self.ui.table_history.model().sourceModel().refresh_transfers()
self.ui.table_history.resizeColumnsToContents()
refresh_task = self.ui.table_history.model().sourceModel().refresh_transfers()
refresh_task.add_done_callback(lambda fut: self.ui.table_history.resizeColumnsToContents())
self.refresh_minimum_maximum()
self.refresh_balance()

Expand Down
16 changes: 14 additions & 2 deletions src/sakia/models/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ def columnCount(self, parent):
return self.sourceModel().columnCount(None) - 2

def change_community(self, community):
"""
Change current community and returns refresh task
:param sakia.core.Community community:
:return: the refresh task
:rtype: asyncio.Task
"""
self.community = community
self.sourceModel().change_community(community)
return self.sourceModel().change_community(community)

def setSourceModel(self, sourceModel):
self.community = sourceModel.community
Expand Down Expand Up @@ -146,9 +152,15 @@ def __init__(self, community, parent=None):
self.nodes_data = []

def change_community(self, community):
"""
Change current community displayed in network and refresh the nodes
:param sakia.core.Community community: the new community
:return: the refresh task
:rtype: asyncio.Task
"""
cancel_once_task(self, self.refresh_nodes)
self.community = community
self.refresh_nodes()
return self.refresh_nodes()

async def data_node(self, node: Node) -> tuple:
"""
Expand Down
6 changes: 6 additions & 0 deletions src/sakia/tools/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def start_task():


def asyncify(fn):
"""
Instanciates a coroutine in a task
:param fn: the coroutine to run
:return: the task
:rtype: asyncio.Task
"""
@functools.wraps(fn)
def wrapper(*args, **kwargs):
return asyncio.ensure_future(asyncio.coroutine(fn)(*args, **kwargs))
Expand Down

0 comments on commit 11b5073

Please sign in to comment.