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

Web of trust component

parent e753511a
No related branches found
No related tags found
No related merge requests found
Showing
with 204 additions and 71 deletions
from ...component.controller import ComponentController
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtGui import QCursor
from sakia.tools.decorators import asyncify, once_at_a_time
from .view import BaseGraphView
from .model import BaseGraphModel
from ...widgets.context_menu import ContextMenu
class BaseGraphController(ComponentController):
"""
The homescreen view
"""
def __init__(self, parent, view, model, password_asker):
"""
Constructor of the homescreen component
:param sakia.gui.homescreen.view.HomeScreenView: the view
:param sakia.gui.homescreen.model.HomeScreenModel model: the model
"""
super().__init__(parent, view, model)
self.password_asker = password_asker
def set_scene(self, scene):
"""
Set the scene and connects the signals
:param sakia.gui.views.scenes.base_scene.BaseScene scene: the scene
:return:
"""
# add scene events
scene.node_context_menu_requested.connect(self.node_context_menu)
scene.node_clicked.connect(self.handle_node_click)
@pyqtSlot(str, dict)
def handle_node_click(self, pubkey, metadata):
identity = self.model.get_identity_from_data(metadata, pubkey)
self.draw_graph(identity)
async def draw_graph(self, identity):
"""
Draw community graph centered on the identity
:param sakia.core.registry.Identity identity: Graph node identity
"""
raise NotImplementedError("draw_graph not implemented")
@once_at_a_time
@asyncify
async def reset(self, checked=False):
"""
Reset graph scene to wallet identity
"""
raise NotImplementedError("reset not implemented")
@once_at_a_time
@asyncify
def refresh(self):
"""
Refresh graph scene to current metadata
"""
raise NotImplementedError("refresh not implemented")
@asyncify
async def node_context_menu(self, pubkey):
"""
Open the node context menu
:param str pubkey: the pubkey of the node to open
"""
identity = await self.model.get_identity(pubkey)
menu = ContextMenu.from_data(self.view, self.model.app, self.model.account, self.model.community, self.password_asker,
(identity,))
menu.view_identity_in_wot.connect(self.draw_graph)
# Show the context menu.
menu.qmenu.popup(QCursor.pos())
...@@ -30,15 +30,6 @@ class GraphTabWidget(QObject): ...@@ -30,15 +30,6 @@ class GraphTabWidget(QObject):
self.app = app self.app = app
def set_scene(self, scene):
"""
Set the scene and connects the signals
:param sakia.gui.views.scenes.base_scene.BaseScene scene: the scene
:return:
"""
# add scene events
scene.node_context_menu_requested.connect(self.node_context_menu)
scene.node_clicked.connect(self.handle_node_click)
@once_at_a_time @once_at_a_time
@asyncify @asyncify
...@@ -120,63 +111,4 @@ class GraphTabWidget(QObject): ...@@ -120,63 +111,4 @@ class GraphTabWidget(QObject):
) )
) )
@pyqtSlot(str, dict)
def handle_node_click(self, pubkey, metadata):
self.draw_graph(
self.app.identities_registry.from_handled_data(
metadata['text'],
pubkey,
None,
BlockchainState.VALIDATED,
self.community
)
)
@once_at_a_time
@asyncify
async def draw_graph(self, identity):
"""
Draw community graph centered on the identity
:param sakia.core.registry.Identity identity: Graph node identity
"""
pass
@once_at_a_time
@asyncify
async def reset(self, checked=False):
"""
Reset graph scene to wallet identity
"""
pass
def refresh(self):
"""
Refresh graph scene to current metadata
"""
pass
@asyncify
async def node_context_menu(self, pubkey):
"""
Open the node context menu
:param str pubkey: the pubkey of the node to open
"""
identity = await self.app.identities_registry.future_find(pubkey, self.community)
menu = ContextMenu.from_data(self.widget, self.app, self.account, self.community, self.password_asker,
(identity,))
menu.view_identity_in_wot.connect(self.draw_graph)
# Show the context menu.
menu.qmenu.popup(QCursor.pos())
def changeEvent(self, event):
"""
Intercepte LanguageChange event to translate UI
:param QEvent QEvent: Event
:return:
"""
if event.type() == QEvent.LanguageChange:
self.retranslateUi(self)
self.refresh()
return super().changeEvent(event)
from sakia.gui.component.model import ComponentModel
from sakia.core.registry import BlockchainState
class BaseGraphModel(ComponentModel):
"""
The model of Navigation component
"""
def __init__(self, parent, app, account, community):
super().__init__(parent)
self.app = app
self.account = account
self.community = community
async def get_identity(self, pubkey):
"""
Get identity from pubkey
:param str pubkey: Identity pubkey
:rtype: sakia.core.registry.Identity
"""
return await self.app.identities_registry.future_find(pubkey, self.community)
def get_identity_from_data(self, metadata, pubkey):
return self.app.identities_registry.from_handled_data(
metadata['text'],
pubkey,
None,
BlockchainState.VALIDATED,
self.community
)
from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import QEvent
class BaseGraphView(QWidget):
"""
Base graph view
"""
def __init__(self, parent):
"""
Constructor
"""
super().__init__(parent)
def changeEvent(self, event):
"""
Intercepte LanguageChange event to translate UI
:param QEvent QEvent: Event
:return:
"""
if event.type() == QEvent.LanguageChange:
self.retranslateUi(self)
self.refresh()
return super().changeEvent(event)
\ No newline at end of file
from ..base.controller import BaseGraphController
from sakia.tools.decorators import asyncify, once_at_a_time
from .view import WotView
from .model import WotModel
class WotController(BaseGraphController):
"""
The homescreen view
"""
def __init__(self, parent, view, model, password_asker=None):
"""
Constructor of the homescreen component
:param sakia.gui.homescreen.view.HomeScreenView: the view
:param sakia.gui.homescreen.model.HomeScreenModel model: the model
"""
super().__init__(parent, view, model, password_asker)
self.set_scene(view.scene())
self.reset()
@classmethod
def create(cls, parent, app, **kwargs):
account = kwargs['account']
community = kwargs['community']
view = WotView(parent.view)
model = WotModel(None, app, account, community)
wot = cls(parent, view, model)
model.setParent(wot)
return wot
@property
def view(self) -> WotView:
return self._view
@property
def model(self) -> WotModel:
return self._model
async def draw_graph(self, identity):
"""
Draw community graph centered on the identity
:param sakia.core.registry.Identity identity: Center identity
"""
await self.model.set_identity(identity)
self.refresh()
@once_at_a_time
@asyncify
async def refresh(self):
"""
Refresh graph scene to current metadata
"""
nx_graph = await self.model.get_nx_graph()
self.view.display_wot(nx_graph, self.model.identity)
path = await self.model.get_shortest_path()
if path:
self.view.display_path(nx_graph, path)
@once_at_a_time
@asyncify
async def reset(self, checked=False):
"""
Reset graph scene to wallet identity
"""
await self.draw_graph(None)
...@@ -2,7 +2,7 @@ from PyQt5.QtCore import Qt, QRectF, QLineF, QPointF, QSizeF, \ ...@@ -2,7 +2,7 @@ from PyQt5.QtCore import Qt, QRectF, QLineF, QPointF, QSizeF, \
qFuzzyCompare qFuzzyCompare
from PyQt5.QtGui import QColor, QPen, QPolygonF from PyQt5.QtGui import QColor, QPen, QPolygonF
import math import math
from .base_edge import BaseEdge from ..base.edge import BaseEdge
from ....core.graph.constants import EdgeStatus from ....core.graph.constants import EdgeStatus
......
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPainter, QWheelEvent from PyQt5.QtGui import QPainter, QWheelEvent
from PyQt5.QtWidgets import QGraphicsView from PyQt5.QtWidgets import QGraphicsView
from .scenes import WotScene from .scene import WotScene
class WotView(QGraphicsView): class WotGraphicsView(QGraphicsView):
def __init__(self, parent=None): def __init__(self, parent=None):
""" """
Create View to display scene Create View to display scene
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment