Skip to content
Snippets Groups Projects
Commit 35036168 authored by inso's avatar inso
Browse files

QProgressBar now displays the cache refreshing

parent 16d64dda
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,8 @@ from ucoinpy.key import SigningKey
import logging
import time
from PyQt5.QtCore import QObject, pyqtSignal, Qt
from .wallet import Wallet
from .community import Community
from .person import Person
......@@ -44,7 +46,7 @@ def relative_zerosum(units, community):
return relative_value - relative_median
class Account(object):
class Account(QObject):
'''
An account is specific to a key.
......@@ -59,11 +61,14 @@ class Account(object):
relative, 'ud {0}')
}
loading_progressed = pyqtSignal(int, int)
def __init__(self, salt, pubkey, name, communities, wallets, contacts,
dead_communities):
'''
Constructor
'''
super().__init__()
self.salt = salt
self.pubkey = pubkey
self.name = name
......@@ -134,9 +139,18 @@ class Account(object):
return community
def refresh_cache(self):
loaded_wallets = 0
def progressing(value, maximum):
account_value = maximum * len(self.communities) * loaded_wallets + value
account_max = maximum * len(self.communities) * len(self.wallets)
self.loading_progressed.emit(account_value, account_max)
for w in self.wallets:
w.refresh_progressed.connect(progressing, type=Qt.DirectConnection)
for c in self.communities:
w.refresh_cache(c)
loaded_wallets = loaded_wallets + 1
def set_display_referential(self, index):
self.referential = index
......
......@@ -10,23 +10,28 @@ import json
import tarfile
import shutil
from PyQt5.QtCore import QObject, pyqtSignal
from . import config
from ..tools.exceptions import NameAlreadyExists, BadAccountFile, KeyAlreadyUsed
from ..tools.exceptions import NameAlreadyExists, BadAccountFile
from .account import Account
from .. import __version__
class Application(object):
class Application(QObject):
'''
Managing core application datas :
Accounts list and general configuration
'''
loading_progressed = pyqtSignal(int, int)
def __init__(self, argv):
'''
Constructor
'''
super().__init__()
self.accounts = {}
self.default_account = ""
self.current_account = None
......@@ -61,9 +66,12 @@ class Application(object):
self.current_account = None
def change_current_account(self, account):
def progressing(value, maximum):
self.loading_progressed.emit(value, maximum)
if self.current_account is not None:
self.save_cache(self.current_account)
account.loading_progressed.connect(progressing)
account.refresh_cache()
self.current_account = account
......@@ -110,8 +118,6 @@ class Application(object):
wallet.load_caches(data)
else:
os.remove(wallet_path)
for community in account.communities:
wallet.refresh_cache(community)
def save(self, account):
with open(config.parameters['data'], 'w') as outfile:
......
......@@ -9,8 +9,12 @@ from ucoinpy.api import bma
from ucoinpy.documents.block import Block
from ucoinpy.documents.transaction import InputSource, OutputSource, Transaction
from ucoinpy.key import SigningKey
from ..tools.exceptions import NotEnoughMoneyError, NoPeerAvailable
from cutecoin.core.transfer import Transfer, Received
from .transfer import Transfer, Received
from PyQt5.QtCore import QObject, pyqtSignal
import logging
......@@ -74,6 +78,7 @@ class Cache():
current_block + 1))
parsed_blocks = [n for n in parsed_blocks
if n in with_tx['result']['blocks']]
self.wallet.refresh_progressed.emit(self.latest_block, current_block)
for block_number in parsed_blocks:
block = community.request(bma.blockchain.Block,
......@@ -124,6 +129,9 @@ class Cache():
metadata['amount'] = amount
self._transfers.append(Received(tx,
metadata.copy()))
logging.debug("Receivers : {0}".format(self.wallet.receivers(self.wallet.refresh_progressed)))
self.wallet.refresh_progressed.emit(current_block - block_number,
current_block - self.latest_block)
if current_block > self.latest_block:
self.available_sources = self.wallet.sources(community)
......@@ -136,15 +144,18 @@ class Cache():
self.latest_block = current_block
class Wallet(object):
class Wallet(QObject):
'''
A wallet is used to manage money with a unique key.
'''
refresh_progressed = pyqtSignal(int, int)
def __init__(self, walletid, pubkey, name):
'''
Constructor
'''
super().__init__()
self.coins = []
self.walletid = walletid
self.pubkey = pubkey
......
......@@ -41,7 +41,8 @@ class Loader(QObject):
def load(self):
if self.account_name != "":
try:
self.app.change_current_account(self.app.get_account(self.account_name))
account = self.app.get_account(self.account_name)
self.app.change_current_account(account)
except requests.exceptions.RequestException as e:
self.connection_error.emit(str(e))
self.loaded.emit()
......@@ -65,6 +66,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.app = app
self.password_asker = None
self.initialized = False
self.busybar = QProgressBar(self.statusbar)
self.busybar.setMinimum(0)
self.busybar.setMaximum(0)
......@@ -104,6 +106,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def loader_finished(self):
self.refresh()
self.busybar.hide()
self.app.disconnect()
@pyqtSlot(str)
def display_error(self, error):
......@@ -144,6 +147,11 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.window().refresh_contacts()
def action_change_account(self, account_name):
def loading_progressed(value, maximum):
logging.debug("Busybar : {:} : {:}".format(value, maximum))
self.busybar.setValue(value)
self.busybar.setMaximum(maximum)
self.app.loading_progressed.connect(loading_progressed)
self.busybar.show()
self.status_label.setText("Loading account {0}".format(account_name))
self.loader.set_account_name(account_name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment