def test_viewport_container(self):
        """ Tests event handling of viewports (scaling and translation) """
        comp = TestComponent(position=[20, 20])

        container = TestContainer(bounds=[100, 100], position=[50, 50])
        container.add(comp)

        viewport = Viewport(component=container,
                            bounds=[400, 400],
                            position=[30, 30])

        # Test unscaled event
        event = BasicEvent(x=105, y=105)
        viewport.dispatch(event, "left_down")

        self.assertTrue(container.last_event.x == 75)
        self.assertTrue(container.last_event.y == 75)
        self.assertTrue(comp.last_event.x == 25)
        self.assertTrue(comp.last_event.y == 25)

        # Translate the viewport's view_position
        container.last_event = None
        comp.last_event = None
        viewport.view_position = [-10, -10]
        event = BasicEvent(x=115, y=115)
        viewport.dispatch(event, "left_down")

        self.assertTrue(container.last_event.x == 75)
        self.assertTrue(container.last_event.y == 75)
        self.assertTrue(comp.last_event.x == 25)
        self.assertTrue(comp.last_event.y == 25)

        # Do a zoom
        container.last_event = None
        comp.last_event = None
        # Zoom in by a factor of 2, so view an area that is 200x200.
        viewport.zoom = 2.0
        viewport.enable_zoom = True
        viewport.view_position = [-50, -50]
        viewport.view_bounds = [200, 200]
        event = BasicEvent(x=280, y=280)
        viewport.dispatch(event, "left_down")

        self.assertTrue(container.last_event.x == 75)
        self.assertTrue(container.last_event.y == 75)
        self.assertTrue(comp.last_event.x == 25)
        self.assertTrue(comp.last_event.y == 25)
        return
 def test_normal_left_dclick_not_in(self):
     event = BasicEvent(x=50, y=50, handled=False)
     node = self.container.components[0]
     node.edit_traits = mock.Mock()
     self.tool.normal_left_dclick(event)
     node.edit_traits.assert_not_called()
     self.assertFalse(event.handled)
 def test_traited_node(self):
     event = BasicEvent(x=0, y=0, handled=False)
     self.container.components.pop(0)
     node = GraphNodeComponent(
         value=TraitedNodeValue(label='traited_node'), position=[0, 0])
     self.container.components.append(node)
     self.tool.normal_left_dclick(event)
     node.value.edit_traits.assert_called_once_with()
示例#4
0
    def test_mouse_capture(self):
        """ Tests saving the event's net_transform as well as the dispatch
        history when capturing a mouse and dispatching subsequent events.
        """

        class MouseCapturingComponent(TestComponent):
            captured_event_pos = Tuple

            def normal_left_down(self, event):
                self.captured_event_pos = (event.x, event.y)
                event.window.set_mouse_owner(self, event.net_transform())

        comp = MouseCapturingComponent(position=[20, 20])

        container = TestContainer(bounds=[100, 100], position=[50, 50])
        container.add(comp)

        viewport = Viewport(
            component=container,
            bounds=[400, 400],
            position=[30, 30],
            fit_window=False,
            resizable="")

        window = DummyWindow(_size=(500, 500))
        window.component = viewport

        # Create the first event (to trigger the mouse capture)
        event = BasicEvent(x=105, y=105, window=window)
        window._handle_mouse_event("left_down", event)

        self.assertTrue(window.mouse_owner == comp)

        # Create the second event
        event = BasicEvent(x=107, y=107, window=window)
        old_pos = comp.captured_event_pos
        window._handle_mouse_event("left_down", event)
        new_pos = comp.captured_event_pos
        self.assertTrue(new_pos[0] == old_pos[0] + 2)
        self.assertTrue(new_pos[1] == old_pos[1] + 2)

        return
示例#5
0
    def test_simple_container(self):
        """ Tests event handling of nested containers """
        comp = TestComponent(position=[50, 50])
        inner_container = TestContainer(
            bounds=[100.0, 100.0], position=[50, 50]
        )
        inner_container.add(comp)
        outer_container = TestContainer(bounds=[200, 200])
        outer_container.add(inner_container)

        event = BasicEvent(x=105, y=105)
        outer_container.dispatch(event, "left_down")

        self.assertTrue(comp.last_event.x == 55)
        self.assertTrue(comp.last_event.y == 55)
        self.assertTrue(inner_container.last_event.x == 105)
        self.assertTrue(inner_container.last_event.y == 105)
 def test_normal_mouse_move(self):
     event = BasicEvent(x=10, y=10, handled=False)
     self.tool.normal_mouse_move(event)
     self.assertEqual(self.tool._last_xy, (10, 10))
 def test_normal_left_dclick_in(self):
     event = BasicEvent(x=0, y=0, handled=False)
     node = self.container.components[0]
     node.edit_traits = mock.Mock()
     self.tool.normal_left_dclick(event)
     node.edit_traits.assert_called_once_with(kind='livemodal')