More config cleanup.

This renames the config instance from "config" to "instance" and adds a
convenience get() function in the config module.
This commit is contained in:
Florian Bruhin 2014-04-17 15:26:27 +02:00
parent a15461b5da
commit 457e173592
14 changed files with 38 additions and 33 deletions

View File

@ -103,7 +103,7 @@ class QuteBrowser(QApplication):
else:
confdir = self._args.confdir
config.init(confdir)
self.config = config.config
self.config = config.instance
websettings.init()
self.commandparser = CommandParser()
@ -221,7 +221,7 @@ class QuteBrowser(QApplication):
if self.mainwindow.tabs.count() == 0:
logging.debug('Opening startpage')
for url in config.config.get('general', 'startpage'):
for url in config.get('general', 'startpage'):
self.mainwindow.tabs.tabopen(url)
def _python_hacks(self):
@ -379,9 +379,9 @@ class QuteBrowser(QApplication):
return
self._shutting_down = True
logging.debug("Shutting down... (do_quit={})".format(do_quit))
if config.config.get('general', 'autosave'):
if config.get('general', 'autosave'):
try:
config.config.save()
config.instance.save()
except AttributeError:
logging.exception("Could not save config.")
try:

View File

@ -243,7 +243,7 @@ class KeyParser(QObject):
Config format: key = command, e.g.:
gg = scrollstart
"""
sect = config.config['keybind']
sect = config.instance['keybind']
if not sect.items():
logging.warn("No keybindings defined!")
for (key, cmd) in sect.items():

View File

@ -62,9 +62,9 @@ class SearchParser(QObject):
self.do_search.emit('', 0)
self._text = text
self._flags = 0
if config.config.get('general', 'ignorecase'):
if config.get('general', 'ignorecase'):
self._flags |= QWebPage.FindCaseSensitively
if config.config.get('general', 'wrapsearch'):
if config.get('general', 'wrapsearch'):
self._flags |= QWebPage.FindWrapsAroundDocument
if rev:
self._flags |= QWebPage.FindBackward
@ -134,7 +134,7 @@ class CommandParser:
cmdstr = parts[0]
if aliases:
try:
alias = config.config.get('aliases', cmdstr)
alias = config.get('aliases', cmdstr)
except (config.NoOptionError, config.NoSectionError):
pass
else:

View File

@ -41,7 +41,7 @@ from qutebrowser.config.iniparsers import (ReadConfigParser,
ReadWriteConfigParser)
from qutebrowser.config.lineparser import LineConfigParser
config = None
instance = None # The main config instance
state = None
cmd_history = None
@ -52,14 +52,19 @@ def init(configdir):
Args:
configdir: The directory where the configs are stored in.
"""
global config, state, cmd_history
global instance, state, cmd_history
logging.debug("Config init, configdir {}".format(configdir))
config = Config(configdir, 'qutebrowser.conf')
instance = Config(configdir, 'qutebrowser.conf')
state = ReadWriteConfigParser(configdir, 'state')
cmd_history = LineConfigParser(configdir, 'cmd_history',
('general', 'cmd_histlen'))
def get(*args, **kwargs):
"""Convenience method to call get(...) of the config instance."""
return instance.get(*args, **kwargs)
class NoSectionError(configparser.NoSectionError):
"""Exception raised when a section was not found."""

View File

@ -75,7 +75,7 @@ class LineConfigParser:
logging.debug("No data to save.")
return
import qutebrowser.config.config as config # FIXME
limit = -1 if self._limit is None else config.config.get(*self._limit)
limit = -1 if self._limit is None else config.get(*self._limit)
if limit == 0:
return
if not os.path.exists(self._configdir):
@ -90,7 +90,7 @@ class LineConfigParser:
if self._limit is None:
return
import qutebrowser.config.config as config # FIXME
value = config.config.get(section, option)
value = config.get(section, option)
if (section, option) == self._limit and value == 0:
if os.path.exists(self._configfile):
os.remove(self._configfile)

View File

@ -36,9 +36,9 @@ def get_stylesheet(template):
"""
global _colordict, _fontdict
if _colordict is None:
_colordict = ColorDict(config.config['colors'])
_colordict = ColorDict(config.instance['colors'])
if _fontdict is None:
_fontdict = FontDict(config.config['fonts'])
_fontdict = FontDict(config.instance['fonts'])
return template.strip().format(color=_colordict, font=_fontdict)
@ -48,7 +48,7 @@ def set_register_stylesheet(obj):
Also, register an update when the config is changed.
"""
obj.setStyleSheet(get_stylesheet(obj.STYLESHEET))
config.config.changed.connect(partial(_update_stylesheet, obj))
config.instance.changed.connect(partial(_update_stylesheet, obj))
def _update_stylesheet(obj, section, option):

