Skip to content
Snippets Groups Projects
Commit 6451795d authored by Vincent Texier's avatar Vincent Texier
Browse files

Add informations tab containing tabs with infos

parent 6f9caa06
No related branches found
No related tags found
No related merge requests found
Icons are from the Noun Project.
iconmonstr-info-2-icon.svg: http://iconmonstr.com/license/
noun_2651_cc.svg : Created by Sergey Bakin
noun_18704_cc.svg : Created by Ian Mawle
noun_22441_cc.svg : Created by Bruno Castro
noun_29542_cc.svg : Created by Chris Kerr
noun_43022_cc.svg : Created by Jon Prepeluh
noun_63271_cc.svg : Created by Mark Shorter
\ No newline at end of file
noun_63271_cc.svg : Created by Mark Shorter
<?xml version="1.0" encoding="utf-8"?>
<!-- The icon can be used freely in both personal and commercial projects with no attribution required, but always appreciated.
You may NOT sub-license, resell, rent, redistribute or otherwise transfer the icon without express written permission from iconmonstr.com -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="512px" height="512px" viewBox="0 0 512 512" enable-background="new 0 0 512 512" xml:space="preserve">
<path id="info-2-icon" d="M255.998,90.001c91.74,0,166.002,74.241,166.002,165.998c0,91.741-74.245,166-166.002,166
c-91.74,0-165.998-74.243-165.998-166C90,164.259,164.243,90.001,255.998,90.001 M255.998,50.001
C142.229,50.001,50,142.229,50,255.999c0,113.771,92.229,206,205.998,206c113.771,0,206.002-92.229,206.002-206
C462,142.229,369.77,50.001,255.998,50.001L255.998,50.001z M285.822,367.567h-57.646V230.6h57.646V367.567z M257,202.268
c-17.522,0-31.729-14.206-31.729-31.73c0-17.522,14.206-31.729,31.729-31.729c17.524,0,31.728,14.206,31.728,31.729
C288.728,188.062,274.524,202.268,257,202.268z"/>
</svg>
<RCC>
<qresource prefix="icons">
<file alias="informations_icon">iconmonstr-info-2-icon.svg</file>
<file alias="community_icon">noun_22441_cc.svg</file>
<file alias="wot_icon">noun_2651_cc.svg</file>
<file alias="members_icon">noun_18704_cc.svg</file>
......
......@@ -122,14 +122,21 @@ class Community(object):
return (other.currency == self.currency)
def dividend(self):
block = self.get_ud_block()
if block:
return block['dividend']
else:
return 1
def get_ud_block(self):
ud = self.request(bma.blockchain.UD)
if len(ud['result']['blocks']) > 0:
block_number = ud['result']['blocks'][-1]
block = self.request(bma.blockchain.Block,
req_args={'number': block_number})
return block['dividend']
return block
else:
return 1
return False
def _peering_traversal(self, peer, found_peers, traversed_pubkeys):
logging.debug("Read {0} peering".format(peer.pubkey))
......
......@@ -14,6 +14,7 @@ from PyQt5.QtCore import QModelIndex, Qt, pyqtSlot, QObject, QThread, pyqtSignal
from PyQt5.QtGui import QIcon
from ..gen_resources.currency_tab_uic import Ui_CurrencyTabWidget
from .community_tab import CommunityTabWidget
from .informations_tab import InformationsTabWidget
from ..models.sent import SentListModel
from ..models.received import ReceivedListModel
from ..models.wallets import WalletsListModel
......@@ -102,6 +103,11 @@ class CurrencyTabWidget(QWidget, Ui_CurrencyTabWidget):
self.tabs_account.addTab(self.tab_community,
QIcon(':/icons/community_icon'),
"Community")
self.tab_informations = InformationsTabWidget(self.app.current_account,
self.community)
self.tabs_account.addTab(self.tab_informations,
QIcon(':/icons/informations_icon'),
"Informations")
blockid = self.community.current_blockid()
block_number = blockid['number']
self.status_label.setText("Connected : Block {0}"
......
"""
Created on 2 févr. 2014
@author: inso
"""
from PyQt5.QtWidgets import QWidget, QHeaderView
from PyQt5.QtCore import Qt
from ..models.parameters import ParametersModel
from ..gen_resources.informations_tab_uic import Ui_InformationsTabWidget
class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
"""
classdocs
"""
def __init__(self, account, community):
"""
Constructor
"""
super().__init__()
self.setupUi(self)
self.community = community
self.account = account
self.table_currency_informations.HorizontalHeader = QHeaderView(Qt.Orientation(Qt.Horizontal))
self.table_currency_informations.HorizontalHeader.setSectionResizeMode(QHeaderView.ResizeToContents)
self.table_currency_informations.HorizontalHeader.setStretchLastSection(True)
#self.table_currency_informations.HorizontalHeader.setSectionResizeMode(QHeaderView.Stretch)
self.table_currency_informations.setHorizontalHeader(self.table_currency_informations.HorizontalHeader)
self.table_currency_informations.horizontalHeader().hide()
self.table_currency_informations.verticalHeader().hide()
params = self.community.get_parameters()
block = self.community.get_ud_block()
infos = [
# variables
{'name': 'dividend', 'value': block['dividend'],
'description': 'Universal Dividend UD(t) in currency units'},
{'name': 'monetaryMass', 'value': block['monetaryMass'],
'description': 'Monetary Mass M(t) in currency units'},
{'name': 'membersCount', 'value': block['membersCount'],
'description': 'Members N(t)'},
{'name': 'monetaryMassPerMember', 'value': "{:.2f}".format(block['monetaryMass'] / block['membersCount']),
'description': 'Monetary Mass per member M(t)/N(t) in currency units'},
{'name': 'actualGrowth',
'value': "{:2.2%}".format(block['dividend'] / ((block['monetaryMass'] - (block['membersCount'] * block['dividend'])) / block['membersCount'])),
'description': 'Actual % Growth (UD(t) / (M(t-1)/Nt))'},
# money params
{'name': 'c', 'value': "{:2.0%}".format(params['c']),
'description': '% growth'},
{'name': 'ud0', 'value': params['ud0'],
'description': 'Initial Universal Dividend in currency units'},
{'name': 'dt', 'value': params['dt'] / 86400,
'description': 'Time period in days between two UD'},
{'name': 'medianTimeBlocks', 'value': params['medianTimeBlocks'],
'description': 'Number of blocks used for calculating median time'},
{'name': 'avgGenTime', 'value': params['avgGenTime'],
'description': 'The average time in seconds for writing 1 block (wished time)'},
{'name': 'dtDiffEval', 'value': params['dtDiffEval'],
'description': 'The number of blocks required to evaluate again PoWMin value'},
{'name': 'blocksRot', 'value': params['blocksRot'],
'description': 'The number of previous blocks to check for personalized difficulty'},
{'name': 'percentRot', 'value': "{:2.0%}".format(params['percentRot']),
'description': 'The percent of previous issuers to reach for personalized difficulty'},
# wot params
{'name': 'sigDelay', 'value': params['sigDelay'] / 86400,
'description': 'Minimum delay between 2 identical certifications (in days)'},
{'name': 'sigValidity', 'value': params['sigValidity'] / 86400,
'description': 'Maximum age of a valid signature (in days)'},
{'name': 'sigQty', 'value': params['sigQty'],
'description': 'Minimum quantity of signatures to be part of the WoT'},
{'name': 'sigWoT', 'value': params['sigWoT'],
'description': 'Minimum quantity of valid made certifications to be part of the WoT for distance rule'},
{'name': 'msValidity', 'value': params['msValidity'] / 86400,
'description': 'Maximum age of a valid membership (in days)'},
{'name': 'stepMax', 'value': params['stepMax'],
'description': 'Maximum distance between each WoT member and a newcomer'},
]
self.table_currency_informations.setModel(ParametersModel(infos))
# -*- coding: utf-8 -*-
from PyQt5.QtCore import (Qt, QAbstractTableModel, QModelIndex)
from PyQt5.QtGui import QFont, QColor
class ParametersModel(QAbstractTableModel):
def __init__(self, infos=list(), parent=None):
super().__init__(parent)
self.infos = infos
def rowCount(self, index=QModelIndex()):
""" Returns the number of rows the model holds. """
return len(self.infos)
def columnCount(self, index=QModelIndex()):
""" Returns the number of columns the model holds. """
return 3
def data(self, index, role=Qt.DisplayRole):
""" Depending on the index and role given, return data. If not
returning data, return None
"""
if not index.isValid():
return None
if not 0 <= index.row() < len(self.infos):
return None
if role == Qt.DisplayRole:
if index.column() == 0:
return self.infos[index.row()]["name"]
elif index.column() == 1:
return self.infos[index.row()]["value"]
elif index.column() == 2:
return self.infos[index.row()]["description"]
elif role == Qt.TextAlignmentRole and index.column() == 0:
return int(Qt.AlignRight | Qt.AlignVCenter)
elif role == Qt.FontRole and index.column() == 0:
font = QFont()
font.setBold(True)
return font
elif role == Qt.BackgroundColorRole:
if index.row() > 12:
return QColor("#dddddd")
elif index.row() > 4:
return QColor("#eeeeee")
return None
def headerData(self, section, orientation, role=Qt.DisplayRole):
""" Set the headers to be displayed. """
if role != Qt.DisplayRole:
return None
if orientation == Qt.Horizontal:
if section == 0:
return "Name"
elif section == 1:
return "Value"
return None
def insertRows(self, position, rows=1, index=QModelIndex()):
""" Insert a row into the model. """
self.beginInsertRows(QModelIndex(), position, position + rows - 1)
for row in range(rows):
self.infos.insert(position + row, {"name": "", "value": ""})
self.endInsertRows()
return True
def removeRows(self, position, rows=1, index=QModelIndex()):
""" Remove a row from the model. """
self.beginRemoveRows(QModelIndex(), position, position + rows - 1)
del self.infos[position:position+rows]
self.endRemoveRows()
return True
def setData(self, index, value, role=Qt.EditRole):
""" Adjust the data (set it to <value>) depending on the given
index and role.
"""
if role != Qt.EditRole:
return False
if index.isValid() and 0 <= index.row() < len(self.infos):
info = self.infos[index.row()]
if index.column() == 0:
info["name"] = value
elif index.column() == 1:
info["value"] = value
else:
return False
self.dataChanged.emit(index, index)
return True
return False
def flags(self, index):
""" Set the item flags at the given index. Seems like we're
implementing this function just to see how it's done, as we
manually adjust each tableView to have NoEditTriggers.
"""
if not index.isValid():
return Qt.ItemIsEnabled | Qt.Item
return Qt.ItemFlags(QAbstractTableModel.flags(self, index))
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