Move SettingValue to own file
This commit is contained in:
parent
04807489b7
commit
575a934892
@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from qutebrowser.config.conftypes import SettingValue
|
from qutebrowser.config.value import SettingValue
|
||||||
import qutebrowser.config.conftypes as types
|
import qutebrowser.config.conftypes as types
|
||||||
import qutebrowser.config.sections as sect
|
import qutebrowser.config.sections as sect
|
||||||
|
|
||||||
|
@ -56,51 +56,6 @@ class ValidValues:
|
|||||||
return self.values.__iter__()
|
return self.values.__iter__()
|
||||||
|
|
||||||
|
|
||||||
class SettingValue:
|
|
||||||
|
|
||||||
"""Base class for setting values.
|
|
||||||
|
|
||||||
Intended to be subclassed by config value "types".
|
|
||||||
|
|
||||||
Attributes:
|
|
||||||
typ: A BaseType subclass.
|
|
||||||
default: Default value if the user has not overridden it, as a string.
|
|
||||||
value: (property) The currently valid, most important value.
|
|
||||||
rawvalue: The current value as a raw string.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, typ, default=None):
|
|
||||||
"""Constructor.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
typ: The BaseType to use.
|
|
||||||
default: Raw value to set.
|
|
||||||
"""
|
|
||||||
self.typ = typ()
|
|
||||||
self.rawvalue = None
|
|
||||||
self.default = default
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
"""Get raw string value."""
|
|
||||||
return self.value
|
|
||||||
|
|
||||||
def transformed(self):
|
|
||||||
"""Get the transformed value."""
|
|
||||||
v = self.value
|
|
||||||
return self.typ.transform(v)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def value(self):
|
|
||||||
"""Get the currently valid value."""
|
|
||||||
return self.rawvalue if self.rawvalue is not None else self.default
|
|
||||||
|
|
||||||
@value.setter
|
|
||||||
def value(self, val):
|
|
||||||
"""Set the currently valid value."""
|
|
||||||
self.typ.validate(val)
|
|
||||||
self.rawvalue = val
|
|
||||||
|
|
||||||
|
|
||||||
class BaseType:
|
class BaseType:
|
||||||
|
|
||||||
"""A type used for a setting value.
|
"""A type used for a setting value.
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import qutebrowser.config.conftypes as conftypes
|
from qutebrowser.config.value import SettingValue
|
||||||
|
|
||||||
|
|
||||||
class KeyValue:
|
class KeyValue:
|
||||||
@ -123,7 +123,7 @@ class ValueList:
|
|||||||
self.valtype = valtype
|
self.valtype = valtype
|
||||||
self.values = OrderedDict()
|
self.values = OrderedDict()
|
||||||
self.default = OrderedDict(
|
self.default = OrderedDict(
|
||||||
[(key, conftypes.SettingValue(valtype, value))
|
[(key, SettingValue(valtype, value))
|
||||||
for key, value in defaults])
|
for key, value in defaults])
|
||||||
self.valdict = OrderedDict()
|
self.valdict = OrderedDict()
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ class ValueList:
|
|||||||
key: The key to set the value for, as a string.
|
key: The key to set the value for, as a string.
|
||||||
value: The value to set, as a string
|
value: The value to set, as a string
|
||||||
"""
|
"""
|
||||||
self.values[key] = conftypes.SettingValue(self.valtype)
|
self.values[key] = SettingValue(self.valtype)
|
||||||
self.values[key].value = value
|
self.values[key].value = value
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
@ -186,4 +186,4 @@ class ValueList:
|
|||||||
for k, v in sect.items():
|
for k, v in sect.items():
|
||||||
keytype.validate(k)
|
keytype.validate(k)
|
||||||
valtype.validate(v)
|
valtype.validate(v)
|
||||||
self.values[k] = conftypes.SettingValue(self.valtype, v)
|
self.values[k] = SettingValue(self.valtype, v)
|
||||||
|
63
qutebrowser/config/value.py
Normal file
63
qutebrowser/config/value.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
|
||||||
|
#
|
||||||
|
# This file is part of qutebrowser.
|
||||||
|
#
|
||||||
|
# qutebrowser is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# qutebrowser is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
"""A single value (with multiple layers possibly) in the config."""
|
||||||
|
|
||||||
|
|
||||||
|
class SettingValue:
|
||||||
|
|
||||||
|
"""Base class for setting values.
|
||||||
|
|
||||||
|
Intended to be subclassed by config value "types".
|
||||||
|
|
||||||
|
Attributes:
|
||||||
|
typ: A BaseType subclass.
|
||||||
|
default: Default value if the user has not overridden it, as a string.
|
||||||
|
value: (property) The currently valid, most important value.
|
||||||
|
rawvalue: The current value as a raw string.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, typ, default=None):
|
||||||
|
"""Constructor.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
typ: The BaseType to use.
|
||||||
|
default: Raw value to set.
|
||||||
|
"""
|
||||||
|
self.typ = typ()
|
||||||
|
self.rawvalue = None
|
||||||
|
self.default = default
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
"""Get raw string value."""
|
||||||
|
return self.value
|
||||||
|
|
||||||
|
def transformed(self):
|
||||||
|
"""Get the transformed value."""
|
||||||
|
v = self.value
|
||||||
|
return self.typ.transform(v)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def value(self):
|
||||||
|
"""Get the currently valid value."""
|
||||||
|
return self.rawvalue if self.rawvalue is not None else self.default
|
||||||
|
|
||||||
|
@value.setter
|
||||||
|
def value(self, val):
|
||||||
|
"""Set the currently valid value."""
|
||||||
|
self.typ.validate(val)
|
||||||
|
self.rawvalue = val
|
Loading…
Reference in New Issue
Block a user