diff --git a/res/ui/currency_tab.ui b/res/ui/currency_tab.ui index 04a102931088059edd6af03e488a454786d270fa..dd51aee30806ad8d6936c2287e48bcc87e4d0644 100644 --- a/res/ui/currency_tab.ui +++ b/res/ui/currency_tab.ui @@ -33,29 +33,8 @@ <bool>false</bool> </property> <property name="currentIndex"> - <number>1</number> + <number>0</number> </property> - <widget class="QWidget" name="tab_wallets"> - <attribute name="icon"> - <iconset resource="../icons/icons.qrc"> - <normaloff>:/icons/wallet_icon</normaloff>:/icons/wallet_icon</iconset> - </attribute> - <attribute name="title"> - <string>Wallets</string> - </attribute> - <layout class="QHBoxLayout" name="horizontalLayout"> - <item> - <widget class="QListView" name="list_wallets"> - <property name="contextMenuPolicy"> - <enum>Qt::CustomContextMenu</enum> - </property> - </widget> - </item> - <item> - <widget class="QListView" name="list_wallet_content"/> - </item> - </layout> - </widget> <widget class="QWidget" name="tab_transactions"> <attribute name="icon"> <iconset resource="../icons/icons.qrc"> @@ -125,38 +104,6 @@ <include location="../icons/icons.qrc"/> </resources> <connections> - <connection> - <sender>list_wallets</sender> - <signal>clicked(QModelIndex)</signal> - <receiver>CurrencyTabWidget</receiver> - <slot>refresh_wallet_content(QModelIndex)</slot> - <hints> - <hint type="sourcelabel"> - <x>113</x> - <y>162</y> - </hint> - <hint type="destinationlabel"> - <x>199</x> - <y>149</y> - </hint> - </hints> - </connection> - <connection> - <sender>list_wallets</sender> - <signal>customContextMenuRequested(QPoint)</signal> - <receiver>CurrencyTabWidget</receiver> - <slot>wallet_context_menu(QPoint)</slot> - <hints> - <hint type="sourcelabel"> - <x>113</x> - <y>162</y> - </hint> - <hint type="destinationlabel"> - <x>199</x> - <y>149</y> - </hint> - </hints> - </connection> <connection> <sender>date_from</sender> <signal>dateTimeChanged(QDateTime)</signal> diff --git a/res/ui/wallets_tab.ui b/res/ui/wallets_tab.ui new file mode 100644 index 0000000000000000000000000000000000000000..32f4bfcd85ca79303c1c965ccf98fd45ac15824f --- /dev/null +++ b/res/ui/wallets_tab.ui @@ -0,0 +1,98 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>WalletsTab</class> + <widget class="QWidget" name="WalletsTab"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>452</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <property name="styleSheet"> + <string notr="true">QGroupBox { + border: 1px solid gray; + border-radius: 9px; + margin-top: 0.5em; +} + +QGroupBox::title { + subcontrol-origin: margin; + left: 10px; + padding: 0 3px 0 3px; + font-weight: bold; +}</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="styleSheet"> + <string notr="true"/> + </property> + <property name="title"> + <string>Account</string> + </property> + <property name="flat"> + <bool>true</bool> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QLabel" name="label_general"> + <property name="text"> + <string>label_general</string> + </property> + <property name="textFormat"> + <enum>Qt::RichText</enum> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> + <string>Balance</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QLabel" name="label_balance"> + <property name="text"> + <string>label_balance</string> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QTableView" name="table_wallets"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Maximum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index aa2f4205482e22a79c4da5591e8c5bebe21ab71e..051596b6eec2be78e45c0cca2db66c982652f3a6 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -200,6 +200,12 @@ class Account(object): sent.append(transfer) return sent + def amount(self, community): + value = 0 + for w in self.wallets: + value += w.value(community) + return value + def member_of(self, community): pubkeys = community.members_pubkeys() if self.pubkey not in pubkeys: diff --git a/src/cutecoin/gui/currency_tab.py b/src/cutecoin/gui/currency_tab.py index 8b9ffc5fef548056802b77bb21125b9ee9500f83..5e059b2fe68b8681f8f767a33b7fa47d9fbf628b 100644 --- a/src/cutecoin/gui/currency_tab.py +++ b/src/cutecoin/gui/currency_tab.py @@ -17,6 +17,7 @@ from PyQt5.QtGui import QIcon from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget from .community_tab import CommunityTabWidget 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 @@ -81,6 +82,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.tab_community = CommunityTabWidget(self.app.current_account, self.community, self.password_asker) + self.tab_wallets = WalletsTabWidget(self.app.current_account, + self.community) + self.bc_watcher = BlockchainWatcher(self.app.current_account, community) self.bc_watcher.new_block_mined.connect(self.refresh_block) @@ -148,6 +152,12 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.tab_community = CommunityTabWidget(self.app.current_account, self.community, self.password_asker) + + self.tab_wallets = WalletsTabWidget(self.app.current_account, + self.community) + self.tabs_account.addTab(self.tab_wallets, + "Wallets") + self.tabs_account.addTab(self.tab_community, QIcon(':/icons/community_icon'), "Community") @@ -170,11 +180,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): @pyqtSlot(int) def refresh_block(self, block_number): - if self.list_wallets.model(): - self.list_wallets.model().dataChanged.emit( - QModelIndex(), - QModelIndex(), - []) + if self.tab_wallets: + self.tab_wallets.refresh() if self.list_wallet_content.model(): self.list_wallet_content.model().dataChanged.emit( @@ -197,12 +204,15 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): self.status_label.setText(text) def refresh_wallets(self): + self.tab_wallets.refresh() + ''' if self.app.current_account: wallets_list_model = WalletsListModel(self.app.current_account, self.community) wallets_list_model.dataChanged.connect(self.wallet_changed) self.list_wallets.setModel(wallets_list_model) self.refresh_wallet_content(QModelIndex()) + ''' def refresh_wallet_content(self, index): if self.app.current_account: @@ -333,10 +343,8 @@ QMessageBox.Ok | QMessageBox.Cancel) QModelIndex(), []) - if self.list_wallets.model(): - self.list_wallets.model().dataChanged.emit( - QModelIndex(), - QModelIndex(), - []) + if self.tab_wallets: + self.tab_wallets.refresh() + if self.tab_informations: self.tab_informations.refresh() diff --git a/src/cutecoin/gui/wallets_tab.py b/src/cutecoin/gui/wallets_tab.py new file mode 100644 index 0000000000000000000000000000000000000000..efe0705c44e8f370a5ae33d5baae36a050c6b7e6 --- /dev/null +++ b/src/cutecoin/gui/wallets_tab.py @@ -0,0 +1,91 @@ +''' +Created on 15 févr. 2015 + +@author: inso +''' + +import logging +from PyQt5.QtWidgets import QWidget +from PyQt5.QtCore import QDateTime +from ..core.person import Person +from ..tools.exceptions import MembershipNotFoundError +from ..gen_resources.wallets_tab_uic import Ui_WalletsTab + + +class WalletsTabWidget(QWidget, Ui_WalletsTab): + ''' + classdocs + ''' + + def __init__(self, account, community): + ''' + Constructor + ''' + super().__init__() + self.setupUi(self) + self.account = account + self.community = community + + self.refresh() + + def refresh(self): + parameters = self.community.get_parameters() + last_renewal = "" + expiration = "" + try: + person = Person.lookup(self.account.pubkey, self.community) + membership = person.membership(self.community) + + renew_block = membership.block_number + last_renewal = self.community.get_block(renew_block).mediantime + expiration = last_renewal + parameters['sigValidity'] + except MembershipNotFoundError: + pass + + certifiers = 0 + certified = 0 + date_renewal = QDateTime.fromTime_t(last_renewal).date().toString() + date_expiration = QDateTime.fromTime_t(expiration).date().toString() + + # set infos in label + self.label_general.setText( + """ + <table cellpadding="5"> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + </table> + """.format( + self.account.name, self.account.pubkey, + "Membership", + "Last renewal on {:}, expiration on {:}".format(date_renewal, date_expiration), + "Your web of trust :", + "Certified by : {0} ; Certifier of : {0}".format(certifiers, certified) + ) + ) + + amount = self.account.amount(self.community) + maximum = self.community.monetary_mass + + # set infos in label + self.label_balance.setText( + """ + <table cellpadding="5"> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> + </table> + """.format("Your money share : ", "{:.2f}%".format(amount/maximum*100), + "Your part : ", "{:.2f} in [{:.2f} - {:.2f}]".format(self.get_referential_value(amount), + self.get_referential_value(0), + self.get_referential_value(maximum)) + ) + ) + + def get_referential_value(self, value): + return self.account.units_to_ref(value, self.community) + + def get_referential_diff_value(self, value): + return self.account.units_to_diff_ref(value, self.community) + + def get_referential_name(self): + return self.account.ref_name(self.community.short_currency)