Пример #1
0
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                  _display_surface_return_none: None):
        window = UIWindow(pygame.Rect(0, 0, 200, 200),
                          window_display_title="Test Window",
                          manager=default_ui_manager)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 6
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container(), window,
            window._window_root_container, window.window_element_container,
            window.title_bar, window.close_window_button
        ]
        window.kill()

        confirm_event_fired = False
        event_object_id = None
        for event in pygame.event.get():
            if (event.type == pygame.USEREVENT
                    and event.user_type == pygame_gui.UI_WINDOW_CLOSE
                    and event.ui_element == window):
                confirm_event_fired = True
                event_object_id = event.ui_object_id
        assert confirm_event_fired
        assert event_object_id == 'window'
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container()
        ]
Пример #2
0
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface):
        panel = UIPanel(relative_rect=pygame.Rect(50, 50, 150, 400),
                        starting_layer_height=5,
                        manager=default_ui_manager,
                        margins={
                            'left': 10,
                            'right': 10,
                            'top': 5,
                            'bottom': 5
                        })

        button = UIButton(
            relative_rect=pygame.Rect(100, 100, 150, 30),
            text="Test Button",
            tool_tip_text=
            "This is a test of the button's tool tip functionality.",
            manager=default_ui_manager,
            container=panel)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 4
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container(), panel,
            panel.get_container(), button
        ]
        panel.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container()
        ]
Пример #3
0
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                  _display_surface_return_none):
        selection_list = UISelectionList(
            relative_rect=pygame.Rect(0, 0, 50, 80),
            item_list=[
                'item 1', 'item 2', 'item 3', 'item 4', 'item 5', 'item 6',
                'item 7', 'item 8', 'item 9', 'item 10', 'item 11', 'item 12',
                'item 13', 'item 14', 'item 15', 'item 16'
            ],
            manager=default_ui_manager,
            allow_multi_select=True)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 13

        selection_list_sprites = [
            default_ui_manager.get_root_container(), selection_list,
            selection_list.list_and_scroll_bar_container,
            selection_list.item_list_container, selection_list.scroll_bar,
            selection_list.scroll_bar.button_container,
            *selection_list.item_list_container.elements,
            selection_list.scroll_bar.top_button,
            selection_list.scroll_bar.bottom_button,
            selection_list.scroll_bar.sliding_button
        ]
        assert default_ui_manager.get_sprite_group().sprites(
        ) == selection_list_sprites
        selection_list.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        empty_ui_sprites = [default_ui_manager.get_root_container()]
        assert default_ui_manager.get_sprite_group().sprites(
        ) == empty_ui_sprites
Пример #4
0
 def test_get_sprite_group(self, _init_pygame, default_ui_manager,
                           _display_surface_return_none):
     """
     Can we get the sprite group? Serves as a test of the sprite group being successfully created.
     """
     sprite_group = default_ui_manager.get_sprite_group()
     assert (type(sprite_group) == pygame.sprite.LayeredUpdates)
Пример #5
0
    def test_clear_and_reset(self, _init_pygame, default_ui_manager):
        """
        Check clear and reset is restoring manager to initial state with no extra, lingering, elements.
        """
        # start with just the root window, and the root window container
        should_be_two_sprites = len(
            default_ui_manager.get_sprite_group().sprites())

        UIButton(relative_rect=pygame.Rect(100, 100, 150, 30),
                 text="Test",
                 manager=default_ui_manager)
        should_be_three_sprites = len(
            default_ui_manager.get_sprite_group().sprites())

        default_ui_manager.clear_and_reset()
        should_be_two_sprites_again = len(
            default_ui_manager.get_sprite_group().sprites())

        assert should_be_two_sprites == 2 and should_be_three_sprites == 3 and should_be_two_sprites_again == 2
Пример #6
0
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                  _display_surface_return_none):
        scroll_bar = UIHorizontalSlider(relative_rect=pygame.Rect(100, 100, 200, 30),
                                        start_value=50,
                                        value_range=(0, 100),
                                        manager=default_ui_manager)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 6
        assert default_ui_manager.get_sprite_group().sprites() == [default_ui_manager.get_root_container(),
                                                                   scroll_bar,
                                                                   scroll_bar.button_container,
                                                                   scroll_bar.left_button,
                                                                   scroll_bar.right_button,
                                                                   scroll_bar.sliding_button]
        scroll_bar.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        assert default_ui_manager.get_sprite_group().sprites() == [default_ui_manager.get_root_container()]
    def test_kill(self, _init_pygame, default_ui_manager: IUIManagerInterface,
                  _display_surface_return_none):
        scroll_bar = UIVerticalScrollBar(relative_rect=pygame.Rect(100, 100, 30, 150),
                                         visible_percentage=0.7,
                                         manager=default_ui_manager)

        assert len(default_ui_manager.get_root_container().elements) == 2
        assert len(default_ui_manager.get_sprite_group().sprites()) == 6
        scroll_bar_sprites = [default_ui_manager.get_root_container(),
                              scroll_bar,
                              scroll_bar.button_container,
                              scroll_bar.top_button,
                              scroll_bar.bottom_button,
                              scroll_bar.sliding_button]
        assert default_ui_manager.get_sprite_group().sprites() == scroll_bar_sprites
        scroll_bar.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        empty_sprites = [default_ui_manager.get_root_container()]
        assert default_ui_manager.get_sprite_group().sprites() == empty_sprites
