Logo Search packages:      
Sourcecode: caribou version File versions  Download package


from gi.repository import GLib, GObject


00012 class Setting(GObject.GObject):
    __gsignals__ = {'value-changed' :
                    'sensitivity-changed' :
    def __init__(self, name, label, children=[]):
        self.name = name
        self.label = label
        self.children = children

    def sensitive(self):
        return getattr(self, '_sensitive', True)

    def sensitive(self, sensitive):
        changed = getattr(self, '_sensitive', sensitive) != sensitive
        self._sensitive = sensitive
        self.emit('sensitivity-changed', sensitive)

    def __len__(self):
        return len(self.children)

    def __getitem__(self, i):
        return self.children[i]

    def __setitem__(self, i, v):
        self.children[i] = v

    def __delitem__(self, i):
        del self.children[i]

    def __iter__(self):
        return self.children.__iter__()

00052 class SettingsGroup(Setting):

00055 class SettingsTopGroup(SettingsGroup):
    def __init__(self, label, path, schema_id, children=[]):
        SettingsGroup.__init__(self, "_top", label, children)
        self.path = path
        self.schema_id = schema_id
        self._manager = None

    def __call__(self):
        if self._manager is None:
            from caribou.settings.settings_manager import SettingsManager
            self._manager =  SettingsManager(self)
        return self._manager

00068 class ValueSetting(Setting):
    variant_type = ''
    def __init__(self, name, label, default, short_desc="", long_desc="",
                 allowed=[], entry_type=ENTRY_DEFAULT, sensitive=None,
                 user_visible=True, children=[],
                 insensitive_when_false=[], insensitive_when_true=[]):
        Setting.__init__(self, name, label, children)
        self.short_desc = short_desc
        self.long_desc = long_desc
        self.allowed = allowed
        self.entry_type = entry_type or self.__class__.entry_type
        if sensitive is not None:
            self.sensitive = sensitive
        self.user_visible = user_visible
        self.default = default
        self.insensitive_when_false = insensitive_when_false
        self.insensitive_when_true = insensitive_when_true
        self.hush = False

    def value(self):
        return getattr(self, '_value', self.default)

    def value(self, val):
        _val = self.convert_value(val)
        if self.allowed and _val not in [a for a, b in self.allowed]:
            raise ValueError, "'%s' not a valid value" % _val
        self._value = _val
        if not self.hush:
            self.emit('value-changed', _val)

    def gsettings_key(self):
        return self.name.replace('_', '-')

    def is_true(self):
        return bool(self.value)

    def gvariant(self):
        return GLib.Variant(self.variant_type, self.value)

00113 class BooleanSetting(ValueSetting):
    variant_type = 'b'
    entry_type = ENTRY_CHECKBOX
    def convert_value(self, val):
        # Almost anything could be a boolean.
        return bool(val)

00120 class IntegerSetting(ValueSetting):
    variant_type = 'i'
    entry_type = ENTRY_SPIN
    def __init__(self, *args, **kwargs):
        self.min = kwargs.pop('min', GObject.G_MININT)
        self.max = kwargs.pop('max', GObject.G_MAXINT)
        ValueSetting.__init__(self, *args, **kwargs)

    def convert_value(self, val):
        return int(val)

00131 class FloatSetting(ValueSetting):
    variant_type = 'd'
    entry_type = ENTRY_SPIN
    def __init__(self, *args, **kwargs):
        self.min = kwargs.pop('min', GObject.G_MINFLOAT)
        self.max = kwargs.pop('max', GObject.G_MAXFLOAT)
        ValueSetting.__init__(self, *args, **kwargs)

    def convert_value(self, val):
        return float(val)

00142 class StringSetting(ValueSetting):
    variant_type = 's'
    def convert_value(self, val):
        return str(val)

00147 class ColorSetting(StringSetting):
    entry_type = ENTRY_COLOR

00150 class FontSetting(StringSetting):
    entry_type = ENTRY_FONT

Generated by  Doxygen 1.6.0   Back to index