Simplify attribute handling in Web(Kit|Engine)Settings

Let's just have lists in _ATTRIBUTES for WebEngineSettings as well, that allows
us to share some more code.
This commit is contained in:
Florian Bruhin 2018-02-23 17:59:12 +01:00
parent fc6a0dbe64
commit 75b65e2f11
3 changed files with 20 additions and 30 deletions

View File

@ -76,35 +76,35 @@ class WebEngineSettings(websettings.AbstractSettings):
_ATTRIBUTES = { _ATTRIBUTES = {
'content.xss_auditing': 'content.xss_auditing':
QWebEngineSettings.XSSAuditingEnabled, [QWebEngineSettings.XSSAuditingEnabled],
'content.images': 'content.images':
QWebEngineSettings.AutoLoadImages, [QWebEngineSettings.AutoLoadImages],
'content.javascript.enabled': 'content.javascript.enabled':
QWebEngineSettings.JavascriptEnabled, [QWebEngineSettings.JavascriptEnabled],
'content.javascript.can_open_tabs_automatically': 'content.javascript.can_open_tabs_automatically':
QWebEngineSettings.JavascriptCanOpenWindows, [QWebEngineSettings.JavascriptCanOpenWindows],
'content.javascript.can_access_clipboard': 'content.javascript.can_access_clipboard':
QWebEngineSettings.JavascriptCanAccessClipboard, [QWebEngineSettings.JavascriptCanAccessClipboard],
'content.plugins': 'content.plugins':
QWebEngineSettings.PluginsEnabled, [QWebEngineSettings.PluginsEnabled],
'content.hyperlink_auditing': 'content.hyperlink_auditing':
QWebEngineSettings.HyperlinkAuditingEnabled, [QWebEngineSettings.HyperlinkAuditingEnabled],
'content.local_content_can_access_remote_urls': 'content.local_content_can_access_remote_urls':
QWebEngineSettings.LocalContentCanAccessRemoteUrls, [QWebEngineSettings.LocalContentCanAccessRemoteUrls],
'content.local_content_can_access_file_urls': 'content.local_content_can_access_file_urls':
QWebEngineSettings.LocalContentCanAccessFileUrls, [QWebEngineSettings.LocalContentCanAccessFileUrls],
'content.webgl': 'content.webgl':
QWebEngineSettings.WebGLEnabled, [QWebEngineSettings.WebGLEnabled],
'content.local_storage': 'content.local_storage':
QWebEngineSettings.LocalStorageEnabled, [QWebEngineSettings.LocalStorageEnabled],
'input.spatial_navigation': 'input.spatial_navigation':
QWebEngineSettings.SpatialNavigationEnabled, [QWebEngineSettings.SpatialNavigationEnabled],
'input.links_included_in_focus_chain': 'input.links_included_in_focus_chain':
QWebEngineSettings.LinksIncludedInFocusChain, [QWebEngineSettings.LinksIncludedInFocusChain],
'scrolling.smooth': 'scrolling.smooth':
QWebEngineSettings.ScrollAnimatorEnabled, [QWebEngineSettings.ScrollAnimatorEnabled],
# Missing QtWebEngine attributes: # Missing QtWebEngine attributes:
# - ScreenCaptureEnabled # - ScreenCaptureEnabled
@ -162,14 +162,7 @@ class WebEngineSettings(websettings.AbstractSettings):
except AttributeError: except AttributeError:
continue continue
self._ATTRIBUTES[name] = value self._ATTRIBUTES[name] = [value]
def set_attribute(self, name, value):
attribute = self._ATTRIBUTES[name]
if value is configutils.UNSET:
self._settings.resetAttribute(attribute)
else:
self._settings.setAttribute(attribute, value)
def _init_stylesheet(profile): def _init_stylesheet(profile):

View File

@ -121,13 +121,6 @@ class WebKitSettings(websettings.AbstractSettings):
QWebSettings.FantasyFont: QFont.Fantasy, QWebSettings.FantasyFont: QFont.Fantasy,
} }
def set_attribute(self, name, value):
for attribute in self._ATTRIBUTES[name]:
if value is configutils.UNSET:
self._settings.resetAttribute(attribute)
else:
self._settings.setAttribute(attribute, value)
def _set_user_stylesheet(settings): def _set_user_stylesheet(settings):
"""Set the generated user-stylesheet.""" """Set the generated user-stylesheet."""

View File

@ -45,7 +45,11 @@ class AbstractSettings:
If the value is configutils.UNSET, the value is reset instead. If the value is configutils.UNSET, the value is reset instead.
""" """
raise NotImplementedError for attribute in self._ATTRIBUTES[name]:
if value is configutils.UNSET:
self._settings.resetAttribute(attribute)
else:
self._settings.setAttribute(attribute, value)
def test_attribute(self, name): def test_attribute(self, name):
"""Get the value for the given attribute.""" """Get the value for the given attribute."""