From 12977787f7b5ebc636ddfb10e68beddb3d9b9f41 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Tue, 17 Feb 2015 20:53:18 +0100 Subject: [PATCH] Created wallets table --- res/ui/wallets_tab.ui | 9 ++++++ src/cutecoin/gui/currency_tab.py | 2 -- src/cutecoin/gui/wallets_tab.py | 4 +++ src/cutecoin/models/wallets.py | 52 ++++++++++++++++++++------------ 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/res/ui/wallets_tab.ui b/res/ui/wallets_tab.ui index 32f4bfcd..53e10c3b 100644 --- a/res/ui/wallets_tab.ui +++ b/res/ui/wallets_tab.ui @@ -89,6 +89,15 @@ QGroupBox::title { <verstretch>0</verstretch> </sizepolicy> </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> + <attribute name="verticalHeaderVisible"> + <bool>false</bool> + </attribute> </widget> </item> </layout> diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 5e059b2f..68c436cc 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -20,8 +20,6 @@ from .transfer import TransferMoneyDialog from .wallets_tab import WalletsTabWidget from ..models.txhistory import HistoryTableModel, TxFilterProxyModel from .informations_tab import InformationsTabWidget -from ..models.wallets import WalletsListModel -from ..models.wallet import WalletListModel from ..tools.exceptions import NoPeerAvailable, MembershipNotFoundError from ..core.wallet import Wallet from ..core.person import Person diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py index b67ce984..9ecd4c3e 100644 --- a/src/cutecoin/gui/wallets_tab.py +++ b/src/cutecoin/gui/wallets_tab.py @@ -8,6 +8,7 @@ import logging from PyQt5.QtWidgets import QWidget from PyQt5.QtCore import QDateTime from ..core.person import Person +from ..models.wallets import WalletsTableModel from ..tools.exceptions import MembershipNotFoundError from ..gen_resources.wallets_tab_uic import Ui_WalletsTab @@ -84,6 +85,9 @@ class WalletsTabWidget(QWidget, Ui_WalletsTab): ) ) + wallets_model = WalletsTableModel(self.account, self.community) + self.table_wallets.setModel(wallets_model) + def get_referential_value(self, value): return self.account.units_to_ref(value, self.community) diff --git a/src/cutecoin/models/wallets.py b/src/cutecoin/models/wallets.py index 3887b36d..5addfb9b 100644 --- a/src/cutecoin/models/wallets.py +++ b/src/cutecoin/models/wallets.py @@ -4,11 +4,11 @@ Created on 8 févr. 2014 @author: inso ''' -from PyQt5.QtCore import QAbstractListModel, Qt +from PyQt5.QtCore import QAbstractTableModel, Qt import logging -class WalletsListModel(QAbstractListModel): +class WalletsTableModel(QAbstractTableModel): ''' A Qt list model to display wallets and edit their names @@ -18,33 +18,45 @@ class WalletsListModel(QAbstractListModel): ''' Constructor ''' - super(WalletsListModel, self).__init__(parent) + super().__init__(parent) self.account = account - self.wallets = account.wallets self.community = community + self.columns_types = ('name', 'pubkey', 'amount') + + @property + def wallets(self): + return self.account.wallets def rowCount(self, parent): return len(self.wallets) + def columnCount(self, parent): + return len(self.columns_types) + + def headerData(self, section, orientation, role): + if role == Qt.DisplayRole: + return self.columns_types[section] + + def wallet_data(self, row): + name = self.wallets[row].name + amount = self.wallets[row].value(self.community) + pubkey = self.wallets[row].pubkey + + return (name, pubkey, amount) + def data(self, index, role): row = index.row() - w = self.wallets[row] + col = index.column() if role == Qt.DisplayRole: - amount = w.value(self.community) - ref_amount = self.account.units_to_ref(amount, self.community) - ref_name = self.account.ref_name(self.community.currency) - return """{0} -{1:.2f} {2}""".format(w.name, ref_amount, ref_name) - elif role == Qt.EditRole: - return self.wallets[row].name - - def setData(self, index, value, role): - if role == Qt.EditRole: - row = index.row() - self.wallets[row].name = value - self.dataChanged.emit(index, index) - return True - return False + return self.wallet_data(row)[col] + +# def setData(self, index, value, role): +# if role == Qt.EditRole: +# row = index.row() +# self.wallets[row].name = value +# self.dataChanged.emit(index, index) +# return True +# return False def flags(self, index): return Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable -- GitLab