log-javascript-console now String option: none, debug, info

Make BaseType.valid_values per-instance variable
This commit is contained in:
Patric Schmitz 2015-11-07 16:14:52 +01:00 committed by Patric Schmitz
parent f847ddf3cb
commit ff6d3e05a6
4 changed files with 145 additions and 86 deletions

View File

@ -503,8 +503,16 @@ class BrowserPage(QWebPage):
def javaScriptConsoleMessage(self, msg, line, source): def javaScriptConsoleMessage(self, msg, line, source):
"""Override javaScriptConsoleMessage to use debug log.""" """Override javaScriptConsoleMessage to use debug log."""
if config.get('general', 'log-javascript-console'):
log.js.debug("[{}:{}] {}".format(source, line, msg)) log_javascript_console = config.get('general',
'log-javascript-console' )
logstring = "[{}:{}] {}".format(source, line, msg)
logmap = {
'debug': log.js.debug,
'info': log.js.info,
'none': lambda arg: None
}
logmap[log_javascript_console](logstring)
def chooseFile(self, _frame, suggested_file): def chooseFile(self, _frame, suggested_file):
"""Override QWebPage's chooseFile to be able to chose a file to upload. """Override QWebPage's chooseFile to be able to chose a file to upload.

View File

@ -356,7 +356,9 @@ class ConfigManager(QObject):
('tabs', 'position'): _transform_position, ('tabs', 'position'): _transform_position,
('ui', 'downloads-position'): _transform_position, ('ui', 'downloads-position'): _transform_position,
('ui', 'remove-finished-downloads'): ('ui', 'remove-finished-downloads'):
_get_value_transformer({'false': '-1', 'true': '1000'}) _get_value_transformer({'false': '-1', 'true': '1000'}),
('general', 'log-javascript-console'):
_get_value_transformer({'false': 'none', 'true': 'debug'}),
} }
changed = pyqtSignal(str, str) changed = pyqtSignal(str, str)

View File