Пример #8
0
    def test_kill(self, _init_pygame: None, default_ui_manager: UIManager,
                  _display_surface_return_none):
        default_ui_manager.preload_fonts([{
            'name': 'fira_code',
            'html_size': 4.5,
            'style': 'bold'
        }, {
            'name': 'fira_code',
            'html_size': 4.5,
            'style': 'regular'
        }, {
            'name': 'fira_code',
            'html_size': 2,
            'style': 'regular'
        }, {
            'name': 'fira_code',
            'html_size': 2,
            'style': 'italic'
        }, {
            'name': 'fira_code',
            'html_size': 6,
            'style': 'bold'
        }, {
            'name': 'fira_code',
            'html_size': 6,
            'style': 'regular'
        }, {
            'name': 'fira_code',
            'html_size': 6,
            'style': 'bold_italic'
        }, {
            'name': 'fira_code',
            'html_size': 4,
            'style': 'bold'
        }, {
            'name': 'fira_code',
            'html_size': 4,
            'style': 'italic'
        }, {
            'name': 'fira_code',
            'html_size': 2,
            'style': 'bold'
        }, {
            'name': 'fira_code',
            'html_size': 2,
            'style': 'bold_italic'
        }])
        text_box = UITextBox(
            html_text=''
            '<font color=regular_text><font color=#E784A2 size=4.5><br><b><u>Lorem</u><br><br><br>'
            'ipsum dolor sit amet</b></font>,'
            ' <b><a href="test">consectetur</a></b> adipiscing elit. in a flibb de dib do '
            'rub a la clob slip the perry tin fo glorp yip dorp'
            'skorp si pork flum de dum be dung, slob be robble glurp destination flum kin slum. '
            'Ram slim gordo, fem tulip squirrel slippers save socks certainly.<br>'
            'Vestibulum in <i>commodo me</i> tellus in nisi finibus a sodales.<br>Vestibulum'
            '<font size=2>hendrerit mi <i>sed nulla</i> scelerisque</font>, posuere ullamcorper '
            'sem pulvinar.'
            'Nulla at pulvinar a odio, a dictum dolor.<br>Maecenas at <font size=6><b>tellus a'
            'tortor. a<br>'
            'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br>'
            'In hac a habitasse to platea dictumst.<br>'
            '<font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec porttitor.<br>Morbi '
            'accumsan, lectus at '
            'tincidunt to dictum, neque <font color=#879AF6>erat tristique erat</font>, '
            'sed a tempus for <b>nunc</b> dolor in nibh.<br>'
            'Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, sit amet on pharetra a ante '
            'sollicitudin.</font></font>'
            '<br><br>'
            '<b>consectetur</b> adipiscing elit. in a<br>'
            'Vestibulum in <i>commodo me</i> tellus in nisi finibus a sodales.<br>'
            'Vestibulum <font size=2>hendrerit mi <i>sed nulla</i> scelerisque</font>, '
            'posuere ullamcorper sem pulvinar. '
            'Nulla at pulvinar a odio, a dictum dolor.<br>'
            'Maecenas at <font size=6><b>tellus a tortor. a<br>'
            'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><br>'
            'In hac a habitasse to platea dictumst.<br>'
            '<font color=#4CD656 size=4>Vivamus I interdum mollis lacus nec porttitor.<br>Morbi '
            'accumsan, lectus at'
            'tincidunt to dictum, neque <font color=#879AF6>erat tristique erat</font>, '
            'sed a tempus for <b>nunc</b> dolor in nibh.<br>'
            'Suspendisse in viverra dui <i>fringilla dolor laoreet</i>, sit amet on pharetra a ante '
            'sollicitudin.</font></font>',
            relative_rect=pygame.Rect(100, 100, 200, 300),
            manager=default_ui_manager)

        assert len(default_ui_manager.get_root_container().elements) == 3
        assert len(default_ui_manager.get_sprite_group().sprites()) == 7
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container(), text_box,
            text_box.scroll_bar, text_box.scroll_bar.button_container,
            text_box.scroll_bar.top_button, text_box.scroll_bar.bottom_button,
            text_box.scroll_bar.sliding_button
        ]
        text_box.kill()
        assert len(default_ui_manager.get_root_container().elements) == 0
        assert len(default_ui_manager.get_sprite_group().sprites()) == 1
        assert default_ui_manager.get_sprite_group().sprites() == [
            default_ui_manager.get_root_container()
        ]