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