diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index c102d759157d3ef0311c6ce7da71ccbffbfd9da8..9a5b02da9da665c1e4a5bcf5a525f45e5efe4468 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -13,7 +13,7 @@ from ucoinpy.key import SigningKey import logging import time -from PyQt5.QtCore import QObject, pyqtSignal, Qt +from PyQt5.QtCore import QObject, pyqtSignal, QCoreApplication from .wallet import Wallet from .community import Community @@ -182,10 +182,11 @@ class Account(QObject): self.loading_progressed.emit(account_value, account_max) for w in self.wallets: - w.refresh_progressed.connect(progressing, type=Qt.DirectConnection) + w.refresh_progressed.connect(progressing) for c in self.communities: w.init_cache(c) loaded_wallets = loaded_wallets + 1 + QCoreApplication.processEvents() def set_display_referential(self, index): self.referential = index diff --git a/src/cutecoin/core/watching/blockchain.py b/src/cutecoin/core/watching/blockchain.py index af9e1aaefb44958edb9b1cd26644980f9d47f353..a1f6c46179912a2a1302525307b20c7fbb4283f1 100644 --- a/src/cutecoin/core/watching/blockchain.py +++ b/src/cutecoin/core/watching/blockchain.py @@ -15,6 +15,8 @@ from PyQt5.QtCore import pyqtSignal class BlockchainWatcher(Watcher): new_transfers = pyqtSignal(list) + loading_progressed = pyqtSignal(int, int) + def __init__(self, account, community): super().__init__() self.account = account @@ -24,15 +26,26 @@ class BlockchainWatcher(Watcher): self.last_block = self.community.network.latest_block def watch(self): + loaded_wallets = 0 + def progressing(value, maximum): + account_value = maximum * loaded_wallets + value + account_max = maximum * len(self.account.wallets) + self.loading_progressed.emit(account_value, account_max) + try: received_list = [] block_number = self.community.network.latest_block if self.last_block != block_number: + + for w in self.account.wallets: + w.refresh_progressed.connect(progressing) + if not self.exiting: self.community.refresh_cache() for w in self.account.wallets: if not self.exiting: w.refresh_cache(self.community, received_list) + loaded_wallets = loaded_wallets + 1 logging.debug("New block, {0} mined in {1}".format(block_number, self.community.currency)) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index f72f041ce195a03361c82a99cf6d87e655ce74ff..6c2a59ffb24d781ba6533880e81cd08620f71acc 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -142,8 +142,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): @param: block_number: The number of the block mined ''' logging.debug("Refresh block") - self.tab_history.progressbar.show() - #self.app.monitor.blockchain_watcher(self.community).thread().start() + self.tab_history.start_progress() + self.app.monitor.blockchain_watcher(self.community).thread().start() self.app.monitor.persons_watcher(self.community).thread().start() self.refresh_status() @@ -158,8 +158,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): if self.tab_history.table_history.model(): self.tab_history.table_history.model().sourceModel().refresh_transfers() - #self.tab_history.refresh_balance() - self.tab_history.progressbar.hide() + self.tab_history.refresh_balance() + self.tab_history.stop_progress() self.refresh_status() @pyqtSlot() diff --git a/src/cutecoin/gui/transactions_tab.py b/src/cutecoin/gui/transactions_tab.py index 2692d8b781659e9d03bbac965ed4690b47cf0159..649f7911e20d981809610d2688e0fb580fa21570 100644 --- a/src/cutecoin/gui/transactions_tab.py +++ b/src/cutecoin/gui/transactions_tab.py @@ -67,6 +67,18 @@ class TransactionsTabWidget(QWidget, Ui_transactionsTabWidget): self.refresh_balance() + def start_progress(self): + def progressing(value, maximum): + self.progressbar.setValue(value) + self.progressbar.setMaximum(maximum) + + self.progressbar.show() + blockchain_watcher = self.app.monitor.blockchain_watcher(self.community) + blockchain_watcher.loading_progressed.connect(progressing) + + def stop_progress(self): + self.progressbar.hide() + def refresh_balance(self): proxy = self.table_history.model() balance = proxy.deposits - proxy.payments