From 80608ccad76c9973785381a84a34ce2bbfabeffa Mon Sep 17 00:00:00 2001 From: Vincent Texier <vit@free.fr> Date: Sat, 21 Feb 2015 10:28:51 +0100 Subject: [PATCH] Refactor context menu functions to be reusable Fix accept button in contact dialog not enabled when adding from context menu --- src/cutecoin/gui/community_tab.py | 27 ++++++++++++++++++--------- src/cutecoin/gui/contact.py | 6 +++--- src/cutecoin/gui/mainwindow.py | 2 +- src/cutecoin/gui/wot_tab.py | 31 +++++++++++-------------------- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/cutecoin/gui/community_tab.py b/src/cutecoin/gui/community_tab.py index 1847b6e1..97e5ad2a 100644 --- a/src/cutecoin/gui/community_tab.py +++ b/src/cutecoin/gui/community_tab.py @@ -49,7 +49,7 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): self.button_membership.setText("Send membership demand") self.button_leaving.hide() - self.wot_tab = WotTabWidget(account, community, password_asker) + self.wot_tab = WotTabWidget(account, community, password_asker, self) self.tabs_information.addTab(self.wot_tab, QIcon(':/icons/wot_icon'), "Wot") def member_context_menu(self, point): @@ -65,15 +65,15 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): menu = QMenu(self) add_contact = QAction("Add as contact", self) - add_contact.triggered.connect(self.add_member_as_contact) + add_contact.triggered.connect(self.menu_add_as_contact) add_contact.setData(member) send_money = QAction("Send money", self) - send_money.triggered.connect(self.send_money_to_member) + send_money.triggered.connect(self.menu_send_money) send_money.setData(member) certify = QAction("Certify identity", self) - certify.triggered.connect(self.certify_member) + certify.triggered.connect(self.menu_certify_member) certify.setData(member) view_wot = QAction("View in WoT", self) @@ -88,16 +88,26 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): # Show the context menu. menu.exec_(QCursor.pos()) - def add_member_as_contact(self): + def menu_add_as_contact(self): person = self.sender().data() + self.add_member_as_contact(person) + + def menu_send_money(self): + person = self.sender().data() + self.send_money_to_member(person) + + def menu_certify_member(self): + person = self.sender().data() + self.certify_member(person) + + def add_member_as_contact(self, person): dialog = ConfigureContactDialog(self.account, self.window(), person) result = dialog.exec_() if result == QDialog.Accepted: self.window().refresh_contacts() - def send_money_to_member(self): + def send_money_to_member(self, person): dialog = TransferMoneyDialog(self.account, self.password_asker) - person = self.sender().data() dialog.edit_pubkey.setText(person.pubkey) dialog.combo_community.setCurrentText(self.community.name()) dialog.radio_pubkey.setChecked(True) @@ -105,9 +115,8 @@ class CommunityTabWidget(QWidget, Ui_CommunityTabWidget): currency_tab = self.window().currencies_tabwidget.currentWidget() currency_tab.table_history.model().invalidate() - def certify_member(self): + def certify_member(self, person): dialog = CertificationDialog(self.account, self.password_asker) - person = self.sender().data() dialog.combo_community.setCurrentText(self.community.name()) dialog.edit_pubkey.setText(person.pubkey) dialog.radio_pubkey.setChecked(True) diff --git a/src/cutecoin/gui/contact.py b/src/cutecoin/gui/contact.py index 3a0cd82d..469b9fb8 100644 --- a/src/cutecoin/gui/contact.py +++ b/src/cutecoin/gui/contact.py @@ -16,7 +16,7 @@ class ConfigureContactDialog(QDialog, Ui_ConfigureContactDialog): classdocs ''' - def __init__(self, account, parent=None, contact=None): + def __init__(self, account, parent=None, contact=None, edit=False): ''' Constructor ''' @@ -28,8 +28,8 @@ class ConfigureContactDialog(QDialog, Ui_ConfigureContactDialog): if contact: self.edit_name.setText(contact.name) self.edit_pubkey.setText(contact.pubkey) - - self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) + if edit: + self.button_box.button(QDialogButtonBox.Ok).setEnabled(False) def accept(self): name = self.edit_name.text() diff --git a/src/cutecoin/gui/mainwindow.py b/src/cutecoin/gui/mainwindow.py index bb7d1c9a..e2d77661 100644 --- a/src/cutecoin/gui/mainwindow.py +++ b/src/cutecoin/gui/mainwindow.py @@ -138,7 +138,7 @@ class MainWindow(QMainWindow, Ui_MainWindow): @pyqtSlot() def edit_contact(self): contact = self.sender().data() - dialog = ConfigureContactDialog(self.app.current_account, self, contact) + dialog = ConfigureContactDialog(self.app.current_account, self, contact, True) result = dialog.exec_() if result == QDialog.Accepted: self.window().refresh_contacts() diff --git a/src/cutecoin/gui/wot_tab.py b/src/cutecoin/gui/wot_tab.py index df97f6d2..9933e022 100644 --- a/src/cutecoin/gui/wot_tab.py +++ b/src/cutecoin/gui/wot_tab.py @@ -23,6 +23,7 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): :return: """ super().__init__(parent) + self.parent = parent # construct from qtDesigner self.setupUi(self) @@ -60,7 +61,7 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): :param dict metadata: Graph node metadata of the identity """ # create Person from node metadata - person = Person(metadata['text'], metadata['id']) + person = self.get_person_from_metadata(metadata) certifiers = person.certifiers_of(self.community) # reset graph @@ -230,32 +231,19 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): ) def sign_node(self, metadata): - # open certify dialog - dialog = CertificationDialog(self.account, self.password_asker) - dialog.combo_community.setCurrentText(self.community.name()) - dialog.edit_pubkey.setText(metadata['id']) - dialog.radio_pubkey.setChecked(True) - dialog.combo_community.setCurrentText(self.community.name()) - dialog.exec_() + person = self.get_person_from_metadata(metadata) + self.parent.certify_member(person) def send_money_to_node(self, metadata): - dialog = TransferMoneyDialog(self.account, self.password_asker) - dialog.edit_pubkey.setText(metadata['id']) - dialog.combo_community.setCurrentText(self.community.name()) - dialog.radio_pubkey.setChecked(True) - - if dialog.exec_() == QDialog.Accepted: - currency_tab = self.window().currencies_tabwidget.currentWidget() - currency_tab.table_history.model().invalidate() + person = self.get_person_from_metadata(metadata) + self.parent.send_money_to_member(person) 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]: return False - dialog = ConfigureContactDialog(self.account, self.window()) - dialog.edit_name.setText(metadata['text']) - dialog.edit_pubkey.setText(metadata['id']) - dialog.exec_() + person = self.get_person_from_metadata(metadata) + self.parent.add_member_as_contact(person) def get_block_mediantime(self, number): try: @@ -264,3 +252,6 @@ class WotTabWidget(QWidget, Ui_WotTabWidget): logging.debug('community.get_block request error : ' + str(e)) return False return block.mediantime + + def get_person_from_metadata(self, metadata): + return Person(metadata['text'], metadata['id']) -- GitLab