@ -214,8 +214,13 @@ def data(readonly=False):
"launched."), "launched."),
('log-javascript-console', ('log-javascript-console',
SettingValue(typ.Bool(), 'false'), SettingValue(
"Whether to log javascript console messages."), typ.String(
valid_values=typ.ValidValues('none', 'debug', 'info')),
'debug'),
"How to log javascript console messages. "
"None suppresses output, debug logs to stdout if in debug mode, "
"info always logs to stdout."),
('save-session', ('save-session',
SettingValue(typ.Bool(), 'false'), SettingValue(typ.Bool(), 'false'),

View File

@ -121,11 +121,11 @@ class BaseType:
mentioned in the config file. mentioned in the config file.
""" """
valid_values = None
special = False special = False
def __init__(self, none_ok=False): def __init__(self, none_ok=False, valid_values=None):
self.none_ok = none_ok self.none_ok = none_ok
self.valid_values = valid_values
def _basic_validation(self, value): def _basic_validation(self, value):
"""Do some basic validation for the value (empty, non-printable chars). """Do some basic validation for the value (empty, non-printable chars).
@ -243,8 +243,8 @@ class String(BaseType):
""" """
def __init__(self, minlen=None, maxlen=None, forbidden=None, def __init__(self, minlen=None, maxlen=None, forbidden=None,
none_ok=False, completions=None): none_ok=False, completions=None, valid_values=None):
super().__init__(none_ok) super().__init__(none_ok, valid_values)
if minlen is not None and minlen < 1: if minlen is not None and minlen < 1:
raise ValueError("minlen ({}) needs to be >= 1!".format(minlen)) raise ValueError("minlen ({}) needs to be >= 1!".format(minlen))
elif maxlen is not None and maxlen < 1: elif maxlen is not None and maxlen < 1:
@ -650,10 +650,13 @@ class ColorSystem(MappingType):
"""Color systems for interpolation.""" """Color systems for interpolation."""
special = True special = True
valid_values = ValidValues(('rgb', "Interpolate in the RGB color system."),
('hsv', "Interpolate in the HSV color system."), def __init__(self):
('hsl', "Interpolate in the HSL color system."), self.valid_values = \
('none', "Don't show a gradient.")) ValidValues(('rgb', "Interpolate in the RGB color system."),
('hsv', "Interpolate in the HSV color system."),
('hsl', "Interpolate in the HSL color system."),
('none', "Don't show a gradient."))
MAPPING = { MAPPING = {
'rgb': QColor.Rgb, 'rgb': QColor.Rgb,
@ -1092,9 +1095,12 @@ class HintMode(BaseType):
"""Base class for the hints -> mode setting.""" """Base class for the hints -> mode setting."""
special = True special = True
valid_values = ValidValues(('number', "Use numeric hints."),
('letter', "Use the chars in the hints -> " def __init__(self):
"chars setting.")) self.valid_values = \
ValidValues(('number', "Use numeric hints."),
('letter', "Use the chars in the hints -> "
"chars setting."))
class Proxy(BaseType): class Proxy(BaseType):
@ -1102,8 +1108,11 @@ class Proxy(BaseType):
"""A proxy URL or special value.""" """A proxy URL or special value."""
special = True special = True
valid_values = ValidValues(('system', "Use the system wide proxy."),
('none', "Don't use any proxy")) def __init__(self):
self.valid_values = \
ValidValues(('system', "Use the system wide proxy."),
('none', "Don't use any proxy"))
PROXY_TYPES = { PROXY_TYPES = {
'http': QNetworkProxy.HttpProxy, 'http': QNetworkProxy.HttpProxy,
@ -1330,7 +1339,8 @@ class Position(MappingType):
"""The position of the tab bar.""" """The position of the tab bar."""
valid_values = ValidValues('top', 'bottom', 'left', 'right') def __init__(self):
self.valid_values = ValidValues('top', 'bottom', 'left', 'right')
MAPPING = { MAPPING = {
'top': QTabWidget.North, 'top': QTabWidget.North,
@ -1344,7 +1354,8 @@ class VerticalPosition(BaseType):
"""The position of the download bar.""" """The position of the download bar."""
valid_values = ValidValues('top', 'bottom') def __init__(self):
self.valid_values = ValidValues('top', 'bottom')
class UrlList(List): class UrlList(List):
@ -1389,10 +1400,11 @@ class SelectOnRemove(MappingType):
"""Which tab to select when the focused tab is removed.""" """Which tab to select when the focused tab is removed."""
special = True special = True
valid_values = ValidValues( def __init__(self):
('left', "Select the tab on the left."), self.valid_values = ValidValues(
('right', "Select the tab on the right."), ('left', "Select the tab on the left."),
('previous', "Select the previously selected tab.")) ('right', "Select the tab on the right."),
('previous', "Select the previously selected tab."))
MAPPING = { MAPPING = {
'left': QTabBar.SelectLeftTab, 'left': QTabBar.SelectLeftTab,
@ -1406,11 +1418,14 @@ class LastClose(BaseType):
"""Behavior when the last tab is closed.""" """Behavior when the last tab is closed."""
special = True special = True
valid_values = ValidValues(('ignore', "Don't do anything."),
('blank', "Load a blank page."), def __init__(self):
('startpage', "Load the start page."), self.valid_values = \
('default-page', "Load the default page."), ValidValues(('ignore', "Don't do anything."),
('close', "Close the window.")) ('blank', "Load a blank page."),
('startpage', "Load the start page."),
('default-page', "Load the default page."),
('close', "Close the window."))
class AcceptCookies(BaseType): class AcceptCookies(BaseType):
@ -1418,13 +1433,16 @@ class AcceptCookies(BaseType):
"""Control which cookies to accept.""" """Control which cookies to accept."""
special = True special = True
valid_values = ValidValues(('all', "Accept all cookies."),
('no-3rdparty', "Accept cookies from the same" def __init__(self):
" origin only."), self.valid_values = \
('no-unknown-3rdparty', "Accept cookies from " ValidValues(('all', "Accept all cookies."),
"the same origin only, unless a cookie is " ('no-3rdparty', "Accept cookies from the same"
"already set for the domain."), " origin only."),
('never', "Don't accept cookies at all.")) ('no-unknown-3rdparty', "Accept cookies from "
"the same origin only, unless a cookie is "
"already set for the domain."),
('never', "Don't accept cookies at all."))
class ConfirmQuit(FlagList): class ConfirmQuit(FlagList):
@ -1432,12 +1450,14 @@ class ConfirmQuit(FlagList):
"""Whether to display a confirmation when the window is closed.""" """Whether to display a confirmation when the window is closed."""
special = True special = True
valid_values = ValidValues(('always', "Always show a confirmation."),
('multiple-tabs', "Show a confirmation if " def __init__(self):
"multiple tabs are opened."), self.valid_values = ValidValues(('always', "Always show a confirmation."),
('downloads', "Show a confirmation if " ('multiple-tabs', "Show a confirmation if "
"downloads are running"), "multiple tabs are opened."),
('never', "Never show a confirmation.")) ('downloads', "Show a confirmation if "
"downloads are running"),
('never', "Never show a confirmation."))
# Values that can be combined with commas # Values that can be combined with commas
combinable_values = ('multiple-tabs', 'downloads') combinable_values = ('multiple-tabs', 'downloads')
@ -1462,10 +1482,13 @@ class ForwardUnboundKeys(BaseType):
"""Whether to forward unbound keys.""" """Whether to forward unbound keys."""
special = True special = True
valid_values = ValidValues(('all', "Forward all unbound keys."),
('auto', "Forward unbound non-alphanumeric " def __init__(self):
"keys."), self.valid_values = \
('none', "Don't forward any keys.")) ValidValues(('all', "Forward all unbound keys."),
('auto', "Forward unbound non-alphanumeric "
"keys."),
('none', "Don't forward any keys."))
class CloseButton(BaseType): class CloseButton(BaseType):
@ -1473,9 +1496,12 @@ class CloseButton(BaseType):
"""Mouse button used to close tabs.""" """Mouse button used to close tabs."""
special = True special = True
valid_values = ValidValues(('right', "Close tabs on right-click."),
('middle', "Close tabs on middle-click."), def __init__(self):
('none', "Don't close tabs using the mouse.")) self.valid_values = \
ValidValues(('right', "Close tabs on right-click."),
('middle', "Close tabs on middle-click."),
('none', "Don't close tabs using the mouse."))
class NewTabPosition(BaseType): class NewTabPosition(BaseType):
@ -1483,10 +1509,13 @@ class NewTabPosition(BaseType):
"""How new tabs are positioned.""" """How new tabs are positioned."""
special = True special = True
valid_values = ValidValues(('left', "On the left of the current tab."),
('right', "On the right of the current tab."), def __init__(self):
('first', "At the left end."), self.valid_values = \
('last', "At the right end.")) ValidValues(('left', "On the left of the current tab."),
('right', "On the right of the current tab."),
('first', "At the left end."),
('last', "At the right end."))
class IgnoreCase(Bool): class IgnoreCase(Bool):
@ -1494,10 +1523,13 @@ class IgnoreCase(Bool):
"""Whether to ignore case when searching.""" """Whether to ignore case when searching."""
special = True special = True
valid_values = ValidValues(('true', "Search case-insensitively"),
('false', "Search case-sensitively"), def __init__(self):
('smart', "Search case-sensitively if there " self.valid_values = \
"are capital chars")) ValidValues(('true', "Search case-insensitively"),
('false', "Search case-sensitively"),
('smart', "Search case-sensitively if there "
"are capital chars"))
def transform(self, value): def transform(self, value):
if value.lower() == 'smart': if value.lower() == 'smart':
@ -1520,19 +1552,22 @@ class NewInstanceOpenTarget(BaseType):
"""How to open links in an existing instance if a new one is launched.""" """How to open links in an existing instance if a new one is launched."""
special = True special = True
valid_values = ValidValues(('tab', "Open a new tab in the existing "
"window and activate the window."), def __init__(self):
('tab-bg', "Open a new background tab in the " self.valid_values = \
"existing window and activate the " ValidValues(('tab', "Open a new tab in the existing "
"window."), "window and activate the window."),
('tab-silent', "Open a new tab in the existing " ('tab-bg', "Open a new background tab in the "
"window without activating " "existing window and activate the "
"the window."), "window."),
('tab-bg-silent', "Open a new background tab " ('tab-silent', "Open a new tab in the existing "
"in the existing window " "window without activating "
"without activating the " "the window."),
"window."), ('tab-bg-silent', "Open a new background tab "
('window', "Open in a new window.")) "in the existing window "
"without activating the "
"window."),
('window', "Open in a new window."))
class DownloadPathSuggestion(BaseType): class DownloadPathSuggestion(BaseType):
@ -1540,21 +1575,26 @@ class DownloadPathSuggestion(BaseType):
"""How to format the question when downloading.""" """How to format the question when downloading."""
special = True special = True
valid_values = ValidValues(('path', "Show only the download path."),
('filename', "Show only download filename."), def __init__(self):
('both', "Show download path and filename.")) self.valid_values = \
ValidValues(('path', "Show only the download path."),
('filename', "Show only download filename."),
('both', "Show download path and filename."))
class Referer(BaseType): class Referer(BaseType):
"""Send the Referer header.""" """Send the Referer header."""
valid_values = ValidValues(('always', "Always send."), def __init__(self):
('never', "Never send; this is not recommended," self.valid_values = \
" as some sites may break."), ValidValues(('always', "Always send."),
('same-domain', "Only send for the same domain." ('never', "Never send; this is not recommended,"
" This will still protect your privacy, but" " as some sites may break."),
" shouldn't break any sites.")) ('same-domain', "Only send for the same domain."
" This will still protect your privacy, but"
" shouldn't break any sites."))
class UserAgent(BaseType): class UserAgent(BaseType):
@ -1624,19 +1664,23 @@ class TabBarShow(BaseType):
"""When to show the tab bar.""" """When to show the tab bar."""
valid_values = ValidValues(('always', "Always show the tab bar."), def __init__(self):
('never', "Always hide the tab bar."), self.valid_values = \
('multiple', "Hide the tab bar if only one tab " ValidValues(('always', "Always show the tab bar."),
"is open."), ('never', "Always hide the tab bar."),
('switching', "Show the tab bar when switching " ('multiple', "Hide the tab bar if only one tab "
"tabs.")) "is open."),
('switching', "Show the tab bar when switching "
"tabs."))
class URLSegmentList(FlagList): class URLSegmentList(FlagList):
"""A list of URL segments.""" """A list of URL segments."""
valid_values = ValidValues('host', 'path', 'query', 'anchor') def __init__(self, none_ok=False):
super().__init__(none_ok)
self.valid_values = ValidValues('host', 'path', 'query', 'anchor')
class TimestampTemplate(BaseType): class TimestampTemplate(BaseType):