Browse Source

Qt: add async JMPasswordDialog

add_frost_channel_encryption
zebra-lucky 2 months ago
parent
commit
3d6e1befe6
  1. 37
      scripts/joinmarket-qt.py
  2. 54
      scripts/qtsupport.py

37
scripts/joinmarket-qt.py

@ -80,7 +80,7 @@ from jmclient.wallet import BaseWallet
from qtsupport import ScheduleWizard, TumbleRestartWizard, config_tips,\ from qtsupport import ScheduleWizard, TumbleRestartWizard, config_tips,\
config_types, QtHandler, XStream, Buttons, OkButton, CancelButton,\ config_types, QtHandler, XStream, Buttons, OkButton, CancelButton,\
PasswordDialog, MyTreeWidget, JMQtMessageBox, BLUE_FG,\ JMPasswordDialog, MyTreeWidget, JMQtMessageBox, BLUE_FG,\
donation_more_message, BitcoinAmountEdit, JMIntValidator,\ donation_more_message, BitcoinAmountEdit, JMIntValidator,\
ReceiveBIP78Dialog, QRCodePopup ReceiveBIP78Dialog, QRCodePopup
@ -2332,29 +2332,8 @@ class JMMainWindow(QMainWindow):
title="Error")) title="Error"))
async def getPassword(self) -> str: async def getPassword(self) -> str:
pd = PasswordDialog() self.textpassword = textpassword = await JMPasswordDialog(parent=self)
while True: return textpassword.encode('utf-8') if textpassword else textpassword
for child in pd.findChildren(QLineEdit):
child.clear()
pd.findChild(QLineEdit).setFocus()
pd_return = pd.exec_()
if pd_return == QDialog.Rejected:
return None
elif pd.new_pw.text() != pd.conf_pw.text():
await JMQtMessageBox(self,
"Passphrases don't match.",
mbtype='warn',
title="Error")
continue
elif pd.new_pw.text() == "":
await JMQtMessageBox(self,
"Passphrase must not be empty.",
mbtype='warn',
title="Error")
continue
break
self.textpassword = str(pd.new_pw.text())
return self.textpassword.encode('utf-8')
def getWalletFileName(self) -> str: def getWalletFileName(self) -> str:
walletname, ok = QInputDialog.getText(self, 'Choose wallet name', walletname, ok = QInputDialog.getText(self, 'Choose wallet name',
@ -2383,10 +2362,14 @@ class JMMainWindow(QMainWindow):
self, seed_recovery_warning, mbtype='info', self, seed_recovery_warning, mbtype='info',
title='Show wallet seed phrase', informative_text=text)) title='Show wallet seed phrase', informative_text=text))
def promptUseMnemonicExtension(self) -> bool: async def promptUseMnemonicExtension(self) -> bool:
msg = "Would you like to use a two-factor mnemonic recovery phrase?\nIf you don\'t know what this is press No." msg = ("Would you like to use a two-factor mnemonic recovery "
reply = QMessageBox.question(self, 'Use mnemonic extension?', "phrase?\nIf you don\'t know what this is press No.")
reply = JMQtMessageBox.question(self, 'Use mnemonic extension?',
msg, QMessageBox.Yes, QMessageBox.No) msg, QMessageBox.Yes, QMessageBox.No)
reply = await JMQtMessageBox(
self, msg, title='Use mnemonic extension?',
mbtype='question')
return reply == QMessageBox.Yes return reply == QMessageBox.Yes
def promptInputMnemonicExtension(self) -> Optional[str]: def promptInputMnemonicExtension(self) -> Optional[str]:

54
scripts/qtsupport.py

@ -153,12 +153,12 @@ async def JMQtMessageBox(parent, msg, mbtype='info', title='',
detailed_text=None, informative_text=None, detailed_text=None, informative_text=None,
finished_cb=None): finished_cb=None):
title = "JoinmarketQt - " + title title = "JoinmarketQt - " + title
result_fut = asyncio.get_event_loop().create_future()
class JMQtDMessageBox(QMessageBox): class JMQtDMessageBox(QMessageBox):
def __init__(self, parent): def __init__(self, parent):
QMessageBox.__init__(self, parent=parent) QMessageBox.__init__(self, parent=parent)
self.result_fut = asyncio.get_event_loop().create_future()
self.setSizeGripEnabled(True) self.setSizeGripEnabled(True)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.layout().setSizeConstraint(QLayout.SetMaximumSize) self.layout().setSizeConstraint(QLayout.SetMaximumSize)
@ -184,7 +184,11 @@ async def JMQtMessageBox(parent, msg, mbtype='info', title='',
@QtCore.Slot(QMessageBox.StandardButton) @QtCore.Slot(QMessageBox.StandardButton)
def on_finished(self, button): def on_finished(self, button):
result_fut.set_result(button) self.result_fut.set_result(button)
async def result(self):
await self.result_fut
return self.result_fut.result()
mb = JMQtDMessageBox(parent) mb = JMQtDMessageBox(parent)
if mbtype == 'question': if mbtype == 'question':
@ -210,7 +214,7 @@ async def JMQtMessageBox(parent, msg, mbtype='info', title='',
mb.setDefaultButton(QMessageBox.NoButton) mb.setDefaultButton(QMessageBox.NoButton)
mb.finished.connect(mb.on_finished) mb.finished.connect(mb.on_finished)
mb.open() mb.open()
result = await result_fut result = await mb.result()
if finished_cb is not None: if finished_cb is not None:
finished_cb(result) finished_cb(result)
return result return result
@ -391,18 +395,56 @@ def make_password_dialog(self, msg):
return vbox return vbox
class PasswordDialog(QDialog): async def JMPasswordDialog(parent):
def __init__(self): class PasswordDialog(QDialog):
super().__init__()
def __init__(self, parent=None):
super().__init__(parent=parent)
self.result_fut = asyncio.get_event_loop().create_future()
self.initUI() self.initUI()
def initUI(self): def initUI(self):
self.setWindowTitle('Create a new passphrase') self.setWindowTitle('Create a new passphrase')
msg = "Enter a new passphrase" msg = "Enter a new passphrase"
self.setLayout(make_password_dialog(self, msg)) self.setLayout(make_password_dialog(self, msg))
self.show() self.show()
@QtCore.Slot(QMessageBox.StandardButton)
def on_finished(self, result):
self.result_fut.set_result(result)
async def result(self):
await self.result_fut
return self.result_fut.result()
while True:
pd = PasswordDialog(parent=parent)
pd.finished.connect(pd.on_finished)
for child in pd.findChildren(QLineEdit):
child.clear()
pd.findChild(QLineEdit).setFocus()
pd.open()
pd_return = await pd.result()
if pd_return == QDialog.Rejected:
return None
elif pd.new_pw.text() != pd.conf_pw.text():
await JMQtMessageBox(parent,
"Passphrases don't match.",
mbtype='warn',
title="Error")
continue
elif pd.new_pw.text() == "":
await JMQtMessageBox(parent,
"Passphrase must not be empty.",
mbtype='warn',
title="Error")
continue
break
textpassword = str(pd.new_pw.text())
return textpassword
class MyTreeWidget(QTreeWidget): class MyTreeWidget(QTreeWidget):

Loading…
Cancel
Save