Exemple #1
0
    def test_scrollarea_position(self) -> None:
        """
        Test position.
        """
        self.assertEqual(
            len(get_scrollbars_from_position(SCROLLAREA_POSITION_FULL)), 4)
        for i in (POSITION_EAST, POSITION_EAST, POSITION_WEST, POSITION_NORTH):
            self.assertIsInstance(get_scrollbars_from_position(i), str)
        self.assertEqual(get_scrollbars_from_position(POSITION_NORTHWEST),
                         (POSITION_NORTH, POSITION_WEST))
        self.assertEqual(get_scrollbars_from_position(POSITION_NORTHEAST),
                         (POSITION_NORTH, POSITION_EAST))
        self.assertEqual(get_scrollbars_from_position(POSITION_SOUTHEAST),
                         (POSITION_SOUTH, POSITION_EAST))
        self.assertEqual(get_scrollbars_from_position(POSITION_SOUTHWEST),
                         (POSITION_SOUTH, POSITION_WEST))
        self.assertEqual(
            get_scrollbars_from_position(SCROLLAREA_POSITION_BOTH_HORIZONTAL),
            (POSITION_SOUTH, POSITION_NORTH))
        self.assertEqual(
            get_scrollbars_from_position(SCROLLAREA_POSITION_BOTH_VERTICAL),
            (POSITION_EAST, POSITION_WEST))

        # Invalid
        self.assertRaises(ValueError,
                          lambda: get_scrollbars_from_position(INPUT_TEXT))
        self.assertRaises(
            ValueError, lambda: get_scrollbars_from_position(POSITION_CENTER))
