First new preference widget tested and working

This commit is contained in:
Kovid Goyal 2010-09-02 17:19:42 -06:00
parent adcf9e2f16
commit 60306d1c90
4 changed files with 17 additions and 9 deletions

View File

@ -391,6 +391,8 @@ class PreferencesPlugin(Plugin): # {{{
#: The category this plugin should be in #: The category this plugin should be in
category = None category = None
#: The category name displayed to the user for this plugin
gui_category = None
#: The name displayed to the user for this plugin #: The name displayed to the user for this plugin
gui_name = None gui_name = None

View File

@ -679,7 +679,8 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
class LookAndFeel(PreferencesPlugin): class LookAndFeel(PreferencesPlugin):
name = 'Look & Feel' name = 'Look & Feel'
gui_name = _('Look and Feel') gui_name = _('Look and Feel')
category = _('Interface') category = 'Interface'
gui_category = _('Interface')
category_order = 1 category_order = 1
name_order = 1 name_order = 1
config_widget = 'calibre.gui2.preferences.look_feel' config_widget = 'calibre.gui2.preferences.look_feel'

View File

@ -58,7 +58,7 @@ class Setting(object):
def initialize(self): def initialize(self):
self.gui_obj.blockSignals(True) self.gui_obj.blockSignals(True)
if self.datatype == 'choices': if self.datatype == 'choice':
self.gui_obj.clear() self.gui_obj.clear()
for x in self.choices: for x in self.choices:
if isinstance(x, basestring): if isinstance(x, basestring):
@ -90,7 +90,7 @@ class Setting(object):
self.gui_obj.setValue(val) self.gui_obj.setValue(val)
elif self.datatype == 'string': elif self.datatype == 'string':
self.gui_obj.setText(val if val else '') self.gui_obj.setText(val if val else '')
elif self.datatype == 'choices': elif self.datatype == 'choice':
idx = self.gui_obj.findData(QVariant(val)) idx = self.gui_obj.findData(QVariant(val))
if idx == -1: if idx == -1:
idx = 0 idx = 0
@ -100,12 +100,12 @@ class Setting(object):
if self.datatype == 'bool': if self.datatype == 'bool':
val = bool(self.gui_obj.isChecked()) val = bool(self.gui_obj.isChecked())
elif self.datatype == 'number': elif self.datatype == 'number':
val = self.gui_obj.value(val) val = self.gui_obj.value()
elif self.datatype == 'string': elif self.datatype == 'string':
val = unicode(self.gui_name.text()).strip() val = unicode(self.gui_name.text()).strip()
if self.empty_string_is_None and not val: if self.empty_string_is_None and not val:
val = None val = None
elif self.datatype == 'choices': elif self.datatype == 'choice':
idx = self.gui_obj.currentIndex() idx = self.gui_obj.currentIndex()
if idx < 0: idx = 0 if idx < 0: idx = 0
val = unicode(self.gui_obj.itemData(idx).toString()) val = unicode(self.gui_obj.itemData(idx).toString())
@ -135,7 +135,7 @@ class ConfigWidgetBase(QWidget, ConfigWidgetInterface):
for setting in self.settings.values(): for setting in self.settings.values():
setting.initialize() setting.initialize()
def commit(self): def commit(self, *args):
for setting in self.settings.values(): for setting in self.settings.values():
setting.commit() setting.commit()
@ -165,11 +165,13 @@ def test_widget(category, name, gui=None): # {{{
w = pl.create_widget(d) w = pl.create_widget(d)
bb.button(bb.RestoreDefaults).clicked.connect(w.restore_defaults) bb.button(bb.RestoreDefaults).clicked.connect(w.restore_defaults)
bb.button(bb.Apply).setEnabled(False) bb.button(bb.Apply).setEnabled(False)
w.changed_signal.connect(lambda : bb.button(bb.Apply).setEnable(True)) bb.button(bb.Apply).clicked.connect(d.accept)
w.changed_signal.connect(lambda : bb.button(bb.Apply).setEnabled(True))
l = QVBoxLayout() l = QVBoxLayout()
d.setLayout(l) d.setLayout(l)
l.addWidget(w) l.addWidget(w)
l.addWidget(bb) l.addWidget(bb)
mygui = gui is None
if gui is None: if gui is None:
from calibre.gui2.ui import Main from calibre.gui2.ui import Main
from calibre.gui2.main import option_parser from calibre.gui2.main import option_parser
@ -181,7 +183,10 @@ def test_widget(category, name, gui=None): # {{{
gui = Main(opts) gui = Main(opts)
gui.initialize(db.library_path, db, None, actions, show_gui=False) gui.initialize(db.library_path, db, None, actions, show_gui=False)
w.genesis(gui) w.genesis(gui)
w.initialize()
if d.exec_() == QDialog.Accepted: if d.exec_() == QDialog.Accepted:
w.commit() w.commit()
if mygui:
gui.shutdown()
# }}} # }}}

View File

@ -32,10 +32,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
if l != lang] if l != lang]
if lang != 'en': if lang != 'en':
items.append(('en', get_language('en'))) items.append(('en', get_language('en')))
items.sort(cmp=lambda x, y: cmp(x[1], y[1])) items.sort(cmp=lambda x, y: cmp(x[1].lower(), y[1].lower()))
choices = [(y, x) for x, y in items] choices = [(y, x) for x, y in items]
# Default language is the autodetected one # Default language is the autodetected one
choices = [get_language(lang), lang] + choices choices = [(get_language(lang), lang)] + choices
r('language', prefs, choices=choices) r('language', prefs, choices=choices)
r('show_avg_rating', config) r('show_avg_rating', config)