Change configdata from function to attribute

This commit is contained in:
Florian Bruhin 2014-04-16 16:32:14 +02:00
parent bc4a01faf3
commit 57baafbf30
4 changed files with 389 additions and 398 deletions

View File

@ -99,7 +99,7 @@ class Config(QObject):
def __init__(self, configdir, fname, parent=None): def __init__(self, configdir, fname, parent=None):
super().__init__(parent) super().__init__(parent)
self.config = configdata.configdata() self.config = configdata.data
self._configparser = ReadConfigParser(configdir, fname) self._configparser = ReadConfigParser(configdir, fname)
self._configfile = os.path.join(configdir, fname) self._configfile = os.path.join(configdir, fname)
self._wrapper_args = { self._wrapper_args = {

View File

@ -95,9 +95,7 @@ SECTION_DESC = {
} }
def configdata(): data = OrderedDict([
"""Get the config structure as an OrderedDict."""
return OrderedDict([
('general', sect.KeyValue( ('general', sect.KeyValue(
('show_completion', ('show_completion',
SettingValue(types.Bool, "true"), SettingValue(types.Bool, "true"),
@ -118,8 +116,7 @@ def configdata():
('startpage', ('startpage',
SettingValue(types.List, "http://www.duckduckgo.com"), SettingValue(types.List, "http://www.duckduckgo.com"),
"The default page(s) to open at the start, separated with " "The default page(s) to open at the start, separated with commas."),
"commas."),
('auto_search', ('auto_search',
SettingValue(types.AutoSearch, "naive"), SettingValue(types.AutoSearch, "naive"),
@ -127,9 +124,8 @@ def configdata():
"entered."), "entered."),
('zoomlevels', ('zoomlevels',
SettingValue(types.PercList, "25%,33%,50%,67%,75%,90%,100%,110%," SettingValue(types.PercList, "25%,33%,50%,67%,75%,90%,100%,110%,125%,"
"125%,150%,175%,200%,250%,300%,400%," "150%,175%,200%,250%,300%,400%,500%"),
"500%"),
"The available zoom levels, separated by commas."), "The available zoom levels, separated by commas."),
('defaultzoom', ('defaultzoom',
@ -157,8 +153,7 @@ def configdata():
('scrollbuttons', ('scrollbuttons',
SettingValue(types.Bool, "true"), SettingValue(types.Bool, "true"),
"Whether there should be scroll buttons if there are too many " "Whether there should be scroll buttons if there are too many tabs."),
"tabs."),
('position', ('position',
SettingValue(types.Position, "north"), SettingValue(types.Position, "north"),
@ -176,8 +171,7 @@ def configdata():
('webkit', sect.KeyValue( ('webkit', sect.KeyValue(
('auto_load_images', ('auto_load_images',
SettingValue(types.Bool, "true"), SettingValue(types.Bool, "true"),
"Specifies whether images are automatically loaded in web " "Specifies whether images are automatically loaded in web pages."),
"pages."),
('dns_prefetch_enabled', ('dns_prefetch_enabled',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
@ -199,8 +193,8 @@ def configdata():
('private_browsing_enabled', ('private_browsing_enabled',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
"Private browsing prevents WebKit from recording visited pages " "Private browsing prevents WebKit from recording visited pages in "
"in the history and storing web page icons."), "the history and storing web page icons."),
('javascript_can_open_windows', ('javascript_can_open_windows',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
@ -221,10 +215,10 @@ def configdata():
('spatial_navigation_enabled', ('spatial_navigation_enabled',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
"Enables or disables the Spatial Navigation feature, which " "Enables or disables the Spatial Navigation feature, which consists "
"consists in the ability to navigate between focusable elements " "in the ability to navigate between focusable elements in a Web "
"in a Web page, such as hyperlinks and form controls, by using " "page, such as hyperlinks and form controls, by using Left, Right, "
"Left, Right, Up and Down arrow keys."), "Up and Down arrow keys."),
('links_included_in_focus_chain', ('links_included_in_focus_chain',
SettingValue(types.Bool, "true"), SettingValue(types.Bool, "true"),
@ -233,18 +227,18 @@ def configdata():
('zoom_text_only', ('zoom_text_only',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
"Specifies whether the zoom factor on a frame applies only to " "Specifies whether the zoom factor on a frame applies only to the "
"the text or to all content."), "text or to all content."),
('print_element_backgrounds', ('print_element_backgrounds',
SettingValue(types.Bool, "true"), SettingValue(types.Bool, "true"),
"Specifies whether the background color and images are also " "Specifies whether the background color and images are also drawn "
"drawn when the page is printed. "), "when the page is printed. "),
('offline_storage_database_enabled', ('offline_storage_database_enabled',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
"Specifies whether support for the HTML 5 offline storage " "Specifies whether support for the HTML 5 offline storage feature is "
"feature is enabled or not. "), "enabled or not. "),
('offline_web_application_storage_enabled', ('offline_web_application_storage_enabled',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
@ -253,48 +247,47 @@ def configdata():
('local_storage_enabled', ('local_storage_enabled',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
"Specifies whether support for the HTML 5 local storage feature " "Specifies whether support for the HTML 5 local storage feature is "
"is enabled or not."), "enabled or not."),
('local_content_can_access_remote_urls', ('local_content_can_access_remote_urls',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
"Specifies whether locally loaded documents are allowed to " "Specifies whether locally loaded documents are allowed to access "
"access remote urls."), "remote urls."),
('local_content_can_access_file_urls', ('local_content_can_access_file_urls',
SettingValue(types.Bool, "true"), SettingValue(types.Bool, "true"),
"Specifies whether locally loaded documents are allowed to " "Specifies whether locally loaded documents are allowed to access "
"access other local urls."), "other local urls."),
('xss_auditing_enabled', ('xss_auditing_enabled',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
"Specifies whether load requests should be monitored for " "Specifies whether load requests should be monitored for cross-site "
"cross-site scripting attempts. Suspicious scripts will be " "scripting attempts. Suspicious scripts will be blocked and reported "
"blocked and reported in the inspector's JavaScript console. " "in the inspector's JavaScript console. Enabling this feature might "
"Enabling this feature might have an impact on performance."), "have an impact on performance."),
#('accelerated_compositing_enabled', #('accelerated_compositing_enabled',
# SettingValue(types.Bool, "true"), # SettingValue(types.Bool, "true"),
# "This feature, when used in conjunction with QGraphicsWebView, " # "This feature, when used in conjunction with QGraphicsWebView, "
# "accelerates animations of web content. CSS animations of the " # "accelerates animations of web content. CSS animations of the "
# "transform and opacity properties will be rendered by composing " # "transform and opacity properties will be rendered by composing the "
# "the cached content of the animated elements. "), # "cached content of the animated elements. "),
#('tiled_backing_store_enabled', #('tiled_backing_store_enabled',
# SettingValue(types.Bool, "false"), # SettingValue(types.Bool, "false"),
# "This setting enables the tiled backing store feature for a " # "This setting enables the tiled backing store feature for a "
# "QGraphicsWebView. With the tiled backing store enabled, the " # "QGraphicsWebView. With the tiled backing store enabled, the web "
# "web page contents in and around the current visible area is " # "page contents in and around the current visible area is "
# "speculatively cached to bitmap tiles. The tiles are " # "speculatively cached to bitmap tiles. The tiles are automatically "
# "automatically kept in sync with the web page as it changes. " # "kept in sync with the web page as it changes. Enabling tiling can "
# "Enabling tiling can significantly speed up painting heavy " # "significantly speed up painting heavy operations like scrolling. "
# "operations like scrolling. Enabling the feature increases " # "Enabling the feature increases memory consuption."),
# "memory consumption. "),
('frame_flattening_enabled', ('frame_flattening_enabled',
SettingValue(types.Bool, "false"), SettingValue(types.Bool, "false"),
"With this setting each subframe is expanded to its contents. " "With this setting each subframe is expanded to its contents. This "
"This will flatten all the frames to become one scrollable " "will flatten all the frames to become one scrollable "
"page."), "page."),
('site_specific_quirks_enabled', ('site_specific_quirks_enabled',
@ -369,10 +362,8 @@ def configdata():
"Background color of completion widget items."), "Background color of completion widget items."),
('completion.category.bg', ('completion.category.bg',
SettingValue( SettingValue(types.Color, "qlineargradient(x1:0, y1:0, x2:0, y2:1, "
types.Color, "stop:0 #e4e4e4, stop:1 #dbdbdb)"),
"qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #e4e4e4, "
"stop:1 #dbdbdb)"),
"Background color of the completion widget category headers."), "Background color of the completion widget category headers."),
('completion.category.border.top', ('completion.category.border.top',
@ -465,10 +456,10 @@ def configdata():
('fonts', sect.KeyValue( ('fonts', sect.KeyValue(
('_monospace', ('_monospace',
SettingValue(types.Font, 'Monospace, "DejaVu Sans Mono", ' SettingValue(types.Font, 'Monospace, "DejaVu Sans Mono", Consolas, '
'Consolas, Monaco, "Bitstream Vera Sans Mono", ' 'Monaco, "Bitstream Vera Sans Mono", "Andale Mono", '
'"Andale Mono", "Liberation Mono", "Courier New", ' '"Liberation Mono", "Courier New", Courier, monospace, '
'Courier, monospace, Fixed, Terminal'), 'Fixed, Terminal'),
"Default monospace fonts."), "Default monospace fonts."),
('completion', ('completion',
@ -484,4 +475,4 @@ def configdata():
"Font used in the statusbar."), "Font used in the statusbar."),
)), )),
]) ])

View File

@ -18,7 +18,7 @@
"""CompletionModels for settings/sections.""" """CompletionModels for settings/sections."""
from qutebrowser.models.completion import CompletionModel, NoCompletionsError from qutebrowser.models.completion import CompletionModel, NoCompletionsError
from qutebrowser.config.configdata import configdata import qutebrowser.config.configdata as configdata
class SettingSectionCompletionModel(CompletionModel): class SettingSectionCompletionModel(CompletionModel):
@ -30,7 +30,7 @@ class SettingSectionCompletionModel(CompletionModel):
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)
cat = self.new_category("Config sections") cat = self.new_category("Config sections")
for name in configdata().keys(): for name in configdata.data.keys():
self.new_item(cat, name) self.new_item(cat, name)
@ -43,7 +43,7 @@ class SettingOptionCompletionModel(CompletionModel):
def __init__(self, section, parent=None): def __init__(self, section, parent=None):
super().__init__(parent) super().__init__(parent)
cat = self.new_category("Config options for {}".format(section)) cat = self.new_category("Config options for {}".format(section))
sectdata = configdata()[section] sectdata = configdata.data[section]
for name, _ in sectdata.items(): for name, _ in sectdata.items():
try: try:
desc = sectdata.descriptions[name] desc = sectdata.descriptions[name]
@ -61,7 +61,7 @@ class SettingValueCompletionModel(CompletionModel):
def __init__(self, section, option, parent=None): def __init__(self, section, option, parent=None):
super().__init__(parent) super().__init__(parent)
cat = self.new_category("Setting values for {}".format(option)) cat = self.new_category("Setting values for {}".format(option))
vals = configdata()[section][option].typ.valid_values vals = configdata.data[section][option].typ.valid_values
if vals is None: if vals is None:
raise NoCompletionsError raise NoCompletionsError
for val in vals: for val in vals:

View File

@ -33,7 +33,7 @@ from PyQt5.QtGui import (QIcon, QPalette, QTextDocument, QTextOption,
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.commands.utils as cmdutils import qutebrowser.commands.utils as cmdutils
from qutebrowser.config.configdata import configdata import qutebrowser.config.configdata as configdata
from qutebrowser.models.completion import ROLE_MARKS, NoCompletionsError from qutebrowser.models.completion import ROLE_MARKS, NoCompletionsError
from qutebrowser.config.style import set_register_stylesheet, get_stylesheet from qutebrowser.config.style import set_register_stylesheet, get_stylesheet
from qutebrowser.commands.parsers import split_cmdline from qutebrowser.commands.parsers import split_cmdline
@ -110,10 +110,10 @@ class CompletionView(QTreeView):
'section': CompletionFilterModel(SettingSectionCompletionModel( 'section': CompletionFilterModel(SettingSectionCompletionModel(
self)), self)),
} }
for sect in configdata().keys(): for sect in configdata.data.keys():
self._completion_models['option_' + sect] = CompletionFilterModel( self._completion_models['option_' + sect] = CompletionFilterModel(
SettingOptionCompletionModel(sect, self)) SettingOptionCompletionModel(sect, self))
for opt in configdata()[sect].keys(): for opt in configdata.data[sect].keys():
try: try:
modelname = 'value_{}_{}'.format(sect, opt) modelname = 'value_{}_{}'.format(sect, opt)
self._completion_models[modelname] = ( self._completion_models[modelname] = (