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

Add context menu to identities tab

parent 5b493be6
Branches
Tags
No related merge requests found
...@@ -63,8 +63,19 @@ ...@@ -63,8 +63,19 @@
</attribute> </attribute>
</widget> </widget>
</item> </item>
<item>
<widget class="Busy" name="busy" native="true"/>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>Busy</class>
<extends>QWidget</extends>
<header>sakia.gui.widgets.busy</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>
...@@ -85,7 +85,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget): ...@@ -85,7 +85,7 @@ class CommunityWidget(QWidget, Ui_CommunityWidget):
QIcon(':/icons/wot_icon'), QIcon(':/icons/wot_icon'),
self.tr(CommunityWidget._tab_wot_label)) self.tr(CommunityWidget._tab_wot_label))
self.tabs.addTab(self.tab_identities, self.tabs.addTab(self.tab_identities.widget,
QIcon(':/icons/members_icon'), QIcon(':/icons/members_icon'),
self.tr(CommunityWidget._tab_identities_label)) self.tr(CommunityWidget._tab_identities_label))
...@@ -414,7 +414,7 @@ The process to join back the community later will have to be done again.""") ...@@ -414,7 +414,7 @@ The process to join back the community later will have to be done again.""")
self.tabs.setTabText(self.tabs.indexOf(self.tab_network), self.tr(CommunityWidget._tab_network_label)) self.tabs.setTabText(self.tabs.indexOf(self.tab_network), self.tr(CommunityWidget._tab_network_label))
self.tabs.setTabText(self.tabs.indexOf(self.tab_informations), self.tr(CommunityWidget._tab_informations_label)) self.tabs.setTabText(self.tabs.indexOf(self.tab_informations), self.tr(CommunityWidget._tab_informations_label))
self.tabs.setTabText(self.tabs.indexOf(self.tab_history.widget), self.tr(CommunityWidget._tab_history_label)) self.tabs.setTabText(self.tabs.indexOf(self.tab_history.widget), self.tr(CommunityWidget._tab_history_label))
self.tabs.setTabText(self.tabs.indexOf(self.tab_identities), self.tr(CommunityWidget._tab_identities_label)) self.tabs.setTabText(self.tabs.indexOf(self.tab_identities.widget), self.tr(CommunityWidget._tab_identities_label))
self.action_publish_uid.setText(self.tr(CommunityWidget._action_publish_uid_text)) self.action_publish_uid.setText(self.tr(CommunityWidget._action_publish_uid_text))
self.action_revoke_uid.setText(self.tr(CommunityWidget._action_revoke_uid_text)) self.action_revoke_uid.setText(self.tr(CommunityWidget._action_revoke_uid_text))
self.action_showinfo.setText(self.tr(CommunityWidget._action_showinfo_text)) self.action_showinfo.setText(self.tr(CommunityWidget._action_showinfo_text))
......
...@@ -4,10 +4,9 @@ Created on 2 févr. 2014 ...@@ -4,10 +4,9 @@ Created on 2 févr. 2014
@author: inso @author: inso
""" """
import asyncio
import logging import logging
from PyQt5.QtCore import Qt, pyqtSignal, QEvent, QT_TRANSLATE_NOOP from PyQt5.QtCore import Qt, pyqtSignal, QEvent, QT_TRANSLATE_NOOP, QObject
from PyQt5.QtGui import QCursor from PyQt5.QtGui import QCursor
from PyQt5.QtWidgets import QWidget, QAction, QMenu, QDialog, \ from PyQt5.QtWidgets import QWidget, QAction, QMenu, QDialog, \
QAbstractItemView QAbstractItemView
...@@ -15,17 +14,14 @@ from ucoinpy.api import bma ...@@ -15,17 +14,14 @@ from ucoinpy.api import bma
from ..models.identities import IdentitiesFilterProxyModel, IdentitiesTableModel from ..models.identities import IdentitiesFilterProxyModel, IdentitiesTableModel
from ..gen_resources.identities_tab_uic import Ui_IdentitiesTab from ..gen_resources.identities_tab_uic import Ui_IdentitiesTab
from .contact import ConfigureContactDialog
from .member import MemberDialog
from .transfer import TransferMoneyDialog
from sakia.gui.widgets.busy import Busy from sakia.gui.widgets.busy import Busy
from .certification import CertificationDialog
from ..core.registry import Identity, BlockchainState from ..core.registry import Identity, BlockchainState
from ..tools.exceptions import NoPeerAvailable from ..tools.exceptions import NoPeerAvailable
from ..tools.decorators import asyncify, once_at_a_time, cancel_once_task from ..tools.decorators import asyncify, once_at_a_time, cancel_once_task
from .widgets import ContextMenu
class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): class IdentitiesTabWidget(QObject):
""" """
classdocs classdocs
...@@ -36,41 +32,45 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): ...@@ -36,41 +32,45 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):
_direct_connections_text = QT_TRANSLATE_NOOP("IdentitiesTabWidget", "Search direct certifications") _direct_connections_text = QT_TRANSLATE_NOOP("IdentitiesTabWidget", "Search direct certifications")
_search_placeholder = QT_TRANSLATE_NOOP("IdentitiesTabWidget", "Research a pubkey, an uid...") _search_placeholder = QT_TRANSLATE_NOOP("IdentitiesTabWidget", "Research a pubkey, an uid...")
def __init__(self, app): def __init__(self, app, account=None, community=None, password_asker=None,
widget=QWidget, view=Ui_IdentitiesTab):
""" """
Init Init
:param sakia.core.account.Account account: Account instance
:param sakia.core.community.Community community: Community instance :param sakia.core.app.Application app: Application instance
:param sakia.gui.password_asker.PasswordAskerDialog password_asker: Password asker dialog :param sakia.core.Account account: The account displayed in the widget
:return: :param sakia.core.Community community: The community displayed in the widget
:param sakia.gui.Password_Asker: password_asker: The widget to ask for passwords
:param class widget: The class of the PyQt5 widget used for this tab
:param class view: The class of the UI View for this tab
""" """
super().__init__() super().__init__()
self.widget = widget()
self.ui = view()
self.ui.setupUi(self.widget)
self.app = app self.app = app
self.community = None self.community = community
self.account = None self.account = account
self.password_asker = None self.password_asker = password_asker
self.direct_connections = QAction(self.tr(IdentitiesTabWidget._direct_connections_text), self) self.direct_connections = QAction(self.tr(IdentitiesTabWidget._direct_connections_text), self)
self.setupUi(self) self.ui.edit_textsearch.setPlaceholderText(self.tr(IdentitiesTabWidget._search_placeholder))
self.edit_textsearch.setPlaceholderText(self.tr(IdentitiesTabWidget._search_placeholder))
identities_model = IdentitiesTableModel() identities_model = IdentitiesTableModel()
proxy = IdentitiesFilterProxyModel() proxy = IdentitiesFilterProxyModel()
proxy.setSourceModel(identities_model) proxy.setSourceModel(identities_model)
self.table_identities.setModel(proxy) self.ui.table_identities.setModel(proxy)
self.table_identities.setSelectionBehavior(QAbstractItemView.SelectRows) self.ui.table_identities.setSelectionBehavior(QAbstractItemView.SelectRows)
self.table_identities.customContextMenuRequested.connect(self.identity_context_menu) self.ui.table_identities.customContextMenuRequested.connect(self.identity_context_menu)
self.table_identities.sortByColumn(0, Qt.AscendingOrder) self.ui.table_identities.sortByColumn(0, Qt.AscendingOrder)
self.table_identities.resizeColumnsToContents() self.ui.table_identities.resizeColumnsToContents()
identities_model.modelAboutToBeReset.connect(lambda: self.table_identities.setEnabled(False)) identities_model.modelAboutToBeReset.connect(lambda: self.ui.table_identities.setEnabled(False))
identities_model.modelReset.connect(lambda: self.table_identities.setEnabled(True)) identities_model.modelReset.connect(lambda: self.ui.table_identities.setEnabled(True))
self.direct_connections.triggered.connect(self._async_search_direct_connections) self.direct_connections.triggered.connect(self._async_search_direct_connections)
self.button_search.addAction(self.direct_connections) self.ui.button_search.addAction(self.direct_connections)
self.button_search.clicked.connect(self._async_execute_search_text) self.ui.button_search.clicked.connect(self._async_execute_search_text)
self.busy = Busy(self.table_identities)
self.busy.hide()
def cancel_once_tasks(self): def cancel_once_tasks(self):
cancel_once_task(self, self.identity_context_menu) cancel_once_task(self, self.identity_context_menu)
...@@ -88,14 +88,14 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): ...@@ -88,14 +88,14 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):
def change_community(self, community): def change_community(self, community):
self.cancel_once_tasks() self.cancel_once_tasks()
self.community = community self.community = community
self.table_identities.model().change_community(community) self.ui.table_identities.model().change_community(community)
self._async_search_direct_connections() self._async_search_direct_connections()
@once_at_a_time @once_at_a_time
@asyncify @asyncify
async def identity_context_menu(self, point): async def identity_context_menu(self, point):
index = self.table_identities.indexAt(point) index = self.ui.table_identities.indexAt(point)
model = self.table_identities.model() model = self.ui.table_identities.model()
if index.isValid() and index.row() < model.rowCount(): if index.isValid() and index.row() < model.rowCount():
source_index = model.mapToSource(index) source_index = model.mapToSource(index)
pubkey_col = model.sourceModel().columns_ids.index('pubkey') pubkey_col = model.sourceModel().columns_ids.index('pubkey')
...@@ -103,102 +103,19 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): ...@@ -103,102 +103,19 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):
pubkey_col) pubkey_col)
pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole) pubkey = model.sourceModel().data(pubkey_index, Qt.DisplayRole)
identity = await self.app.identities_registry.future_find(pubkey, self.community) identity = await self.app.identities_registry.future_find(pubkey, self.community)
menu = QMenu(self) menu = ContextMenu.from_data(self.widget, self.app, self.account, self.community, self.password_asker,
(identity,))
informations = QAction(self.tr("Informations"), self)
informations.triggered.connect(self.menu_informations)
informations.setData(identity)
add_contact = QAction(self.tr("Add as contact"), self)
add_contact.triggered.connect(self.menu_add_as_contact)
add_contact.setData(identity)
send_money = QAction(self.tr("Send money"), self)
send_money.triggered.connect(self.menu_send_money)
send_money.setData(identity)
certify = QAction(self.tr("Certify identity"), self)
certify.triggered.connect(self.menu_certify_member)
certify.setData(identity)
view_wot = QAction(self.tr("View in Web of Trust"), self)
view_wot.triggered.connect(self.view_wot)
view_wot.setData(identity)
copy_pubkey = QAction(self.tr("Copy pubkey"), self)
copy_pubkey.triggered.connect(self.copy_identity_pubkey)
copy_pubkey.setData(identity)
menu.addAction(informations)
menu.addAction(add_contact)
menu.addAction(send_money)
menu.addAction(certify)
menu.addAction(view_wot)
menu.addAction(copy_pubkey)
# Show the context menu. # Show the context menu.
menu.popup(QCursor.pos()) menu.qmenu.popup(QCursor.pos())
def menu_informations(self):
person = self.sender().data()
self.identity_informations(person)
def menu_add_as_contact(self):
person = self.sender().data()
self.add_identity_as_contact({'name': person.uid,
'pubkey': person.pubkey})
def menu_send_money(self):
person = self.sender().data()
self.send_money_to_identity(person)
def menu_certify_member(self):
person = self.sender().data()
self.certify_identity(person)
def identity_informations(self, person):
dialog = MemberDialog(self.app, self.account, self.community, person)
dialog.exec_()
def add_identity_as_contact(self, person):
dialog = ConfigureContactDialog(self.account, self.window(), person)
result = dialog.exec_()
if result == QDialog.Accepted:
self.window().refresh_contacts()
@asyncify
async def send_money_to_identity(self, identity):
result = await TransferMoneyDialog.send_money_to_identity(self.app, self.account, self.password_asker,
self.community, identity)
if result == QDialog.Accepted:
self.money_sent.emit()
@asyncify
async def certify_identity(self, identity):
await CertificationDialog.certify_identity(self.app, self.account, self.password_asker,
self.community, identity)
def copy_identity_pubkey(self):
"""
Copy the identity pubkey to the clipboard
:param sakia.core.registry.Identity identity: The identity
"""
identity = self.sender().data()
cb = self.app.qapp.clipboard()
cb.clear(mode=cb.Clipboard)
cb.setText(identity.pubkey, mode=cb.Clipboard)
def view_wot(self):
identity = self.sender().data()
self.view_in_wot.emit(identity)
@once_at_a_time @once_at_a_time
@asyncify @asyncify
async def _async_execute_search_text(self, checked): async def _async_execute_search_text(self, checked):
cancel_once_task(self, self._async_search_direct_connections) cancel_once_task(self, self._async_search_direct_connections)
self.busy.show() self.ui.busy.show()
text = self.edit_textsearch.text() text = self.ui.edit_textsearch.text()
if len(text) < 2: if len(text) < 2:
return return
try: try:
...@@ -212,13 +129,13 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): ...@@ -212,13 +129,13 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):
BlockchainState.BUFFERED) BlockchainState.BUFFERED)
identities.append(identity) identities.append(identity)
self.edit_textsearch.clear() self.ui.edit_textsearch.clear()
self.edit_textsearch.setPlaceholderText(text) self.ui.edit_textsearch.setPlaceholderText(text)
await self.refresh_identities(identities) await self.refresh_identities(identities)
except ValueError as e: except ValueError as e:
logging.debug(str(e)) logging.debug(str(e))
finally: finally:
self.busy.hide() self.ui.busy.hide()
@once_at_a_time @once_at_a_time
@asyncify @asyncify
...@@ -230,9 +147,9 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): ...@@ -230,9 +147,9 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):
if self.account and self.community: if self.account and self.community:
try: try:
self.edit_textsearch.setPlaceholderText(self.tr(IdentitiesTabWidget._search_placeholder)) self.ui.edit_textsearch.setPlaceholderText(self.tr(IdentitiesTabWidget._search_placeholder))
await self.refresh_identities([]) await self.refresh_identities([])
self.busy.show() self.ui.busy.show()
self_identity = await self.account.identity(self.community) self_identity = await self.account.identity(self.community)
account_connections = [] account_connections = []
certs_of = await self_identity.unique_valid_certifiers_of(self.app.identities_registry, self.community) certs_of = await self_identity.unique_valid_certifiers_of(self.app.identities_registry, self.community)
...@@ -245,25 +162,25 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab): ...@@ -245,25 +162,25 @@ class IdentitiesTabWidget(QWidget, Ui_IdentitiesTab):
certified_by = [p for p in account_connections certified_by = [p for p in account_connections
if p.pubkey not in [i.pubkey for i in certifiers_of]] if p.pubkey not in [i.pubkey for i in certifiers_of]]
identities = certifiers_of + certified_by identities = certifiers_of + certified_by
self.busy.hide() self.ui.busy.hide()
await self.refresh_identities(identities) await self.refresh_identities(identities)
except NoPeerAvailable: except NoPeerAvailable:
self.busy.hide() self.ui.busy.hide()
async def refresh_identities(self, identities): async def refresh_identities(self, identities):
""" """
Refresh the table with specified identities. Refresh the table with specified identities.
If no identities is passed, use the account connections. If no identities is passed, use the account connections.
""" """
await self.table_identities.model().sourceModel().refresh_identities(identities) await self.ui.table_identities.model().sourceModel().refresh_identities(identities)
self.table_identities.resizeColumnsToContents() self.ui.table_identities.resizeColumnsToContents()
def retranslateUi(self, widget): def retranslateUi(self, widget):
self.direct_connections.setText(self.tr(IdentitiesTabWidget._direct_connections_text)) self.direct_connections.setText(self.tr(IdentitiesTabWidget._direct_connections_text))
super().retranslateUi(self) super().retranslateUi(self)
def resizeEvent(self, event): def resizeEvent(self, event):
self.busy.resize(event.size()) self.ui.busy.resize(event.size())
super().resizeEvent(event) super().resizeEvent(event)
def changeEvent(self, event): def changeEvent(self, event):
......
...@@ -184,7 +184,7 @@ class TransactionsTabWidget(QObject): ...@@ -184,7 +184,7 @@ class TransactionsTabWidget(QObject):
(identity, transfer)) (identity, transfer))
# Show the context menu. # Show the context menu.
menu.popup(QCursor.pos()) menu.qmenu.popup(QCursor.pos())
def dates_changed(self): def dates_changed(self):
logging.debug("Changed dates") logging.debug("Changed dates")
......
from PyQt5.QtWidgets import QMenu, QAction, QApplication, QMessageBox from PyQt5.QtWidgets import QMenu, QAction, QApplication, QMessageBox
from PyQt5.QtCore import QObject, pyqtSignal
from ucoinpy.documents import Block from ucoinpy.documents import Block
from ..member import MemberDialog from ..member import MemberDialog
from ..contact import ConfigureContactDialog from ..contact import ConfigureContactDialog
...@@ -9,16 +10,19 @@ from ...core.transfer import Transfer, TransferState ...@@ -9,16 +10,19 @@ from ...core.transfer import Transfer, TransferState
from ...core.registry import Identity from ...core.registry import Identity
class ContextMenu(QMenu): class ContextMenu(QObject):
def __init__(self, parent, app, account, community, password_asker): view_identity_in_wot = pyqtSignal(object)
def __init__(self, qmenu, app, account, community, password_asker):
""" """
:param PyQt5.QtWidgets.QWidget: the parent widget :param PyQt5.QtWidgets.QMenu: the qmenu widget
:param sakia.core.Application app: Application instance :param sakia.core.Application app: Application instance
:param sakia.core.Account account: The current account instance :param sakia.core.Account account: The current account instance
:param sakia.core.Community community: The community instance :param sakia.core.Community community: The community instance
:param sakia.gui.PasswordAsker password_asker: The password dialog :param sakia.gui.PasswordAsker password_asker: The password dialog
""" """
super().__init__(parent) super().__init__()
self.qmenu = qmenu
self._app = app self._app = app
self._community = community self._community = community
self._account = account self._account = account
...@@ -30,27 +34,31 @@ class ContextMenu(QMenu): ...@@ -30,27 +34,31 @@ class ContextMenu(QMenu):
:param ContextMenu menu: the qmenu to add actions to :param ContextMenu menu: the qmenu to add actions to
:param Identity identity: the identity :param Identity identity: the identity
""" """
menu.addSeparator().setText(menu.tr("Identity")) menu.qmenu.addSeparator().setText(menu.qmenu.tr("Identity"))
informations = QAction(menu.tr("Informations"), menu.parent()) informations = QAction(menu.qmenu.tr("Informations"), menu.qmenu.parent())
informations.triggered.connect(lambda checked, i=identity: menu.informations(i)) informations.triggered.connect(lambda checked, i=identity: menu.informations(i))
menu.addAction(informations) menu.qmenu.addAction(informations)
add_as_contact = QAction(menu.tr("Add as contact"), menu.parent()) add_as_contact = QAction(menu.qmenu.tr("Add as contact"), menu.qmenu.parent())
add_as_contact.triggered.connect(lambda checked,i=identity: menu.add_as_contact(i)) add_as_contact.triggered.connect(lambda checked,i=identity: menu.add_as_contact(i))
menu.addAction(add_as_contact) menu.qmenu.addAction(add_as_contact)
send_money = QAction(menu.tr("Send money"), menu.parent()) send_money = QAction(menu.qmenu.tr("Send money"), menu.qmenu.parent())
send_money.triggered.connect(lambda checked, i=identity: menu.send_money(i)) send_money.triggered.connect(lambda checked, i=identity: menu.send_money(i))
menu.addAction(send_money) menu.qmenu.addAction(send_money)
certify = QAction(menu.tr("Certify identity"), menu.qmenu.parent())
certify.triggered.connect(lambda checked, i=identity: menu.certify_identity(i))
menu.qmenu.addAction(certify)
view_wot = QAction(menu.tr("View in Web of Trust"), menu.parent()) view_wot = QAction(menu.qmenu.tr("View in Web of Trust"), menu.qmenu.parent())
view_wot.triggered.connect(lambda checked, i=identity: menu.view_wot(i)) view_wot.triggered.connect(lambda checked, i=identity: menu.view_wot(i))
menu.addAction(view_wot) menu.qmenu.addAction(view_wot)
copy_pubkey = QAction(menu.tr("Copy pubkey to clipboard"), menu.parent()) copy_pubkey = QAction(menu.qmenu.tr("Copy pubkey to clipboard"), menu.qmenu.parent())
copy_pubkey.triggered.connect(lambda checked, i=identity: ContextMenu.copy_pubkey_to_clipboard(i)) copy_pubkey.triggered.connect(lambda checked, i=identity: ContextMenu.copy_pubkey_to_clipboard(i))
menu.addAction(copy_pubkey) menu.qmenu.addAction(copy_pubkey)
@staticmethod @staticmethod
def _add_transfers_actions(menu, transfer): def _add_transfers_actions(menu, transfer):
...@@ -58,25 +66,25 @@ class ContextMenu(QMenu): ...@@ -58,25 +66,25 @@ class ContextMenu(QMenu):
:param ContextMenu menu: the qmenu to add actions to :param ContextMenu menu: the qmenu to add actions to
:param Transfer transfer: the transfer :param Transfer transfer: the transfer
""" """
menu.addSeparator().setText(menu.tr("Transfer")) menu.qmenu.addSeparator().setText(menu.qmenu.tr("Transfer"))
if transfer.state in (TransferState.REFUSED, TransferState.TO_SEND): if transfer.state in (TransferState.REFUSED, TransferState.TO_SEND):
send_back = QAction(menu.tr("Send again"), menu.parent()) send_back = QAction(menu.qmenu.tr("Send again"), menu.qmenu.parent())
send_back.triggered.connect(lambda checked, tr=transfer: menu.send_again(tr)) send_back.triggered.connect(lambda checked, tr=transfer: menu.send_again(tr))
menu.addAction(send_back) menu.qmenu.addAction(send_back)
cancel = QAction(menu.tr("Cancel"), menu.parent()) cancel = QAction(menu.qmenu.tr("Cancel"), menu.qmenu.parent())
cancel.triggered.connect(lambda checked, tr=transfer: menu.cancel_transfer(tr)) cancel.triggered.connect(lambda checked, tr=transfer: menu.cancel_transfer(tr))
menu.addAction(cancel) menu.qmenu.addAction(cancel)
if menu._app.preferences['expert_mode']: if menu._app.preferences['expert_mode']:
copy_doc = QAction(menu.tr("Copy raw transaction to clipboard"), menu.parent()) copy_doc = QAction(menu.qmenu.tr("Copy raw transaction to clipboard"), menu.qmenu.parent())
copy_doc.triggered.connect(lambda checked, tx=transfer: menu.copy_transaction_to_clipboard(tx)) copy_doc.triggered.connect(lambda checked, tx=transfer: menu.copy_transaction_to_clipboard(tx))
menu.addAction(copy_doc) menu.qmenu.addAction(copy_doc)
copy_doc = QAction(menu.tr("Copy transaction block to clipboard"), menu.parent()) copy_doc = QAction(menu.qmenu.tr("Copy transaction block to clipboard"), menu.qmenu.parent())
copy_doc.triggered.connect(lambda checked, number=transfer.blockid.number: copy_doc.triggered.connect(lambda checked, number=transfer.blockid.number:
menu.copy_block_to_clipboard(number)) menu.copy_block_to_clipboard(number))
menu.addAction(copy_doc) menu.qmenu.addAction(copy_doc)
@classmethod @classmethod
...@@ -94,7 +102,7 @@ class ContextMenu(QMenu): ...@@ -94,7 +102,7 @@ class ContextMenu(QMenu):
:param tuple data: a tuple of data to add to the menu :param tuple data: a tuple of data to add to the menu
:rtype: ContextMenu :rtype: ContextMenu
""" """
menu = cls(parent, app, account, community, password_asker) menu = cls(QMenu(parent), app, account, community, password_asker)
build_actions = { build_actions = {
Identity: ContextMenu._add_identity_actions, Identity: ContextMenu._add_identity_actions,
Transfer: ContextMenu._add_transfers_actions, Transfer: ContextMenu._add_transfers_actions,
...@@ -129,7 +137,7 @@ class ContextMenu(QMenu): ...@@ -129,7 +137,7 @@ class ContextMenu(QMenu):
#self.ui.table_history.model().sourceModel().refresh_transfers() #self.ui.table_history.model().sourceModel().refresh_transfers()
def view_wot(self, identity): def view_wot(self, identity):
self._app.view_identity_in_wot.emit(identity) self.view_identity_in_wot.emit(identity)
@asyncify @asyncify
async def certify_identity(self, identity): async def certify_identity(self, identity):
......
...@@ -5,24 +5,28 @@ from asynctest.mock import MagicMock as AsyncMagicMock ...@@ -5,24 +5,28 @@ from asynctest.mock import MagicMock as AsyncMagicMock
from PyQt5.QtCore import QLocale, pyqtSignal from PyQt5.QtCore import QLocale, pyqtSignal
from sakia.tests import QuamashTest from sakia.tests import QuamashTest
from sakia.tests.mocks.bma import nice_blockchain from sakia.tests.mocks.bma import nice_blockchain
from sakia.gui.transactions_tab import TransactionsTabWidget, Ui_transactionsTabWidget, QWidget from sakia.gui.widgets import ContextMenu
class TestTransactionTab(unittest.TestCase, QuamashTest): class TestContextMenu(unittest.TestCase, QuamashTest):
def setUp(self): def setUp(self):
self.setUpQuamash() self.setUpQuamash()
QLocale.setDefault(QLocale("en_GB")) QLocale.setDefault(QLocale("en_GB"))
self.identity = Mock(specs='core.registry.Identity') self.identity = Mock(specs='sakia.core.registry.Identity')
self.identity.pubkey = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk" self.identity.pubkey = "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk"
self.identity.uid = "A" self.identity.uid = "A"
self.app = MagicMock(specs='sakia.core.Application')
self.account = MagicMock(specs='sakia.core.Account')
self.community = MagicMock(specs='sakia.core.Community')
self.password_asker = MagicMock(specs='sakia.gui.password_asker.PasswordAsker')
def tearDown(self): def tearDown(self):
self.tearDownQuamash() self.tearDownQuamash()
@patch('sakia.gen_resources.transactions_tab_uic.Ui_transactionsTabWidget', create=True) @patch('PyQt5.QtWidgets.QMenu', create=True)
@patch('PyQt5.QtWidgets.QWidget', create=True) def test_view_in_wot(self, qmenu):
def test_view_in_wot(self, widget, view):
wot_refreshed = False wot_refreshed = False
def refresh_wot(identity): def refresh_wot(identity):
...@@ -30,37 +34,32 @@ class TestTransactionTab(unittest.TestCase, QuamashTest): ...@@ -30,37 +34,32 @@ class TestTransactionTab(unittest.TestCase, QuamashTest):
self.assertEqual(identity, self.identity) self.assertEqual(identity, self.identity)
wot_refreshed = True wot_refreshed = True
app = Mock('sakia.core.Application')
async def exec_test(): async def exec_test():
transaction_tab = TransactionsTabWidget(app, widget, view) context_menu = ContextMenu(qmenu, self.app, self.account, self.community, self.password_asker)
transaction_tab.view_in_wot.connect(refresh_wot) context_menu.view_identity_in_wot.connect(refresh_wot)
transaction_tab.view_wot(self.identity) context_menu.view_wot(self.identity)
self.lp.run_until_complete(exec_test()) self.lp.run_until_complete(exec_test())
self.assertTrue(wot_refreshed) self.assertTrue(wot_refreshed)
@patch('sakia.gen_resources.transactions_tab_uic.Ui_transactionsTabWidget', create=True) @patch('PyQt5.QtWidgets.QMenu', create=True)
@patch('PyQt5.QtWidgets.QWidget', create=True) def test_copy_pubkey_to_clipboard(self, qmenu):
def copy_pubkey_to_clipboard(self, widget, view):
app = Mock('sakia.core.Application') app = Mock('sakia.core.Application')
async def exec_test(): async def exec_test():
transaction_tab = TransactionsTabWidget(app, widget, view) context_menu = ContextMenu(qmenu, self.app, self.account, self.community, self.password_asker)
transaction_tab.copy_pubkey_to_clipboard(self.identity) context_menu.copy_pubkey_to_clipboard(self.identity)
self.lp.run_until_complete(exec_test()) self.lp.run_until_complete(exec_test())
self.assertEqual(self.qapplication.clipboard().text(), "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk") self.assertEqual(self.qapplication.clipboard().text(), "HnFcSms8jzwngtVomTTnzudZx7SHUQY8sVE1y8yBmULk")
@patch('sakia.gen_resources.transactions_tab_uic.Ui_transactionsTabWidget', create=True) @patch('PyQt5.QtWidgets.QMenu', create=True)
@patch('PyQt5.QtWidgets.QWidget', create=True) def test_copy_block_to_clipboard(self, qmenu):
def test_copy_block_to_clipboard(self, widget, view): self.community.get_block = CoroutineMock(side_effect=lambda n: nice_blockchain.bma_blockchain_current if n == 15 \
app = AsyncMagicMock('sakia.core.Application')
community = Mock('sakia.core.Community')
community.get_block = CoroutineMock(side_effect=lambda n: nice_blockchain.bma_blockchain_current if n == 15 \
else nice_blockchain.bma_blockchain_0) else nice_blockchain.bma_blockchain_0)
self.qapplication.clipboard().clear() self.qapplication.clipboard().clear()
async def exec_test(): async def exec_test():
transaction_tab = TransactionsTabWidget(app, widget, view) context_menu = ContextMenu(qmenu, self.app, self.account, self.community, self.password_asker)
transaction_tab.community = community context_menu.community = self.community
transaction_tab.copy_block_to_clipboard(15) context_menu.copy_block_to_clipboard(15)
self.lp.run_until_complete(exec_test()) self.lp.run_until_complete(exec_test())
raw_block = "{0}{1}\n".format(nice_blockchain.bma_blockchain_current["raw"], raw_block = "{0}{1}\n".format(nice_blockchain.bma_blockchain_current["raw"],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment