コード例 #1
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_get_interactive_components_should_return_all_and_no_more(self):
        """Given a hierarchy of components
        when asked for all interactive components
        then all and no more are returned"""
        # Given
        root = gui.Component()
        child1 = gui.Component()
        child2 = gui.InteractiveComponent(Rectangle(0, 0, 0, 0))
        child11 = gui.Component()
        child12 = gui.InteractiveComponent(Rectangle(0, 0, 0, 0))
        child21 = gui.InteractiveComponent(Rectangle(0, 0, 0, 0))
        child22 = gui.Component()
        child222 = gui.InteractiveComponent(Rectangle(0, 0, 0, 0))

        root.add_subcomponent(child1)
        root.add_subcomponent(child2)
        child1.add_subcomponent(child11)
        child1.add_subcomponent(child12)
        child2.add_subcomponent(child21)
        child2.add_subcomponent(child22)
        child22.add_subcomponent(child222)

        # When
        interactives = gui.GuiState._get_interactive_components(root)

        # Then
        assert len(interactives) == 4
        assert root not in interactives
        assert child1 not in interactives
        assert child2 in interactives
        assert child11 not in interactives
        assert child12 in interactives
        assert child21 in interactives
        assert child22 not in interactives
        assert child222 in interactives
コード例 #2
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_mouse_move_over_shouldnt_activate_nonhard_component(self):
        # Given
        gui_state = gui.GuiState()
        userinput = UserInput()
        userinput.mouse.feed_pos(Vec2D(50, 150))

        component = gui.InteractiveComponent(Rectangle(100, 100, 100, 100))

        hardcomp = gui.InteractiveComponent(Rectangle(100, 300, 100, 100))
        hardcomp.lock_input(True)

        base = gui.Component()
        base.add_subcomponent(component)
        base.add_subcomponent(hardcomp)

        gui_state.set_active(hardcomp)

        assert gui_state.get_active() <> component
        assert gui_state.get_active() == hardcomp

        # When
        userinput.update()
        userinput.mouse.feed_pos(Vec2D(150, 150))
        gui_state.update(userinput, base)

        # Then
        assert gui_state.get_active() <> component
        assert gui_state.get_active() == hardcomp
コード例 #3
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_only_one_selected(self):
        # Given
        rb = gui.Radiobuttons()
        rb.append(gui.Checkbox(Rectangle(100, 100, 50, 50), False))
        rb.append(gui.Checkbox(Rectangle(100, 200, 50, 50), False))
        rb.append(gui.Checkbox(Rectangle(100, 300, 50, 50), False))
        userinput = UserInput()
        guistate = gui.GuiState()

        # When select checkbox 0
        userinput.mouse.feed_pos(Vec2D(110, 110))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert rb[0].is_selected()
        assert not rb[1].is_selected()
        assert not rb[2].is_selected()
        assert rb.get_selected() is rb[0]
        assert rb.get_selected_index() == 0

        # And when select checkbox 2
        userinput.mouse.feed_pos(Vec2D(110, 310))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert not rb[0].is_selected()
        assert not rb[1].is_selected()
        assert rb[2].is_selected()
        assert rb.get_selected() is rb[2]
        assert rb.get_selected_index() == 2

        # And when select checkbox 1
        userinput.mouse.feed_pos(Vec2D(110, 210))
        userinput.mouse.feed_down(Mouse.LEFT)
        rb.tick(userinput, guistate)

        # Then
        assert not rb[0].is_selected()
        assert rb[1].is_selected()
        assert not rb[2].is_selected()
        assert rb.get_selected() is rb[1]
        assert rb.get_selected_index() == 1
コード例 #4
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_mouse_still_over_shouldnt_activate_component(self):
        # Given
        gui_state = gui.GuiState()
        userinput = UserInput()
        userinput.mouse.feed_pos(Vec2D(150, 150))

        component1 = gui.InteractiveComponent(Rectangle(100, 100, 100, 100))
        component = gui.InteractiveComponent(Rectangle(100, 100, 100, 100))

        base = gui.Component()
        base.add_subcomponent(component1)
        base.add_subcomponent(component)

        assert gui_state.get_active() <> component

        # When
        userinput.update()
        userinput.mouse.feed_pos(Vec2D(150, 150))
        gui_state.update(userinput, base)

        # Then
        assert gui_state.get_active() <> component
コード例 #5
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_get_text_returns_set_text(self):
        """Given a TextField
            when a text is set
            then that text can be retrieved"""
        # Given
        textfield = gui.TextField(Rectangle(100, 100, 50, 50), gfx.Font())
        TEST_TEXT = "Testing 1 2 3"

        # When
        textfield.text = TEST_TEXT

        # Then
        assert textfield.text == TEST_TEXT
コード例 #6
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_mouse_move_over_should_activate_component(self):
        # Given
        gui_state = gui.GuiState()
        userinput = UserInput()
        userinput.mouse.feed_pos(Vec2D(50, 150))

        component = gui.InteractiveComponent(Rectangle(100, 100, 100, 100))

        assert gui_state.get_active() <> component

        # When
        userinput.update()
        userinput.mouse.feed_pos(Vec2D(150, 150))
        gui_state.update(userinput, component)

        # Then
        assert gui_state.get_active() == component
コード例 #7
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_not_clicked_when_mousepress_outside(self):
        """Given a button
            when mouse clicks outside
            then button shouldn't return clicked state"""
        # Given
        button = gui.Button(Rectangle(100, 100, 50, 50))
        userinput = UserInput()
        guistate = gui.GuiState()
        assert not button.went_down()

        # When
        userinput.mouse.feed_pos(Vec2D(110, 90))
        userinput.mouse.feed_down(Mouse.LEFT)
        button.tick(userinput, guistate)

        # Then
        assert not button.went_down()
コード例 #8
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_non_active_receives_no_input(self):
        """Given an non-active TextField
            when keys are pressed
            then the text isn't entered"""
        # Given
        textfield = gui.TextField(Rectangle(100, 100, 50, 50), gfx.Font())
        userinput = UserInput()
        guistate = gui.GuiState()
        guistate.set_active(None)

        # When
        # loop 1
        userinput.key.feed_char("A")
        textfield.tick(userinput, guistate)
        userinput.update()
        userinput.key.feed_char("b")
        textfield.tick(userinput, guistate)
        userinput.update()

        # Then
        assert textfield.text == ""
コード例 #9
0
ファイル: test_gui.py プロジェクト: heinervdm/MysticMine
    def test_clicked_when_mousepress_inside(self):
        # Given
        checkbox = gui.Checkbox(Rectangle(100, 100, 50, 50), False)
        userinput = UserInput()
        guistate = gui.GuiState()
        assert not checkbox.is_selected()

        # When
        userinput.mouse.feed_pos(Vec2D(110, 110))
        userinput.mouse.feed_down(Mouse.LEFT)
        checkbox.tick(userinput, guistate)

        # Then
        assert checkbox.went_down()
        assert checkbox.is_selected()

        # And when
        checkbox.tick(userinput, guistate)

        # Then
        assert not checkbox.is_selected()