util: more code-style cleanup
This commit is contained in:
@@ -15,7 +15,7 @@ from PyQt5.QtCore import (Qt, pyqtSignal, QCoreApplication, QThread, QSize, QRec
|
|||||||
from PyQt5.QtWidgets import (QPushButton, QLabel, QMessageBox, QHBoxLayout, QVBoxLayout, QLineEdit,
|
from PyQt5.QtWidgets import (QPushButton, QLabel, QMessageBox, QHBoxLayout, QVBoxLayout, QLineEdit,
|
||||||
QStyle, QDialog, QGroupBox, QButtonGroup, QRadioButton,
|
QStyle, QDialog, QGroupBox, QButtonGroup, QRadioButton,
|
||||||
QFileDialog, QWidget, QToolButton, QPlainTextEdit, QApplication, QToolTip,
|
QFileDialog, QWidget, QToolButton, QPlainTextEdit, QApplication, QToolTip,
|
||||||
QGraphicsEffect, QGraphicsScene, QGraphicsPixmapItem)
|
QGraphicsEffect, QGraphicsScene, QGraphicsPixmapItem, QLayoutItem, QLayout, QMenu)
|
||||||
|
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.util import FileImportFailed, FileExportFailed, resource_path
|
from electrum.util import FileImportFailed, FileExportFailed, resource_path
|
||||||
@@ -45,16 +45,16 @@ _logger = get_logger(__name__)
|
|||||||
dialogs = []
|
dialogs = []
|
||||||
|
|
||||||
pr_icons = {
|
pr_icons = {
|
||||||
PR_UNKNOWN:"warning.png",
|
PR_UNKNOWN: "warning.png",
|
||||||
PR_UNPAID:"unpaid.png",
|
PR_UNPAID: "unpaid.png",
|
||||||
PR_PAID:"confirmed.png",
|
PR_PAID: "confirmed.png",
|
||||||
PR_EXPIRED:"expired.png",
|
PR_EXPIRED: "expired.png",
|
||||||
PR_INFLIGHT:"unconfirmed.png",
|
PR_INFLIGHT: "unconfirmed.png",
|
||||||
PR_FAILED:"warning.png",
|
PR_FAILED: "warning.png",
|
||||||
PR_ROUTING:"unconfirmed.png",
|
PR_ROUTING: "unconfirmed.png",
|
||||||
PR_UNCONFIRMED:"unconfirmed.png",
|
PR_UNCONFIRMED: "unconfirmed.png",
|
||||||
PR_BROADCASTING:"unconfirmed.png",
|
PR_BROADCASTING: "unconfirmed.png",
|
||||||
PR_BROADCAST:"unconfirmed.png",
|
PR_BROADCAST: "unconfirmed.png",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -190,17 +190,20 @@ class Buttons(QHBoxLayout):
|
|||||||
continue
|
continue
|
||||||
self.addWidget(b)
|
self.addWidget(b)
|
||||||
|
|
||||||
|
|
||||||
class CloseButton(QPushButton):
|
class CloseButton(QPushButton):
|
||||||
def __init__(self, dialog):
|
def __init__(self, dialog):
|
||||||
QPushButton.__init__(self, _("Close"))
|
QPushButton.__init__(self, _("Close"))
|
||||||
self.clicked.connect(dialog.close)
|
self.clicked.connect(dialog.close)
|
||||||
self.setDefault(True)
|
self.setDefault(True)
|
||||||
|
|
||||||
|
|
||||||
class CopyButton(QPushButton):
|
class CopyButton(QPushButton):
|
||||||
def __init__(self, text_getter, app):
|
def __init__(self, text_getter, app):
|
||||||
QPushButton.__init__(self, _("Copy"))
|
QPushButton.__init__(self, _("Copy"))
|
||||||
self.clicked.connect(lambda: app.clipboard().setText(text_getter()))
|
self.clicked.connect(lambda: app.clipboard().setText(text_getter()))
|
||||||
|
|
||||||
|
|
||||||
class CopyCloseButton(QPushButton):
|
class CopyCloseButton(QPushButton):
|
||||||
def __init__(self, text_getter, app, dialog):
|
def __init__(self, text_getter, app, dialog):
|
||||||
QPushButton.__init__(self, _("Copy and Close"))
|
QPushButton.__init__(self, _("Copy and Close"))
|
||||||
@@ -208,17 +211,20 @@ class CopyCloseButton(QPushButton):
|
|||||||
self.clicked.connect(dialog.close)
|
self.clicked.connect(dialog.close)
|
||||||
self.setDefault(True)
|
self.setDefault(True)
|
||||||
|
|
||||||
|
|
||||||
class OkButton(QPushButton):
|
class OkButton(QPushButton):
|
||||||
def __init__(self, dialog, label=None):
|
def __init__(self, dialog, label=None):
|
||||||
QPushButton.__init__(self, label or _("OK"))
|
QPushButton.__init__(self, label or _("OK"))
|
||||||
self.clicked.connect(dialog.accept)
|
self.clicked.connect(dialog.accept)
|
||||||
self.setDefault(True)
|
self.setDefault(True)
|
||||||
|
|
||||||
|
|
||||||
class CancelButton(QPushButton):
|
class CancelButton(QPushButton):
|
||||||
def __init__(self, dialog, label=None):
|
def __init__(self, dialog, label=None):
|
||||||
QPushButton.__init__(self, label or _("Cancel"))
|
QPushButton.__init__(self, label or _("Cancel"))
|
||||||
self.clicked.connect(dialog.reject)
|
self.clicked.connect(dialog.reject)
|
||||||
|
|
||||||
|
|
||||||
class MessageBoxMixin(object):
|
class MessageBoxMixin(object):
|
||||||
def top_level_window_recurse(self, window=None, test_func=None):
|
def top_level_window_recurse(self, window=None, test_func=None):
|
||||||
window = window or self
|
window = window or self
|
||||||
@@ -385,6 +391,7 @@ def line_dialog(parent, title, label, ok_label, default=None):
|
|||||||
if dialog.exec_():
|
if dialog.exec_():
|
||||||
return txt.text()
|
return txt.text()
|
||||||
|
|
||||||
|
|
||||||
def text_dialog(
|
def text_dialog(
|
||||||
*,
|
*,
|
||||||
parent,
|
parent,
|
||||||
@@ -412,6 +419,7 @@ def text_dialog(
|
|||||||
if dialog.exec_():
|
if dialog.exec_():
|
||||||
return txt.toPlainText()
|
return txt.toPlainText()
|
||||||
|
|
||||||
|
|
||||||
class ChoicesLayout(object):
|
class ChoicesLayout(object):
|
||||||
def __init__(self, msg, choices, on_clicked=None, checked_index=0):
|
def __init__(self, msg, choices, on_clicked=None, checked_index=0):
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
@@ -558,6 +566,7 @@ def address_field(addresses):
|
|||||||
address_e.setText(addresses[0])
|
address_e.setText(addresses[0])
|
||||||
else:
|
else:
|
||||||
addresses = []
|
addresses = []
|
||||||
|
|
||||||
def func():
|
def func():
|
||||||
try:
|
try:
|
||||||
i = addresses.index(str(address_e.text())) + 1
|
i = addresses.index(str(address_e.text())) + 1
|
||||||
@@ -576,7 +585,6 @@ def address_field(addresses):
|
|||||||
|
|
||||||
|
|
||||||
def filename_field(parent, config, defaultname, select_msg):
|
def filename_field(parent, config, defaultname, select_msg):
|
||||||
|
|
||||||
vbox = QVBoxLayout()
|
vbox = QVBoxLayout()
|
||||||
vbox.addWidget(QLabel(_("Format")))
|
vbox.addWidget(QLabel(_("Format")))
|
||||||
gb = QGroupBox("format", parent)
|
gb = QGroupBox("format", parent)
|
||||||
@@ -625,9 +633,6 @@ def filename_field(parent, config, defaultname, select_msg):
|
|||||||
return vbox, filename_e, b1
|
return vbox, filename_e, b1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_iconname_qrcode() -> str:
|
def get_iconname_qrcode() -> str:
|
||||||
return "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png"
|
return "qrcode_white.png" if ColorScheme.dark_scheme else "qrcode.png"
|
||||||
|
|
||||||
@@ -646,7 +651,6 @@ def editor_contextMenuEvent(self, p: 'PayToEdit', e: 'QContextMenuEvent') -> Non
|
|||||||
|
|
||||||
|
|
||||||
class GenericInputHandler:
|
class GenericInputHandler:
|
||||||
|
|
||||||
def input_qr_from_camera(
|
def input_qr_from_camera(
|
||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
@@ -666,7 +670,7 @@ class GenericInputHandler:
|
|||||||
if not data:
|
if not data:
|
||||||
data = ''
|
data = ''
|
||||||
if allow_multi:
|
if allow_multi:
|
||||||
new_text = self.text() + data + '\n'
|
new_text = self.text() + data + '\n' # TODO: unused?
|
||||||
else:
|
else:
|
||||||
new_text = data
|
new_text = data
|
||||||
try:
|
try:
|
||||||
@@ -711,7 +715,7 @@ class GenericInputHandler:
|
|||||||
return
|
return
|
||||||
data = scanned_qr[0].data
|
data = scanned_qr[0].data
|
||||||
if allow_multi:
|
if allow_multi:
|
||||||
new_text = self.text() + data + '\n'
|
new_text = self.text() + data + '\n' # TODO: unused?
|
||||||
else:
|
else:
|
||||||
new_text = data
|
new_text = data
|
||||||
try:
|
try:
|
||||||
@@ -951,12 +955,12 @@ class OverlayControlMixin(GenericInputHandler):
|
|||||||
btn.setMenu(menu)
|
btn.setMenu(menu)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ButtonsLineEdit(OverlayControlMixin, QLineEdit):
|
class ButtonsLineEdit(OverlayControlMixin, QLineEdit):
|
||||||
def __init__(self, text=None):
|
def __init__(self, text=None):
|
||||||
QLineEdit.__init__(self, text)
|
QLineEdit.__init__(self, text)
|
||||||
OverlayControlMixin.__init__(self, middle=True)
|
OverlayControlMixin.__init__(self, middle=True)
|
||||||
|
|
||||||
|
|
||||||
class ShowQRLineEdit(ButtonsLineEdit):
|
class ShowQRLineEdit(ButtonsLineEdit):
|
||||||
""" read-only line with qr and copy buttons """
|
""" read-only line with qr and copy buttons """
|
||||||
def __init__(self, text: str, config, title=None):
|
def __init__(self, text: str, config, title=None):
|
||||||
@@ -966,6 +970,7 @@ class ShowQRLineEdit(ButtonsLineEdit):
|
|||||||
self.add_qr_show_button(config=config, title=title)
|
self.add_qr_show_button(config=config, title=title)
|
||||||
self.addCopyButton()
|
self.addCopyButton()
|
||||||
|
|
||||||
|
|
||||||
class ButtonsTextEdit(OverlayControlMixin, QPlainTextEdit):
|
class ButtonsTextEdit(OverlayControlMixin, QPlainTextEdit):
|
||||||
def __init__(self, text=None):
|
def __init__(self, text=None):
|
||||||
QPlainTextEdit.__init__(self, text)
|
QPlainTextEdit.__init__(self, text)
|
||||||
@@ -1216,6 +1221,7 @@ def icon_path(icon_basename: str):
|
|||||||
def read_QIcon(icon_basename: str) -> QIcon:
|
def read_QIcon(icon_basename: str) -> QIcon:
|
||||||
return QIcon(icon_path(icon_basename))
|
return QIcon(icon_path(icon_basename))
|
||||||
|
|
||||||
|
|
||||||
class IconLabel(QWidget):
|
class IconLabel(QWidget):
|
||||||
HorizontalSpacing = 2
|
HorizontalSpacing = 2
|
||||||
def __init__(self, *, text='', final_stretch=True):
|
def __init__(self, *, text='', final_stretch=True):
|
||||||
@@ -1408,6 +1414,7 @@ class QtEventListener(EventListener):
|
|||||||
# decorator for members of the QtEventListener class
|
# decorator for members of the QtEventListener class
|
||||||
def qt_event_listener(func):
|
def qt_event_listener(func):
|
||||||
func = event_listener(func)
|
func = event_listener(func)
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def decorator(self, *args):
|
def decorator(self, *args):
|
||||||
self.qt_callback_signal.emit( (func,) + args)
|
self.qt_callback_signal.emit( (func,) + args)
|
||||||
|
|||||||
Reference in New Issue
Block a user