コード例 #1
0
    def test_check_theme_completeness_with_partial_config(self):
        theme_options = config.get_options_for_section("theme")
        theme_options[REQUIRED_THEME_OPTIONS[0]] = "Test"

        self.assertEqual(
            theme.check_theme_completeness(theme_options),
            theme.ThemeCompleteness.PARTIALLY_DEFINED,
        )
コード例 #2
0
 def test_check_theme_completeness_with_theme_fully_set(self):
     theme_options = config.get_options_for_section("theme")
     for opt in REQUIRED_THEME_OPTIONS:
         theme_options[opt] = "Test"
     self.assertEqual(
         theme.check_theme_completeness(theme_options),
         theme.ThemeCompleteness.FULLY_DEFINED,
     )
コード例 #3
0
    def test_get_options_for_section(self):
        config._set_option("theme.primaryColor", "000000", "test")
        config._set_option("theme.font", "serif", "test")

        expected = {
            "primaryColor": "000000",
            "secondaryBackgroundColor": None,
            "backgroundColor": None,
            "textColor": None,
            "font": "serif",
        }
        self.assertEqual(config.get_options_for_section("theme"), expected)
コード例 #4
0
def _populate_theme_msg(msg: CustomThemeConfig) -> None:
    enum_encoded_options = {"base", "font"}
    theme_opts = config.get_options_for_section("theme")

    if not any(theme_opts.values()):
        return

    for option_name, option_val in theme_opts.items():
        if option_name not in enum_encoded_options and option_val is not None:
            setattr(msg, to_snake_case(option_name), option_val)

    # NOTE: If unset, base and font will default to the protobuf enum zero
    # values, which are BaseTheme.LIGHT and FontFamily.SANS_SERIF,
    # respectively. This is why we both don't handle the cases explicitly and
    # also only log a warning when receiving invalid base/font options.
    base_map = {
        "light": msg.BaseTheme.LIGHT,
        "dark": msg.BaseTheme.DARK,
    }
    base = theme_opts["base"]
    if base is not None:
        if base not in base_map:
            LOGGER.warning(
                f'"{base}" is an invalid value for theme.base.'
                f" Allowed values include {list(base_map.keys())}."
                ' Setting theme.base to "light".'
            )
        else:
            msg.base = base_map[base]

    font_map = {
        "sans serif": msg.FontFamily.SANS_SERIF,
        "serif": msg.FontFamily.SERIF,
        "monospace": msg.FontFamily.MONOSPACE,
    }
    font = theme_opts["font"]
    if font is not None:
        if font not in font_map:
            LOGGER.warning(
                f'"{font}" is an invalid value for theme.font.'
                f" Allowed values include {list(font_map.keys())}."
                ' Setting theme.font to "sans serif".'
            )
        else:
            msg.font = font_map[font]
コード例 #5
0
def _populate_theme_msg(msg: CustomThemeConfig) -> None:
    theme_opts = config.get_options_for_section("theme")

    if (theme.check_theme_completeness(theme_opts) !=
            theme.ThemeCompleteness.FULLY_DEFINED):
        return

    for option_name, option_val in theme_opts.items():
        # We don't set the "font" option here as it needs to be converted
        # from string -> enum.
        if option_name != "font" and option_val is not None:
            setattr(msg, to_snake_case(option_name), option_val)

    font_map = {
        "sans serif": msg.FontFamily.SANS_SERIF,
        "serif": msg.FontFamily.SERIF,
        "monospace": msg.FontFamily.MONOSPACE,
    }
    msg.font = font_map.get(
        config.get_option("theme.font"),
        msg.FontFamily.SANS_SERIF,
    )
コード例 #6
0
 def get_options_for_section(section):
     if section == "theme":
         return theme_opts
     return config.get_options_for_section(section)