From 60a22179e9fb844930e38eafbaf060c4b4a92ba0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 29 Oct 2024 07:13:04 +0530 Subject: [PATCH] Linux: ToC Editor: Fix a regression in 7.17 that broke using the Create new entry button. Fixes #2085576 [Book editor crashes when adding new entry in ToC editor](https://bugs.launchpad.net/calibre/+bug/2085576) Apparently as of Qt 6.7 having a webview in a dialog run with exec() breaks. So run the dialog with open() instead. --- src/calibre/gui2/toc/main.py | 18 ++++++++++-------- src/calibre/gui2/tweak_book/boss.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/calibre/gui2/toc/main.py b/src/calibre/gui2/toc/main.py index 6bc94f3dd9..015d2f4289 100644 --- a/src/calibre/gui2/toc/main.py +++ b/src/calibre/gui2/toc/main.py @@ -1194,13 +1194,15 @@ class TOCEditor(QDialog): # {{{ def develop(): - from calibre.utils.webengine import setup_fake_protocol - setup_fake_protocol() from calibre.gui2 import Application app = Application([]) + from calibre.utils.webengine import setup_default_profile, setup_fake_protocol + setup_fake_protocol() + setup_default_profile() d = TOCEditor(sys.argv[-1]) d.start() - d.exec() + d.open() + app.exec() del app @@ -1234,9 +1236,10 @@ def main(shm_name=None): setup_default_profile() d = TOCEditor(path, title=title, write_result_to=path + '.result') d.start() - ok = 0 - if d.exec() == QDialog.DialogCode.Accepted: - ok = 1 + # Using d.exec() causes showing the webview to hide the dialog + d.open() + app.exec() + ok = 1 if d.result() == QDialog.DialogCode.Accepted else 0 s = struct.pack('>II', 2, ok) shm.seek(0), shm.write(s), shm.flush() @@ -1246,5 +1249,4 @@ def main(shm_name=None): if __name__ == '__main__': - main(path=sys.argv[-1], title='test') - os.remove(sys.argv[-1] + '.lock') + develop() diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index ddffe49128..fb644cdd0a 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -630,8 +630,14 @@ class Boss(QObject): if not self.ensure_book(_('You must open a book before trying to edit the Table of Contents.')): return self.add_savepoint(_('Before: Edit Table of Contents')) - d = TOCEditor(title=self.current_metadata.title, parent=self.gui) - if d.exec() != QDialog.DialogCode.Accepted: + self.__current_toc_editor = d = TOCEditor(title=self.current_metadata.title, parent=self.gui) + d.finished.connect(self.toc_edit_finished) + # Using d.exec() causes showing the webview to hide the dialog + d.open() + + def toc_edit_finished(self, retcode: int): + self.__current_toc_editor = None + if retcode != QDialog.DialogCode.Accepted: self.rewind_savepoint() return with BusyCursor():