-
Notifications
You must be signed in to change notification settings - Fork 34
/
config.py
80 lines (61 loc) · 3.12 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from __future__ import unicode_literals, division, absolute_import, print_function
__license__ = 'GPL v3'
__copyright__ = '2011, Grant Drake'
from collections import OrderedDict
try:
from qt.core import QLabel, QVBoxLayout, Qt, QGroupBox, QHBoxLayout, QCheckBox
except ImportError:
from PyQt5.Qt import QLabel, QVBoxLayout, Qt, QGroupBox, QHBoxLayout, QCheckBox
try:
load_translations()
except NameError:
pass # load_translations() added in calibre 1.9
from calibre.gui2.metadata.config import ConfigWidget as DefaultConfigWidget
from calibre.utils.config import JSONConfig
from calibre_plugins.fantastic_fiction.common_widgets import KeyValueComboBox
STORE_NAME = 'Options'
KEY_GENRE_ACTION = 'genreAction'
KEY_REDUCE_HEADINGS = 'reduceHeadings'
DEFAULT_STORE_VALUES = {
KEY_GENRE_ACTION: 'DISCARD',
KEY_REDUCE_HEADINGS: False
}
GENRE_TYPES = OrderedDict([
('DISCARD', 'Discard genre from comments'),
('TAGS', 'Move genre into Tags column'),
('KEEP', 'Keep genre in comments')
])
# This is where all preferences for this plugin will be stored
plugin_prefs = JSONConfig('plugins/Fantastic Fiction')
# Set defaults
plugin_prefs.defaults[STORE_NAME] = DEFAULT_STORE_VALUES
class ConfigWidget(DefaultConfigWidget):
def __init__(self, plugin):
DefaultConfigWidget.__init__(self, plugin)
c = plugin_prefs[STORE_NAME]
options_group_box = QGroupBox(_('Other Options'), self)
self.l.addWidget(options_group_box, self.l.rowCount(), 0, 1, 2)
options_group_box_layout = QVBoxLayout()
options_group_box.setLayout(options_group_box_layout)
genre_layout = QHBoxLayout()
options_group_box_layout.addLayout(genre_layout)
genre_label = QLabel(_('If genre found in comments:'), self)
genre_label.setToolTip(_('A subset (at this time) of the books in Fantastic Fiction\n'
'contain a hyperlinked Genre at the bottom of the comments.'))
genre_layout.addWidget(genre_label)
self.genreCombo = KeyValueComboBox(self, GENRE_TYPES, c.get(KEY_GENRE_ACTION, 'KEEP'))
genre_layout.addWidget(self.genreCombo)
self.headings_checkbox = QCheckBox(_('Reduce header sizes in comments'), self)
self.headings_checkbox.setToolTip(_('For some books the website book description uses larger heading\n'
'tags that look out of place inside a calibre library.\n'
'Enabling this option reduces those header tags in size values'))
options_group_box_layout.addWidget(self.headings_checkbox)
reduce_headings = c.get(KEY_REDUCE_HEADINGS, False)
self.headings_checkbox.setChecked(reduce_headings)
options_group_box_layout.addStretch(1)
def commit(self):
DefaultConfigWidget.commit(self)
new_prefs = {}
new_prefs[KEY_GENRE_ACTION] = self.genreCombo.selected_key()
new_prefs[KEY_REDUCE_HEADINGS] = self.headings_checkbox.checkState() == Qt.Checked
plugin_prefs[STORE_NAME] = new_prefs