qt.util.ButtonsWidget: add custom setText arg to methods
I am planning to use this in qt.PayToEdit.
This commit is contained in:
@@ -858,19 +858,24 @@ class ButtonsWidget(QWidget):
|
|||||||
return button
|
return button
|
||||||
|
|
||||||
def addCopyButton(self, app: QApplication):
|
def addCopyButton(self, app: QApplication):
|
||||||
self.app = app
|
def on_copy():
|
||||||
self.addButton("copy.png", self.on_copy, _("Copy to clipboard"))
|
app.clipboard().setText(self.text())
|
||||||
|
QToolTip.showText(QCursor.pos(), _("Text copied to clipboard"), self)
|
||||||
|
|
||||||
def on_copy(self):
|
self.addButton("copy.png", on_copy, _("Copy to clipboard"))
|
||||||
self.app.clipboard().setText(self.text())
|
|
||||||
QToolTip.showText(QCursor.pos(), _("Text copied to clipboard"), self)
|
|
||||||
|
|
||||||
def addPasteButton(self, app: QApplication):
|
def addPasteButton(
|
||||||
self.app = app
|
self,
|
||||||
self.addButton("copy.png", self.on_paste, _("Paste from clipboard"))
|
app: QApplication,
|
||||||
|
*,
|
||||||
|
setText: Callable[[str], None] = None,
|
||||||
|
):
|
||||||
|
if setText is None:
|
||||||
|
setText = self.setText
|
||||||
|
def on_paste():
|
||||||
|
setText(app.clipboard().text())
|
||||||
|
|
||||||
def on_paste(self):
|
self.addButton("copy.png", on_paste, _("Paste from clipboard"))
|
||||||
self.setText(self.app.clipboard().text())
|
|
||||||
|
|
||||||
def add_qr_show_button(self, *, config: 'SimpleConfig', title: Optional[str] = None):
|
def add_qr_show_button(self, *, config: 'SimpleConfig', title: Optional[str] = None):
|
||||||
if title is None:
|
if title is None:
|
||||||
@@ -902,7 +907,10 @@ class ButtonsWidget(QWidget):
|
|||||||
config: 'SimpleConfig',
|
config: 'SimpleConfig',
|
||||||
allow_multi: bool = False,
|
allow_multi: bool = False,
|
||||||
show_error: Callable[[str], None],
|
show_error: Callable[[str], None],
|
||||||
|
setText: Callable[[str], None] = None,
|
||||||
):
|
):
|
||||||
|
if setText is None:
|
||||||
|
setText = self.setText
|
||||||
def qr_input():
|
def qr_input():
|
||||||
def cb(success: bool, error: str, data):
|
def cb(success: bool, error: str, data):
|
||||||
if not success:
|
if not success:
|
||||||
@@ -915,7 +923,7 @@ class ButtonsWidget(QWidget):
|
|||||||
new_text = self.text() + data + '\n'
|
new_text = self.text() + data + '\n'
|
||||||
else:
|
else:
|
||||||
new_text = data
|
new_text = data
|
||||||
self.setText(new_text)
|
setText(new_text)
|
||||||
|
|
||||||
from .qrreader import scan_qrcode
|
from .qrreader import scan_qrcode
|
||||||
scan_qrcode(parent=self, config=config, callback=cb)
|
scan_qrcode(parent=self, config=config, callback=cb)
|
||||||
@@ -930,7 +938,10 @@ class ButtonsWidget(QWidget):
|
|||||||
*,
|
*,
|
||||||
config: 'SimpleConfig',
|
config: 'SimpleConfig',
|
||||||
show_error: Callable[[str], None],
|
show_error: Callable[[str], None],
|
||||||
|
setText: Callable[[str], None] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
|
if setText is None:
|
||||||
|
setText = self.setText
|
||||||
def file_input():
|
def file_input():
|
||||||
fileName = getOpenFileName(
|
fileName = getOpenFileName(
|
||||||
parent=self,
|
parent=self,
|
||||||
@@ -950,7 +961,7 @@ class ButtonsWidget(QWidget):
|
|||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
show_error(_('Error opening file') + ':\n' + repr(e))
|
show_error(_('Error opening file') + ':\n' + repr(e))
|
||||||
else:
|
else:
|
||||||
self.setText(data)
|
setText(data)
|
||||||
|
|
||||||
self.addButton("file.png", file_input, _("Read file"))
|
self.addButton("file.png", file_input, _("Read file"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user