commit f38cc4780239085ebe85c9cd027fb25efae25bc0
parent 4742b03aeaafae455f913d8700041805f721fb87
Author: thomasv <thomasv@gitorious>
Date: Sun, 15 Sep 2013 12:17:51 +0200
add context menu to transaction input/outputs
Diffstat:
3 files changed, 46 insertions(+), 34 deletions(-)
diff --git a/gui/gui_classic/main_window.py b/gui/gui_classic/main_window.py
@@ -75,22 +75,6 @@ import re
from qt_util import *
-class MyTreeWidget(QTreeWidget):
- def __init__(self, parent):
- QTreeWidget.__init__(self, parent)
- def ddfr(item):
- if not item: return
- for i in range(0,self.viewport().height()/5):
- if self.itemAt(QPoint(0,i*5)) == item:
- break
- else:
- return
- for j in range(0,30):
- if self.itemAt(QPoint(0,i*5 + j)) != item:
- break
- self.emit(SIGNAL('customContextMenuRequested(const QPoint&)'), QPoint(50, i*5 + j - 1))
-
- self.connect(self, SIGNAL('itemActivated(QTreeWidgetItem*, int)'), ddfr)
@@ -600,7 +584,6 @@ class ElectrumWindow(QMainWindow):
self.connect(l, SIGNAL('itemDoubleClicked(QTreeWidgetItem*, int)'), self.tx_label_clicked)
self.connect(l, SIGNAL('itemChanged(QTreeWidgetItem*, int)'), self.tx_label_changed)
- l.setContextMenuPolicy(Qt.CustomContextMenu)
l.customContextMenuRequested.connect(self.create_history_menu)
return l
diff --git a/gui/gui_classic/qt_util.py b/gui/gui_classic/qt_util.py
@@ -83,3 +83,22 @@ def text_dialog(parent, title, label, ok_label):
if dialog.exec_():
return unicode(txt.toPlainText())
+
+class MyTreeWidget(QTreeWidget):
+ def __init__(self, parent):
+ QTreeWidget.__init__(self, parent)
+ self.setContextMenuPolicy(Qt.CustomContextMenu)
+ self.connect(self, SIGNAL('itemActivated(QTreeWidgetItem*, int)'), self.itemactivated)
+
+ def itemactivated(self, item):
+ if not item: return
+ for i in range(0,self.viewport().height()/5):
+ if self.itemAt(QPoint(0,i*5)) == item:
+ break
+ else:
+ return
+ for j in range(0,30):
+ if self.itemAt(QPoint(0,i*5 + j)) != item:
+ break
+ self.emit(SIGNAL('customContextMenuRequested(const QPoint&)'), QPoint(50, i*5 + j - 1))
+
diff --git a/gui/gui_classic/transaction_dialog.py b/gui/gui_classic/transaction_dialog.py
@@ -34,7 +34,7 @@ from PyQt4.QtCore import *
import PyQt4.QtCore as QtCore
from electrum import transaction
-
+from qt_util import MyTreeWidget
class TxDialog(QDialog):
@@ -162,6 +162,14 @@ class TxDialog(QDialog):
self.amount_label.setText("Transaction unrelated to your wallet")
+ def exec_menu(self, position,l):
+ item = l.itemAt(position)
+ if not item: return
+ addr = unicode(item.text(0))
+ menu = QMenu()
+ menu.addAction(_("Copy to clipboard"), lambda: self.parent.app.clipboard().setText(addr))
+ menu.exec_(l.viewport().mapToGlobal(position))
+
def io_widget(self, tx):
tabs = QTabWidget(self)
@@ -171,36 +179,38 @@ class TxDialog(QDialog):
grid_ui.setColumnStretch(0,1)
tabs.addTab(tab1, _('Outputs') )
- tree_widget = QTreeWidget(self)
- tree_widget.setColumnCount(2)
- tree_widget.setHeaderLabels( [_('Address'), _('Amount')] )
- tree_widget.setColumnWidth(0, 300)
- tree_widget.setColumnWidth(1, 50)
+ self.output_list = l = MyTreeWidget(self)
+ l.setMaximumHeight(100)
+ l.setColumnCount(2)
+ l.setHeaderLabels( [_('Address'), _('Amount')] )
+ l.setColumnWidth(0, 350)
+ l.setColumnWidth(1, 50)
+ l.customContextMenuRequested.connect(lambda pos: self.exec_menu(pos, self.output_list))
for address, value in tx.outputs:
item = QTreeWidgetItem( [address, "%s" % ( self.parent.format_amount(value))] )
- tree_widget.addTopLevelItem(item)
+ l.addTopLevelItem(item)
- tree_widget.setMaximumHeight(100)
-
- grid_ui.addWidget(tree_widget)
+ grid_ui.addWidget(l)
tab2 = QWidget()
grid_ui = QGridLayout(tab2)
grid_ui.setColumnStretch(0,1)
tabs.addTab(tab2, _('Inputs') )
- tree_widget = QTreeWidget(self)
- tree_widget.setColumnCount(2)
- tree_widget.setHeaderLabels( [ _('Address'), _('Previous output')] )
+ self.input_list = l = MyTreeWidget(self)
+ l.setMaximumHeight(100)
+ l.setColumnCount(2)
+ l.setColumnWidth(0, 350)
+ l.setColumnWidth(1, 50)
+ l.setHeaderLabels( [ _('Address'), _('Previous output')] )
+ l.customContextMenuRequested.connect(lambda pos: self.exec_menu(pos, self.input_list))
for input_line in tx.inputs:
item = QTreeWidgetItem( [ str(input_line["address"]), str(input_line.get("prevout_hash"))] )
- tree_widget.addTopLevelItem(item)
-
- tree_widget.setMaximumHeight(100)
+ l.addTopLevelItem(item)
- grid_ui.addWidget(tree_widget)
+ grid_ui.addWidget(l)
return tabs