diff --git a/src/cutecoin/core/app.py b/src/cutecoin/core/app.py index 7b8195377cd8740a65aa63716ba1e11fe979d96d..56a4369033e080a9fd3ab8efe1aedbeb92cbf646 100644 --- a/src/cutecoin/core/app.py +++ b/src/cutecoin/core/app.py @@ -35,10 +35,14 @@ class Application(QObject): def __init__(self, qapp, loop, network_manager, identities_registry): """ - Create a new "cutecoin" application - - :param argv: The argv parameters of the call + Init a new "cutecoin" application + :param QCoreApplication qapp: Qt Application + :param quamash.QEventLoop loop: quamash.QEventLoop instance + :param QNetworkAccessManager network_manager: QNetworkAccessManager instance + :param IdentitiesRegistry identities_registry: IdentitiesRegistry instance + :return: """ + super().__init__() self.qapp = qapp self.accounts = {} diff --git a/src/cutecoin/core/graph.py b/src/cutecoin/core/graph.py index 9ec2ed88b6eb3107f5c107440addfe6288eb8b70..fea0c925035831fad5593359741855b017fd1a99 100644 --- a/src/cutecoin/core/graph.py +++ b/src/cutecoin/core/graph.py @@ -2,18 +2,20 @@ import logging import time import datetime from PyQt5.QtCore import QLocale, QDateTime -from ..core.registry import Identity +from ..core.registry import Identity, BlockchainState from cutecoin.gui.views.wot import NODE_STATUS_HIGHLIGHTED, NODE_STATUS_OUT, ARC_STATUS_STRONG, ARC_STATUS_WEAK class Graph(object): - def __init__(self, community, graph=None): + def __init__(self, app, community, graph=None): """ Init Graph instance - :param cutecoin.core.community.Community community: + :param cutecoin.core.app.Application app: Application instance + :param cutecoin.core.community.Community community: Community instance + :param dict graph: Dict of the graph :return: """ - + self.app = app self.community = community self.signature_validity = self.community.parameters['sigValidity'] #  arc considered strong during 75% of signature validity time @@ -87,7 +89,7 @@ class Graph(object): node = self._graph[pubkey] if node['id'] in tuple(done): continue - identity_selected = identity.from_metadata(node) + identity_selected = identity.from_handled_data(node['text'], node['id'], BlockchainState.VALIDATED) certifier_list = identity_selected.certifiers_of(self.app.identities_registry, self.community) self.add_certifier_list(certifier_list, identity_selected, identity) if identity.pubkey in tuple(self._graph.keys()): diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index bd78bdd530e7d107653301fc138eb4009ba15fb8..6928f1e8e22af4b2b5fac5426cd33f74b5da24f5 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -145,7 +145,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): self.certify_identity(person) def identity_informations(self, person): - dialog = MemberDialog(self.account, self.community, person) + dialog = MemberDialog(none, self.account, self.community, person) dialog.exec_() def add_identity_as_contact(self, person): diff --git a/src/cutecoin/gui/member.py b/src/cutecoin/gui/member.py index 1b89afa9adcde8b41583bcad016e1642314eaa6e..3f3139abe35e7581a99b880b6b986289fffb2f5c 100644 --- a/src/cutecoin/gui/member.py +++ b/src/cutecoin/gui/member.py @@ -1,4 +1,3 @@ - import datetime from PyQt5.QtWidgets import QDialog @@ -7,24 +6,32 @@ from ..core.graph import Graph from ..gen_resources.member_uic import Ui_DialogMember from ..tools.exceptions import MembershipNotFoundError + class MemberDialog(QDialog, Ui_DialogMember): """ classdocs """ - def __init__(self, account, community, person): + def __init__(self, app, account, community, identity): """ - Constructor + Init MemberDialog + + :param cutecoin.core.app.Application app: Application instance + :param cutecoin.core.account.Account account: Account instance + :param cutecoin.core.community.Community community: Community instance + :param cutecoin.core.registry.identity.Identity identity: Identity instance + :return: """ super().__init__() self.setupUi(self) + self.app = app self.community = community self.account = account - self.person = person - self.label_uid.setText(person.uid) + self.identity = identity + self.label_uid.setText(identity.uid) try: - join_date = self.person.get_join_date(self.community) + join_date = self.identity.get_join_date(self.community) except MembershipNotFoundError: join_date = None @@ -34,36 +41,42 @@ class MemberDialog(QDialog, Ui_DialogMember): join_date = datetime.datetime.fromtimestamp(join_date).strftime("%d/%m/%Y %I:%M") # calculate path to account member - graph = Graph(self.community) + graph = Graph(self.app, self.community) path = None # if selected member is not the account member... - if person.pubkey != self.account.pubkey: + if identity.pubkey != self.account.pubkey: # add path from selected member to account member - path = graph.get_shortest_path_between_members(person, self.account.identity(self.community)) + path = graph.get_shortest_path_between_members(identity, self.account.identity(self.community)) text = self.tr(""" <table cellpadding="5"> <tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr> """).format( - self.tr('Public key'), - self.person.pubkey, - self.tr('Join date'), - join_date - ) + self.tr('Public key'), + self.identity.pubkey, + self.tr('Join date'), + join_date + ) if path: distance = len(path) - 1 - text += self.tr("""<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format(self.tr('Distance'), distance)) + text += self.tr( + """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format(self.tr('Distance'), + distance)) if distance > 1: index = 0 for node in path: if index == 0: - text += self.tr("""<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""").format(self.tr('Path'), node['text']) + text += self.tr("""<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""").format( + self.tr('Path'), node['text']) else: - text += self.tr("""<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""").format('', node['text']) + text += self.tr("""<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""").format('', + node[ + 'text']) if index == distance and node['id'] != self.account.pubkey: - text += self.tr("""<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""").format('', self.account.name) + text += self.tr("""<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""").format('', + self.account.name) index += 1 # close html text text += "</table>" diff --git a/src/cutecoin/gui/wot_tab.py b/src/cutecoin/gui/wot_tab.py index ac600f732bfbce87b630243158079c24e8f4d8ba..597c9904ee88fe0d768dacd6820d4c41e6f36981 100644 --- a/src/cutecoin/gui/wot_tab.py +++ b/src/cutecoin/gui/wot_tab.py @@ -5,17 +5,19 @@ from cutecoin.core.graph import Graph from PyQt5.QtWidgets import QWidget, QComboBox, QLineEdit from PyQt5.QtCore import pyqtSlot from cutecoin.core.net.api import bma +from cutecoin.core.registry import BlockchainState from ..gen_resources.wot_tab_uic import Ui_WotTabWidget -from cutecoin.gui.views.wot import NODE_STATUS_HIGHLIGHTED, NODE_STATUS_SELECTED, NODE_STATUS_OUT, ARC_STATUS_STRONG, ARC_STATUS_WEAK +from cutecoin.gui.views.wot import NODE_STATUS_HIGHLIGHTED, NODE_STATUS_SELECTED, NODE_STATUS_OUT, ARC_STATUS_STRONG, \ + ARC_STATUS_WEAK class WotTabWidget(QWidget, Ui_WotTabWidget): def __init__(self, app, account, community, password_asker, parent=None): """ - - :param cutecoin.core.account.Account account: - :param cutecoin.core.community.Community community: - :param parent: + :param cutecoin.core.app.Application app: Application instance + :param cutecoin.core.account.Account account: Account instance + :param cutecoin.core.community.Community community: Community instance + :param QWidget parent: Parent :return: """ super().__init__(parent) @@ -26,7 +28,7 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): # Default text when combo lineEdit is empty self.comboBoxSearch.lineEdit().setPlaceholderText(self.tr('Research a pubkey, an uid...')) - # add combobox events + #  add combobox events self.comboBoxSearch.lineEdit().returnPressed.connect(self.search) # To fix a recall of the same item with different case, # the edited text is not added in the item list @@ -53,7 +55,13 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): @pyqtSlot(dict) def handle_node_click(self, metadata): - self.draw_graph(self.app.identities_registry.from_metadata(metadata)) + self.draw_graph( + self.app.identities_registry.from_handled_data( + metadata['text'], + metadata['id'], + BlockchainState.VALIDATED + ) + ) def draw_graph(self, identity): """ @@ -65,7 +73,7 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): identity_account = self.account.identity(self.community) - #Disconnect old identity + # Disconnect old identity try: if self._current_identity and self._current_identity != identity: self._current_identity.inner_data_changed.disconnect(self.handle_identity_change) @@ -83,7 +91,7 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): certified_list = identity.certified_by(self.app.identities_registry, self.community) # create empty graph instance - graph = Graph(self.community) + graph = Graph(self.app, self.community) # add wallet node node_status = 0 @@ -163,28 +171,44 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): node = self.nodes[index] metadata = {'id': node['pubkey'], 'text': node['uid']} self.draw_graph( - self.app.identities_registry.from_metadata(metadata) + self.app.identities_registry.from_handled_data( + metadata['text'], + metadata['id'], + BlockchainState.VALIDATED + ) ) def identity_informations(self, metadata): - identity = self.app.identities_registry.from_metadata(metadata) + identity = self.app.identities_registry.from_handled_data( + metadata['text'], + metadata['id'], + BlockchainState.VALIDATED + ) self.parent.identity_informations(identity) def sign_node(self, metadata): - identity = self.app.identities_registry.from_metadata(metadata) + identity = self.app.identities_registry.from_handled_data( + metadata['text'], + metadata['id'], + BlockchainState.VALIDATED + ) self.parent.certify_identity(identity) def send_money_to_node(self, metadata): - identity = self.app.identities_registry.from_metadata(metadata) + identity = self.app.identities_registry.from_handled_data( + metadata['text'], + metadata['id'], + BlockchainState.VALIDATED + ) self.parent.send_money_to_identity(identity) def add_node_as_contact(self, metadata): # check if contact already exists... if metadata['id'] == self.account.pubkey \ - or metadata['id'] in [contact['pubkey'] for contact in self.account.contacts]: + or metadata['id'] in [contact['pubkey'] for contact in self.account.contacts]: return False self.parent.add_identity_as_contact({'name': metadata['text'], - 'pubkey': metadata['id']}) + 'pubkey': metadata['id']}) def get_block_mediantime(self, number): try: diff --git a/src/cutecoin/main.py b/src/cutecoin/main.py index 3f17978b75be8d0e19ffc97fa8e205386abdb974..71468dd2e8c812acd81eeadd425be2f0d8e37b49 100755 --- a/src/cutecoin/main.py +++ b/src/cutecoin/main.py @@ -5,7 +5,6 @@ Created on 1 févr. 2014 """ import signal import sys -import logging import asyncio from quamash import QEventLoop @@ -20,7 +19,6 @@ if __name__ == '__main__': cutecoin = QApplication(sys.argv) loop = QEventLoop(cutecoin) asyncio.set_event_loop(loop) - print("Debug enabled : {0}".format(loop.get_debug())) with loop: app = Application.startup(sys.argv, cutecoin, loop)