From 9a58af4de586d6e0f0322214a4f4a23fa4740c0e Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Mon, 25 Mar 2019 18:35:33 +0200 Subject: [PATCH] New method foldertree.AccountMixin.accountString(): composes the 'label
' string which is used in MyForm.on_action_Send() instead of bare address. --- src/bitmessageqt/__init__.py | 12 ++++++------ src/bitmessageqt/foldertree.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 3f9f98d1..0a26bdbc 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -2610,7 +2610,10 @@ class MyForm(settingsmixin.SMainWindow): def on_action_Send(self): """Send message to current selected address""" self.click_pushButtonClear() - self.ui.lineEditTo.setText(self.getCurrentAccount()) + account_item = self.getCurrentItem() + if not account_item: + return + self.ui.lineEditTo.setText(account_item.accountString()) self.ui.tabWidget.setCurrentIndex( self.ui.tabWidget.indexOf(self.ui.send) ) @@ -3662,11 +3665,8 @@ class MyForm(settingsmixin.SMainWindow): if treeWidget is None: treeWidget = self.getCurrentTreeWidget() if treeWidget: - currentItem = treeWidget.currentItem() - if currentItem: - return currentItem - return False - + return treeWidget.currentItem() + def getCurrentAccount(self, treeWidget=None): currentItem = self.getCurrentItem(treeWidget) if currentItem: diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index 563bb1ee..fe31191f 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -56,6 +56,14 @@ class AccountMixin(object): brush.setStyle(QtCore.Qt.NoBrush) return brush + def accountString(self): + """Account string suitable for use in To: field: label """ + label = self._getLabel() + return ( + self.address if label == self.address + else '%s <%s>' % (label, self.address) + ) + def setAddress(self, address): """Set bitmessage address of the object""" if address is None: @@ -359,6 +367,9 @@ class BMAddressWidget(BMTableWidgetItem, AccountMixin): def _setup(self): self.setEnabled(True) + def _getLabel(self): + return self.label + def data(self, role): """Return object data (QT UI)""" if role == QtCore.Qt.ToolTipRole: