Exemplo n.º 1
0
    def addConfigSection(self, section, label, desc, expl, config):
        """Adds a section to the config. `config` is a list of config tuples as used in plugin api defined as:
        The order of the config elements is preserved with OrderedDict
        """
        d = OrderedDict()

        for entry in config:
            if len(entry) != 4:
                raise ValueError("Config entry must be of length 4")

            # Values can have different roles depending on the two config formats
            conf_name, type_label, label_desc, default_input = entry

            # name, label, desc, input
            if isinstance(default_input, Input):
                input = default_input
                conf_label = type_label
                conf_desc = label_desc
            # name, type, label, default
            else:
                input = Input(to_input(type_label))
                input.default_value = from_string(default_input, input.type)
                conf_label = label_desc
                conf_desc = ""

            d[conf_name] = ConfigData(gettext(conf_label), gettext(conf_desc), input)

        data = SectionTuple(gettext(label), gettext(desc), gettext(expl), d)
        self.config[section] = data
Exemplo n.º 2
0
    def set(self, section, option, value, sync=True):
        """set value"""

        data = self.config[section].config[option]
        value = from_string(value, data.input.type)
        old_value = self.get(section, option)

        # only save when different values
        if value != old_value:
            if section not in self.values: self.values[section] = {}
            self.values[section][option] = value
            if sync:
                self.save()
            return True

        return False
Exemplo n.º 3
0
    def set(self, section, option, value, sync=True):
        """set value"""

        data = self.config[section].config[option]
        value = from_string(value, data.input.type)
        old_value = self.get(section, option)

        # only save when different values
        if value != old_value:
            if section not in self.values: self.values[section] = {}
            self.values[section][option] = value
            if sync:
                self.save()
            return True

        return False
Exemplo n.º 4
0
    def set(self, section, option, value, sync=True, user=None):
        """ set config value  """

        changed = False
        if section in self.parser and user is None:
            changed = self.parser.set(section, option, value, sync)
        else:
            data = self.config[section].config[option]
            value = from_string(value, data.input.type)
            old_value = self.get(section, option)

            # Values will always be saved to db, sync is ignored
            if value != old_value:
                changed = True
                self.values[user, section][option] = value
                if sync:
                    self.saveValues(user, section)

        if changed:
            self.core.evm.dispatchEvent("config:changed", section, option, value)
        return changed
Exemplo n.º 5
0
    def set(self, section, option, value, sync=True, user=None):
        """ set config value  """

        changed = False
        if section in self.parser and user is None:
            changed = self.parser.set(section, option, value, sync)
        else:
            data = self.config[section].config[option]
            value = from_string(value, data.input.type)
            old_value = self.get(section, option)

            # Values will always be saved to db, sync is ignored
            if value != old_value:
                changed = True
                self.values[user, section][option] = value
                if sync: self.saveValues(user, section)

        if changed:
            self.core.evm.dispatchEvent("config:changed", section, option,
                                        value)
        return changed