Skip to content
Snippets Groups Projects
Commit 7bab52c9 authored by inso's avatar inso
Browse files

New wallet tab initialized

parent 392fa9f5
No related branches found
No related tags found
No related merge requests found
...@@ -33,29 +33,8 @@ ...@@ -33,29 +33,8 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </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"> <widget class="QWidget" name="tab_transactions">
<attribute name="icon"> <attribute name="icon">
<iconset resource="../icons/icons.qrc"> <iconset resource="../icons/icons.qrc">
...@@ -125,38 +104,6 @@ ...@@ -125,38 +104,6 @@
<include location="../icons/icons.qrc"/> <include location="../icons/icons.qrc"/>
</resources> </resources>
<connections> <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> <connection>
<sender>date_from</sender> <sender>date_from</sender>
<signal>dateTimeChanged(QDateTime)</signal> <signal>dateTimeChanged(QDateTime)</signal>
......
<?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>
...@@ -200,6 +200,12 @@ class Account(object): ...@@ -200,6 +200,12 @@ class Account(object):
sent.append(transfer) sent.append(transfer)
return sent return sent
def amount(self, community):
value = 0
for w in self.wallets:
value += w.value(community)
return value
def member_of(self, community): def member_of(self, community):
pubkeys = community.members_pubkeys() pubkeys = community.members_pubkeys()
if self.pubkey not in pubkeys: if self.pubkey not in pubkeys:
......
...@@ -17,6 +17,7 @@ from PyQt5.QtGui import QIcon ...@@ -17,6 +17,7 @@ from PyQt5.QtGui import QIcon
from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget
from .community_tab import CommunityTabWidget from .community_tab import CommunityTabWidget
from .transfer import TransferMoneyDialog from .transfer import TransferMoneyDialog
from .wallets_tab import WalletsTabWidget
from ..models.txhistory import HistoryTableModel, TxFilterProxyModel from ..models.txhistory import HistoryTableModel, TxFilterProxyModel
from .informations_tab import InformationsTabWidget from .informations_tab import InformationsTabWidget
from ..models.wallets import WalletsListModel from ..models.wallets import WalletsListModel
...@@ -81,6 +82,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -81,6 +82,9 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.tab_community = CommunityTabWidget(self.app.current_account, self.tab_community = CommunityTabWidget(self.app.current_account,
self.community, self.community,
self.password_asker) self.password_asker)
self.tab_wallets = WalletsTabWidget(self.app.current_account,
self.community)
self.bc_watcher = BlockchainWatcher(self.app.current_account, self.bc_watcher = BlockchainWatcher(self.app.current_account,
community) community)
self.bc_watcher.new_block_mined.connect(self.refresh_block) self.bc_watcher.new_block_mined.connect(self.refresh_block)
...@@ -148,6 +152,12 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -148,6 +152,12 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.tab_community = CommunityTabWidget(self.app.current_account, self.tab_community = CommunityTabWidget(self.app.current_account,
self.community, self.community,
self.password_asker) 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, self.tabs_account.addTab(self.tab_community,
QIcon(':/icons/community_icon'), QIcon(':/icons/community_icon'),
"Community") "Community")
...@@ -170,11 +180,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -170,11 +180,8 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
@pyqtSlot(int) @pyqtSlot(int)
def refresh_block(self, block_number): def refresh_block(self, block_number):
if self.list_wallets.model(): if self.tab_wallets:
self.list_wallets.model().dataChanged.emit( self.tab_wallets.refresh()
QModelIndex(),
QModelIndex(),
[])
if self.list_wallet_content.model(): if self.list_wallet_content.model():
self.list_wallet_content.model().dataChanged.emit( self.list_wallet_content.model().dataChanged.emit(
...@@ -197,12 +204,15 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget): ...@@ -197,12 +204,15 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.status_label.setText(text) self.status_label.setText(text)
def refresh_wallets(self): def refresh_wallets(self):
self.tab_wallets.refresh()
'''
if self.app.current_account: if self.app.current_account:
wallets_list_model = WalletsListModel(self.app.current_account, wallets_list_model = WalletsListModel(self.app.current_account,
self.community) self.community)
wallets_list_model.dataChanged.connect(self.wallet_changed) wallets_list_model.dataChanged.connect(self.wallet_changed)
self.list_wallets.setModel(wallets_list_model) self.list_wallets.setModel(wallets_list_model)
self.refresh_wallet_content(QModelIndex()) self.refresh_wallet_content(QModelIndex())
'''
def refresh_wallet_content(self, index): def refresh_wallet_content(self, index):
if self.app.current_account: if self.app.current_account:
...@@ -333,10 +343,8 @@ QMessageBox.Ok | QMessageBox.Cancel) ...@@ -333,10 +343,8 @@ QMessageBox.Ok | QMessageBox.Cancel)
QModelIndex(), QModelIndex(),
[]) [])
if self.list_wallets.model(): if self.tab_wallets:
self.list_wallets.model().dataChanged.emit( self.tab_wallets.refresh()
QModelIndex(),
QModelIndex(),
[])
if self.tab_informations: if self.tab_informations:
self.tab_informations.refresh() self.tab_informations.refresh()
'''
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)
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