From 9f2523cae893fdf050606afa7386b7d373350364 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Thu, 1 Jan 2015 18:00:38 +0100 Subject: [PATCH] Fixing few bugs Renaming actions in the member tab Added a BlockchainInspector thread to check for new blocs and refresh the UI --- res/ui/currency_tab.ui | 7 +++++ src/cutecoin/core/app.py | 1 - src/cutecoin/core/community.py | 7 +++-- src/cutecoin/core/wallet.py | 8 ++--- src/cutecoin/gui/community_tab.py | 2 +- src/cutecoin/gui/currency_tab.py | 49 +++++++++++++++++++++++++------ src/cutecoin/gui/mainwindow.py | 32 +++++++++++++++++++- 7 files changed, 86 insertions(+), 20 deletions(-) diff --git a/res/ui/currency_tab.ui b/res/ui/currency_tab.ui index 8218af48..c41d3366 100644 --- a/res/ui/currency_tab.ui +++ b/res/ui/currency_tab.ui @@ -100,6 +100,13 @@ </layout> </widget> </item> + <item> + <widget class="QLabel" name="label_current_block"> + <property name="text"> + <string/> + </property> + </widget> + </item> </layout> </widget> <resources> diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index ea365405..8546bb17 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -121,7 +121,6 @@ class Application(object): tar.getmember(obj) except KeyError: raise BadAccountFile(file) - return tar.extractall(path) account_path = os.path.join(config.parameters['home'], diff --git a/src/cutecoin/core/community.py b/src/cutecoin/core/community.py index f7ec25dd..1f83bb47 100644 --- a/src/cutecoin/core/community.py +++ b/src/cutecoin/core/community.py @@ -114,9 +114,10 @@ class Community(object): "number": block['number']} elif self.last_block["request_ts"] < time.time() - 300: block = bma.blockchain.Current(e.conn_handler()).get() - self.last_block = {"request_ts": time.time(), - "number": block['number']} - self.requests_cache = {} + if block['number'] > self.last_block['number']: + self.last_block = {"request_ts": time.time(), + "number": block['number']} + self.requests_cache = {} cache_key = (hash(request), hash(tuple(frozenset(sorted(req_args.keys())))), diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 4d65c372..0d395ec5 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -91,17 +91,15 @@ class Cache(): in_inputs = [i for i in tx.issuers if i == self.wallet.pubkey] if len(in_inputs) > 0: - logging.debug("TX:{0}".format(tx.compact())) # remove from waiting transactions list the one which were # validated in the blockchain - confirmed_tx = [awaiting for awaiting in self.awaiting_tx - if awaiting.compact() == tx.compact()] - for c in confirmed_tx: - logging.debug("Awaiting:{0}".format(c.compact())) self.awaiting_tx = [awaiting for awaiting in self.awaiting_tx if awaiting.compact() != tx.compact()] self.tx_sent.append(tx) + self.tx_sent = self.tx_sent[:50] + self.tx_received = self.tx_received[:50] + self.latest_block = current_block['number'] diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index e17f8ae7..04538790 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -59,7 +59,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): send_money.triggered.connect(self.send_money_to_member) send_money.setData(member) - certify = QAction("Certify individual", self) + certify = QAction("Certify identity", self) certify.triggered.connect(self.certify_member) certify.setData(member) diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 46fec4a2..df6adf0b 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -5,14 +5,15 @@ Created on 2 févr. 2014 ''' import logging +from ucoinpy.api import bma from PyQt5.QtWidgets import QWidget, QMenu, QAction, QApplication -from PyQt5.QtCore import QModelIndex, Qt +from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot from PyQt5.QtGui import QIcon -from cutecoin.gen_resources.currency_tab_uic import Ui_CurrencyTabWidget -from cutecoin.gui.community_tab import CommunityTabWidget -from cutecoin.models.sent import SentListModel -from cutecoin.models.received import ReceivedListModel -from cutecoin.models.wallets import WalletsListModel +from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget +from .community_tab import CommunityTabWidget +from ..models.sent import SentListModel +from ..models.received import ReceivedListModel +from ..models.wallets import WalletsListModel from ..models.wallet import WalletListModel @@ -30,6 +31,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.setupUi(self) self.app = app self.community = community + self.tab_community = CommunityTabWidget(self.app.current_account, + self.community) def refresh(self): if self.app.current_account is None: @@ -42,11 +45,40 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): SentListModel(self.app.current_account, self.community)) self.list_transactions_received.setModel( ReceivedListModel(self.app.current_account, self.community)) - tab_community = CommunityTabWidget(self.app.current_account, + self.tab_community = CommunityTabWidget(self.app.current_account, self.community) - self.tabs_account.addTab(tab_community, + self.tabs_account.addTab(self.tab_community, QIcon(':/icons/community_icon'), "Community") + block_number = self.community.request(bma.blockchain.Current)['number'] + self.label_current_block.setText("Current Block : {0}".format(block_number)) + + @pyqtSlot(int) + def refresh_block(self, block_number): + if self.list_wallet_content.model(): + self.list_wallet_content.model().dataChanged.emit( + QModelIndex(), + QModelIndex(), + []) + if self.list_wallet_content.model(): + self.list_transactions_sent.model().dataChanged.emit( + QModelIndex(), + QModelIndex(), + []) + + if self.list_transactions_received.model(): + self.list_transactions_received.model().dataChanged.emit( + QModelIndex(), + QModelIndex(), + []) + + if self.tab_community.list_community_members.model(): + self.tab_community.list_community_members.model().dataChanged.emit( + QModelIndex(), + QModelIndex(), + []) + + self.label_current_block.setText("Current Block : {0}".format(block_number)) def refresh_wallets(self): wallets_list_model = WalletsListModel(self.app.current_account, @@ -65,7 +97,6 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): model = self.list_wallets.model() if index.row() < model.rowCount(None): wallet = model.wallets[index.row()] - logging.debug(wallet) menu = QMenu(model.data(index, Qt.DisplayRole), self) rename = QAction("Rename", self) diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index ad505cd2..8add61f6 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -5,7 +5,7 @@ Created on 1 févr. 2014 ''' from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow from PyQt5.QtWidgets import QMainWindow, QAction, QFileDialog -from PyQt5.QtCore import QSignalMapper, QModelIndex +from PyQt5.QtCore import QSignalMapper, QModelIndex, QThread, pyqtSignal from PyQt5.QtGui import QIcon from cutecoin.gui.process_cfg_account import ProcessConfigureAccount from cutecoin.gui.transfer import TransferMoneyDialog @@ -14,7 +14,34 @@ from cutecoin.gui.add_contact import AddContactDialog from cutecoin.gui.import_account import ImportAccountDialog from cutecoin.gui.certification import CertificationDialog +from ucoinpy.api import bma + import logging +import time + + +class BlockchainInspector(QThread): + def __init__(self, community): + QThread.__init__(self) + self.community = community + self.exiting = False + self.last_block = self.community.request(bma.blockchain.Current)['number'] + + def __del__(self): + self.exiting = True + self.wait() + + def run(self): + while not self.exiting: + time.sleep(10) + current_block = self.community.request(bma.blockchain.Current) + if self.last_block != current_block['number']: + logging.debug("New block, {0} mined in {1}".format(self.last_block, + self.community.currency)) + self.new_block_mined.emit(current_block) + self.last_block = current_block['number'] + + new_block_mined = pyqtSignal(int) class MainWindow(QMainWindow, Ui_MainWindow): @@ -97,6 +124,9 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.currencies_tabwidget.clear() for community in self.app.current_account.communities: tab_currency = CurrencyTabWidget(self.app, community) + bc_inspector = BlockchainInspector(community) + bc_inspector.new_block_mined.connect(tab_currency.refresh_block) + bc_inspector.start() tab_currency.refresh() self.currencies_tabwidget.addTab(tab_currency, QIcon(":/icons/currency_icon"), -- GitLab