Exemple #1
0
    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
Exemple #2
0
    def test_rebuild(self, _init_pygame, default_ui_manager):
        message_window = UIMessageWindow(message_window_rect=pygame.Rect(100, 100, 200, 300),
                                         message_title="Test Message",
                                         html_message="This is a bold test of the message box functionality.",
                                         manager=default_ui_manager)

        message_window.rebuild()

        assert message_window.image is not None
Exemple #3
0
    def test_update_menu_bar_grab(self, _init_pygame, default_ui_manager):
        message_window = UIMessageWindow(message_window_rect=pygame.Rect(100, 100, 200, 300),
                                         message_title="Test Message",
                                         html_message="This is a bold test of the message box functionality.",
                                         manager=default_ui_manager)

        message_window.menu_bar.held = True
        message_window.update(0.01)

        assert message_window.grabbed_window is True
Exemple #4
0
    def test_rebuild(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)

        message_window.rebuild()

        assert message_window.image is not None
Exemple #5
0
    def test_update_menu_bar_grab(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)

        message_window.title_bar.held = True
        message_window.update(0.01)

        assert message_window.grabbed_window is True
Exemple #6
0
    def test_bad_values_theme_build(self, _init_pygame):
        manager = UIManager((800, 600), os.path.join("tests", "data", "themes", "ui_message_window_bad_values.json"))
        message_window = UIMessageWindow(message_window_rect=pygame.Rect(100, 100, 200, 300),
                                         message_title="Test Message",
                                         html_message="This is a bold test of the message box functionality.",
                                         manager=manager)

        assert message_window.image is not None
Exemple #7
0
 def test_creation(self, _init_pygame, default_ui_manager,
                   _display_surface_return_none):
     default_ui_manager.preload_fonts([{'name': 'fira_code',
                                        'point_size': 14,
                                        'style': 'bold'}])
     UIMessageWindow(rect=pygame.Rect(100, 100, 250, 300),
                     window_title="Test Message",
                     html_message="This is a <b>bold</b> test "
                                  "of the message box functionality.",
                     manager=default_ui_manager)
 def test_process_events(self, _init_pygame, default_ui_manager, _display_surface_return_none):
     """
     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(rect=pygame.Rect(500, 400, 250, 300),
                     window_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.held
Exemple #9
0
    def test_create_too_small(self, _init_pygame, default_ui_manager,
                              _display_surface_return_none):
        default_ui_manager.preload_fonts([{'name': 'fira_code',
                                           'point_size': 14,
                                           'style': 'bold'}])

        with pytest.warns(UserWarning, match="Initial size"):
            UIMessageWindow(rect=pygame.Rect(100, 100, 50, 50),
                            window_title="Test Message",
                            html_message="This is a <b>bold</b> test of the "
                                         "message box functionality.",
                            manager=default_ui_manager)
Exemple #10
0
    def test_non_default_theme_build(self, _init_pygame,
                                     _display_surface_return_none):
        manager = UIManager((800, 600), os.path.join("tests", "data",
                                                     "themes",
                                                     "ui_message_window_non_default.json"))
        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=manager)

        assert message_window.image is not None
Exemple #11
0
    def test_show_hide_rendering(self, _init_pygame, default_ui_manager,
                                 _display_surface_return_none):
        resolution = (600, 600)
        empty_surface = pygame.Surface(resolution)
        empty_surface.fill(pygame.Color(0, 0, 0))

        surface = empty_surface.copy()
        manager = UIManager(resolution)

        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=manager,
            visible=0)
        manager.update(0.01)
        manager.draw_ui(surface)
        assert compare_surfaces(empty_surface, surface)

        surface.fill(pygame.Color(0, 0, 0))
        message_window.show()
        manager.update(0.01)
        manager.draw_ui(surface)
        assert not compare_surfaces(empty_surface, surface)

        surface.fill(pygame.Color(0, 0, 0))
        message_window.hide()
        manager.update(0.01)
        manager.draw_ui(surface)
        assert compare_surfaces(empty_surface, surface)
Exemple #12
0
    def test_hide(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)

        assert message_window.visible == 1

        assert message_window.close_window_button.visible == 1
        assert message_window.dismiss_button.visible == 1
        assert message_window.text_block.visible == 1

        message_window.hide()

        assert message_window.visible == 0

        assert message_window.close_window_button.visible == 0
        assert message_window.dismiss_button.visible == 0
        assert message_window.text_block.visible == 0
Exemple #13
0
    def test_rebuild_rounded_rectangle(self, _init_pygame, default_ui_manager):
        message_window = UIMessageWindow(message_window_rect=pygame.Rect(100, 100, 200, 300),
                                         message_title="Test Message",
                                         html_message="This is a bold test of the message box functionality.",
                                         manager=default_ui_manager)

        message_window.shape_corner_radius = 15
        message_window.shape_type = 'rounded_rectangle'
        message_window.rebuild()

        assert message_window.image is not None
Exemple #14
0
    def test_update_dismiss_button(self, _init_pygame, default_ui_manager):
        message_window = UIMessageWindow(message_window_rect=pygame.Rect(100, 100, 200, 300),
                                         message_title="Test Message",
                                         html_message="This is a bold test of the message box functionality.",
                                         manager=default_ui_manager)

        message_window.dismiss_button.pressed = True
        is_alive_pre_update = message_window.alive()
        message_window.update(0.01)
        is_dead_post_update = not message_window.alive()

        assert is_alive_pre_update is True and is_dead_post_update is True
 def create_message_window(self):
     self.button_response_timer.tick()
     UIMessageWindow(pygame.Rect((random.randint(0, self.options.resolution[0] - 300),
                                  random.randint(0, self.options.resolution[1] - 200)),
                                 (350, 250)),
                     'Test Message Window',
                     '<font color=normal_text>'
                     'This is a <a href="test">test</a> message to see if '
                     'this box <a href=actually_link>actually</a> works.'
                     ''
                     'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><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 blob</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>'
                     '<br><br>'
                     'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><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>'
                     '<br><br>'
                     'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><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>',
                     self.ui_manager)
     time_taken = self.button_response_timer.tick()/1000.0
     # currently taking about 0.35 seconds down from 0.55 to create an elaborately themed message window.
     # still feels a little slow but it's better than it was.
     print("Time taken to create message window: " + str(time_taken))
 def create_message_window(self):
     UIMessageWindow(
         pygame.Rect((random.randint(0, self.options.resolution[0] - 300),
                      random.randint(0, self.options.resolution[1] - 200)),
                     (350, 250)), 'Test Message Window',
         '<font color=normal_text>'
         'This is a <a href="test">test</a> message to see if '
         'this box <a href=actually_link>actually</a> works.'
         ''
         'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><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 blob</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>'
         '<br><br>'
         'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><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>'
         '<br><br>'
         'In <i>bibendum</i> orci et velit</b> gravida lacinia.<br><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>', self.ui_manager)