new class to show buttons in LineEdit. fixes #1050
This commit is contained in:
parent
8251c5b6d9
commit
a3ed4ce2a7
|
@ -576,14 +576,15 @@ class ElectrumWindow(QMainWindow):
|
||||||
def create_receive_tab(self):
|
def create_receive_tab(self):
|
||||||
|
|
||||||
self.receive_grid = grid = QGridLayout()
|
self.receive_grid = grid = QGridLayout()
|
||||||
grid.setColumnMinimumWidth(3, 150)
|
grid.setColumnMinimumWidth(3, 300)
|
||||||
|
|
||||||
self.receive_address_e = MyLineEdit()
|
self.receive_address_e = ButtonsLineEdit()
|
||||||
self.receive_address_e.setFrozen(True)
|
self.receive_address_e.addButton(":icons/copy.png", lambda: self.app.clipboard().setText(str(self.receive_address_e.text())), _("Copy Address to Clibboard"))
|
||||||
|
self.receive_address_e.setReadOnly(True)
|
||||||
self.receive_address_label = QLabel(_('Receiving address'))
|
self.receive_address_label = QLabel(_('Receiving address'))
|
||||||
self.receive_address_e.textChanged.connect(self.update_receive_qr)
|
self.receive_address_e.textChanged.connect(self.update_receive_qr)
|
||||||
grid.addWidget(self.receive_address_label, 0, 0)
|
grid.addWidget(self.receive_address_label, 0, 0)
|
||||||
grid.addWidget(self.receive_address_e, 0, 1, 1, 3)
|
grid.addWidget(self.receive_address_e, 0, 1, 1, 4)
|
||||||
|
|
||||||
self.receive_message_e = QLineEdit()
|
self.receive_message_e = QLineEdit()
|
||||||
grid.addWidget(QLabel(_('Description')), 1, 0)
|
grid.addWidget(QLabel(_('Description')), 1, 0)
|
||||||
|
@ -603,27 +604,22 @@ class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
self.save_request_button = QPushButton(_('Save'))
|
self.save_request_button = QPushButton(_('Save'))
|
||||||
self.save_request_button.clicked.connect(self.save_payment_request)
|
self.save_request_button.clicked.connect(self.save_payment_request)
|
||||||
grid.addWidget(self.save_request_button, 4, 1)
|
|
||||||
|
|
||||||
self.new_request_button = QPushButton(_('New'))
|
self.new_request_button = QPushButton(_('New'))
|
||||||
self.new_request_button.clicked.connect(self.new_receive_address)
|
self.new_request_button.clicked.connect(self.new_receive_address)
|
||||||
grid.addWidget(self.new_request_button, 4, 2)
|
|
||||||
grid.setRowStretch(5, 1)
|
|
||||||
|
|
||||||
self.copy_button = QPushButton()
|
|
||||||
self.copy_button.setIcon(QIcon(":icons/copy.png"))
|
|
||||||
self.copy_button.setToolTip(_("Copy Address to Clibboard"))
|
|
||||||
self.copy_button.clicked.connect(lambda: self.app.clipboard().setText(str(self.receive_address_e.text())))
|
|
||||||
|
|
||||||
self.qr_button = QPushButton()
|
self.qr_button = QPushButton()
|
||||||
self.qr_button.setIcon(QIcon(":icons/qrcode.png"))
|
self.qr_button.setIcon(QIcon(":icons/qrcode.png"))
|
||||||
self.qr_button.setToolTip(_("Show Payment Request with QR code"))
|
self.qr_button.setToolTip(_("Show/Hide QR code window"))
|
||||||
self.qr_button.clicked.connect(lambda x: self.toggle_qr_window())
|
self.qr_button.clicked.connect(lambda x: self.toggle_qr_window())
|
||||||
|
|
||||||
buttons = QHBoxLayout()
|
buttons = QHBoxLayout()
|
||||||
buttons.addWidget(self.copy_button)
|
|
||||||
buttons.addWidget(self.qr_button)
|
buttons.addWidget(self.qr_button)
|
||||||
grid.addLayout(buttons, 0, 4)
|
buttons.addWidget(self.save_request_button)
|
||||||
|
buttons.addWidget(self.new_request_button)
|
||||||
|
buttons.addStretch(1)
|
||||||
|
grid.addLayout(buttons, 4, 1, 1, 3)
|
||||||
|
grid.setRowStretch(5, 1)
|
||||||
|
|
||||||
self.receive_requests_label = QLabel(_('My Requests'))
|
self.receive_requests_label = QLabel(_('My Requests'))
|
||||||
self.receive_list = MyTreeWidget(self, self.receive_list_menu, [_('Date'), _('Account'), _('Address'), _('Description'), _('Amount'), _('Status')], [])
|
self.receive_list = MyTreeWidget(self, self.receive_list_menu, [_('Date'), _('Account'), _('Address'), _('Description'), _('Amount'), _('Status')], [])
|
||||||
|
|
|
@ -3,42 +3,14 @@ from electrum.plugins import run_hook
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
|
|
||||||
class QRTextEdit(QPlainTextEdit):
|
from util import ButtonsTextEdit
|
||||||
"""Abstract class for QR-code related TextEdits. Do not use directly."""
|
|
||||||
def __init__(self, text=None):
|
|
||||||
super(QRTextEdit, self).__init__(text)
|
|
||||||
self.setText = self.setPlainText
|
|
||||||
self.buttons = []
|
|
||||||
|
|
||||||
def resizeEvent(self, e):
|
|
||||||
o = QPlainTextEdit.resizeEvent(self, e)
|
|
||||||
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
|
|
||||||
x = self.rect().right() - frameWidth
|
|
||||||
y = self.rect().bottom() - frameWidth
|
|
||||||
for button in self.buttons:
|
|
||||||
sz = button.sizeHint()
|
|
||||||
x -= sz.width()
|
|
||||||
button.move(x, y - sz.height())
|
|
||||||
return o
|
|
||||||
|
|
||||||
def add_button(self, icon_name, on_click, tooltip):
|
|
||||||
button = QToolButton(self)
|
|
||||||
button.setIcon(QIcon(icon_name))
|
|
||||||
button.setStyleSheet("QToolButton { border: none; padding: 0px; }")
|
|
||||||
button.setVisible(True)
|
|
||||||
button.setToolTip(tooltip)
|
|
||||||
button.clicked.connect(on_click)
|
|
||||||
self.buttons.append(button)
|
|
||||||
return button
|
|
||||||
|
|
||||||
|
|
||||||
|
class ShowQRTextEdit(ButtonsTextEdit):
|
||||||
|
|
||||||
class ShowQRTextEdit(QRTextEdit):
|
|
||||||
def __init__(self, text=None):
|
def __init__(self, text=None):
|
||||||
super(ShowQRTextEdit, self).__init__(text)
|
super(ShowQRTextEdit, self).__init__(text)
|
||||||
self.setReadOnly(1)
|
self.setReadOnly(1)
|
||||||
self.add_button(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
|
self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
|
||||||
run_hook('show_text_edit', self)
|
run_hook('show_text_edit', self)
|
||||||
|
|
||||||
def qr_show(self):
|
def qr_show(self):
|
||||||
|
@ -55,7 +27,7 @@ class ShowQRTextEdit(QRTextEdit):
|
||||||
m.exec_(e.globalPos())
|
m.exec_(e.globalPos())
|
||||||
|
|
||||||
|
|
||||||
class ScanQRTextEdit(QRTextEdit):
|
class ScanQRTextEdit(ButtonsTextEdit):
|
||||||
def __init__(self, win, text=""):
|
def __init__(self, win, text=""):
|
||||||
super(ScanQRTextEdit,self).__init__(text)
|
super(ScanQRTextEdit,self).__init__(text)
|
||||||
self.setReadOnly(0)
|
self.setReadOnly(0)
|
||||||
|
@ -63,7 +35,7 @@ class ScanQRTextEdit(QRTextEdit):
|
||||||
assert win, "You must pass a window with access to the config to ScanQRTextEdit constructor."
|
assert win, "You must pass a window with access to the config to ScanQRTextEdit constructor."
|
||||||
if win:
|
if win:
|
||||||
assert hasattr(win,"config"), "You must pass a window with access to the config to ScanQRTextEdit constructor."
|
assert hasattr(win,"config"), "You must pass a window with access to the config to ScanQRTextEdit constructor."
|
||||||
self.add_button(":icons/qrcode.png", self.qr_input, _("Read QR code"))
|
self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code"))
|
||||||
run_hook('scan_text_edit', self)
|
run_hook('scan_text_edit', self)
|
||||||
|
|
||||||
def qr_input(self):
|
def qr_input(self):
|
||||||
|
|
|
@ -58,7 +58,9 @@ class TxDialog(QDialog):
|
||||||
self.setLayout(vbox)
|
self.setLayout(vbox)
|
||||||
|
|
||||||
vbox.addWidget(QLabel(_("Transaction ID:")))
|
vbox.addWidget(QLabel(_("Transaction ID:")))
|
||||||
self.tx_hash_e = QLineEdit()
|
self.tx_hash_e = ButtonsLineEdit()
|
||||||
|
qr_show = lambda: self.parent.show_qrcode(str(self.tx_hash_e.text()), 'Transaction ID')
|
||||||
|
self.tx_hash_e.addButton(":icons/qrcode.png", qr_show, _("Show as QR code"))
|
||||||
self.tx_hash_e.setReadOnly(True)
|
self.tx_hash_e.setReadOnly(True)
|
||||||
vbox.addWidget(self.tx_hash_e)
|
vbox.addWidget(self.tx_hash_e)
|
||||||
self.status_label = QLabel()
|
self.status_label = QLabel()
|
||||||
|
|
|
@ -324,6 +324,46 @@ class MyTreeWidget(QTreeWidget):
|
||||||
self.parent.update_completions()
|
self.parent.update_completions()
|
||||||
|
|
||||||
|
|
||||||
|
class ButtonsWidget(QWidget):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(QWidget, self).__init__()
|
||||||
|
self.buttons = []
|
||||||
|
|
||||||
|
def resizeEvent(self, e):
|
||||||
|
o = QWidget.resizeEvent(self, e)
|
||||||
|
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
|
||||||
|
x = self.rect().right() - frameWidth
|
||||||
|
y = self.rect().bottom() - frameWidth
|
||||||
|
for button in self.buttons:
|
||||||
|
sz = button.sizeHint()
|
||||||
|
x -= sz.width()
|
||||||
|
button.move(x, y - sz.height())
|
||||||
|
return o
|
||||||
|
|
||||||
|
def addButton(self, icon_name, on_click, tooltip):
|
||||||
|
button = QToolButton(self)
|
||||||
|
button.setIcon(QIcon(icon_name))
|
||||||
|
button.setStyleSheet("QToolButton { border: none; padding: 0px; }")
|
||||||
|
button.setVisible(True)
|
||||||
|
button.setToolTip(tooltip)
|
||||||
|
button.clicked.connect(on_click)
|
||||||
|
self.buttons.append(button)
|
||||||
|
return button
|
||||||
|
|
||||||
|
class ButtonsLineEdit(QLineEdit, ButtonsWidget):
|
||||||
|
def __init__(self, text=None):
|
||||||
|
QLineEdit.__init__(self, text)
|
||||||
|
self.buttons = []
|
||||||
|
|
||||||
|
class ButtonsTextEdit(QPlainTextEdit, ButtonsWidget):
|
||||||
|
def __init__(self, text=None):
|
||||||
|
QPlainTextEdit.__init__(self, text)
|
||||||
|
self.setText = self.setPlainText
|
||||||
|
self.buttons = []
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done", _('OK')))
|
t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done", _('OK')))
|
||||||
|
|
|
@ -92,7 +92,7 @@ class Plugin(BasePlugin):
|
||||||
def handler():
|
def handler():
|
||||||
self.receiver = self._recv(parent=parent)
|
self.receiver = self._recv(parent=parent)
|
||||||
self.receiver.start()
|
self.receiver.start()
|
||||||
parent.add_button(':icons/microphone.png', handler, _("Read from microphone"))
|
parent.addButton(':icons/microphone.png', handler, _("Read from microphone"))
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def show_text_edit(self, parent):
|
def show_text_edit(self, parent):
|
||||||
|
@ -100,7 +100,7 @@ class Plugin(BasePlugin):
|
||||||
blob = str(parent.toPlainText())
|
blob = str(parent.toPlainText())
|
||||||
self.sender = self._send(parent=parent, blob=blob)
|
self.sender = self._send(parent=parent, blob=blob)
|
||||||
self.sender.start()
|
self.sender.start()
|
||||||
parent.add_button(':icons/speaker.png', handler, _("Send to speaker"))
|
parent.addButton(':icons/speaker.png', handler, _("Send to speaker"))
|
||||||
|
|
||||||
def _audio_interface(self):
|
def _audio_interface(self):
|
||||||
interface = amodem.audio.Interface(config=self.modem_config)
|
interface = amodem.audio.Interface(config=self.modem_config)
|
||||||
|
|
Loading…
Reference in New Issue