Exemple #1
0
class GconfComboBox(gtk.ComboBox):
    def __init__(self, key=None, texts=None, values=None, type="string"):
        super(GconfComboBox, self).__init__()

        self.__setting = GconfSetting(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 dict(zip(texts, values)).items():
            iter = model.append(None)
            model.set(iter, 0, text, 1, 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("GconfComboBox value changed to %s" % text)

        self.__setting.get_client().set_value(self.__setting.get_key(), text)
Exemple #2
0
class GconfComboBox(gtk.ComboBox):
    def __init__(self, key=None, texts=None, values=None):
        super(GconfComboBox, self).__init__()

        self.__setting = GconfSetting(key=key)
        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 dict(zip(texts, values)).items():
            iter = model.append(None)
            model.set(iter, 0, text, 1, 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("GconfComboBox value changed to %s" % text)

        self.__setting.get_client().set_value(self.__setting.get_key(), text)
Exemple #3
0
class GconfEntry(gtk.Entry):
    def __init__(self, key=None, default=None):
        gtk.Entry.__init__(self)
        self.__setting = GconfSetting(key=key, default=default, type=str)

        string = self.__setting.get_value()
        if string:
            self.set_text(string)
        else:
            self.set_text(_("Unset"))

    def is_changed(self):
        return self.get_string_value() != self.get_text()

    def get_string_value(self):
        return self.__setting.get_value()

    def connect_activate_signal(self):
        self.connect('activate', self.on_edit_finished_cb)

    def get_gsetting(self):
        return self.__setting

    def reset(self):
        self.set_text(self.get_string_value())

    def on_edit_finished_cb(self, widget):
        string = self.get_text()
        client = self.__setting.get_client()
        key = self.__setting.get_key()
        if string:
            client.set_string(key, self.get_text())
        else:
            client.unset(key)
            self.set_text(_("Unset"))
Exemple #4
0
class GconfEntry(gtk.Entry):
    def __init__(self, key=None, default=None):
        gtk.Entry.__init__(self)
        self.__setting = GconfSetting(key=key, default=default, type=str)

        string = self.__setting.get_value()
        if string:
            self.set_text(string)
        else:
            self.set_text(_("Unset"))

    def is_changed(self):
        return self.get_string_value() != self.get_text()

    def get_string_value(self):
        return self.__setting.get_value()

    def connect_activate_signal(self):
        self.connect('activate', self.on_edit_finished_cb)

    def get_gsetting(self):
        return self.__setting

    def reset(self):
        self.set_text(self.get_string_value())

    def on_edit_finished_cb(self, widget):
        string = self.get_text()
        client = self.__setting.get_client()
        key = self.__setting.get_key()
        if string:
            client.set_string(key, self.get_text())
        else:
            client.unset(key)
            self.set_text(_("Unset"))
Exemple #5
0
    def __init__(self, key=None, default=None):
        gtk.Entry.__init__(self)
        self.__setting = GconfSetting(key=key, default=default, type=str)

        string = self.__setting.get_value()
        if string:
            self.set_text(string)
        else:
            self.set_text(_("Unset"))
Exemple #6
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())
Exemple #7
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())
Exemple #8
0
    def __init__(self, key):
        super(gtk.Button, self).__init__()

        self.__setting = GconfSetting(key=key)

        reset_image = gtk.image_new_from_stock(gtk.STOCK_REVERT_TO_SAVED,
                                               gtk.ICON_SIZE_MENU)
        self.set_property('image', reset_image)

        self.set_tooltip_text(
            _('Reset setting to default value: %s') % self.get_default_value())
Exemple #9
0
    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)
Exemple #10
0
 def __init__(self, key=None, min=None, max=None, digits=0):
     gtk.HScale.__init__(self)
     if digits > 0:
         self.__setting = GconfSetting(key=key, type=float)
     else:
         self.__setting = GconfSetting(key=key, type=int)
     
     self.set_range(min, max)
     self.set_digits(digits)
     self.set_value_pos(gtk.POS_RIGHT)
     self.connect("value-changed", self.on_value_changed) 
     self.set_value(self.__setting.get_value())
Exemple #11
0
    def __init__(self, key=None, default=None):
        gtk.Entry.__init__(self)
        self.__setting = GconfSetting(key=key, default=default, type=str)

        string = self.__setting.get_value()
        if string:
            self.set_text(string)
        else:
            self.set_text(_("Unset"))