Exemple #2
0
    def validate(self) -> 'Theme':
        """
        Validate the values of the theme. If there's a invalid parameter throws an
        ``AssertionError``.

        This function also converts all lists to tuples. This is done because lists
        are mutable.

        :return: Self reference
        """
        if self._disable_validation:
            return self

        # Boolean asserts
        assert isinstance(self.scrollbar_shadow, bool)
        assert isinstance(self.title_bar_modify_scrollarea, bool)
        assert isinstance(self.title_close_button, bool)
        assert isinstance(self.title_font_antialias, bool)
        assert isinstance(self.title_font_shadow, bool)
        assert isinstance(self.widget_font_antialias, bool)
        assert isinstance(self.widget_font_background_color_from_menu, bool)
        assert isinstance(self.widget_font_shadow, bool)

        # Value type checks
        assert_alignment(self.widget_alignment)
        assert_cursor(self.scrollbar_cursor)
        assert_cursor(self.title_close_button_cursor)
        assert_cursor(self.widget_cursor)
        assert_font(self.title_font)
        assert_font(self.widget_font)
        assert_position(self.scrollbar_shadow_position)
        assert_position(self.title_font_shadow_position)
        assert_position(self.widget_font_shadow_position)

        assert _check_menubar_style(self.title_bar_style)
        assert get_scrollbars_from_position(self.scrollarea_position) is not None

        # Check selection effect if None
        if self.widget_selection_effect is None:
            self.widget_selection_effect = NoneSelection()

        assert isinstance(self.cursor_switch_ms, NumberInstance)
        assert isinstance(self.fps, NumberInstance)
        assert isinstance(self.scrollbar_shadow_offset, int)
        assert isinstance(self.scrollbar_slider_pad, NumberInstance)
        assert isinstance(self.scrollbar_thick, int)
        assert isinstance(self.title_floating, bool)
        assert isinstance(self.title_font_shadow_offset, int)
        assert isinstance(self.title_font_size, int)
        assert isinstance(self.title_updates_pygame_display, bool)
        assert isinstance(self.widget_background_inflate_to_selection, bool)
        assert isinstance(self.widget_border_width, int)
        assert isinstance(self.widget_box_border_width, int)
        assert isinstance(self.widget_font_shadow_offset, int)
        assert isinstance(self.widget_font_size, int)
        assert isinstance(self.widget_padding, PaddingInstance)
        assert isinstance(self.widget_selection_effect, Selection)
        assert isinstance(self.widget_tab_size, int)

        # Format colors, this converts all color lists to tuples automatically,
        # if image, return the same object
        self.background_color = self._format_color_opacity(self.background_color)
        self.cursor_color = self._format_color_opacity(self.cursor_color)
        self.cursor_selection_color = self._format_color_opacity(self.cursor_selection_color)
        self.focus_background_color = self._format_color_opacity(self.focus_background_color)
        self.readonly_color = self._format_color_opacity(self.readonly_color)
        self.readonly_selected_color = self._format_color_opacity(self.readonly_selected_color)
        self.scrollbar_color = self._format_color_opacity(self.scrollbar_color)
        self.scrollbar_shadow_color = self._format_color_opacity(self.scrollbar_shadow_color)
        self.scrollbar_slider_color = self._format_color_opacity(self.scrollbar_slider_color)
        self.selection_color = self._format_color_opacity(self.selection_color)
        self.surface_clear_color = self._format_color_opacity(self.surface_clear_color)
        self.title_background_color = self._format_color_opacity(self.title_background_color)
        self.title_font_color = self._format_color_opacity(self.title_font_color)
        self.title_font_shadow_color = self._format_color_opacity(self.title_font_shadow_color)
        self.widget_background_color = self._format_color_opacity(self.widget_background_color, none=True)
        self.widget_border_color = self._format_color_opacity(self.widget_border_color)
        self.widget_box_arrow_color = self._format_color_opacity(self.widget_box_arrow_color)
        self.widget_box_background_color = self._format_color_opacity(self.widget_box_background_color)
        self.widget_box_border_color = self._format_color_opacity(self.widget_box_border_color)
        self.widget_font_background_color = self._format_color_opacity(self.widget_font_background_color, none=True)
        self.widget_font_color = self._format_color_opacity(self.widget_font_color)
        self.widget_font_shadow_color = self._format_color_opacity(self.widget_font_shadow_color)
        self.widget_url_color = self._format_color_opacity(self.widget_url_color)

        # List to tuple
        self.scrollarea_outer_margin = self._vec_to_tuple(self.scrollarea_outer_margin, 2, NumberInstance)
        self.title_offset = self._vec_to_tuple(self.title_offset, 2, NumberInstance)
        self.widget_background_inflate = self._vec_to_tuple(self.widget_background_inflate, 2, int)
        self.widget_border_inflate = self._vec_to_tuple(self.widget_border_inflate, 2, int)
        self.widget_box_arrow_margin = self._vec_to_tuple(self.widget_box_arrow_margin, 3, int)
        self.widget_box_inflate = self._vec_to_tuple(self.widget_box_inflate, 2, int)
        self.widget_box_margin = self._vec_to_tuple(self.widget_box_margin, 2, NumberInstance)
        self.widget_margin = self._vec_to_tuple(self.widget_margin, 2, NumberInstance)
        if isinstance(self.widget_padding, VectorInstance):
            self.widget_padding = self._vec_to_tuple(self.widget_padding)
            assert 2 <= len(self.widget_padding) <= 4, 'widget padding tuple length must be 2, 3 or 4'
            for p in self.widget_padding:
                assert isinstance(p, NumberInstance), 'each padding element must be numeric (integer or float)'
                assert p >= 0, 'all padding elements must be equal or greater than zero'
        else:
            assert self.widget_padding >= 0, 'padding cannot be a negative number'
        self.widget_offset = self._vec_to_tuple(self.widget_offset, 2, NumberInstance)

        # Check sizes
        assert self.scrollarea_outer_margin[0] >= 0 and self.scrollarea_outer_margin[1] >= 0, \
            'scroll area outer margin must be equal or greater than zero on both axis'
        assert self.widget_offset[0] >= 0 and self.widget_offset[1] >= 0, \
            'widget offset must be equal or greater than zero'
        assert self.widget_background_inflate[0] >= 0 and self.widget_background_inflate[1] >= 0, \
            'widget background inflate must be equal or greater than zero on both axis'
        assert self.widget_border_inflate[0] >= 0 and self.widget_border_inflate[1] >= 0, \
            'widget border inflate must be equal or greater than zero on both axis'
        assert self.widget_box_inflate[0] >= 0 and self.widget_box_inflate[1] >= 0, \
            'widget box inflate inflate must be equal or greater than zero on both axis'

        assert self.cursor_switch_ms > 0, 'cursor switch ms must be greater than zero'
        assert self.fps >= 0, 'fps must be equal or greater than zero'
        assert self.scrollbar_shadow_offset > 0, 'scrollbar shadow offset must be greater than zero'
        assert self.scrollbar_slider_pad >= 0, 'slider pad must be equal or greater than zero'
        assert self.scrollbar_thick > 0, 'scrollbar thickness must be greater than zero'
        assert self.title_font_size > 0, 'title font size must be greater than zero'
        assert self.widget_border_width >= 0, 'widget border width must be equal or greater than zero'
        assert self.widget_box_border_width >= 0, 'widget border box width must be equal or greater than zero'
        assert self.widget_font_shadow_offset > 0, 'widget font shadow offset must be greater than zero'
        assert self.widget_font_size > 0, 'widget font size must be greater than zero'
        assert self.widget_tab_size >= 0, 'widget tab size must be equal or greater than zero'

        # Color asserts
        assert self.focus_background_color[3] != 0, \
            'focus background color cannot be fully transparent, suggested opacity between 1 and 255'

        return self
