From 10a31e1536691f01c0766e6442f3825862606fb1 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Wed, 28 Jan 2015 23:22:25 +0100 Subject: [PATCH] Added a selector for viewing units type --- src/cutecoin/core/account.py | 4 ++++ src/cutecoin/core/wallet.py | 24 ++++++++++++++++++++++++ src/cutecoin/gui/mainwindow.py | 17 ++++++++++++++++- src/cutecoin/models/txhistory.py | 1 - 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index bc11e9ad..a85a4c3c 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -102,6 +102,10 @@ class Account(object): self.communities.append(community) return community + def set_display_referential(self, index): + for w in self.wallets: + w.set_display_referential(index) + def set_walletpool_size(self, size, password): logging.debug("Defining wallet pool size") if len(self.wallets) < size: diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index f1f6889a..74429851 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -146,6 +146,12 @@ class Wallet(object): self.pubkey = pubkey self.name = name self.caches = {} + self.referentials = [self.value, + self.relative_value, + self.value_from_zero, + self.relative_from_zero + ] + self.referential = self.referentials[0] @classmethod def create(cls, walletid, salt, password, name): @@ -189,6 +195,9 @@ class Wallet(object): key = SigningKey("{0}{1}".format(salt, self.walletid), password) return (key.pubkey == self.pubkey) + def show_value(self, community): + return self.referential(community) + def relative_value(self, community): value = self.value(community) ud = community.dividend() @@ -201,6 +210,21 @@ class Wallet(object): value += s.amount return value + def relative_from_zero(self, community): + value = self.value(community) + ud = community.dividend() + relative_value = value / float(ud) + return relative_value + + def value_from_zero(self, community): + value = 0 + for s in self.sources(community): + value += s.amount + return value + + def set_display_referential(self, index): + self.referential = self.referentials[index] + def tx_inputs(self, amount, community): value = 0 inputs = [] diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index 675c4c4c..260771bb 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -4,7 +4,8 @@ Created on 1 févr. 2014 @author: inso ''' from cutecoin.gen_resources.mainwindow_uic import Ui_MainWindow -from PyQt5.QtWidgets import QMainWindow, QAction, QFileDialog, QProgressBar, QMessageBox, QLabel +from PyQt5.QtWidgets import QMainWindow, QAction, QFileDialog, QProgressBar, \ + QMessageBox, QLabel, QComboBox from PyQt5.QtCore import QSignalMapper, QModelIndex, QObject, QThread, pyqtSlot, pyqtSignal from PyQt5.QtGui import QIcon from .process_cfg_account import ProcessConfigureAccount @@ -68,8 +69,15 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.statusbar.addWidget(self.busybar) self.busybar.hide() + self.combo_referential = QComboBox(self) + self.combo_referential.setEnabled(False) + self.combo_referential.currentIndexChanged.connect(self.referential_changed) + self.combo_referential.addItems(("Units", "UD", + "Units to zero", "UD to zero")) + self.status_label = QLabel("", self.statusbar) self.statusbar.addPermanentWidget(self.status_label) + self.statusbar.addPermanentWidget(self.combo_referential) self.loader_thread = QThread() self.loader = Loader(self.app) @@ -97,6 +105,11 @@ class MainWindow(QMainWindow, Ui_MainWindow): error, QMessageBox.Ok) + @pyqtSlot(int) + def referential_changed(self, index): + if self.app.current_account: + self.app.current_account.set_display_referential(index) + def action_change_account(self, account_name): self.busybar.show() self.status_label.setText("Loading account {0}".format(account_name)) @@ -171,10 +184,12 @@ class MainWindow(QMainWindow, Ui_MainWindow): self.menu_actions.setEnabled(False) self.action_configure_parameters.setEnabled(False) self.action_set_as_default.setEnabled(False) + self.combo_referential.setEnabled(False) else: self.action_set_as_default.setEnabled(self.app.current_account.name != self.app.default_account) self.password_asker = PasswordAskerDialog(self.app.current_account) + self.combo_referential.setEnabled(True) self.menu_contacts.setEnabled(True) self.action_configure_parameters.setEnabled(True) self.menu_actions.setEnabled(True) diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index d93e1f39..5374ee0a 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -38,7 +38,6 @@ class TxFilterProxyModel(QSortFilterProxyModel): """ Sort table by given column number. """ - logging.debug(self.sortOrder()) left_data = self.sourceModel().data(left, Qt.DisplayRole) right_data = self.sourceModel().data(right, Qt.DisplayRole) return (left_data < right_data) -- GitLab