def test_set_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) 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), container=test_container) channel_editor.set_position((150, 30)) assert channel_editor.relative_rect.topleft == (50, -70)
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_creation(self, _init_pygame, default_ui_manager, _display_surface_return_none): 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))
def test_set_value(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)) assert channel_editor.entry.get_text() == '0' assert channel_editor.slider.get_current_value() == 0 channel_editor.set_value(200) assert channel_editor.entry.get_text() == '200' assert channel_editor.slider.get_current_value() == 200 assert channel_editor.current_value == 200
def test_hide(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) 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), container=test_container, visible=1) channel_editor.set_dimensions((200, 29)) assert channel_editor.visible == 1 assert channel_editor.element_container.visible == 1 assert channel_editor.label.visible == 1 assert channel_editor.entry.visible == 1 assert channel_editor.slider.visible == 1 channel_editor.hide() assert channel_editor.visible == 0 assert channel_editor.element_container.visible == 0 assert channel_editor.label.visible == 0 assert channel_editor.entry.visible == 0 assert channel_editor.slider.visible == 0
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_gui.UI_HORIZONTAL_SLIDER_MOVED, {'ui_element': channel_editor.slider})) assert channel_editor.entry.get_text() == '100'
def test_show_hide_rendering(self, _init_pygame, default_ui_manager, _display_surface_return_none): resolution = (400, 400) empty_surface = pygame.Surface(resolution) empty_surface.fill(pygame.Color(0, 0, 0)) surface = empty_surface.copy() manager = pygame_gui.UIManager(resolution) test_container = UIContainer(relative_rect=pygame.Rect( 100, 100, 300, 60), manager=manager) manager.draw_ui(empty_surface) channel_editor = UIColourChannelEditor(relative_rect=pygame.Rect( 0, 0, 150, 29), manager=manager, name='H:', channel_index=0, initial_value=0, value_range=(0, 360), container=test_container, visible=0) channel_editor.set_dimensions((200, 29)) manager.update(0.01) manager.draw_ui(surface) assert compare_surfaces(empty_surface, surface) surface.fill(pygame.Color(0, 0, 0)) channel_editor.show() manager.update(0.01) manager.draw_ui(surface) assert not compare_surfaces(empty_surface, surface) surface.fill(pygame.Color(0, 0, 0)) channel_editor.hide() manager.update(0.01) manager.draw_ui(surface) assert compare_surfaces(empty_surface, surface)