mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
If there is both an attribute validate_before_accept=True and a method validate() in the config_widget then calll validate() when the config dialog OK button is pressed.
This commit is contained in:
parent
ff4e978ce5
commit
d4fdd34d74
@ -149,17 +149,35 @@ class Plugin: # {{{
|
||||
|
||||
from calibre.gui2 import gprefs
|
||||
|
||||
class ConfigDialog(QDialog):
|
||||
|
||||
def __init__(self, parent, config_widget):
|
||||
super().__init__(parent)
|
||||
self.config_widget = config_widget
|
||||
|
||||
def accept(self):
|
||||
print('in accept')
|
||||
if ((validate := getattr(self.config_widget, 'validate', None)) and
|
||||
getattr(self.config_widget, 'validate_before_accept', False)):
|
||||
print('have validate and validate_before_accept')
|
||||
if not validate():
|
||||
return
|
||||
print('accepting')
|
||||
super().accept()
|
||||
|
||||
try:
|
||||
config_widget = self.config_widget()
|
||||
except NotImplementedError:
|
||||
config_widget = None
|
||||
|
||||
prefname = 'plugin config dialog:'+self.type + ':' + self.name
|
||||
config_dialog = QDialog(parent)
|
||||
|
||||
config_dialog = ConfigDialog(parent, config_widget)
|
||||
button_box = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
|
||||
v = QVBoxLayout(config_dialog)
|
||||
button_box.accepted.connect(config_dialog.accept)
|
||||
button_box.rejected.connect(config_dialog.reject)
|
||||
config_dialog.setWindowTitle(_('Customize') + ' ' + self.name)
|
||||
try:
|
||||
config_widget = self.config_widget()
|
||||
except NotImplementedError:
|
||||
config_widget = None
|
||||
|
||||
if isinstance(config_widget, tuple):
|
||||
from calibre.gui2 import warning_dialog
|
||||
|
@ -54,11 +54,13 @@ class KOBOTOUCHConfig(TabbedDeviceConfig):
|
||||
|
||||
def __init__(self, device_settings, all_formats, supports_subdirs,
|
||||
must_read_metadata, supports_use_author_sort,
|
||||
extra_customization_message, device, extra_customization_choices=None, parent=None):
|
||||
extra_customization_message, device, extra_customization_choices=None,
|
||||
parent=None):
|
||||
|
||||
super().__init__(device_settings, all_formats, supports_subdirs,
|
||||
must_read_metadata, supports_use_author_sort,
|
||||
extra_customization_message, device, extra_customization_choices, parent)
|
||||
extra_customization_message, device, extra_customization_choices, parent,
|
||||
validate_before_accept=True)
|
||||
|
||||
self.device_settings = device_settings
|
||||
self.all_formats = all_formats
|
||||
@ -570,7 +572,6 @@ class CollectionsGroupBox(DeviceOptionsGroupBox):
|
||||
self.use_collections_template_checkbox.clicked.connect(self.use_collections_template_checkbox_clicked)
|
||||
self.use_collections_columns_checkbox_clicked(device.get_pref('use_collections_columns'))
|
||||
self.use_collections_template_checkbox_clicked(device.get_pref('use_collections_template'))
|
||||
self.collections_columns_edit.editingFinished.connect(self.validate_collections_columns)
|
||||
|
||||
def validate(self):
|
||||
v = self.validate_collections_columns()
|
||||
@ -590,7 +591,6 @@ class CollectionsGroupBox(DeviceOptionsGroupBox):
|
||||
error_dialog(self, _('Kobo configuration: Invalid collection column names'),
|
||||
'<p>'+_("Collection column names that don't exist in the library: {0}").format(s),
|
||||
show=True)
|
||||
self.collections_columns_edit.setFocus(Qt.FocusReason.OtherFocusReason)
|
||||
return False
|
||||
return True
|
||||
|
||||
|
@ -63,15 +63,19 @@ class TabbedDeviceConfig(QTabWidget):
|
||||
DeviceConfigTab, for each set of options. Within the tabs, group boxes, subclassed
|
||||
from DeviceOptionsGroupBox, are created to further group the options. The group
|
||||
boxes can be coded to support any control type and dependencies between them.
|
||||
|
||||
Set validate_before_accept to True if you want validation() to be called
|
||||
when OK is pressed
|
||||
'''
|
||||
|
||||
def __init__(self, device_settings, all_formats, supports_subdirs,
|
||||
must_read_metadata, supports_use_author_sort,
|
||||
extra_customization_message, device,
|
||||
extra_customization_choices=None, parent=None):
|
||||
extra_customization_choices=None, parent=None, validate_before_accept = False):
|
||||
QTabWidget.__init__(self, parent)
|
||||
self._device = weakref.ref(device)
|
||||
|
||||
self.validate_before_accept = validate_before_accept
|
||||
self.device_settings = device_settings
|
||||
self.all_formats = set(all_formats)
|
||||
self.supports_subdirs = supports_subdirs
|
||||
|
Loading…
x
Reference in New Issue
Block a user