Start implementing config changed signal
This commit is contained in:
parent
175eabdc80
commit
aa616e5ac7
@ -130,6 +130,10 @@ class QuteBrowser(QApplication):
|
||||
self.mainwindow.status.keystring.setText)
|
||||
message.bridge.error.connect(self.mainwindow.status.disp_error)
|
||||
message.bridge.info.connect(self.mainwindow.status.disp_tmp_text)
|
||||
self.config.changed.connect(self.mainwindow.tabs.on_config_changed)
|
||||
self.config.changed.connect(
|
||||
self.mainwindow.completion.on_config_changed)
|
||||
self.config.changed.connect(self.mainwindow.resize_completion)
|
||||
|
||||
self.mainwindow.show()
|
||||
self._python_hacks()
|
||||
|
@ -30,6 +30,8 @@ import configparser
|
||||
from configparser import ConfigParser, ExtendedInterpolation
|
||||
from collections.abc import MutableMapping
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, QObject
|
||||
|
||||
#from qutebrowser.utils.misc import read_file
|
||||
import qutebrowser.config.configdata as configdata
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
@ -68,7 +70,7 @@ def init(configdir):
|
||||
state = ReadWriteConfigParser(configdir, 'state')
|
||||
|
||||
|
||||
class Config:
|
||||
class Config(QObject):
|
||||
|
||||
"""Configuration manager for qutebrowser.
|
||||
|
||||
@ -80,9 +82,16 @@ class Config:
|
||||
_configfile: The config file path.
|
||||
_interpolation: An configparser.Interpolation object
|
||||
_proxies: configparser.SectionProxy objects for sections.
|
||||
|
||||
Signals:
|
||||
changed: Gets emitted when the config has changed.
|
||||
Args: the changed section and option.
|
||||
"""
|
||||
|
||||
def __init__(self, configdir, fname):
|
||||
changed = pyqtSignal(str, str)
|
||||
|
||||
def __init__(self, configdir, fname, parent=None):
|
||||
super().__init__(parent)
|
||||
self.config = configdata.configdata()
|
||||
self._configparser = ReadConfigParser(configdir, fname)
|
||||
self._configfile = os.path.join(configdir, fname)
|
||||
@ -265,7 +274,20 @@ class Config:
|
||||
message.error("set: {} - {}".format(e.__class__.__name__, e))
|
||||
|
||||
def set(self, section, option, value):
|
||||
"""Set an option."""
|
||||
"""Set an option.
|
||||
|
||||
Args:
|
||||
section: The name of the section to change.
|
||||
option: The name of the option to change.
|
||||
value: The new value.
|
||||
|
||||
Raise:
|
||||
NoSectionError: If the specified section doesn't exist.
|
||||
NoOptionError: If the specified option doesn't exist.
|
||||
|
||||
Emit:
|
||||
changed: If the config was changed.
|
||||
"""
|
||||
if value:
|
||||
value = self._interpolation.before_set(self, section, option,
|
||||
value)
|
||||
@ -277,6 +299,8 @@ class Config:
|
||||
sectdict[self.optionxform(option)] = value
|
||||
except KeyError:
|
||||
raise NoOptionError(option, section)
|
||||
else:
|
||||
self.changed.emit(section, option)
|
||||
|
||||
def save(self):
|
||||
"""Save the config file."""
|
||||
|
@ -70,10 +70,8 @@ class BrowserTab(QWebView):
|
||||
self._shutdown_callback = None
|
||||
self._open_new_tab = False
|
||||
self._destroyed = {}
|
||||
self._zoom = NeighborList(
|
||||
config.config.get('general', 'zoomlevels'),
|
||||
default=config.config.get('general', 'defaultzoom'),
|
||||
mode=NeighborList.BLOCK)
|
||||
self._zoom = None
|
||||
self._init_neighborlist()
|
||||
self.page_ = BrowserPage(self)
|
||||
self.setPage(self.page_)
|
||||
self.signal_cache = SignalCache(uncached=['linkHovered'])
|
||||
@ -82,6 +80,13 @@ class BrowserTab(QWebView):
|
||||
self.linkClicked.connect(self.on_link_clicked)
|
||||
# FIXME find some way to hide scrollbars without setScrollBarPolicy
|
||||
|
||||
def _init_neighborlist(self):
|
||||
"""Initialize the _zoom neighborlist."""
|
||||
self._zoom = NeighborList(
|
||||
config.config.get('general', 'zoomlevels'),
|
||||
default=config.config.get('general', 'defaultzoom'),
|
||||
mode=NeighborList.BLOCK)
|
||||
|
||||
def openurl(self, url):
|
||||
"""Open an URL in the browser.
|
||||
|
||||
@ -171,6 +176,11 @@ class BrowserTab(QWebView):
|
||||
netman.deleteLater()
|
||||
logging.debug("Tab shutdown scheduled")
|
||||
|
||||
def on_config_changed(self, section, option):
|
||||
"""Update tab config when config was changed."""
|
||||
if section == 'general' and option in ['zoomlevels', 'defaultzoom']:
|
||||
self._init_neighborlist()
|
||||
|
||||
def _on_destroyed(self, sender):
|
||||
"""Called when a subsystem has been destroyed during shutdown.
|
||||
|
||||
|
@ -201,6 +201,12 @@ class CompletionView(QTreeView):
|
||||
self.expandAll()
|
||||
self.resizeColumnToContents(0)
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
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')
|
||||
|
||||
@pyqtSlot(str)
|
||||
def on_cmd_text_changed(self, text):
|
||||
"""Check if completions are available and activate them.
|
||||
|
@ -97,17 +97,8 @@ class MainWindow(QWidget):
|
||||
#self.tabWidget.setCurrentIndex(0)
|
||||
#QtCore.QMetaObject.connectSlotsByName(MainWindow)
|
||||
|
||||
def _set_default_geometry(self):
|
||||
"""Set some sensible default geometry."""
|
||||
self.setGeometry(QRect(50, 50, 800, 600))
|
||||
|
||||
def resizeEvent(self, e):
|
||||
"""Extend resizewindow's resizeEvent to adjust completion.
|
||||
|
||||
Args:
|
||||
e: The QResizeEvent
|
||||
"""
|
||||
super().resizeEvent(e)
|
||||
def resize_completion(self):
|
||||
"""Adjust completion according to config."""
|
||||
confheight = str(config.config.get('general', 'completion_height'))
|
||||
if confheight.endswith('%'):
|
||||
perc = int(confheight.rstrip('%'))
|
||||
@ -119,3 +110,16 @@ class MainWindow(QWidget):
|
||||
topleft = QPoint(0, self.height() - self.status.height() - height)
|
||||
bottomright = self.status.geometry().topRight()
|
||||
self.completion.setGeometry(QRect(topleft, bottomright))
|
||||
|
||||
def _set_default_geometry(self):
|
||||
"""Set some sensible default geometry."""
|
||||
self.setGeometry(QRect(50, 50, 800, 600))
|
||||
|
||||
def resizeEvent(self, e):
|
||||
"""Extend resizewindow's resizeEvent to adjust completion.
|
||||
|
||||
Args:
|
||||
e: The QResizeEvent
|
||||
"""
|
||||
super().resizeEvent(e)
|
||||
self.resize_completion()
|
||||
|
@ -139,6 +139,12 @@ class TabbedBrowser(TabWidget):
|
||||
else:
|
||||
return None
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def on_config_changed(self, section, option):
|
||||
"""Update tab config when config was changed."""
|
||||
for tab in self._tabs:
|
||||
tab.on_config_changed(section, option)
|
||||
|
||||
def _titleChanged_handler(self, text):
|
||||
"""Set the title of a tab.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user