From 062b7b177bfd29fd52f547243514e754ec0dd8b0 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Wed, 4 Jun 2014 06:42:57 +0200 Subject: [PATCH] Simplify setting value completion models. --- qutebrowser/models/completion.py | 10 ++++------ qutebrowser/utils/completer.py | 27 +++++++-------------------- 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/qutebrowser/models/completion.py b/qutebrowser/models/completion.py index ce0f9ff26..ffc3340d2 100644 --- a/qutebrowser/models/completion.py +++ b/qutebrowser/models/completion.py @@ -91,19 +91,17 @@ class SettingValueCompletionModel(BaseCompletionModel): super().__init__(parent) if hasattr(configdata.DATA[section], 'valtype'): # Same type for all values (ValueList) - cat = self.new_category(section) vals = configdata.DATA[section].valtype.complete() else: if option is None: raise ValueError("option may only be None for ValueList " "sections, but {} is not!".format(section)) # Different type for each value (KeyValue) - cat = self.new_category(option) vals = configdata.DATA[section][option].typ.complete() - if vals is None: - raise NoCompletionsError - for (val, desc) in vals: - self.new_item(cat, val, desc) + if vals is not None: + cat = self.new_category(section) + for (val, desc) in vals: + self.new_item(cat, val, desc) class CommandCompletionModel(BaseCompletionModel): diff --git a/qutebrowser/utils/completer.py b/qutebrowser/utils/completer.py index 42f8f6c40..439458420 100644 --- a/qutebrowser/utils/completer.py +++ b/qutebrowser/utils/completer.py @@ -73,26 +73,13 @@ class Completer(QObject): self._models['option'] = {} self._models['value'] = {} for sectname, sect in configdata.DATA.items(): - optmodel = CFM(SettingOptionCompletionModel(sectname, self)) - self._models['option'][sectname] = optmodel - config.instance().changed.connect( - optmodel.srcmodel.on_config_changed) - if hasattr(sect, 'valtype'): - # Same type for all values (ValueList) - try: - model = CFM(SettingValueCompletionModel( - sectname, parent=self)) - self._models['value'][sectname] = FakeDict(model) - except NoCompletionsError: - pass - else: - self._models['value'][sectname] = {} - for opt in configdata.DATA[sectname].keys(): - try: - self._models['value'][sectname][opt] = CFM( - SettingValueCompletionModel(sectname, opt, self)) - except NoCompletionsError: - pass + model = SettingOptionCompletionModel(sectname, self) + self._models['option'][sectname] = CFM(model) + config.instance().changed.connect(model.on_config_changed) + self._models['value'][sectname] = {} + for opt in configdata.DATA[sectname].keys(): + model = SettingValueCompletionModel(sectname, opt, self) + self._models['value'][sectname][opt] = CFM(model) def _get_new_completion(self, parts, cursor_part): """Get a new completion model.