Ejemplo n.º 1
0
class Scale(Gtk.HScale):
    def __init__(self, key=None, min=None, max=None, digits=0,
                 reversed=False, backend='gconf'):
        GObject.GObject.__init__(self)

        if digits > 0:
            type = float
        else:
            type = int

        if backend == 'gconf':
            self._setting = GconfSetting(key=key, type=type)
        elif backend == 'compiz':
            self._setting = CompizSetting(key=key)

        if reversed:
            self._reversed = True
        else:
            self._reversed = False

        self.set_range(min, max)
        self.set_digits(digits)
        self.set_value_pos(Gtk.PositionType.RIGHT)
        if self._reversed:
            self.set_value(max - self._setting.get_value())
        else:
            self.set_value(self._setting.get_value())

        self.connect("value-changed", self.on_value_changed)

    def on_value_changed(self, widget, data=None):
        if self._reversed:
            self._setting.set_value(100 - widget.get_value())
        else:
            self._setting.set_value(widget.get_value())
Ejemplo n.º 2
0
    def on_edge_changed(self, widget, plugin):
        edges = ['TopLeft', 'TopRight', 'BottomLeft', 'BottomRight']
        edges.remove(widget.edge)

        if plugin:
            for edge in edges:
                edge_combobox = getattr(self, edge)

                if edge_combobox.get_current_plugin() == plugin:
                    edge_combobox.set_to_none()
                    break

            setting = CompizSetting("%s.%s" % (widget.get_current_plugin(),
                widget.get_current_key()))
            setting.set_value(widget.edge)
Ejemplo n.º 3
0
    def on_changed(self, widget):
        plugin = self.get_current_plugin()
        key = self.get_current_key()
        log.debug("ComboBox changed: from %s to %s" % (self.old_plugin, plugin))

        if self.old_plugin:
            for name, key, text in self.edge_settings:
                if name == self.old_plugin:
                    log.debug('%s has to unset (%s)' % (name, key))
                    setting = CompizSetting("%s.%s" % (name, key))
                    setting.set_value('')
                    break

        self.old_plugin = plugin
        self.old_key = key

        log.debug('%s changed to "%s"' % (widget.edge, plugin))
        self.emit('edge_changed', plugin)
Ejemplo n.º 4
0
class ComboBox(Gtk.ComboBox):
    def __init__(self, key=None, texts=None, values=None,
                 type="string", backend='gconf'):
        GObject.GObject.__init__(self)

        if backend == 'gconf':
            self._setting = GconfSetting(key=key, type=str)
        elif backend == 'gsettings':
            self._setting = GSetting(key=key, type=str)
        elif backend == 'config':
            self._setting = ConfigSetting(key=key, type=str)
        elif backend == 'compiz':
            self._setting = CompizSetting(key=key)

        if type == 'int':
            model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_INT)
        else:
            model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
        self.set_model(model)

        cell = Gtk.CellRendererText()
        self.pack_start(cell, True)
        self.add_attribute(cell, 'text', 0)

        current_value = self._setting.get_value()

        for text, value in zip(texts, values):
            iter = model.append((text, value))
            if current_value == value:
                self.set_active_iter(iter)

        self.connect("changed", self.value_changed_cb)

    def value_changed_cb(self, widget):
        iter = widget.get_active_iter()
        text = self.get_model().get_value(iter, 1)
        log.debug("ComboBox value changed to %s" % text)

        self._setting.set_value(text)