Exemple #3
0
    def validate(self) -> 'Theme':
        """
        Validate the values of the theme. If there's a invalid parameter throws an
        ``AssertionError``.

        This function also converts all lists to tuples. This is done because lists
        are mutable.

        :return: Self reference
        """
        if self._disable_validation:
            return self

        # Boolean asserts
        assert isinstance(self.title_close_button, bool)
        assert isinstance(self.title_bar_modify_scrollarea, bool)
        assert isinstance(self.title_font_antialias, bool)
        assert isinstance(self.title_shadow, bool)
        assert isinstance(self.scrollbar_shadow, bool)
        assert isinstance(self.widget_font_antialias, bool)
        assert isinstance(self.widget_font_background_color_from_menu, bool)
        assert isinstance(self.widget_shadow, bool)

        # Value type checks
        _utils.assert_alignment(self.widget_alignment)
        _utils.assert_position(self.scrollbar_shadow_position)
        _utils.assert_position(self.title_shadow_position)
        _utils.assert_position(self.widget_shadow_position)
        assert _check_menubar_style(self.title_bar_style)
        assert get_scrollbars_from_position(self.scrollarea_position) is not None

        assert isinstance(self.cursor_switch_ms, (int, float))
        assert isinstance(self.fps, (int, float))
        assert isinstance(self.scrollbar_shadow_offset, (int, float))
        assert isinstance(self.scrollbar_slider_pad, (int, float))
        assert isinstance(self.scrollbar_thick, (int, float))
        assert isinstance(self.title_floating, bool)
        assert isinstance(self.title_font, str)
        assert isinstance(self.title_font_size, int)
        assert isinstance(self.title_shadow_offset, (int, float))
        assert isinstance(self.title_updates_pygame_display, bool)
        assert isinstance(self.widget_border_width, int)
        assert isinstance(self.widget_font, str)
        assert isinstance(self.widget_font_size, int)
        assert isinstance(self.widget_padding, (int, float, tuple, list))
        assert isinstance(self.widget_selection_effect, _widgets.core.Selection)
        assert isinstance(self.widget_shadow_offset, (int, float))

        # Format colors, this converts all color lists to tuples automatically
        self.background_color = self._format_opacity(self.background_color)
        self.cursor_color = self._format_opacity(self.cursor_color)
        self.cursor_selection_color = self._format_opacity(self.cursor_selection_color)
        self.focus_background_color = self._format_opacity(self.focus_background_color)
        self.readonly_color = self._format_opacity(self.readonly_color)
        self.readonly_selected_color = self._format_opacity(self.readonly_selected_color)
        self.scrollbar_color = self._format_opacity(self.scrollbar_color)
        self.scrollbar_shadow_color = self._format_opacity(self.scrollbar_shadow_color)
        self.scrollbar_slider_color = self._format_opacity(self.scrollbar_slider_color)
        self.selection_color = self._format_opacity(self.selection_color)
        self.surface_clear_color = self._format_opacity(self.surface_clear_color)
        self.title_background_color = self._format_opacity(self.title_background_color)
        self.widget_border_color = self._format_opacity(self.widget_border_color)
        self.title_font_color = self._format_opacity(self.title_font_color)
        self.title_shadow_color = self._format_opacity(self.title_shadow_color)
        self.widget_background_color = self._format_opacity(self.widget_background_color)
        self.widget_font_background_color = self._format_opacity(self.widget_font_background_color)
        self.widget_font_color = self._format_opacity(self.widget_font_color)

        # List to tuple
        self.scrollarea_outer_margin = self._vec_to_tuple(self.scrollarea_outer_margin, 2)
        self.title_offset = self._vec_to_tuple(self.title_offset, 2)
        self.widget_background_inflate = self._vec_to_tuple(self.widget_background_inflate, 2)
        self.widget_border_inflate = self._vec_to_tuple(self.widget_border_inflate, 2)
        self.widget_margin = self._vec_to_tuple(self.widget_margin, 2)
        if isinstance(self.widget_padding, (tuple, list)):
            self.widget_padding = self._vec_to_tuple(self.widget_padding)
            assert 2 <= len(self.widget_padding) <= 4, 'widget padding tuple length must be 2, 3 or 4'
            for p in self.widget_padding:
                assert p >= 0, 'all padding elements must be equal or greater than zero'
        else:
            assert self.widget_padding >= 0, 'padding cannot be a negative number'
        self.widget_offset = self._vec_to_tuple(self.widget_offset, 2)

        # Check sizes
        assert self.scrollarea_outer_margin[0] >= 0 and self.scrollarea_outer_margin[1] >= 0, \
            'scroll area outer margin must be equal or greater than zero in both axis'
        assert self.widget_offset[0] >= 0 and self.widget_offset[1] >= 0, \
            'widget offset must be equal or greater than zero'
        assert self.widget_border_inflate[0] >= 0 and self.widget_border_inflate[1] >= 0, \
            'widget border inflate must be equal or greater than zero in both axis'

        assert self.cursor_switch_ms > 0, 'cursor switch ms must be greater than zero'
        assert self.fps >= 0, 'fps must be equal or greater than zero'
        assert self.scrollbar_shadow_offset > 0, 'scrollbar shadow offset must be greater than zero'
        assert self.scrollbar_slider_pad >= 0, 'slider pad must be equal or greater than zero'
        assert self.scrollbar_thick > 0, 'scrollbar thickness must be greater than zero'
        assert self.title_font_size > 0, 'title font size must be greater than zero'
        assert self.widget_font_size > 0, 'widget font size must be greater than zero'
        assert self.widget_shadow_offset > 0, 'widget shadow offset must be greater than zero'

        # Configs
        self.widget_selection_effect.set_color(self.selection_color)

        # Color asserts
        assert self.focus_background_color[3] != 0, \
            'focus background color cannot be fully transparent, suggested opacity between 1 and 255'

        return self