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

Display sentries

parent 2e1b81a8
No related branches found
No related tags found
No related merge requests found
import logging
import time
import networkx
from PyQt5.QtCore import QLocale, QDateTime, QObject
from PyQt5.QtCore import QLocale, QDateTime, QObject, QT_TRANSLATE_NOOP
from sakia.errors import NoPeerAvailable
from .constants import EdgeStatus, NodeStatus
from sakia.constants import MAX_CONFIRMATIONS
def sentry_display(identity):
sentry_text = ""
sentry_symbol = ""
if identity.sentry:
sentry_symbol = ""
sentry_text = QT_TRANSLATE_NOOP("BaseGraph", "(sentry)") + " "
return sentry_symbol, sentry_text
class BaseGraph(QObject):
def __init__(self, app, blockchain_service, identities_service, nx_graph):
"""
......@@ -92,29 +101,12 @@ class BaseGraph(QObject):
return "{0} %".format(QLocale().toString(float(confirmation), 'f', 0))
return None
def is_sentry(self, nb_certs, nb_members):
"""
Check if it is a sentry or not
:param int nb_certs: the number of certs
:param int nb_members: the number of members
:return: True if a sentry
"""
Y = {
10: 2,
100: 4,
1000: 6,
10000: 12,
100000: 20
}
for k in reversed(sorted(Y.keys())):
if nb_members >= k:
return nb_certs >= Y[k]
return False
def add_certifier_node(self, certifier, identity, certification, node_status):
sentry_symbol, sentry_text = sentry_display(certifier)
name_text = certifier.uid if certifier.uid else certifier.pubkey[:12]
metadata = {
'text': certifier.uid if certifier.uid else certifier.pubkey[:12],
'tooltip': certifier.pubkey,
'text': sentry_symbol + name_text,
'tooltip': sentry_text + certifier.pubkey,
'identity': certifier,
'status': node_status
}
......@@ -135,9 +127,11 @@ class BaseGraph(QObject):
self.nx_graph.add_edge(certifier.pubkey, identity.pubkey, attr_dict=arc)
def add_certified_node(self, identity, certified, certification, node_status):
sentry_symbol, sentry_text = sentry_display(certified)
name_text = certified.uid if certified.uid else certified.pubkey[:12]
metadata = {
'text': certified.uid if certified.uid else certified.pubkey[:12],
'tooltip': certified.pubkey,
'text': sentry_symbol + name_text,
'tooltip': sentry_text + certified.pubkey,
'identity': certified,
'status': node_status
}
......@@ -237,9 +231,11 @@ class BaseGraph(QObject):
:param list edges: Optional, default=None, List of edges (certified by identity)
:param list connected: Optional, default=None, Public key list of the connected nodes around the identity
"""
sentry_symbol, sentry_text = sentry_display(identity)
name_text = identity.uid
metadata = {
'text': identity.uid,
'tooltip': identity.pubkey,
'text': sentry_symbol + name_text,
'tooltip': sentry_text + identity.pubkey,
'status': status,
'identity': identity
}
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CongratulationPopup</class>
<widget class="QDialog" name="CongratulationPopup">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>198</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>350</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Congratulation</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>label</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
<property name="alignment">
<set>Qt::AlignJustify|Qt::AlignTop</set>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
<property name="textInteractionFlags">
<set>Qt::TextBrowserInteraction</set>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>CongratulationPopup</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
from PyQt5.QtWidgets import QDialog
from PyQt5.QtCore import pyqtSignal, Qt
from .connection_cfg_uic import Ui_ConnectionConfigurationDialog
from .congratulation_uic import Ui_CongratulationPopup
from duniterpy.key import SigningKey, ScryptParams
from math import ceil, log
from sakia.gui.widgets import toast
from sakia.helpers import timestamp_to_dhms
from sakia.gui.widgets.dialogs import QAsyncMessageBox
from sakia.gui.widgets.dialogs import dialog_async_exec, QAsyncMessageBox
from sakia.constants import ROOT_SERVERS
......@@ -153,13 +154,23 @@ class ConnectionConfigView(QDialog, Ui_ConnectionConfigurationDialog):
hours=hours,
min=minutes)
await QAsyncMessageBox.information(self, self.tr("Registration"), self.tr("""
<b>Congratulations !</b><br>
dialog = QDialog(self)
about_dialog = Ui_CongratulationPopup()
about_dialog.setupUi(dialog)
dialog.setWindowTitle("Registration")
about_dialog.label.setText(self.tr("""
<p><b>Congratulations !</b><br>
<br>
You just published your identity to the network.<br>
For your identity to be registered, you will need <b>{certs} certifications</b> from members.<br>
Once you got the required certifications, you will be able to validate your registration
For your identity to be registered, you will need<br>
<b>{certs} certifications</b> from members.<br>
Once you got the required certifications, <br>
you will be able to validate your registration<br>
by <b>publishing your membership request !</b><br>
Please notice that your identity document <b>will expire in {expiration_time_str}.</b> If you failed
to get {certs} certifications before this time, the process will have to be restarted from scratch.
Please notice that your identity document <br>
<b>will expire in {expiration_time_str}.</b><br>
If you failed to get {certs} certifications before this time, <br>
the process will have to be restarted from scratch.</p>
""".format(certs=blockchain_parameters.sig_qty, expiration_time_str=expiration_time_str)))
await dialog_async_exec(dialog)
......@@ -150,8 +150,10 @@ class IdentitiesTableModel(QAbstractTableModel):
expiration_date = self.identities_service.expiration_date(identity)
sigdate_ts = identity.timestamp
sigdate_block = identity.blockstamp
name = "" if identity.sentry else ""
name += identity.uid
return identity.uid, identity.pubkey, join_date, expiration_date, sigdate_ts, sigdate_block, identity
return name, identity.pubkey, join_date, expiration_date, sigdate_ts, sigdate_block, identity
def refresh_identities(self, identities):
"""
......
from PyQt5.QtWidgets import QApplication, QMessageBox
from PyQt5.QtWidgets import QApplication, QMessageBox, QDialog
from PyQt5.QtCore import Qt
from PyQt5.QtTest import QTest
......@@ -6,5 +6,7 @@ from PyQt5.QtTest import QTest
def click_on_top_message_box():
topWidgets = QApplication.topLevelWidgets()
for w in topWidgets:
if type(w) is QMessageBox:
if isinstance(w, QMessageBox):
QTest.keyClick(w, Qt.Key_Enter)
elif isinstance(w, QDialog) and w.windowTitle() == "Registration":
QTest.keyClick(w, Qt.Key_Enter)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment