qutebrowser/qutebrowser/models/settingcompletion.py
2014-04-22 15:19:01 +02:00

70 lines
2.4 KiB
Python

# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""CompletionModels for settings/sections."""
from qutebrowser.models.completion import CompletionModel, NoCompletionsError
import qutebrowser.config.configdata as configdata
class SettingSectionCompletionModel(CompletionModel):
"""A CompletionModel filled with settings sections."""
# pylint: disable=abstract-method
def __init__(self, parent=None):
super().__init__(parent)
cat = self.new_category("Config sections")
for name in configdata.DATA.keys():
desc = configdata.SECTION_DESC[name].splitlines()[0].strip()
self.new_item(cat, name, desc)
class SettingOptionCompletionModel(CompletionModel):
"""A CompletionModel filled with settings and their descriptions."""
# pylint: disable=abstract-method
def __init__(self, section, parent=None):
super().__init__(parent)
cat = self.new_category("Config options for {}".format(section))
sectdata = configdata.DATA[section]
for name, _ in sectdata.items():
try:
desc = sectdata.descriptions[name]
except (KeyError, AttributeError):
desc = ""
self.new_item(cat, name, desc)
class SettingValueCompletionModel(CompletionModel):
"""A CompletionModel filled with setting values."""
# pylint: disable=abstract-method
def __init__(self, section, option, parent=None):
super().__init__(parent)
cat = self.new_category("Setting values for {}".format(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)