From a4e79a2a59b61b2e544878d2570afd38d2da0959 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 6 Mar 2019 20:53:44 +0530 Subject: [PATCH] EPUB/MOBI Catalogs: Fix presets not saving title and format information. Fixes #1818838 [Catalog Json file don't store Title and Format](https://bugs.launchpad.net/calibre/+bug/1818838) --- src/calibre/gui2/catalog/catalog_epub_mobi.py | 37 +++++++------------ src/calibre/gui2/dialogs/catalog.py | 3 +- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/calibre/gui2/catalog/catalog_epub_mobi.py b/src/calibre/gui2/catalog/catalog_epub_mobi.py index d067647ab7..d2b80a416f 100644 --- a/src/calibre/gui2/catalog/catalog_epub_mobi.py +++ b/src/calibre/gui2/catalog/catalog_epub_mobi.py @@ -45,6 +45,7 @@ class PluginWidget(QWidget,Ui_Form): self.setupUi(self) self._initControlArrays() self.blocking_all_signals = None + self.parent_ref = lambda: None def _initControlArrays(self): # Default values for controls @@ -283,17 +284,10 @@ class PluginWidget(QWidget,Ui_Form): def get_format_and_title(self): current_format = None current_title = None - self.parentWidget().blockSignals(True) - for peer in self.parentWidget().children(): - if peer == self: - continue - elif peer.children(): - for child in peer.children(): - if child.objectName() == 'format': - current_format = child.currentText().strip() - elif child.objectName() == 'title': - current_title = unicode(child.text()).strip() - self.parentWidget().blockSignals(False) + parent = self.parent_ref() + if parent is not None: + current_title = parent.title.text().strip() + current_format = parent.format.currentText().strip() return current_format, current_title def header_note_source_field_changed(self,new_index): @@ -795,18 +789,15 @@ class PluginWidget(QWidget,Ui_Form): self.preset_field.setCurrentIndex(self.preset_field.findText(name)) def set_format_and_title(self, format, title): - for peer in self.parentWidget().children(): - if peer == self: - continue - elif peer.children(): - for child in peer.children(): - if child.objectName() == 'format': - index = child.findText(format) - child.blockSignals(True) - child.setCurrentIndex(index) - child.blockSignals(False) - elif child.objectName() == 'title': - child.setText(title) + parent = self.parent_ref() + if parent is not None: + if format: + index = parent.format.findText(format) + parent.format.blockSignals(True) + parent.format.setCurrentIndex(index) + parent.format.blockSignals(False) + if title: + parent.title.setText(title) def settings_changed(self, source): ''' diff --git a/src/calibre/gui2/dialogs/catalog.py b/src/calibre/gui2/dialogs/catalog.py index 99a7d32a28..05b3fce85a 100644 --- a/src/calibre/gui2/dialogs/catalog.py +++ b/src/calibre/gui2/dialogs/catalog.py @@ -6,7 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os, sys, importlib +import os, sys, importlib, weakref from PyQt5.Qt import QDialog, QCoreApplication, QSize, QScrollArea @@ -47,6 +47,7 @@ class Catalog(QDialog, Ui_Dialog): try: catalog_widget = importlib.import_module('calibre.gui2.catalog.'+name) pw = catalog_widget.PluginWidget() + pw.parent_ref = weakref.ref(self) pw.initialize(name, db) pw.ICON = I('forward.png') self.widgets.append(pw)