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. 34
      scripts/joinmarket-qt.py
  3. 66
      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",

34
scripts/joinmarket-qt.py

@ -1683,23 +1683,37 @@ 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:
quit_msg = "Are you sure you want to quit?"
asyncio.ensure_future(
JMQtMessageBox(
self, quit_msg, mbtype='question',
finished_cb=finished_cb))
event.ignore() event.ignore()
def initUI(self): def initUI(self):

66
scripts/qtsupport.py

@ -148,31 +148,29 @@ 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
if mbtype == 'question': result_fut = asyncio.get_event_loop().create_future()
return QMessageBox.question(obj, title, msg, QMessageBox.Yes,
QMessageBox.No)
else:
if detailed_text:
assert mbtype == 'info'
class JMQtDMessageBox(QMessageBox): class JMQtDMessageBox(QMessageBox, QtCore.QObject):
def __init__(self):
QMessageBox.__init__(self) def __init__(self, parent):
QMessageBox.__init__(self, parent=parent)
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)
def resizeEvent(self, event): def resizeEvent(self, event):
self.setMinimumHeight(0) self.setMinimumHeight(0)
self.setMaximumHeight(16777215) self.setMaximumHeight(16777215)
self.setMinimumWidth(0) self.setMinimumWidth(0)
self.setMaximumWidth(16777215) self.setMaximumWidth(16777215)
result = super().resizeEvent(event) result = super().resizeEvent(event)
if detailed_text:
assert mbtype == 'info'
details_box = self.findChild(QTextEdit) details_box = self.findChild(QTextEdit)
if details_box is not None: if details_box is not None:
details_box.setMinimumHeight(0) details_box.setMinimumHeight(0)
@ -183,19 +181,37 @@ def JMQtMessageBox(obj, msg, mbtype='info', title='', detailed_text= None):
QSizePolicy.Expanding) QSizePolicy.Expanding)
return result return result
b = JMQtDMessageBox() @QtCore.Slot(QMessageBox.StandardButton)
b.setIcon(QMessageBox.Information) def on_finished(self, button):
b.setWindowTitle(title) result_fut.set_result(button)
b.setText(msg)
b.setDetailedText(detailed_text) mb = JMQtDMessageBox(parent)
b.setStandardButtons(QMessageBox.Ok) if mbtype == 'question':
b.open(self.message_box_clicked) icon = QMessageBox.Question
elif mbtype == 'warn':
icon = QMessageBox.Warning
elif mbtype == 'crit':
icon = QMessageBox.Critical
else: else:
mbtypes[mbtype](obj, title, msg) icon = QMessageBox.Information
mb.setIcon(icon)
mb.setWindowTitle(title)
mb.setText(msg)
if detailed_text:
mb.setDetailedText(detailed_text)
if mbtype == 'question':
mb.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
mb.setDefaultButton(QMessageBox.No)
else:
mb.setStandardButtons(QMessageBox.Ok)
mb.setDefaultButton(QMessageBox.NoButton)
mb.finished.connect(mb.on_finished)
mb.open()
result = await result_fut
if finished_cb is not None:
finished_cb(result)
return result
@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