View File

@ -65,12 +65,12 @@ def init():
global settings
settings = QWebSettings.globalSettings()
for name, item in MAPPING.items():
settings.setAttribute(item, config.config.get('webkit', name))
settings.setAttribute(item, config.get('webkit', name))
@pyqtSlot(str, str)
def on_config_changed(section, option):
"""Update global settings when qwebsettings changed."""
if section == 'webkit':
value = config.config.get(section, option)
value = config.get(section, option)
settings.setAttribute(MAPPING[option], value)

View File

@ -52,14 +52,14 @@ def _get_search_url(txt):
if m:
engine = m.group(2)
try:
template = config.config.get('searchengines', engine)
template = config.get('searchengines', engine)
except config.NoOptionError:
raise SearchEngineError("Search engine {} not found!".format(
engine))
term = r.sub('', txt)
logging.debug('engine {}, term "{}"'.format(engine, term))
else:
template = config.config.get('searchengines', 'DEFAULT')
template = config.get('searchengines', 'DEFAULT')
term = txt
logging.debug('engine: default, term "{}"'.format(txt))
if not term:
@ -177,7 +177,7 @@ def is_url(url):
"""
urlstr = urlstring(url)
autosearch = config.config.get('general', 'auto_search')
autosearch = config.get('general', 'auto_search')
logging.debug('Checking if "{}" is an URL (autosearch={}).'.format(
urlstr, autosearch))

View File

@ -83,8 +83,8 @@ class BrowserTab(QWebView):
def _init_neighborlist(self):
"""Initialize the _zoom neighborlist."""
self._zoom = NeighborList(
config.config.get('general', 'zoomlevels'),
default=config.config.get('general', 'defaultzoom'),
config.get('general', 'zoomlevels'),
default=config.get('general', 'defaultzoom'),
mode=NeighborList.BLOCK)
def openurl(self, url):

View File

@ -102,7 +102,7 @@ class CompletionView(QTreeView):
def __init__(self, parent=None):
super().__init__(parent)
self._enabled = config.config.get('general', 'show_completion')
self._enabled = config.get('general', 'show_completion')
self._model = None
self._lastmodel = None
self._completion_models = {
@ -215,7 +215,7 @@ class CompletionView(QTreeView):
def on_config_changed(self, section, option):
"""Update self._enabled when the config changed."""
if section == 'general' and option == 'show_completion':
self._enabled = config.config.get('general', 'show_completion')
self._enabled = config.get('general', 'show_completion')
@pyqtSlot(str)
def on_cmd_text_changed(self, text):

View File

@ -104,7 +104,7 @@ class CrashDialog(QDialog):
('Open Pages', '\n'.join(pages)),
('Command history', '\n'.join(cmdhist)),
('Commandline args', ' '.join(sys.argv[1:])),
('Config', config.config.dump_userconfig()),
('Config', config.instance.dump_userconfig()),
]
chunks = []
for (header, body) in outputs:

View File

@ -114,7 +114,7 @@ class MainWindow(QWidget):
def resize_completion(self):
"""Adjust completion according to config."""
confheight = str(config.config.get('general', 'completion_height'))
confheight = str(config.get('general', 'completion_height'))
if confheight.endswith('%'):
perc = int(confheight.rstrip('%'))
height = self.height() * perc / 100

View File

@ -199,7 +199,7 @@ class TabbedBrowser(TabWidget):
tab = self.cntwidget(count)
if tab is None:
return
last_close = config.config.get('tabbar', 'last_close')
last_close = config.get('tabbar', 'last_close')
if self.count() > 1:
# FIXME maybe we actually should store the webview objects here
self._url_stack.append(tab.url())

View File

@ -88,11 +88,11 @@ class TabWidget(QTabWidget):
'right': QTabBar.SelectRightTab,
'previous': QTabBar.SelectPreviousTab,
}
self.setMovable(config.config.get('tabbar', 'movable'))
self.setTabsClosable(config.config.get('tabbar', 'closebuttons'))
self.setUsesScrollButtons(config.config.get('tabbar', 'scrollbuttons'))
posstr = config.config.get('tabbar', 'position')
selstr = config.config.get('tabbar', 'select_on_remove')
self.setMovable(config.get('tabbar', 'movable'))
self.setTabsClosable(config.get('tabbar', 'closebuttons'))
self.setUsesScrollButtons(config.get('tabbar', 'scrollbuttons'))
posstr = config.get('tabbar', 'position')
selstr = config.get('tabbar', 'select_on_remove')
try:
self.setTabPosition(position_conv[posstr])
self.tabBar().setSelectionBehaviorOnRemove(select_conv[selstr])