Esempio n. 1
0
class GconfScale(gtk.HScale):
    def __init__(self, key=None, min=None, max=None, digits=0, reversed=False):
        gtk.HScale.__init__(self)
        if digits > 0:
            self.__setting = GconfSetting(key=key, type=float)
        else:
            self.__setting = GconfSetting(key=key, type=int)

        if reversed:
            self.__reversed = True
        else:
            self.__reversed = False
        
        self.set_range(min, max)
        self.set_digits(digits)
        self.set_value_pos(gtk.POS_RIGHT)
        self.connect("value-changed", self.on_value_changed) 
        if self.__reversed:
            self.set_value(max - self.__setting.get_value())
        else:
            self.set_value(self.__setting.get_value())

    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())
Esempio n. 2
0
class GconfScale(gtk.HScale):
    def __init__(self, key=None, min=None, max=None, digits=0, reversed=False):
        gtk.HScale.__init__(self)
        if digits > 0:
            self.__setting = GconfSetting(key=key, type=float)
        else:
            self.__setting = GconfSetting(key=key, type=int)

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

        self.set_range(min, max)
        self.set_digits(digits)
        self.set_value_pos(gtk.POS_RIGHT)
        self.connect("value-changed", self.on_value_changed)
        if self.__reversed:
            self.set_value(max - self.__setting.get_value())
        else:
            self.set_value(self.__setting.get_value())

    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())
Esempio n. 3
0
class GconfSpinButton(gtk.SpinButton):
    def __init__(self, key, min=0, max=0, step=0):
        self.__setting = GconfSetting(key=key, type=int)
        adjust = gtk.Adjustment(self.__setting.get_value(), min, max, step)

        gtk.SpinButton.__init__(self, adjust)
        self.connect('value-changed', self.on_value_changed) 

    def on_value_changed(self, widget):
        self.__setting.set_value(widget.get_value())
Esempio n. 4
0
class GconfSpinButton(gtk.SpinButton):
    def __init__(self, key, min=0, max=0, step=0):
        self.__setting = GconfSetting(key=key, type=int)
        adjust = gtk.Adjustment(self.__setting.get_value(), min, max, step)

        gtk.SpinButton.__init__(self, adjust)
        self.connect('value-changed', self.on_value_changed)

    def on_value_changed(self, widget):
        self.__setting.set_value(widget.get_value())
Esempio n. 5
0
class GconfCheckButton(gtk.CheckButton):
    def __init__(self, label=None, key=None, default=None, tooltip=None):
        super(GconfCheckButton, self).__init__()
        self.__setting = GconfSetting(key=key, default=default, type=bool)

        self.set_label(label)
        self.set_active(self.__setting.get_value())
        if tooltip:
            self.set_tooltip_text(tooltip)

        self.__setting.get_client().notify_add(key, self.value_changed)
        self.connect('toggled', self.button_toggled)

    def value_changed(self, client, id, entry, data=None):
        self.set_active(self.__setting.get_value())

    def button_toggled(self, widget, data=None):
        self.__setting.set_value(self.get_active())
Esempio n. 6
0
class GconfCheckButton(gtk.CheckButton):
    def __init__(self, label=None, key=None, default=None, tooltip=None):
        super(GconfCheckButton, self).__init__()
        self.__setting = GconfSetting(key=key, default=default, type=bool)

        self.set_label(label)
        self.set_active(self.__setting.get_value())
        if tooltip:
            self.set_tooltip_text(tooltip)

        self.__setting.get_client().notify_add(key, self.value_changed)
        self.connect('toggled', self.button_toggled)

    def value_changed(self, client, id, entry, data=None):
        self.set_active(self.__setting.get_value())

    def button_toggled(self, widget, data=None):
        self.__setting.set_value(self.get_active())
Esempio n. 7
0
class ButtonView(gtk.IconView):
    (COLUMN_KEY,
     COLUMN_LABEL,
    ) = range(2)

    values = {
        'menu': _('Menu'),
        ':': _('Title'),
        'maximize': _('Maximize'),
        'minimize': _('Minimize'),
        'close': _('Close'),
        'spacer': _('Spacer'),
    }

    def __init__(self):
        gtk.IconView.__init__(self)

        self.config = GconfSetting(key='/apps/metacity/general/button_layout')
        model = self.__create_model()
        self.set_model(model)
        self.update_model()

        self.set_text_column(self.COLUMN_LABEL)
        self.set_reorderable(True)
        self.set_orientation(gtk.ORIENTATION_HORIZONTAL)
        self.connect('selection-changed', self.on_button_changed)

    def __create_model(self):
        model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)

        return model

    def update_model(self, default=None):
        model = self.get_model()
        model.clear()

        value = default or self.config.get_value()
        if value:
            list = value.replace(':', ',:,').split(',')
        else:
            return model

        for k in list:
            k = k.strip()
            iter = model.append()
            if k in self.values:
                model.set(iter,
                          self.COLUMN_KEY, k,
                          self.COLUMN_LABEL, self.values[k])
            else:
                continue

        return model

    def on_button_changed(self, widget, data=None):
        model = widget.get_model()
        value = ','.join([i[self.COLUMN_KEY] for i in model])
        value = value.replace(',:', ':').replace(':,', ':')
        self.config.set_value(value)

    def add_spacer(self):
        model = self.get_model()
        iter = model.append()
        model.set(iter,
                  self.COLUMN_KEY, 'spacer',
                  self.COLUMN_LABEL, self.values['spacer'])
        self.on_button_changed(self)

    def remove_spacer(self):
        model = self.get_model()
        for i, row in enumerate(model):
            if row[self.COLUMN_KEY] == 'spacer':
                del model[i, self.COLUMN_KEY]
                break
        self.on_button_changed(self)

    def has_spacer(self):
        model = self.get_model()
        for i, row in enumerate(model):
            if row[self.COLUMN_KEY] == 'spacer':
                return True
        return False