Browse Source

Qt: fix async JMQtMessageBox usage part4

add_frost_channel_encryption
zebra-lucky 2 months ago
parent
commit
3f8a9755ed
  1. 94
      scripts/joinmarket-qt.py
  2. 10
      scripts/qtsupport.py

94
scripts/joinmarket-qt.py

@ -1797,9 +1797,6 @@ class JMMainWindow(QMainWindow):
aboutMenu = menubar.addMenu('&About') aboutMenu = menubar.addMenu('&About')
aboutMenu.addAction(aboutAction) aboutMenu.addAction(aboutAction)
self.show()
def receiver_bip78_init(self): def receiver_bip78_init(self):
""" Initializes BIP78 workflow with modal dialog. """ Initializes BIP78 workflow with modal dialog.
""" """
@ -2260,7 +2257,7 @@ class JMMainWindow(QMainWindow):
async def generateWallet(self): async def generateWallet(self):
log.debug('generating wallet') log.debug('generating wallet')
if jm_single().config.get("BLOCKCHAIN", "blockchain_source") == "regtest": if jm_single().config.get("BLOCKCHAIN", "blockchain_source") == "regtest":
seed = self.getTestnetSeed() seed = await self.getTestnetSeed()
await self.selectWallet(testnet_seed=seed) await self.selectWallet(testnet_seed=seed)
else: else:
await self.initWallet() await self.initWallet()
@ -2281,32 +2278,30 @@ class JMMainWindow(QMainWindow):
mbtype='warn', title="Error")) mbtype='warn', title="Error"))
return True return True
def changePassphrase(self): async def changePassphrase(self):
if not self.wallet_service: if not self.wallet_service:
asyncio.ensure_future( await JMQtMessageBox(
JMQtMessageBox( self, "Cannot change passphrase without loaded wallet.",
self, "Cannot change passphrase without loaded wallet.", mbtype="crit", title="Error")
mbtype="crit", title="Error"))
return return
if not (self.checkPassphrase() change_res = False
and wallet_change_passphrase(self.wallet_service, self.getPassword)): check_res = self.checkPassphrase()
asyncio.ensure_future( if check_res:
JMQtMessageBox(self, "Failed to change passphrase.", change_res = await wallet_change_passphrase(
title="Error", mbtype="warn")) self.wallet_service, self.getPassword)
if not check_res or not change_res:
await JMQtMessageBox(self, "Failed to change passphrase.",
title="Error", mbtype="warn")
return return
asyncio.ensure_future( await JMQtMessageBox(self, "Passphrase changed successfully.",
JMQtMessageBox(self, "Passphrase changed successfully.", title="Passphrase changed")
title="Passphrase changed"))
def getTestnetSeed(self): async def getTestnetSeed(self):
text, ok = QInputDialog.getText( text, ok = QInputDialog.getText(
self, 'Testnet seed', 'Enter a 32 char hex string as seed:') self, 'Testnet seed', 'Enter a 32 char hex string as seed:')
if not ok or not text: if not ok or not text:
asyncio.ensure_future( await JMQtMessageBox(self, "No seed entered, aborting",
JMQtMessageBox(self, mbtype='warn', title="Error")
"No seed entered, aborting",
mbtype='warn',
title="Error"))
return return
return str(text).strip() return str(text).strip()
@ -2327,7 +2322,7 @@ class JMMainWindow(QMainWindow):
mbtype='info', mbtype='info',
title="Error")) title="Error"))
def getPassword(self) -> str: async def getPassword(self) -> str:
pd = PasswordDialog() pd = PasswordDialog()
while True: while True:
for child in pd.findChildren(QLineEdit): for child in pd.findChildren(QLineEdit):
@ -2337,16 +2332,16 @@ class JMMainWindow(QMainWindow):
if pd_return == QDialog.Rejected: if pd_return == QDialog.Rejected:
return None return None
elif pd.new_pw.text() != pd.conf_pw.text(): elif pd.new_pw.text() != pd.conf_pw.text():
JMQtMessageBox(self, await JMQtMessageBox(self,
"Passphrases don't match.", "Passphrases don't match.",
mbtype='warn', mbtype='warn',
title="Error") title="Error")
continue continue
elif pd.new_pw.text() == "": elif pd.new_pw.text() == "":
JMQtMessageBox(self, await JMQtMessageBox(self,
"Passphrase must not be empty.", "Passphrase must not be empty.",
mbtype='warn', mbtype='warn',
title="Error") title="Error")
continue continue
break break
self.textpassword = str(pd.new_pw.text()) self.textpassword = str(pd.new_pw.text())
@ -2357,7 +2352,8 @@ class JMMainWindow(QMainWindow):
'Enter wallet file name:', 'Enter wallet file name:',
QLineEdit.Normal, "wallet.jmdat") QLineEdit.Normal, "wallet.jmdat")
if not ok: if not ok:
JMQtMessageBox(self, "Create wallet aborted", mbtype='warn') asyncio.ensure_future(
JMQtMessageBox(self, "Create wallet aborted", mbtype='warn'))
# cannot use None for a 'fail' condition, as this is used # cannot use None for a 'fail' condition, as this is used
# for the case where the default wallet name is to be used in non-Qt. # for the case where the default wallet name is to be used in non-Qt.
return "cancelled" return "cancelled"
@ -2413,15 +2409,17 @@ class JMMainWindow(QMainWindow):
enter_do_support_fidelity_bonds=lambda: False) enter_do_support_fidelity_bonds=lambda: False)
if not success: if not success:
JMQtMessageBox(self, "Failed to create new wallet file.", await JMQtMessageBox(self,
title="Error", mbtype="warn") "Failed to create new wallet file.",
title="Error", mbtype="warn")
return return
except Exception as e: except Exception as e:
JMQtMessageBox(self, e.args[0], title="Error", mbtype="warn") await JMQtMessageBox(self, e.args[0],
title="Error", mbtype="warn")
return return
JMQtMessageBox(self, 'Wallet saved to ' + self.walletname, await JMQtMessageBox(self, 'Wallet saved to ' + self.walletname,
title="Wallet created") title="Wallet created")
await self.loadWalletFromBlockchain( await self.loadWalletFromBlockchain(
self.walletname, pwd=self.textpassword) self.walletname, pwd=self.textpassword)
@ -2498,14 +2496,17 @@ if jm_single().bc_interface is None:
"Go to the 'Settings' tab and configure blockchain settings there."]) "Go to the 'Settings' tab and configure blockchain settings there."])
JMQtMessageBox(None, blockchain_warning, mbtype='warn', JMQtMessageBox(None, blockchain_warning, mbtype='warn',
title='No blockchain source') title='No blockchain source')
#refuse to load non-segwit wallet (needs extra work in wallet-utils).
if not jm_single().config.get("POLICY", "segwit") == "true": async def refuse_if_non_segwit_wallet():
wallet_load_error = ''.join(["Joinmarket-Qt only supports segwit based wallets, ", #refuse to load non-segwit wallet (needs extra work in wallet-utils).
"please edit the config file and remove any setting ", if not jm_single().config.get("POLICY", "segwit") == "true":
"of the field `segwit` in the `POLICY` section."]) wallet_load_error = ''.join([
JMQtMessageBox(None, wallet_load_error, mbtype='crit', "Joinmarket-Qt only supports segwit based wallets, ",
title='Incompatible wallet type') "please edit the config file and remove any setting ",
sys.exit(EXIT_FAILURE) "of the field `segwit` in the `POLICY` section."])
await JMQtMessageBox(None, wallet_load_error, mbtype='crit',
title='Incompatible wallet type')
sys.exit(EXIT_FAILURE)
update_config_for_gui() update_config_for_gui()
@ -2540,6 +2541,7 @@ mainWindow = JMMainWindow(reactor)
async def main(): async def main():
await refuse_if_non_segwit_wallet()
tabWidget = QTabWidget(mainWindow) tabWidget = QTabWidget(mainWindow)
jm_wallet_tab = JMWalletTab() jm_wallet_tab = JMWalletTab()
await jm_wallet_tab.async_initUI() await jm_wallet_tab.async_initUI()

10
scripts/qtsupport.py

@ -860,8 +860,9 @@ class ScheduleWizard(QWizard):
if validate_address(daddrstring)[0]: if validate_address(daddrstring)[0]:
self.destaddrs.append(daddrstring) self.destaddrs.append(daddrstring)
elif daddrstring != "": elif daddrstring != "":
JMQtMessageBox(self, "Error, invalid address", mbtype='crit', asyncio.ensure_future(
title='Error') JMQtMessageBox(self, "Error, invalid address",
mbtype='crit', title='Error'))
return None return None
self.opts = {} self.opts = {}
self.opts['mixdepthcount'] = int(self.field("mixdepthcount")) self.opts['mixdepthcount'] = int(self.field("mixdepthcount"))
@ -960,8 +961,9 @@ class CopyOnClickLineEdit(QLineEdit):
self.selectAll() self.selectAll()
self.copy() self.copy()
if not self.was_copied: if not self.was_copied:
JMQtMessageBox(self, asyncio.ensure_future(
"URI copied to clipboard", mbtype="info") JMQtMessageBox(self,
"URI copied to clipboard", mbtype="info"))
self.was_copied = True self.was_copied = True

Loading…
Cancel
Save