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

The return of the informations tab !

parent e60de62e
No related branches found
No related tags found
No related merge requests found
......@@ -141,12 +141,13 @@ class Community(QObject):
:return: The computed UD or 1 if no UD was generated.
"""
block = yield from self.get_ud_block()
if block and block != bma.blockchain.Block.null_value:
if block:
parameters = yield from self.parameters()
return math.ceil(
max(
self.dividend,
(yield from self.dividend()),
float(0) if block['membersCount'] == 0 else
self.parameters['c'] * block['monetaryMass'] / block['membersCount']
parameters['c'] * block['monetaryMass'] / block['membersCount']
)
)
......
......@@ -6,7 +6,7 @@ Created on 2 févr. 2014
import time
import logging
from PyQt5.QtWidgets import QWidget, QMessageBox, QDialog
from PyQt5.QtWidgets import QWidget, QMessageBox, QDialog, QPushButton, QTabBar
from PyQt5.QtCore import pyqtSlot, QDateTime, QLocale, QEvent
from PyQt5.QtGui import QIcon
......@@ -15,6 +15,7 @@ from .wot_tab import WotTabWidget
from .identities_tab import IdentitiesTabWidget
from .transactions_tab import TransactionsTabWidget
from .network_tab import NetworkTabWidget
from .informations_tab import InformationsTabWidget
from .dialogs import QAsyncMessageBox
from . import toast
import asyncio
......@@ -55,6 +56,8 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
self.tab_history = TransactionsTabWidget(self.app)
self.tab_informations = InformationsTabWidget(self.app)
self.tab_network = NetworkTabWidget(self.app)
self.tab_identities.view_in_wot.connect(self.tab_wot.draw_graph)
self.tab_identities.view_in_wot.connect(lambda: self.tabs.setCurrentWidget(self.tab_wot))
......@@ -79,6 +82,15 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
QIcon(":/icons/network_icon"),
self.tr("Network"))
self.tabs.addTab(self.tab_informations,
QIcon(":/icons/informations_icon"),
self.tr("Informations"))
style = self.app.qapp.style()
icon = style.standardIcon(style.SP_DockWidgetCloseButton)
close_button = QPushButton(icon, '')
close_button.setStyleSheet('border-style: inset;')
self.tabs.tabBar().setTabButton(4, QTabBar.RightSide, close_button)
self.button_membership.clicked.connect(self.send_membership_demand)
def cancel_once_tasks(self):
......@@ -95,6 +107,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
self.tab_wot.change_account(account, self.password_asker)
self.tab_identities.change_account(account, self.password_asker)
self.tab_history.change_account(account, self.password_asker)
self.tab_informations.change_account(account)
def change_community(self, community):
self.cancel_once_tasks()
......@@ -103,6 +116,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
self.tab_wot.change_community(community)
self.tab_history.change_community(community)
self.tab_identities.change_community(community)
self.tab_informations.change_community(community)
if self.community:
self.community.network.new_block_mined.disconnect(self.refresh_block)
......@@ -228,7 +242,6 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
label_text += self.tr(" - Median fork window : {0}")\
.format("#")
self.status_label.setText(label_text)
@once_at_a_time
......@@ -267,6 +280,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
if self.community and self.tab_history.table_history.model():
self.tab_history.table_history.model().sourceModel().refresh_transfers()
self.tab_history.refresh_balance()
self.tab_informations.refresh()
@asyncify
@asyncio.coroutine
......
......@@ -5,10 +5,13 @@ Created on 31 janv. 2015
"""
import logging
import asyncio
import math
from PyQt5.QtCore import QLocale, QDateTime, QEvent
from PyQt5.QtWidgets import QWidget
from ..gen_resources.informations_tab_uic import Ui_InformationsTabWidget
from ..tools.decorators import asyncify
from ..tools.exceptions import NoPeerAvailable
class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
......@@ -16,7 +19,7 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
classdocs
"""
def __init__(self, app, community):
def __init__(self, app):
"""
Constructor of the InformationsTabWidget
......@@ -26,52 +29,61 @@ class InformationsTabWidget(QWidget, Ui_InformationsTabWidget):
"""
super().__init__()
self.app = app
self.community = community
self.community.inner_data_changed.connect(self.refresh)
self.account = None
self.community = None
self.setupUi(self)
self.refresh()
@property
def account(self):
return self.app.current_account
def change_account(self, account):
self.account = account
def change_community(self, community):
self.community = community
self.refresh()
def refresh(self):
if self.account and self.community:
self.refresh_labels()
@asyncify
@asyncio.coroutine
def refresh_labels(self):
# try to request money parameters
try:
params = self.community.parameters
except Exception as e:
params = yield from self.community.parameters()
except NoPeerAvailable as e:
logging.debug('community parameters error : ' + str(e))
return False
# try to request money variables from last ud block
try:
block_ud = self.community.get_ud_block()
except Exception as e:
block_ud = yield from self.community.get_ud_block()
except NoPeerAvailable as e:
logging.debug('community get_ud_block error : ' + str(e))
return False
try:
block_ud_minus_1 = self.community.get_ud_block(1)
except Exception as e:
block_ud_minus_1 = yield from self.community.get_ud_block(1)
except NoPeerAvailable as e:
logging.debug('community get_ud_block error : ' + str(e))
return False
if block_ud:
# display float values
localized_ud = self.account.current_ref(block_ud['dividend'], self.community, self.app).diff_localized()
localized_ud = yield from self.account.current_ref(block_ud['dividend'], self.community, self.app).diff_localized()
computed_dividend = yield from self.community.computed_dividend()
# display float values
localized_ud_plus_1 = self.account.current_ref(self.community.computed_dividend,
localized_ud_plus_1 = yield from self.account.current_ref(computed_dividend,
self.community, self.app).diff_localized()
localized_mass = self.account.current_ref(block_ud['monetaryMass'],
localized_mass = yield from self.account.current_ref(block_ud['monetaryMass'],
self.community, self.app).diff_localized()
if block_ud_minus_1:
mass_minus_1 = (float(0) if block_ud['membersCount'] == 0 else
block_ud_minus_1['monetaryMass'] / block_ud['membersCount'])
localized_mass_minus_1_per_member = self.account.current_ref(mass_minus_1,
localized_mass_minus_1_per_member = yield from self.account.current_ref(mass_minus_1,
self.community, self.app).diff_localized()
localized_mass_minus_1 = self.account.current_ref(block_ud_minus_1['monetaryMass'],
localized_mass_minus_1 = yield from self.account.current_ref(block_ud_minus_1['monetaryMass'],
self.community, self.app).diff_localized()
else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment