コード例 #1
0
ファイル: core.py プロジェクト: joernnilsson/py3status
    def get_config_attribute(self, name, attribute):
        """
        Look for the attribute in the config.  Start with the named module and
        then walk up through any containing group and then try the general
        section of the config.
        """

        # A user can set a param to None in the config to prevent a param
        # being used.  This is important when modules do something like
        #
        # color = self.py3.COLOR_MUTED or self.py3.COLOR_BAD
        config = self.config["py3_config"]
        param = config[name].get(attribute, self.none_setting)
        if hasattr(param, "none_setting") and name in config[".module_groups"]:
            for module in config[".module_groups"][name]:
                if attribute in config.get(module, {}):
                    param = config[module].get(attribute)
                    break
        if hasattr(param, "none_setting"):
            # check py3status config section
            param = config["py3status"].get(attribute, self.none_setting)
        if hasattr(param, "none_setting"):
            # check py3status general section
            param = config["general"].get(attribute, self.none_setting)
        if param and (attribute == "color" or attribute.startswith("color_")):
            if param[0] != "#":
                # named color
                param = COLOR_NAMES.get(param.lower(), self.none_setting)
            elif len(param) == 4:
                # This is a color like #123 convert it to #112233
                param = ("#" + param[1] + param[1] + param[2] + param[2] +
                         param[3] + param[3])
        return param
コード例 #2
0
    def _get_config_setting(self, name, default=None):
        try:
            return self._config_setting[name]
        except KeyError:
            fn = self._py3_wrapper.get_config_attribute
            param = fn(self._module_full_name, name)

            # colors are special we want to make sure that we treat a color
            # that was explicitly set to None as a True value.  Ones that are
            # not set should be treated as None
            if name.startswith("color_"):
                _name = name[6:].lower()
                # use color "hidden" to hide blocks
                if _name == "hidden":
                    param = "hidden"
                elif hasattr(param, "none_setting"):
                    # see if named color and use if it is
                    param = COLOR_NAMES.get(_name)
                elif param is None:
                    param = self._none_color
            # if a non-color parameter and was not set then set to default
            elif hasattr(param, "none_setting"):
                param = default
            self._config_setting[name] = param
        return self._config_setting[name]
コード例 #3
0
ファイル: core.py プロジェクト: tobes/py3status
    def get_config_attribute(self, name, attribute):
        """
        Look for the attribute in the config.  Start with the named module and
        then walk up through any containing group and then try the general
        section of the config.
        """

        # A user can set a param to None in the config to prevent a param
        # being used.  This is important when modules do something like
        #
        # color = self.py3.COLOR_MUTED or self.py3.COLOR_BAD
        config = self.config['py3_config']
        param = config[name].get(attribute, self.none_setting)
        if hasattr(param, 'none_setting') and name in config['.module_groups']:
            for module in config['.module_groups'][name]:
                if attribute in config.get(module, {}):
                    param = config[module].get(attribute)
                    break
        if hasattr(param, 'none_setting'):
            # check py3status config section
            param = config['py3status'].get(attribute, self.none_setting)
        if hasattr(param, 'none_setting'):
            # check py3status general section
            param = config['general'].get(attribute, self.none_setting)
        if param and (attribute == 'color' or attribute.startswith('color_')):
            if param[0] != '#':
                # named color
                param = COLOR_NAMES.get(param.lower(), self.none_setting)
            elif len(param) == 4:
                # This is a color like #123 convert it to #112233
                param = (
                    '#' + param[1] + param[1] + param[2] +
                    param[2] + param[3] + param[3]
                )
        return param
コード例 #4
0
ファイル: py3.py プロジェクト: ultrabug/py3status
    def _get_config_setting(self, name, default=None):
        try:
            return self._config_setting[name]
        except KeyError:
            fn = self._py3_wrapper.get_config_attribute
            param = fn(self._module_full_name, name)

            # colors are special we want to make sure that we treat a color
            # that was explicitly set to None as a True value.  Ones that are
            # not set should be treated as None
            if name.startswith("color_"):
                _name = name[6:].lower()
                # use color "hidden" to hide blocks
                if _name == "hidden":
                    param = "hidden"
                elif hasattr(param, "none_setting"):
                    # see if named color and use if it is
                    param = COLOR_NAMES.get(_name)
                elif param is None:
                    param = self._none_color
            # if a non-color parameter and was not set then set to default
            elif hasattr(param, "none_setting"):
                param = default
            self._config_setting[name] = param
        return self._config_setting[name]
コード例 #5
0
ファイル: formatter.py プロジェクト: vladvasiliu/py3status
def expand_color(color, default=None, passthrough=False):
    """
    Expand various colors to #RRGGBB.
    """
    if color and color[0] == "#":
        color = color[1:]
        try:
            int(color, 16)
        except ValueError:
            return
        length = len(color)
        if length in [3, 4]:
            color = "".join(color[x] * 2 for x in range(length))
        elif length not in [6, 8]:
            return
        return "#" + color.upper()
    return COLOR_NAMES.get(color, color if passthrough else default)