diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index aa2f4205482e22a79c4da5591e8c5bebe21ab71e..094da3a1476c82b5a5e6398fd5a04f43bf94b204 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -259,3 +259,6 @@ class Account(object): 'wallets': data_wallets, 'contacts': data_contacts} return data + + def get_person(self): + return Person(self.name, self.pubkey) diff --git a/src/cutecoin/core/graph.py b/src/cutecoin/core/graph.py index ef2e9db39b72a6355f559220c63daa808c2f7bad..b4f1aa8e743399f9fc054b03212199992a9727b6 100644 --- a/src/cutecoin/core/graph.py +++ b/src/cutecoin/core/graph.py @@ -18,6 +18,13 @@ class Graph(dict): path = list() graph_tmp = copy.deepcopy(self) + if from_person.pubkey not in graph_tmp.keys(): + graph_tmp.add_person(from_person) + certifier_list = from_person.certifiers_of(self.community) + graph_tmp.add_certifier_list(certifier_list, from_person, to_person) + certified_list = from_person.certified_by(self.community) + graph_tmp.add_certified_list(certified_list, from_person, to_person) + if to_person.pubkey not in graph_tmp.keys(): # recursively feed graph searching for account node... graph_tmp.explore_to_find_member(to_person, graph_tmp[from_person.pubkey]['nodes'], list()) diff --git a/src/cutecoin/gui/member.py b/src/cutecoin/gui/member.py index fbb38d31462b70f006b5390633c0a29794a6f611..d961db04146f74fa9a3e22fe1ff2d6520cf36139 100644 --- a/src/cutecoin/gui/member.py +++ b/src/cutecoin/gui/member.py @@ -1,6 +1,4 @@ -import logging -import datetime -import math +from cutecoin.core.graph import Graph from PyQt5.QtWidgets import QDialog from ..gen_resources.member_uic import Ui_DialogMember @@ -25,18 +23,41 @@ class MemberDialog(QDialog, Ui_DialogMember): if join_date is None: join_date = 'not a member' - # set infos in label - self.label_properties.setText( - """ + # calculate path to account member + graph = Graph(self.community) + path = None + # if selected member is not the account member... + if person.pubkey != self.account.pubkey: + # add path from selected member to account member + path = graph.get_shortest_path_between_members(person, self.account.get_person()) + + text = """ <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> - </table> """.format( 'Public key', self.person.pubkey, 'Join date', join_date ) - ) + + if path: + distance = len(path) - 1 + text += """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format('Distance', distance) + if distance > 1: + index = 0 + for node in path: + if index == 0: + text += """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format('Path', node['text']) + else: + text += """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format('', node['text']) + if index == distance and node['id'] != self.account.pubkey: + text += """<tr><td align="right"><b>{:}</b></div></td><td>{:}</td></tr>""".format('', self.account.name) + index += 1 + # close html text + text += "</table>" + + # set text in label + self.label_properties.setText(text)