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