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:
parent
a15461b5da
commit
457e173592
@ -103,7 +103,7 @@ class QuteBrowser(QApplication):
|
|||||||
else:
|
else:
|
||||||
confdir = self._args.confdir
|
confdir = self._args.confdir
|
||||||
config.init(confdir)
|
config.init(confdir)
|
||||||
self.config = config.config
|
self.config = config.instance
|
||||||
websettings.init()
|
websettings.init()
|
||||||
|
|
||||||
self.commandparser = CommandParser()
|
self.commandparser = CommandParser()
|
||||||
@ -221,7 +221,7 @@ class QuteBrowser(QApplication):
|
|||||||
|
|
||||||
if self.mainwindow.tabs.count() == 0:
|
if self.mainwindow.tabs.count() == 0:
|
||||||
logging.debug('Opening startpage')
|
logging.debug('Opening startpage')
|
||||||
for url in config.config.get('general', 'startpage'):
|
for url in config.get('general', 'startpage'):
|
||||||
self.mainwindow.tabs.tabopen(url)
|
self.mainwindow.tabs.tabopen(url)
|
||||||
|
|
||||||
def _python_hacks(self):
|
def _python_hacks(self):
|
||||||
@ -379,9 +379,9 @@ class QuteBrowser(QApplication):
|
|||||||
return
|
return
|
||||||
self._shutting_down = True
|
self._shutting_down = True
|
||||||
logging.debug("Shutting down... (do_quit={})".format(do_quit))
|
logging.debug("Shutting down... (do_quit={})".format(do_quit))
|
||||||
if config.config.get('general', 'autosave'):
|
if config.get('general', 'autosave'):
|
||||||
try:
|
try:
|
||||||
config.config.save()
|
config.instance.save()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
logging.exception("Could not save config.")
|
logging.exception("Could not save config.")
|
||||||
try:
|
try:
|
||||||
|
@ -243,7 +243,7 @@ class KeyParser(QObject):
|
|||||||
Config format: key = command, e.g.:
|
Config format: key = command, e.g.:
|
||||||
gg = scrollstart
|
gg = scrollstart
|
||||||
"""
|
"""
|
||||||
sect = config.config['keybind']
|
sect = config.instance['keybind']
|
||||||
if not sect.items():
|
if not sect.items():
|
||||||
logging.warn("No keybindings defined!")
|
logging.warn("No keybindings defined!")
|
||||||
for (key, cmd) in sect.items():
|
for (key, cmd) in sect.items():
|
||||||
|
@ -62,9 +62,9 @@ class SearchParser(QObject):
|
|||||||
self.do_search.emit('', 0)
|
self.do_search.emit('', 0)
|
||||||
self._text = text
|
self._text = text
|
||||||
self._flags = 0
|
self._flags = 0
|
||||||
if config.config.get('general', 'ignorecase'):
|
if config.get('general', 'ignorecase'):
|
||||||
self._flags |= QWebPage.FindCaseSensitively
|
self._flags |= QWebPage.FindCaseSensitively
|
||||||
if config.config.get('general', 'wrapsearch'):
|
if config.get('general', 'wrapsearch'):
|
||||||
self._flags |= QWebPage.FindWrapsAroundDocument
|
self._flags |= QWebPage.FindWrapsAroundDocument
|
||||||
if rev:
|
if rev:
|
||||||
self._flags |= QWebPage.FindBackward
|
self._flags |= QWebPage.FindBackward
|
||||||
@ -134,7 +134,7 @@ class CommandParser:
|
|||||||
cmdstr = parts[0]
|
cmdstr = parts[0]
|
||||||
if aliases:
|
if aliases:
|
||||||
try:
|
try:
|
||||||
alias = config.config.get('aliases', cmdstr)
|
alias = config.get('aliases', cmdstr)
|
||||||
except (config.NoOptionError, config.NoSectionError):
|
except (config.NoOptionError, config.NoSectionError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -41,7 +41,7 @@ from qutebrowser.config.iniparsers import (ReadConfigParser,
|
|||||||
ReadWriteConfigParser)
|
ReadWriteConfigParser)
|
||||||
from qutebrowser.config.lineparser import LineConfigParser
|
from qutebrowser.config.lineparser import LineConfigParser
|
||||||
|
|
||||||
config = None
|
instance = None # The main config instance
|
||||||
state = None
|
state = None
|
||||||
cmd_history = None
|
cmd_history = None
|
||||||
|
|
||||||
@ -52,14 +52,19 @@ def init(configdir):
|
|||||||
Args:
|
Args:
|
||||||
configdir: The directory where the configs are stored in.
|
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))
|
logging.debug("Config init, configdir {}".format(configdir))
|
||||||
config = Config(configdir, 'qutebrowser.conf')
|
instance = Config(configdir, 'qutebrowser.conf')
|
||||||
state = ReadWriteConfigParser(configdir, 'state')
|
state = ReadWriteConfigParser(configdir, 'state')
|
||||||
cmd_history = LineConfigParser(configdir, 'cmd_history',
|
cmd_history = LineConfigParser(configdir, 'cmd_history',
|
||||||
('general', 'cmd_histlen'))
|
('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):
|
class NoSectionError(configparser.NoSectionError):
|
||||||
|
|
||||||
"""Exception raised when a section was not found."""
|
"""Exception raised when a section was not found."""
|
||||||
|
@ -75,7 +75,7 @@ class LineConfigParser:
|
|||||||
logging.debug("No data to save.")
|
logging.debug("No data to save.")
|
||||||
return
|
return
|
||||||
import qutebrowser.config.config as config # FIXME
|
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:
|
if limit == 0:
|
||||||
return
|
return
|
||||||
if not os.path.exists(self._configdir):
|
if not os.path.exists(self._configdir):
|
||||||
@ -90,7 +90,7 @@ class LineConfigParser:
|
|||||||
if self._limit is None:
|
if self._limit is None:
|
||||||
return
|
return
|
||||||
import qutebrowser.config.config as config # FIXME
|
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 (section, option) == self._limit and value == 0:
|
||||||
if os.path.exists(self._configfile):
|
if os.path.exists(self._configfile):
|
||||||
os.remove(self._configfile)
|
os.remove(self._configfile)
|
||||||
|
@ -36,9 +36,9 @@ def get_stylesheet(template):
|
|||||||
"""
|
"""
|
||||||
global _colordict, _fontdict
|
global _colordict, _fontdict
|
||||||
if _colordict is None:
|
if _colordict is None:
|
||||||
_colordict = ColorDict(config.config['colors'])
|
_colordict = ColorDict(config.instance['colors'])
|
||||||
if _fontdict is None:
|
if _fontdict is None:
|
||||||
_fontdict = FontDict(config.config['fonts'])
|
_fontdict = FontDict(config.instance['fonts'])
|
||||||
return template.strip().format(color=_colordict, font=_fontdict)
|
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.
|
Also, register an update when the config is changed.
|
||||||
"""
|
"""
|
||||||
obj.setStyleSheet(get_stylesheet(obj.STYLESHEET))
|
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):
|
def _update_stylesheet(obj, section, option):
|
||||||
|
@ -65,12 +65,12 @@ def init():
|
|||||||
global settings
|
global settings
|
||||||
settings = QWebSettings.globalSettings()
|
settings = QWebSettings.globalSettings()
|
||||||
for name, item in MAPPING.items():
|
for name, item in MAPPING.items():
|
||||||
settings.setAttribute(item, config.config.get('webkit', name))
|
settings.setAttribute(item, config.get('webkit', name))
|
||||||
|
|
||||||
|
|
||||||
@pyqtSlot(str, str)
|
@pyqtSlot(str, str)
|
||||||
def on_config_changed(section, option):
|
def on_config_changed(section, option):
|
||||||
"""Update global settings when qwebsettings changed."""
|
"""Update global settings when qwebsettings changed."""
|
||||||
if section == 'webkit':
|
if section == 'webkit':
|
||||||
value = config.config.get(section, option)
|
value = config.get(section, option)
|
||||||
settings.setAttribute(MAPPING[option], value)
|
settings.setAttribute(MAPPING[option], value)
|
||||||
|
@ -52,14 +52,14 @@ def _get_search_url(txt):
|
|||||||
if m:
|
if m:
|
||||||
engine = m.group(2)
|
engine = m.group(2)
|
||||||
try:
|
try:
|
||||||
template = config.config.get('searchengines', engine)
|
template = config.get('searchengines', engine)
|
||||||
except config.NoOptionError:
|
except config.NoOptionError:
|
||||||
raise SearchEngineError("Search engine {} not found!".format(
|
raise SearchEngineError("Search engine {} not found!".format(
|
||||||
engine))
|
engine))
|
||||||
term = r.sub('', txt)
|
term = r.sub('', txt)
|
||||||
logging.debug('engine {}, term "{}"'.format(engine, term))
|
logging.debug('engine {}, term "{}"'.format(engine, term))
|
||||||
else:
|
else:
|
||||||
template = config.config.get('searchengines', 'DEFAULT')
|
template = config.get('searchengines', 'DEFAULT')
|
||||||
term = txt
|
term = txt
|
||||||
logging.debug('engine: default, term "{}"'.format(txt))
|
logging.debug('engine: default, term "{}"'.format(txt))
|
||||||
if not term:
|
if not term:
|
||||||
@ -177,7 +177,7 @@ def is_url(url):
|
|||||||
"""
|
"""
|
||||||
urlstr = urlstring(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(
|
logging.debug('Checking if "{}" is an URL (autosearch={}).'.format(
|
||||||
urlstr, autosearch))
|
urlstr, autosearch))
|
||||||
|
@ -83,8 +83,8 @@ class BrowserTab(QWebView):
|
|||||||
def _init_neighborlist(self):
|
def _init_neighborlist(self):
|
||||||
"""Initialize the _zoom neighborlist."""
|
"""Initialize the _zoom neighborlist."""
|
||||||
self._zoom = NeighborList(
|
self._zoom = NeighborList(
|
||||||
config.config.get('general', 'zoomlevels'),
|
config.get('general', 'zoomlevels'),
|
||||||
default=config.config.get('general', 'defaultzoom'),
|
default=config.get('general', 'defaultzoom'),
|
||||||
mode=NeighborList.BLOCK)
|
mode=NeighborList.BLOCK)
|
||||||
|
|
||||||
def openurl(self, url):
|
def openurl(self, url):
|
||||||
|
@ -102,7 +102,7 @@ class CompletionView(QTreeView):
|
|||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self._enabled = config.config.get('general', 'show_completion')
|
self._enabled = config.get('general', 'show_completion')
|
||||||
self._model = None
|
self._model = None
|
||||||
self._lastmodel = None
|
self._lastmodel = None
|
||||||
self._completion_models = {
|
self._completion_models = {
|
||||||
@ -215,7 +215,7 @@ class CompletionView(QTreeView):
|
|||||||
def on_config_changed(self, section, option):
|
def on_config_changed(self, section, option):
|
||||||
"""Update self._enabled when the config changed."""
|
"""Update self._enabled when the config changed."""
|
||||||
if section == 'general' and option == 'show_completion':
|
if section == 'general' and option == 'show_completion':
|
||||||
self._enabled = config.config.get('general', 'show_completion')
|
self._enabled = config.get('general', 'show_completion')
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def on_cmd_text_changed(self, text):
|
def on_cmd_text_changed(self, text):
|
||||||
|
@ -104,7 +104,7 @@ class CrashDialog(QDialog):
|
|||||||
('Open Pages', '\n'.join(pages)),
|
('Open Pages', '\n'.join(pages)),
|
||||||
('Command history', '\n'.join(cmdhist)),
|
('Command history', '\n'.join(cmdhist)),
|
||||||
('Commandline args', ' '.join(sys.argv[1:])),
|
('Commandline args', ' '.join(sys.argv[1:])),
|
||||||
('Config', config.config.dump_userconfig()),
|
('Config', config.instance.dump_userconfig()),
|
||||||
]
|
]
|
||||||
chunks = []
|
chunks = []
|
||||||
for (header, body) in outputs:
|
for (header, body) in outputs:
|
||||||
|
@ -114,7 +114,7 @@ class MainWindow(QWidget):
|
|||||||
|
|
||||||
def resize_completion(self):
|
def resize_completion(self):
|
||||||
"""Adjust completion according to config."""
|
"""Adjust completion according to config."""
|
||||||
confheight = str(config.config.get('general', 'completion_height'))
|
confheight = str(config.get('general', 'completion_height'))
|
||||||
if confheight.endswith('%'):
|
if confheight.endswith('%'):
|
||||||
perc = int(confheight.rstrip('%'))
|
perc = int(confheight.rstrip('%'))
|
||||||
height = self.height() * perc / 100
|
height = self.height() * perc / 100
|
||||||
|
@ -199,7 +199,7 @@ class TabbedBrowser(TabWidget):
|
|||||||
tab = self.cntwidget(count)
|
tab = self.cntwidget(count)
|
||||||
if tab is None:
|
if tab is None:
|
||||||
return
|
return
|
||||||
last_close = config.config.get('tabbar', 'last_close')
|
last_close = config.get('tabbar', 'last_close')
|
||||||
if self.count() > 1:
|
if self.count() > 1:
|
||||||
# FIXME maybe we actually should store the webview objects here
|
# FIXME maybe we actually should store the webview objects here
|
||||||
self._url_stack.append(tab.url())
|
self._url_stack.append(tab.url())
|
||||||
|
@ -88,11 +88,11 @@ class TabWidget(QTabWidget):
|
|||||||
'right': QTabBar.SelectRightTab,
|
'right': QTabBar.SelectRightTab,
|
||||||
'previous': QTabBar.SelectPreviousTab,
|
'previous': QTabBar.SelectPreviousTab,
|
||||||
}
|
}
|
||||||
self.setMovable(config.config.get('tabbar', 'movable'))
|
self.setMovable(config.get('tabbar', 'movable'))
|
||||||
self.setTabsClosable(config.config.get('tabbar', 'closebuttons'))
|
self.setTabsClosable(config.get('tabbar', 'closebuttons'))
|
||||||
self.setUsesScrollButtons(config.config.get('tabbar', 'scrollbuttons'))
|
self.setUsesScrollButtons(config.get('tabbar', 'scrollbuttons'))
|
||||||
posstr = config.config.get('tabbar', 'position')
|
posstr = config.get('tabbar', 'position')
|
||||||
selstr = config.config.get('tabbar', 'select_on_remove')
|
selstr = config.get('tabbar', 'select_on_remove')
|
||||||
try:
|
try:
|
||||||
self.setTabPosition(position_conv[posstr])
|
self.setTabPosition(position_conv[posstr])
|
||||||
self.tabBar().setSelectionBehaviorOnRemove(select_conv[selstr])
|
self.tabBar().setSelectionBehaviorOnRemove(select_conv[selstr])
|
||||||
|
Loading…
Reference in New Issue
Block a user