def test_new_file_selection(self, _init_pygame, default_ui_manager, _display_surface_return_none): file_dialog = UIFileDialog(rect=pygame.Rect(100, 100, 440, 500), manager=default_ui_manager, initial_file_path='tests/data/images/') select_event = pygame.event.Event( pygame.USEREVENT, { 'user_type': pygame_gui.UI_SELECTION_LIST_NEW_SELECTION, 'ui_element': file_dialog.file_selection_list, 'text': 'splat.png' }) default_ui_manager.process_events(select_event) assert file_dialog.current_file_path is not None assert file_dialog.current_file_path.name == 'splat.png' assert file_dialog.ok_button.is_enabled select_event = pygame.event.Event( pygame.USEREVENT, { 'user_type': pygame_gui.UI_SELECTION_LIST_NEW_SELECTION, 'ui_element': file_dialog.file_selection_list, 'text': 'not_a_file.not' }) default_ui_manager.process_events(select_event) assert not file_dialog.ok_button.is_enabled
def test_enable(self, _init_pygame: None, default_ui_manager: UIManager, _display_surface_return_none: None): selection_list = UISelectionList( relative_rect=pygame.Rect(50, 50, 150, 400), item_list=['green', 'eggs', 'and', 'ham'], manager=default_ui_manager) assert selection_list.get_single_selection() is None selection_list.disable() selection_list.enable() assert selection_list.is_enabled is True assert selection_list.item_list_container.is_enabled is True # process a mouse button down event list_button = selection_list.item_list_container.elements[0] list_button.process_event( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': list_button.rect.center })) # process a mouse button up event list_button.process_event( pygame.event.Event(pygame.MOUSEBUTTONUP, { 'button': 1, 'pos': list_button.rect.center })) for event in pygame.event.get(): default_ui_manager.process_events(event) assert selection_list.get_single_selection() == 'green'
def test_set_dimensions(self, _init_pygame, default_ui_manager, _display_surface_return_none): text_box = UITextBox(html_text='la la LA LA LAL LAL ALALA' 'LLALAALALA ALALA ALAL ALA' 'LAALA ALALA ALALA AAaal aa' 'ALALAa laalal alalal alala' 'alalalala alalalalalal alal' 'alalalala <a href=none>alala<a/> ' 'alalala ala' 'alalalalal lalal alalalal al' 'al alalalal lfed alal alal alal al' 'ala lalalal lasda lal a lalalal slapl' 'alalala lal la blop lal alal aferlal al', relative_rect=pygame.Rect(0, 0, 150, 100), manager=default_ui_manager) text_box.set_dimensions((200, 80)) # try to click on the slider default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (195, 75) })) # if we successfully clicked on the moved slider then this button should be True assert text_box.scroll_bar.bottom_button.held is True
def test_update_saturation_value_square(self, _init_pygame, default_ui_manager, _display_surface_return_none): colour_picker = UIColourPickerDialog(rect=pygame.Rect( 100, 100, 400, 400), manager=default_ui_manager) default_ui_manager.process_events( pygame.event.Event( pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': colour_picker.sat_value_square.rect.center })) assert colour_picker.current_colour == pygame.Color(127, 63, 63, 255) colour_picker.hue_channel.current_value = 150 colour_picker.update_saturation_value_square() default_ui_manager.process_events( pygame.event.Event( pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': colour_picker.sat_value_square.rect.center })) assert colour_picker.current_colour == pygame.Color(63, 127, 95, 255)
def test_select_option_from_drop_down(self, _init_pygame, default_ui_manager, _display_surface_return_none): test_container = UIContainer(relative_rect=pygame.Rect(0, 0, 300, 300), manager=default_ui_manager) menu = UIDropDownMenu(options_list=['eggs', 'flour', 'sugar'], starting_option='eggs', relative_rect=pygame.Rect(10, 10, 200, 30), manager=default_ui_manager, container=test_container) menu.current_state.should_transition = True menu.update(0.01) assert menu.selected_option == 'eggs' flour_button = menu.current_state.options_selection_list.item_list_container.elements[1] flour_button.process_event(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': pygame.BUTTON_LEFT, 'pos': flour_button.rect.center})) flour_button.process_event(pygame.event.Event(pygame.MOUSEBUTTONUP, {'button': pygame.BUTTON_LEFT, 'pos': flour_button.rect.center})) for event in pygame.event.get(): default_ui_manager.process_events(event) for event in pygame.event.get(): default_ui_manager.process_events(event) assert menu.selected_option == 'flour'
def test_set_dimensions(self, _init_pygame, default_ui_manager, _display_surface_return_none): menu = UIDropDownMenu(options_list=['eggs', 'flour', 'sugar'], starting_option='eggs', relative_rect=pygame.Rect(100, 100, 200, 30), manager=default_ui_manager) menu.set_dimensions((300, 50)) assert (menu.current_state.open_button.relative_rect.right == (100 + 300) - (menu.border_width + menu.shadow_width)) assert (menu.current_state.open_button.relative_rect.bottom == (100 + 50) - (menu.border_width + menu.shadow_width)) # try to click on the menu default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': pygame.BUTTON_LEFT, 'pos': (390, 125)})) # if we successfully clicked on the moved menu then this button should be True assert menu.current_state.open_button.held is True menu.current_state.should_transition = True menu.update(0.01) menu.set_dimensions((200, 30)) # try to click on the menu default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (290, 115)})) # if we successfully clicked on the moved menu then this button should be True assert menu.current_state.close_button.held is True
def test_set_relative_position(self, _init_pygame, default_ui_manager, _display_surface_return_none): test_container = UIContainer(relative_rect=pygame.Rect( 100, 100, 300, 60), manager=default_ui_manager) menu = UIDropDownMenu(options_list=['eggs', 'flour', 'sugar'], starting_option='eggs', relative_rect=pygame.Rect(100, 100, 200, 30), container=test_container, manager=default_ui_manager) menu.set_relative_position((150.0, 30.0)) # try to click on the menu default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': (260, 145) })) assert menu.rect.topleft == ( 250, 130) and menu.current_state.selected_option_button.held is True menu.current_state.should_transition = True menu.update(0.01) menu.set_relative_position((50.0, 20.0)) assert menu.rect.topleft == (150, 120)
def test_set_dimensions(self, _init_pygame, default_ui_manager, _display_surface_return_none): scroll_bar = UIVerticalScrollBar(relative_rect=pygame.Rect(0, 100, 30, 200), visible_percentage=0.25, manager=default_ui_manager) scroll_bar.set_dimensions((60, 100)) # try to click on the slider default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (40, 195)})) # if we successfully clicked on the moved slider then this button should be True assert scroll_bar.bottom_button.held is True
def test_set_position(self, _init_pygame, default_ui_manager, _display_surface_return_none): slider = UIHorizontalSlider(relative_rect=pygame.Rect(300, 400, 150, 40), start_value=50, value_range=(0, 200), manager=default_ui_manager) slider.set_position((200, 200)) # try to click on the slider default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (205, 205)})) # if we successfully clicked on the moved slider then this button should be True assert slider.left_button.held is True
def test_press_delete_button_and_cancel(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.current_file_path = Path( 'tests/data/images/splat.png').resolve() file_dialog.delete_button.enable() event_data = { 'button': pygame.BUTTON_LEFT, 'pos': file_dialog.delete_button.rect.center } default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, event_data)) default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONUP, event_data)) for event in pygame.event.get(): default_ui_manager.process_events(event) assert file_dialog.delete_confirmation_dialog is not None event_data = { 'user_type': pygame_gui.UI_BUTTON_PRESSED, 'ui_element': file_dialog.delete_confirmation_dialog.cancel_button } cancel_event = pygame.event.Event(pygame.USEREVENT, event_data) default_ui_manager.process_events(cancel_event) assert (not file_dialog.delete_confirmation_dialog.alive())
def test_file_path_entry_finished(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.file_path_text_line.set_text('tests/data/images') event_data = { 'button': pygame.BUTTON_LEFT, 'pos': file_dialog.file_path_text_line.rect.center } default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, event_data)) default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONUP, event_data)) default_ui_manager.process_events( pygame.event.Event(pygame.KEYDOWN, {'key': pygame.K_RETURN})) for event in pygame.event.get(): default_ui_manager.process_events(event) assert file_dialog.current_file_path is None assert str(Path( file_dialog.current_directory_path).parts[-1]) == 'images' assert file_dialog.current_file_list == [('splat.png', '#file_list_item')]
def test_text_entry_finished(self, _init_pygame, default_ui_manager, _display_surface_return_none): channel_editor = UIColourChannelEditor(relative_rect=pygame.Rect( 0, 0, 150, 29), manager=default_ui_manager, name='H:', channel_index=0, initial_value=0, value_range=(0, 360)) channel_editor.entry.set_text('50') default_ui_manager.process_events( pygame.event.Event( pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': channel_editor.entry.rect.center })) default_ui_manager.process_events( pygame.event.Event( pygame.MOUSEBUTTONUP, { 'button': pygame.BUTTON_LEFT, 'pos': channel_editor.entry.rect.center })) default_ui_manager.process_events( pygame.event.Event(pygame.KEYDOWN, {'key': pygame.K_RETURN})) for event in pygame.event.get(): default_ui_manager.process_events(event) assert channel_editor.slider.current_value == 50
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'
def test_press_home_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, initial_file_path='tests/data/images/') home_event = pygame.event.Event(pygame.USEREVENT, {'user_type': pygame_gui.UI_BUTTON_PRESSED, 'ui_element': file_dialog.home_button}) default_ui_manager.process_events(home_event) assert Path(file_dialog.current_directory_path).name == Path.home().name
def test_enable(self, _init_pygame, default_ui_manager, _display_surface_return_none): test_container = UIContainer(relative_rect=pygame.Rect(0, 0, 300, 300), manager=default_ui_manager) menu = UIDropDownMenu(options_list=['eggs', 'flour', 'sugar'], starting_option='eggs', relative_rect=pygame.Rect(10, 10, 200, 30), manager=default_ui_manager, container=test_container) menu.current_state.should_transition = True menu.update(0.01) assert menu.current_state == menu.menu_states['expanded'] assert menu.selected_option == 'eggs' menu.disable() assert menu.is_enabled is False menu.enable() assert menu.is_enabled is True assert menu.current_state == menu.menu_states['closed'] expand_button = menu.current_state.open_button expand_button.process_event( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': expand_button.rect.center })) expand_button.process_event( pygame.event.Event(pygame.MOUSEBUTTONUP, { 'button': pygame.BUTTON_LEFT, 'pos': expand_button.rect.center })) for event in pygame.event.get(): default_ui_manager.process_events(event) for event in pygame.event.get(): default_ui_manager.process_events(event) assert menu.current_state.should_transition is True menu.update(0.01) assert menu.current_state == menu.menu_states['expanded'] assert menu.selected_option == 'eggs'
def test_set_relative_position(self, _init_pygame, default_ui_manager, _display_surface_return_none): test_container = UIContainer(relative_rect=pygame.Rect(100, 100, 300, 60), manager=default_ui_manager) slider = UIHorizontalSlider(relative_rect=pygame.Rect(300, 400, 150, 40), start_value=50, container=test_container, value_range=(0, 200), manager=default_ui_manager) slider.set_relative_position((150.0, 30.0)) # try to click on the slider default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (260, 150)})) assert slider.rect.topleft == (250, 130) and slider.left_button.held is True
def test_set_position(self, _init_pygame, default_ui_manager, _display_surface_return_none): test_container = UIContainer(relative_rect=pygame.Rect( 10, 10, 300, 300), manager=default_ui_manager) menu = UIDropDownMenu(options_list=['eggs', 'flour', 'sugar'], starting_option='eggs', relative_rect=pygame.Rect(100, 100, 200, 30), manager=default_ui_manager) menu.set_position((0, 0)) menu.current_state.should_transition = True menu.update(0.01) menu.set_position((200, 200)) # try to click on the menu default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (250, 215) })) # if we successfully clicked on the moved menu then this button should be True assert menu.current_state.selected_option_button.held is True drop_down_anchor_bottom_right = UIDropDownMenu( relative_rect=pygame.Rect(0, 0, 50, 50), options_list=['eggs', 'flour', 'sugar'], starting_option='eggs', manager=default_ui_manager, container=test_container, anchors={ 'left': 'right', 'right': 'right', 'top': 'bottom', 'bottom': 'bottom' }) drop_down_anchor_bottom_right.current_state.should_transition = True drop_down_anchor_bottom_right.update(0.01) drop_down_anchor_bottom_right.set_position((230, 230)) assert drop_down_anchor_bottom_right.relative_rect.topleft == (-80, -80) assert drop_down_anchor_bottom_right.relative_rect.size == (50, 50) assert drop_down_anchor_bottom_right.relative_rect.bottomright == (-30, -30)
def test_click_in_saturation_value_square_button( self, _init_pygame, default_ui_manager, _display_surface_return_none): colour_picker = UIColourPickerDialog( rect=pygame.Rect(100, 100, 400, 400), manager=default_ui_manager, initial_colour=pygame.Color(200, 220, 50, 255)) assert colour_picker.current_colour == pygame.Color(200, 220, 50, 255) default_ui_manager.process_events( pygame.event.Event( pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': colour_picker.sat_value_square.rect.center })) assert colour_picker.current_colour == pygame.Color(120, 127, 63, 255)
def test_directory_double_clicked(self, _init_pygame, default_ui_manager, _display_surface_return_none): file_dialog = UIFileDialog(rect=pygame.Rect(100, 100, 440, 500), manager=default_ui_manager, initial_file_path='tests/data/') directory_event = pygame.event.Event(pygame.USEREVENT, {'user_type': pygame_gui.UI_SELECTION_LIST_DOUBLE_CLICKED_SELECTION, 'ui_element': file_dialog.file_selection_list, 'text': 'images'}) default_ui_manager.process_events(directory_event) assert file_dialog.current_directory_path == abspath('tests/data/images') assert not file_dialog.ok_button.is_enabled assert not file_dialog.delete_button.is_enabled assert file_dialog.file_path_text_line.text == abspath('tests/data/images')
def test_process_events(self, _init_pygame, default_ui_manager): """ Fake a click button event on a button to check they are going through the ui event manager properly/ """ test_button = UIButton(relative_rect=pygame.Rect(100, 100, 150, 30), text="Test", manager=default_ui_manager) UIMessageWindow( message_window_rect=pygame.Rect(500, 400, 200, 300), message_title="Test Message", html_message= "This is a bold test of the message box functionality.", manager=default_ui_manager) default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (125, 115) })) assert test_button.is_selected
def test_slider_moved_finished(self, _init_pygame, default_ui_manager, _display_surface_return_none): channel_editor = UIColourChannelEditor(relative_rect=pygame.Rect( 0, 0, 150, 29), manager=default_ui_manager, name='H:', channel_index=0, initial_value=0, value_range=(0, 360)) channel_editor.slider.current_value = 100 default_ui_manager.process_events( pygame.event.Event( pygame.USEREVENT, { 'user_type': pygame_gui.UI_HORIZONTAL_SLIDER_MOVED, 'ui_element': channel_editor.slider })) assert channel_editor.entry.get_text() == '100'
def test_update_menu_bar_grab(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") default_ui_manager.process_events( pygame.event.Event( pygame.MOUSEBUTTONDOWN, { 'button': pygame.BUTTON_LEFT, 'pos': confirm_dialog.title_bar.rect.center })) confirm_dialog.update(0.01) assert confirm_dialog.grabbed_window is True
def test_press_delete_button_and_ok(self, _init_pygame, default_ui_manager, _display_surface_return_none): file_dialog = UIFileDialog(rect=pygame.Rect(100, 100, 440, 500), manager=default_ui_manager) with open(str(Path('tests/data/for_delete.txt')), 'w') as file_to_delete: file_to_delete.write('Some text') file_dialog.current_file_path = Path( 'tests/data/for_delete.txt').absolute() file_dialog.delete_button.enable() event_data = { 'button': pygame.BUTTON_LEFT, 'pos': file_dialog.delete_button.rect.center } default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, event_data)) default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONUP, event_data)) for event in pygame.event.get(): default_ui_manager.process_events(event) assert file_dialog.delete_confirmation_dialog is not None ok_event_data = { 'user_type': pygame_gui.UI_BUTTON_PRESSED, 'ui_element': file_dialog.delete_confirmation_dialog.confirm_button } ok_event = pygame.event.Event(pygame.USEREVENT, ok_event_data) default_ui_manager.process_events(ok_event) assert (not file_dialog.delete_confirmation_dialog.alive()) for event in pygame.event.get(): default_ui_manager.process_events(event) assert not Path('tests/data/for_delete.txt').exists()
def test_set_position_with_scrollbar(self, _init_pygame: None, default_ui_manager: UIManager, _display_surface_return_none): text_box = UITextBox(html_text='la la LA LA LAL LAL ALALA' 'LLALAALALA ALALA ALAL ALA' 'LAALA ALALA ALALA AAaal aa' 'ALALAa laalal alalal alala' 'alalalala alalalalalal alal' 'alalalala alala alalala ala' 'alalalalal lalal alalalal al', relative_rect=pygame.Rect(100, 100, 100, 100), manager=default_ui_manager) text_box.set_position(pygame.math.Vector2(0.0, 0.0)) assert text_box.rect.topleft == (0, 0) default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (92, 8)})) # if we successfully clicked on the moved text box scroll bar then this button should be True assert text_box.scroll_bar.top_button.held is True
def test_update_dismiss_button(self, _init_pygame, default_ui_manager, _display_surface_return_none): message_window = UIMessageWindow( rect=pygame.Rect(100, 100, 250, 300), window_title="Test Message", html_message="This is a bold test of the " "message box functionality.", manager=default_ui_manager) is_alive_pre_events = message_window.alive() event_data = { 'button': pygame.BUTTON_LEFT, 'pos': message_window.dismiss_button.rect.center } default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, event_data)) event_data = { 'button': pygame.BUTTON_LEFT, 'pos': message_window.dismiss_button.rect.center } default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONUP, event_data)) for event in pygame.event.get(): default_ui_manager.process_events(event) is_dead_post_events = not message_window.alive() assert is_alive_pre_events is True and is_dead_post_events is True
def test_set_relative_position(self, _init_pygame, default_ui_manager, _display_surface_return_none): test_container = UIContainer(relative_rect=pygame.Rect(50, 50, 300, 250), manager=default_ui_manager) scroll_bar = UIVerticalScrollBar(relative_rect=pygame.Rect(80, 100, 30, 200), visible_percentage=0.25, manager=default_ui_manager, container=test_container) scroll_bar.set_relative_position((50, 50)) # try to click on the scroll bar's top button default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (115, 105)})) # if we successfully clicked on the moved scroll bar then this button should be True assert scroll_bar.top_button.held is True default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (115, 295)})) # if we successfully clicked on the moved scroll bar then this button should be True assert scroll_bar.bottom_button.held is True default_ui_manager.process_events(pygame.event.Event(pygame.MOUSEBUTTONDOWN, {'button': 1, 'pos': (115, 150)})) # if we successfully clicked on the moved scroll bar then this button should be True assert scroll_bar.sliding_button.held is True
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
def test_set_position(self, _init_pygame, default_ui_manager, _display_surface_return_none): scroll_bar = UIHorizontalScrollBar(relative_rect=pygame.Rect( 80, 100, 200, 30), visible_percentage=0.25, manager=default_ui_manager) scroll_bar.set_position((200, 200)) # try to click on the scroll bar's left button default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (205, 215) })) # if we successfully clicked on the moved scroll bar then this button should be True assert scroll_bar.left_button.held is True default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (395, 215) })) # if we successfully clicked on the moved scroll bar then this button should be True assert scroll_bar.right_button.held is True default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (250, 215) })) # if we successfully clicked on the moved scroll bar then this button should be True assert scroll_bar.sliding_button.held is True
def test_get_multi_selection(self, _init_pygame, default_ui_manager, _display_surface_return_none): selection_list = UISelectionList( relative_rect=pygame.Rect(50, 50, 150, 400), item_list=['green', 'eggs', 'and', 'ham'], manager=default_ui_manager, allow_multi_select=True) assert selection_list.get_multi_selection() == [] event_data = { 'user_type': pygame_gui.UI_BUTTON_PRESSED, 'ui_element': selection_list.item_list_container.elements[0] } press_list_item_event = pygame.event.Event(pygame.USEREVENT, event_data) default_ui_manager.process_events(press_list_item_event) assert selection_list.get_multi_selection() == ['green'] event_data = { 'user_type': pygame_gui.UI_BUTTON_PRESSED, 'ui_element': selection_list.item_list_container.elements[1] } press_list_item_event = pygame.event.Event(pygame.USEREVENT, event_data) default_ui_manager.process_events(press_list_item_event) assert selection_list.get_multi_selection() == ['green', 'eggs'] single_selection_list = UISelectionList( relative_rect=pygame.Rect(50, 50, 150, 400), item_list=['green', 'eggs', 'and', 'ham'], manager=default_ui_manager) with pytest.raises( RuntimeError, match='Requesting multi selection, from single-selection list' ): single_selection_list.get_multi_selection()
def test_set_dimensions(self, _init_pygame, default_ui_manager, _display_surface_return_none): slider = UIHorizontalSlider(relative_rect=pygame.Rect(0, 0, 150, 40), start_value=50, value_range=(0, 200), manager=default_ui_manager) slider.set_dimensions((200, 60)) # try to click on the slider default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (195, 50) })) # if we successfully clicked on the moved slider then this button should be True assert slider.right_button.held is True assert slider.right_button.rect.top == (slider.shadow_width + slider.border_width) assert slider.right_button.rect.bottom == 60 - (slider.shadow_width + slider.border_width) assert slider.right_button.rect.right == 200 - (slider.shadow_width + slider.border_width) slider.set_dimensions((100, 30)) # try to click on the slider default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (95, 15) })) # if we successfully clicked on the moved slider then this button should be True assert slider.right_button.held is True assert slider.right_button.rect.top == (slider.shadow_width + slider.border_width) assert slider.right_button.rect.bottom == 30 - (slider.shadow_width + slider.border_width) assert slider.right_button.rect.right == 100 - (slider.shadow_width + slider.border_width) slider.set_dimensions((150, 45)) # try to click on the slider default_ui_manager.process_events( pygame.event.Event(pygame.MOUSEBUTTONDOWN, { 'button': 1, 'pos': (145, 22) })) # if we successfully clicked on the moved slider then this button should be True assert slider.right_button.held is True assert slider.right_button.rect.top == (slider.shadow_width + slider.border_width) assert slider.right_button.rect.bottom == 45 - (slider.shadow_width + slider.border_width) assert slider.right_button.rect.right == 150 - (slider.shadow_width + slider.border_width)