Browse Source

Qt: make JMQtMessageBox async, fix closeEvent usage

add_frost_channel_encryption
zebra-lucky 2 months ago
parent
commit
847c9216d2
  1. 2
      pyproject.toml
  2. 36
      scripts/joinmarket-qt.py
  3. 104
      scripts/qtsupport.py

2
pyproject.toml

@ -37,7 +37,7 @@ jmdaemon = [
jmfrost = [ jmfrost = [
] ]
jmqtui = [ jmqtui = [
"PySide6==6.9.0", # https://bugreports.qt.io/browse/QTBUG-88688 "PySide6==6.9.3", # https://bugreports.qt.io/browse/QTBUG-88688
"qrcode[pil]==7.3.1", "qrcode[pil]==7.3.1",
'pywin32; platform_system == "Windows"', 'pywin32; platform_system == "Windows"',
"qt5reactor@git+https://github.com/zebra-lucky/qt5reactor@update_versioneer#egg=qt5reactor", "qt5reactor@git+https://github.com/zebra-lucky/qt5reactor@update_versioneer#egg=qt5reactor",

36
scripts/joinmarket-qt.py

@ -1683,24 +1683,38 @@ class JMMainWindow(QMainWindow):
# a flag to indicate that shutdown should not # a flag to indicate that shutdown should not
# depend on user input # depend on user input
self.unconditional_shutdown = False self.unconditional_shutdown = False
self.close_event_confirmed = False
def closeEvent(self, event): def closeEvent(self, event):
if self.unconditional_shutdown:
JMQtMessageBox(self, if self.close_event_confirmed:
"RPC connection is lost; shutting down.",
mbtype='crit',
title="Error")
reply = QMessageBox.Yes
else:
quit_msg = "Are you sure you want to quit?"
reply = JMQtMessageBox(self, quit_msg, mbtype='question')
if reply == QMessageBox.Yes:
event.accept() event.accept()
if self.reactor.threadpool is not None: if self.reactor.threadpool is not None:
self.reactor.threadpool.stop() self.reactor.threadpool.stop()
stop_reactor() stop_reactor()
return
def finished_cb(result):
if result == QMessageBox.Yes:
self.close_event_confirmed = True
self.close()
elif result == QMessageBox.Ok and self.unconditional_shutdown:
self.close_event_confirmed = True
self.close()
if self.unconditional_shutdown:
quit_msg = "RPC connection is lost; shutting down."
asyncio.ensure_future(
JMQtMessageBox(
self, quit_msg, mbtype='crit', title="Error",
finished_cb=finished_cb))
else: else:
event.ignore() quit_msg = "Are you sure you want to quit?"
asyncio.ensure_future(
JMQtMessageBox(
self, quit_msg, mbtype='question',
finished_cb=finished_cb))
event.ignore()
def initUI(self): def initUI(self):
self.statusBar().showMessage("Ready") self.statusBar().showMessage("Ready")

104
scripts/qtsupport.py

@ -148,54 +148,70 @@ donation_more_message = '\n'.join(
'is no change output that can be linked with your inputs later.']) 'is no change output that can be linked with your inputs later.'])
""" """
def JMQtMessageBox(obj, msg, mbtype='info', title='', detailed_text= None):
mbtypes = {'info': QMessageBox.information, async def JMQtMessageBox(parent, msg, mbtype='info', title='',
'crit': QMessageBox.critical, detailed_text=None, finished_cb=None):
'warn': QMessageBox.warning,
'question': QMessageBox.question}
title = "JoinmarketQt - " + title title = "JoinmarketQt - " + title
result_fut = asyncio.get_event_loop().create_future()
class JMQtDMessageBox(QMessageBox, QtCore.QObject):
def __init__(self, parent):
QMessageBox.__init__(self, parent=parent)
self.setSizeGripEnabled(True)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.layout().setSizeConstraint(QLayout.SetMaximumSize)
def resizeEvent(self, event):
self.setMinimumHeight(0)
self.setMaximumHeight(16777215)
self.setMinimumWidth(0)
self.setMaximumWidth(16777215)
result = super().resizeEvent(event)
if detailed_text:
assert mbtype == 'info'
details_box = self.findChild(QTextEdit)
if details_box is not None:
details_box.setMinimumHeight(0)
details_box.setMaximumHeight(16777215)
details_box.setMinimumWidth(0)
details_box.setMaximumWidth(16777215)
details_box.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
return result
@QtCore.Slot(QMessageBox.StandardButton)
def on_finished(self, button):
result_fut.set_result(button)
mb = JMQtDMessageBox(parent)
if mbtype == 'question': if mbtype == 'question':
return QMessageBox.question(obj, title, msg, QMessageBox.Yes, icon = QMessageBox.Question
QMessageBox.No) elif mbtype == 'warn':
icon = QMessageBox.Warning
elif mbtype == 'crit':
icon = QMessageBox.Critical
else: else:
if detailed_text: icon = QMessageBox.Information
assert mbtype == 'info' mb.setIcon(icon)
mb.setWindowTitle(title)
class JMQtDMessageBox(QMessageBox): mb.setText(msg)
def __init__(self): if detailed_text:
QMessageBox.__init__(self) mb.setDetailedText(detailed_text)
self.setSizeGripEnabled(True) if mbtype == 'question':
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) mb.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
self.layout().setSizeConstraint(QLayout.SetMaximumSize) mb.setDefaultButton(QMessageBox.No)
def resizeEvent(self, event): else:
self.setMinimumHeight(0) mb.setStandardButtons(QMessageBox.Ok)
self.setMaximumHeight(16777215) mb.setDefaultButton(QMessageBox.NoButton)
self.setMinimumWidth(0) mb.finished.connect(mb.on_finished)
self.setMaximumWidth(16777215) mb.open()
result = super().resizeEvent(event) result = await result_fut
details_box = self.findChild(QTextEdit) if finished_cb is not None:
if details_box is not None: finished_cb(result)
details_box.setMinimumHeight(0) return result
details_box.setMaximumHeight(16777215)
details_box.setMinimumWidth(0)
details_box.setMaximumWidth(16777215)
details_box.setSizePolicy(QSizePolicy.Expanding,
QSizePolicy.Expanding)
return result
b = JMQtDMessageBox()
b.setIcon(QMessageBox.Information)
b.setWindowTitle(title)
b.setText(msg)
b.setDetailedText(detailed_text)
b.setStandardButtons(QMessageBox.Ok)
b.open(self.message_box_clicked)
else:
mbtypes[mbtype](obj, title, msg)
@QtCore.Slot(QMessageBox.StandardButton)
def message_box_clicked(self, button_id):
print('QMessageBox.StandardButton', button_id)
class QtHandler(logging.Handler): class QtHandler(logging.Handler):

Loading…
Cancel
Save