Exemple #12
0
    def __init__(self, key):
        super(gtk.Button, self).__init__()

        self.__setting = GconfSetting(key=key)

        reset_image = gtk.image_new_from_stock(gtk.STOCK_REVERT_TO_SAVED, gtk.ICON_SIZE_MENU)
        self.set_property('image', reset_image)

        self.set_tooltip_text(_('Reset setting to default value: %s') % self.get_default_value())
def GconfComboBox(key=None, texts=None, values=None):
    def value_changed_cb(widget, setting):
        text = widget.get_active_text()

        setting.get_client().set_value(setting.get_key(), setting.values[setting.texts.index(text)])

    combobox = gtk.combo_box_new_text()
    setting = GconfSetting(key=key)
    setting.texts = texts
    setting.values = values

    for text in texts:
        combobox.append_text(text)

    if setting.get_value() in values:
        combobox.set_active(values.index(setting.get_value()))
    combobox.connect("changed", value_changed_cb, setting)

    return combobox
Exemple #14
0
    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)
Exemple #15
0
    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())
Exemple #16
0
    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)
Exemple #17
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())
Exemple #18
0
    def __init__(self, key=None, texts=None, values=None, type="string"):
        super(GconfComboBox, self).__init__()

        self.__setting = GconfSetting(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 dict(zip(texts, values)).items():
            iter = model.append(None)
            model.set(iter, 0, text, 1, value)
            if current_value == value:
                self.set_active_iter(iter)

        self.connect("changed", self.value_changed_cb)
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())
Exemple #20
0
from ubuntutweak.common.config import Config, TweakSettings
from ubuntutweak.common.package import PACKAGE_WORKER, PackageInfo
from ubuntutweak.common.notify import notify
from ubuntutweak.common.misc import URLLister

log = logging.getLogger("SourceCenter")

APP_PARSER = AppParser()
CONFIG = Config()
PPA_MIRROR = []
UNCONVERT = False
WARNING_KEY = '/apps/ubuntu-tweak/disable_thirdparty_warning'
UBUNTU_CN_STR = 'archive.ubuntu.org.cn/ubuntu-cn'
UBUNTU_CN_URL = 'http://archive.ubuntu.org.cn/ubuntu-cn/'
#UBUNTU_CN_URL = 'http://127.0.0.1:8000'
UPDATE_SETTING = GconfSetting(key='/apps/ubuntu-tweak/sourcecenter_update',
                              type=bool)
VERSION_SETTING = GconfSetting(key='/apps/ubuntu-tweak/sourcecenter_version',
                               type=str)

SOURCE_ROOT = os.path.join(consts.CONFIG_ROOT, 'sourcecenter')
SOURCE_VERSION_URL = utdata.get_version_url('/sourcecenter_version/')
UPGRADE_DICT = {}


def get_source_data_url():
    return utdata.get_download_url('/static/utdata/sourcecenter-%s.tar.gz' %
                                   VERSION_SETTING.get_value())


def get_source_logo_from_filename(file_name):
    path = os.path.join(SOURCE_ROOT, file_name)
    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)
Exemple #22
0
class ButtonView(gtk.IconView):
    (
        COLUMN_VALUE,
        COLUMN_LABEL,
    ) = range(2)

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

    config = GconfSetting(key='/apps/metacity/general/button_layout')

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

        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_selection_changed)

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

        return model

    @classmethod
    def get_control_items(cls):
        dict = cls.values.copy()
        dict.pop(':')
        return dict.items()

    @classmethod
    def is_value(cls, value):
        if value == cls.config.get_value():
            return True
        else:
            return False

    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()
            if k in self.values:
                iter = model.append()
                model.set(iter, self.COLUMN_VALUE, k, self.COLUMN_LABEL,
                          self.values[k])
            else:
                continue

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

    def add_button(self, value):
        model = self.get_model()
        iter = model.append()
        model.set(iter, self.COLUMN_VALUE, value, self.COLUMN_LABEL,
                  self.values[value])
        self.on_selection_changed(self)

    def remove_button(self, value):
        model = self.get_model()
        for i, row in enumerate(model):
            if row[self.COLUMN_VALUE] == value:
                del model[i, self.COLUMN_VALUE]
        self.on_selection_changed(self)

    def has_button(self, value):
        model = self.get_model()
        for i, row in enumerate(model):
            if row[self.COLUMN_VALUE] == value:
                return True
        return False
Exemple #23
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