Exemplo n.º 1
0
    def test_press_ok_button(self, _init_pygame, default_ui_manager,
                             _display_surface_return_none):
        file_dialog = UIFileDialog(rect=pygame.Rect(100, 100, 440, 500),
                                   manager=default_ui_manager)

        file_dialog.selected_file_path = abspath('tests/data/images/splat.png')
        file_dialog.ok_button.enable()

        is_alive_pre_events = file_dialog.alive()
        default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN,
                                                             {'button': pygame.BUTTON_LEFT,
                                                              'pos': file_dialog.ok_button.rect.center}))
        default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONUP,
                                                             {'button': pygame.BUTTON_LEFT,
                                                              'pos': file_dialog.ok_button.rect.center}))

        for event in pygame.event.get():
            default_ui_manager.process_events(event)

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

            if (event.type == pygame.USEREVENT and event.user_type == pygame_gui.UI_FILE_DIALOG_PATH_PICKED and
                    event.ui_element == file_dialog):
                confirm_event_fired = True
                event_path = event.text
        is_dead_post_events = not file_dialog.alive()

        assert is_alive_pre_events
        assert is_dead_post_events
        assert confirm_event_fired
        assert event_path is not None and Path(event_path).name == 'splat.png'
Exemplo n.º 2
0
    def test_press_cancel_button(self, _init_pygame, default_ui_manager,
                                 _display_surface_return_none):
        file_dialog = UIFileDialog(rect=pygame.Rect(100, 100, 440, 500),
                                   manager=default_ui_manager)

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

        is_dead_post_events = not file_dialog.alive()

        assert is_alive_pre_events is True and is_dead_post_events is True