def test_press_close_window_button(self, _init_pygame, default_ui_manager,
                                       _display_surface_return_none):
        confirm_dialog = UIConfirmationDialog(rect=pygame.Rect(100, 100, 400, 300),
                                              manager=default_ui_manager,
                                              action_long_desc="Confirm a test of the confirmation "
                                                               "dialog.",
                                              window_title="Confirm",
                                              action_short_name="Confirm")

        is_alive_pre_process_event = confirm_dialog.alive()

        close_button_x = confirm_dialog.close_window_button.rect.centerx
        close_button_y = confirm_dialog.close_window_button.rect.centery

        # initiate a button press by clicking the left mouse down and up on the close button
        default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN,
                                                             {'button': pygame.BUTTON_LEFT,
                                                              'pos': (close_button_x,
                                                                      close_button_y)}))

        default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONUP,
                                                             {'button': pygame.BUTTON_LEFT,
                                                              'pos': (close_button_x,
                                                                      close_button_y)}))
        # let the window process the 'close window' event
        for event in pygame.event.get():
            default_ui_manager.process_events(event)

        is_dead_post_process_event = not confirm_dialog.alive()

        assert is_alive_pre_process_event is True and is_dead_post_process_event is True
    def test_press_confirm_button(self, _init_pygame, default_ui_manager,
                                  _display_surface_return_none):
        confirm_dialog = UIConfirmationDialog(rect=pygame.Rect(100, 100, 400, 300),
                                              manager=default_ui_manager,
                                              action_long_desc="Confirm a test of the "
                                                               "confirmation dialog.",
                                              window_title="Confirm",
                                              action_short_name="Confirm")

        is_alive_pre_events = confirm_dialog.alive()
        default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN,
                                                             {'button': pygame.BUTTON_LEFT,
                                                              'pos': confirm_dialog.confirm_button.rect.center}))
        default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONUP,
                                                             {'button': pygame.BUTTON_LEFT,
                                                              'pos': confirm_dialog.confirm_button.rect.center}))
        for event in pygame.event.get():
            default_ui_manager.process_events(event)

        confirm_event_fired = False
        for event in pygame.event.get():
            default_ui_manager.process_events(event)

            if (event.type == pygame_gui.UI_CONFIRMATION_DIALOG_CONFIRMED and
                    event.ui_element == confirm_dialog):
                confirm_event_fired = True
        is_dead_post_events = not confirm_dialog.alive()

        assert is_alive_pre_events
        assert is_dead_post_events
        assert confirm_event_fired
Esempio n. 3
0
    def test_press_cancel_button(self, _init_pygame, default_ui_manager,
                                 _display_surface_return_none):
        confirm_dialog = UIConfirmationDialog(
            rect=pygame.Rect(100, 100, 400, 300),
            manager=default_ui_manager,
            action_long_desc="Confirm a test of the confirmation "
            "dialog.",
            window_title="Confirm",
            action_short_name="Confirm")

        is_alive_pre_events = confirm_dialog.alive()
        default_ui_manager.process_events(
            pygame.event.Event(
                pygame.MOUSEBUTTONDOWN, {
                    'button': pygame.BUTTON_LEFT,
                    'pos': confirm_dialog.cancel_button.rect.center
                }))
        default_ui_manager.process_events(
            pygame.event.Event(
                pygame.MOUSEBUTTONUP, {
                    'button': pygame.BUTTON_LEFT,
                    'pos': confirm_dialog.cancel_button.rect.center
                }))
        for event in pygame.event.get():
            default_ui_manager.process_events(event)
        is_dead_post_events = not confirm_dialog.alive()

        assert is_alive_pre_events is True and is_dead_post_events is True