log-javascript-console now String option: none, debug, info
Make BaseType.valid_values per-instance variable
This commit is contained in:
parent
f847ddf3cb
commit
ff6d3e05a6
@ -503,8 +503,16 @@ class BrowserPage(QWebPage):
|
||||
|
||||
def javaScriptConsoleMessage(self, msg, line, source):
|
||||
"""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):
|
||||
"""Override QWebPage's chooseFile to be able to chose a file to upload.
|
||||
|
@ -356,7 +356,9 @@ class ConfigManager(QObject):
|
||||
('tabs', 'position'): _transform_position,
|
||||
('ui', 'downloads-position'): _transform_position,
|
||||
('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)
|
||||
|
@ -214,8 +214,13 @@ def data(readonly=False):
|
||||
"launched."),
|
||||
|
||||
('log-javascript-console',
|
||||
SettingValue(typ.Bool(), 'false'),
|
||||
"Whether to log javascript console messages."),
|
||||
SettingValue(
|
||||
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',
|
||||
SettingValue(typ.Bool(), 'false'),
|
||||
|
@ -121,11 +121,11 @@ class BaseType:
|
||||
mentioned in the config file.
|
||||
"""
|
||||
|
||||
valid_values = None
|
||||
special = False
|
||||
|
||||
def __init__(self, none_ok=False):
|
||||
def __init__(self, none_ok=False, valid_values=None):
|
||||
self.none_ok = none_ok
|
||||
self.valid_values = valid_values
|
||||
|
||||
def _basic_validation(self, value):
|
||||
"""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,
|
||||
none_ok=False, completions=None):
|
||||
super().__init__(none_ok)
|
||||
none_ok=False, completions=None, valid_values=None):
|
||||
super().__init__(none_ok, valid_values)
|
||||
if minlen is not None and minlen < 1:
|
||||
raise ValueError("minlen ({}) needs to be >= 1!".format(minlen))
|
||||
elif maxlen is not None and maxlen < 1:
|
||||
@ -650,7 +650,10 @@ class ColorSystem(MappingType):
|
||||
"""Color systems for interpolation."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('rgb', "Interpolate in the RGB color system."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
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."))
|
||||
@ -1092,7 +1095,10 @@ class HintMode(BaseType):
|
||||
"""Base class for the hints -> mode setting."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('number', "Use numeric hints."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('number', "Use numeric hints."),
|
||||
('letter', "Use the chars in the hints -> "
|
||||
"chars setting."))
|
||||
|
||||
@ -1102,7 +1108,10 @@ class Proxy(BaseType):
|
||||
"""A proxy URL or special value."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('system', "Use the system wide proxy."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('system', "Use the system wide proxy."),
|
||||
('none', "Don't use any proxy"))
|
||||
|
||||
PROXY_TYPES = {
|
||||
@ -1330,7 +1339,8 @@ class Position(MappingType):
|
||||
|
||||
"""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 = {
|
||||
'top': QTabWidget.North,
|
||||
@ -1344,7 +1354,8 @@ class VerticalPosition(BaseType):
|
||||
|
||||
"""The position of the download bar."""
|
||||
|
||||
valid_values = ValidValues('top', 'bottom')
|
||||
def __init__(self):
|
||||
self.valid_values = ValidValues('top', 'bottom')
|
||||
|
||||
|
||||
class UrlList(List):
|
||||
@ -1389,7 +1400,8 @@ class SelectOnRemove(MappingType):
|
||||
"""Which tab to select when the focused tab is removed."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(
|
||||
def __init__(self):
|
||||
self.valid_values = ValidValues(
|
||||
('left', "Select the tab on the left."),
|
||||
('right', "Select the tab on the right."),
|
||||
('previous', "Select the previously selected tab."))
|
||||
@ -1406,7 +1418,10 @@ class LastClose(BaseType):
|
||||
"""Behavior when the last tab is closed."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('ignore', "Don't do anything."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('ignore', "Don't do anything."),
|
||||
('blank', "Load a blank page."),
|
||||
('startpage', "Load the start page."),
|
||||
('default-page', "Load the default page."),
|
||||
@ -1418,7 +1433,10 @@ class AcceptCookies(BaseType):
|
||||
"""Control which cookies to accept."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('all', "Accept all cookies."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('all', "Accept all cookies."),
|
||||
('no-3rdparty', "Accept cookies from the same"
|
||||
" origin only."),
|
||||
('no-unknown-3rdparty', "Accept cookies from "
|
||||
@ -1432,7 +1450,9 @@ class ConfirmQuit(FlagList):
|
||||
"""Whether to display a confirmation when the window is closed."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('always', "Always show a confirmation."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = ValidValues(('always', "Always show a confirmation."),
|
||||
('multiple-tabs', "Show a confirmation if "
|
||||
"multiple tabs are opened."),
|
||||
('downloads', "Show a confirmation if "
|
||||
@ -1462,7 +1482,10 @@ class ForwardUnboundKeys(BaseType):
|
||||
"""Whether to forward unbound keys."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('all', "Forward all unbound keys."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('all', "Forward all unbound keys."),
|
||||
('auto', "Forward unbound non-alphanumeric "
|
||||
"keys."),
|
||||
('none', "Don't forward any keys."))
|
||||
@ -1473,7 +1496,10 @@ class CloseButton(BaseType):
|
||||
"""Mouse button used to close tabs."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('right', "Close tabs on right-click."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('right', "Close tabs on right-click."),
|
||||
('middle', "Close tabs on middle-click."),
|
||||
('none', "Don't close tabs using the mouse."))
|
||||
|
||||
@ -1483,7 +1509,10 @@ class NewTabPosition(BaseType):
|
||||
"""How new tabs are positioned."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('left', "On the left of the current tab."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
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."))
|
||||
@ -1494,7 +1523,10 @@ class IgnoreCase(Bool):
|
||||
"""Whether to ignore case when searching."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('true', "Search case-insensitively"),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('true', "Search case-insensitively"),
|
||||
('false', "Search case-sensitively"),
|
||||
('smart', "Search case-sensitively if there "
|
||||
"are capital chars"))
|
||||
@ -1520,7 +1552,10 @@ class NewInstanceOpenTarget(BaseType):
|
||||
"""How to open links in an existing instance if a new one is launched."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('tab', "Open a new tab in the existing "
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('tab', "Open a new tab in the existing "
|
||||
"window and activate the window."),
|
||||
('tab-bg', "Open a new background tab in the "
|
||||
"existing window and activate the "
|
||||
@ -1540,7 +1575,10 @@ class DownloadPathSuggestion(BaseType):
|
||||
"""How to format the question when downloading."""
|
||||
|
||||
special = True
|
||||
valid_values = ValidValues(('path', "Show only the download path."),
|
||||
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('path', "Show only the download path."),
|
||||
('filename', "Show only download filename."),
|
||||
('both', "Show download path and filename."))
|
||||
|
||||
@ -1549,7 +1587,9 @@ class Referer(BaseType):
|
||||
|
||||
"""Send the Referer header."""
|
||||
|
||||
valid_values = ValidValues(('always', "Always send."),
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('always', "Always send."),
|
||||
('never', "Never send; this is not recommended,"
|
||||
" as some sites may break."),
|
||||
('same-domain', "Only send for the same domain."
|
||||
@ -1624,7 +1664,9 @@ class TabBarShow(BaseType):
|
||||
|
||||
"""When to show the tab bar."""
|
||||
|
||||
valid_values = ValidValues(('always', "Always show the tab bar."),
|
||||
def __init__(self):
|
||||
self.valid_values = \
|
||||
ValidValues(('always', "Always show the tab bar."),
|
||||
('never', "Always hide the tab bar."),
|
||||
('multiple', "Hide the tab bar if only one tab "
|
||||
"is open."),
|
||||
@ -1636,7 +1678,9 @@ class URLSegmentList(FlagList):
|
||||
|
||||
"""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):
|
||||
|
Loading…
Reference in New Issue
Block a user