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)

This commit is contained in:
Kovid Goyal 2019-03-06 20:53:44 +05:30
parent 24a9ebd3af
commit a4e79a2a59
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 16 additions and 24 deletions

View File

@ -45,6 +45,7 @@ class PluginWidget(QWidget,Ui_Form):
self.setupUi(self) self.setupUi(self)
self._initControlArrays() self._initControlArrays()
self.blocking_all_signals = None self.blocking_all_signals = None
self.parent_ref = lambda: None
def _initControlArrays(self): def _initControlArrays(self):
# Default values for controls # Default values for controls
@ -283,17 +284,10 @@ class PluginWidget(QWidget,Ui_Form):
def get_format_and_title(self): def get_format_and_title(self):
current_format = None current_format = None
current_title = None current_title = None
self.parentWidget().blockSignals(True) parent = self.parent_ref()
for peer in self.parentWidget().children(): if parent is not None:
if peer == self: current_title = parent.title.text().strip()
continue current_format = parent.format.currentText().strip()
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)
return current_format, current_title return current_format, current_title
def header_note_source_field_changed(self,new_index): 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)) self.preset_field.setCurrentIndex(self.preset_field.findText(name))
def set_format_and_title(self, format, title): def set_format_and_title(self, format, title):
for peer in self.parentWidget().children(): parent = self.parent_ref()
if peer == self: if parent is not None:
continue if format:
elif peer.children(): index = parent.format.findText(format)
for child in peer.children(): parent.format.blockSignals(True)
if child.objectName() == 'format': parent.format.setCurrentIndex(index)
index = child.findText(format) parent.format.blockSignals(False)
child.blockSignals(True) if title:
child.setCurrentIndex(index) parent.title.setText(title)
child.blockSignals(False)
elif child.objectName() == 'title':
child.setText(title)
def settings_changed(self, source): def settings_changed(self, source):
''' '''

View File

@ -6,7 +6,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import os, sys, importlib import os, sys, importlib, weakref
from PyQt5.Qt import QDialog, QCoreApplication, QSize, QScrollArea from PyQt5.Qt import QDialog, QCoreApplication, QSize, QScrollArea
@ -47,6 +47,7 @@ class Catalog(QDialog, Ui_Dialog):
try: try:
catalog_widget = importlib.import_module('calibre.gui2.catalog.'+name) catalog_widget = importlib.import_module('calibre.gui2.catalog.'+name)
pw = catalog_widget.PluginWidget() pw = catalog_widget.PluginWidget()
pw.parent_ref = weakref.ref(self)
pw.initialize(name, db) pw.initialize(name, db)
pw.ICON = I('forward.png') pw.ICON = I('forward.png')
self.widgets.append(pw) self.widgets.append(pw)