mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 17:55:20 +00:00
generic add_button method for TextEdit, with tooltips
This commit is contained in:
parent
e620f36971
commit
94c0d86821
2 changed files with 24 additions and 32 deletions
|
@ -7,25 +7,38 @@ class QRTextEdit(QPlainTextEdit):
|
||||||
"""Abstract class for QR-code related TextEdits. Do not use directly."""
|
"""Abstract class for QR-code related TextEdits. Do not use directly."""
|
||||||
def __init__(self, text=None):
|
def __init__(self, text=None):
|
||||||
super(QRTextEdit, self).__init__(text)
|
super(QRTextEdit, self).__init__(text)
|
||||||
self.button = QToolButton(self)
|
|
||||||
self.button.setIcon(QIcon(":icons/qrcode.png"))
|
|
||||||
self.button.setStyleSheet("QToolButton { border: none; padding: 0px; }")
|
|
||||||
self.button.setVisible(True)
|
|
||||||
self.setText = self.setPlainText
|
self.setText = self.setPlainText
|
||||||
|
self.buttons = []
|
||||||
|
|
||||||
def resizeEvent(self, e):
|
def resizeEvent(self, e):
|
||||||
o = QPlainTextEdit.resizeEvent(self, e)
|
o = QPlainTextEdit.resizeEvent(self, e)
|
||||||
sz = self.button.sizeHint()
|
|
||||||
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
|
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
|
||||||
self.button.move(self.rect().right() - frameWidth - sz.width(),
|
x = self.rect().right() - frameWidth
|
||||||
(self.rect().bottom() - frameWidth - sz.height()))
|
y = self.rect().bottom() - frameWidth
|
||||||
|
for button in self.buttons:
|
||||||
|
sz = button.sizeHint()
|
||||||
|
x -= sz.width()
|
||||||
|
button.move(x, y - sz.height())
|
||||||
return o
|
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(QRTextEdit):
|
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.button.clicked.connect(self.qr_show)
|
self.add_button(":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):
|
||||||
|
@ -50,10 +63,9 @@ 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.button.clicked.connect(self.qr_input)
|
self.add_button(":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):
|
||||||
from electrum import qrscanner
|
from electrum import qrscanner
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -92,8 +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()
|
||||||
button = add_button(parent=parent, icon_name=':icons/microphone.png')
|
parent.add_button(':icons/microphone.png', handler, _("Read from microphone"))
|
||||||
button.clicked.connect(handler)
|
|
||||||
|
|
||||||
@hook
|
@hook
|
||||||
def show_text_edit(self, parent):
|
def show_text_edit(self, parent):
|
||||||
|
@ -101,8 +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()
|
||||||
button = add_button(parent=parent, icon_name=':icons/speaker.png')
|
parent.add_button(':icons/speaker.png', handler, _("Send to speaker"))
|
||||||
button.clicked.connect(handler)
|
|
||||||
|
|
||||||
def _audio_interface(self):
|
def _audio_interface(self):
|
||||||
interface = amodem.audio.Interface(config=self.modem_config)
|
interface = amodem.audio.Interface(config=self.modem_config)
|
||||||
|
@ -148,21 +146,3 @@ class Plugin(BasePlugin):
|
||||||
run_task=receiver_thread, on_success=on_success)
|
run_task=receiver_thread, on_success=on_success)
|
||||||
|
|
||||||
|
|
||||||
def add_button(parent, icon_name):
|
|
||||||
audio_button = QToolButton(parent)
|
|
||||||
audio_button.setIcon(QIcon(icon_name))
|
|
||||||
audio_button.setStyleSheet("QToolButton { border: none; padding: 0px; }")
|
|
||||||
audio_button.setVisible(True)
|
|
||||||
|
|
||||||
parent_resizeEvent = parent.resizeEvent
|
|
||||||
|
|
||||||
def resizeEvent(e):
|
|
||||||
result = parent_resizeEvent(e)
|
|
||||||
qr_button = parent.button
|
|
||||||
left = qr_button.geometry().left() - audio_button.sizeHint().width()
|
|
||||||
top = qr_button.geometry().top()
|
|
||||||
audio_button.move(left, top)
|
|
||||||
return result
|
|
||||||
|
|
||||||
parent.resizeEvent = resizeEvent
|
|
||||||
return audio_button
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue