コード例 #1
0
ファイル: zoomed_event_demo.py プロジェクト: anthonyfk/enable
    def _create_window(self):

        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)
        canvas.overlays.append(EventTracer(canvas, color="green", size=8,
                                           angle=45.0))

        viewport = Viewport(component=canvas, enable_zoom=True)
        viewport.view_position = [0,0]
        viewport.tools.append(ViewportPanTool(viewport, drag_button="right"))
        viewport.overlays.append(EventTracer(viewport))

        if 1:
            scrolled = Scrolled(canvas, inside_padding_width = 0,
                            mousewheel_scroll = False,
                            viewport_component = viewport,
                            always_show_sb = True,
                            continuous_drag_update = True)
            return Window(self, -1, component=scrolled)

        elif 1:
            viewport.bounds = [300, 300]
            viewport.position = [10,10]
            container = Container(fit_window=True, auto_size=False,
                                  border_visible=True,
                                  border_color = "blue")
            container.padding = 20
            container.add(viewport)
            return Window(self, -1, component=container)

        else:
            return Window(self, -1, component=viewport)
コード例 #2
0
ファイル: test_viewport.py プロジェクト: alexlib/enable
    def test_adjust_bounds_vanchor_center_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(
            component=container,
            view_bounds=[50.0, 50.0],
            view_position=[20, 20],
            position=[0, 0],
            bounds=[50, 50],
            vertical_anchor="center",
            stay_inside=True,
        )

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [20, 15.0])

        # resize beyond left
        view.bounds = [95, 95]
        self.assertEqual(view.view_position, [5, 0.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [0, -10.0])
コード例 #3
0
ファイル: test_viewport.py プロジェクト: alexlib/enable
    def test_adjust_bounds_hanchor_top_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(
            component=container,
            view_bounds=[50.0, 50.0],
            view_position=[20, 20],
            position=[0, 0],
            bounds=[50, 50],
            horizontal_anchor="right",
            stay_inside=True,
        )

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [10, 20.0])

        # resize beyond left
        view.bounds = [80, 80]
        self.assertEqual(view.view_position, [0, 20.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [-20.0, 0])
コード例 #4
0
    def __container_default(self):
        """ default setter for _container
        """

        viewport = Viewport(component=self._canvas, enable_zoom=True)
        viewport.view_position = [0, 0]
        viewport.tools.append(ViewportPanTool(viewport))

        return Scrolled(self._canvas, viewport_component=viewport)
コード例 #5
0
ファイル: welcome_view.py プロジェクト: robmcmullen/puddle
    def _viewport_default(self):
        """ Trait initialiser.
        """
        vp = Viewport(component=self.canvas)

        vp.enable_zoom=False
        vp.view_position = [-5, -5]

        return vp
コード例 #6
0
ファイル: graph_view.py プロジェクト: enthought/graphcanvas
    def __container_default(self):
        """ default setter for _container
        """

        viewport = Viewport(component=self._canvas, enable_zoom=True)
        viewport.view_position = [0, 0]
        viewport.tools.append(ViewportPanTool(viewport))

        return Scrolled(self._canvas, viewport_component=viewport)
コード例 #7
0
 def create_component(self):
     canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)
     from basic_move import Box
     box = Box(color="red", bounds=[50, 50], resizable="")
     box.position = [75, 75]
     canvas.add(box)
     viewport = Viewport(component=canvas)
     viewport.view_position = [0, 0]
     viewport.tools.append(ViewportPanTool(viewport))
     return viewport
コード例 #8
0
    def test_adjust_bounds(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[10, 10],
                        position=[0, 0],
                        bounds=[50, 50])

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [10, 10])
コード例 #9
0
    def test_adjust_bounds(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[10,10],
                        position=[0,0],
                        bounds=[50,50])

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [10, 10])
コード例 #10
0
ファイル: canvas_demo.py プロジェクト: anthonyfk/enable
    def _create_window(self):

        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)
        from basic_move import Box
        box = Box(color="red", bounds=[50,50], resizable="")
        box.position= [75,75]
        canvas.add(box)


        viewport = Viewport(component=canvas)
        viewport.view_position = [0,0]
        viewport.tools.append(ViewportPanTool(viewport))

        return Window(self, -1, component=viewport)
コード例 #11
0
ファイル: test_viewport.py プロジェクト: alexlib/enable
    def test_adjust_container_bounds_vanchor_top(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(
            component=container,
            view_bounds=[50.0, 50.0],
            view_position=[20, 20],
            position=[0, 0],
            bounds=[50, 50],
            vertical_anchor="top",
        )

        # simple resize bigger
        container.bounds = [120, 120]
        self.assertEqual(view.view_position, [20, 40.0])

        # simple resize smaller
        container.height = 90
        container.width = 90
        self.assertEqual(view.view_position, [20, 10.0])

        # simple resize much smaller
        container.bounds[0] = 40
        container.bounds[1] = 40
        self.assertEqual(view.view_position, [20, -40.0])
コード例 #12
0
    def test_adjust_container_bounds_hanchor_right_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0, 0],
                        bounds=[50, 50],
                        horizontal_anchor='right',
                        stay_inside=True)

        # simple resize bigger
        container.bounds = [120, 120]
        self.assertEqual(view.view_position, [40, 20])

        # simple resize smaller
        container.height = 90
        container.width = 90
        self.assertEqual(view.view_position, [10, 20])

        # simple resize much smaller
        container.bounds[0] = 40
        container.bounds[1] = 40
        self.assertEqual(view.view_position, [-10, 0])
コード例 #13
0
ファイル: sierpinski_zoom.py プロジェクト: alexlib/enable
    def _comp_default(self):
        canvas = Canvas(draw_axes=True, bgcolor="gray")
        self.triangle = SierpinskiTriangle(
            position=[0.0, 0.0],
            bounds=[self.base_width, self.base_width * (SQRT3 / 2)],
            iterations=self.iterations,
            max_iters=self.max_iters,
            base_width=self.base_width,
            bgcolor="gray")
        canvas.add(self.triangle)

        self.viewport = Viewport(component=canvas,
                                 enable_zoom=True,
                                 stay_inside=True)
        self.viewport.zoom_tool.min_zoom = 1.0
        self.viewport.tools.append(
            ViewportPanTool(self.viewport, drag_button="right"))

        scrolled = Scrolled(
            canvas,
            inside_padding_width=0,
            mousewheel_scroll=False,
            viewport_component=self.viewport,
            always_show_sb=True,
            continuous_drag_update=True,
        )
        return scrolled
コード例 #14
0
    def _create_component(self):
        canvas = DropCanvas(bgcolor="lightsteelblue", draw_axes=True)
        canvas.overlays.append(EventTracer(canvas, color="green", size=8,
                                           angle=45.0))

        viewport = Viewport(component=canvas, enable_zoom=True)
        viewport.view_position = [0, 0]
        viewport.tools.append(ViewportPanTool(viewport, drag_button="right"))
        viewport.overlays.append(EventTracer(viewport))

        scrolled = Scrolled(canvas, inside_padding_width=0,
                            mousewheel_scroll=False,
                            viewport_component=viewport,
                            always_show_sb=True,
                            continuous_drag_update=True)
        return scrolled
コード例 #15
0
ファイル: zoomed_event_demo.py プロジェクト: GaZ3ll3/enable
    def _create_window(self):

        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)
        canvas.overlays.append(EventTracer(canvas, color="green", size=8,
                                           angle=45.0))

        viewport = Viewport(component=canvas, enable_zoom=True)
        viewport.view_position = [0,0]
        viewport.tools.append(ViewportPanTool(viewport, drag_button="right"))
        viewport.overlays.append(EventTracer(viewport))

        scrolled = Scrolled(canvas, inside_padding_width = 0,
                        mousewheel_scroll = False,
                        viewport_component = viewport,
                        always_show_sb = True,
                        continuous_drag_update = True)
        return Window(self, -1, component=scrolled)
コード例 #16
0
    def test_adjust_bounds_hanchor_center_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0, 0],
                        bounds=[50, 50],
                        horizontal_anchor='center',
                        stay_inside=True)

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [15.0, 20])

        # resize beyond left
        view.height = 95
        view.width = 95
        self.assertEqual(view.view_position, [0.0, 5])

        # resize bigger than view
        view.bounds[0] = 120
        view.bounds[1] = 120
        self.assertEqual(view.view_position, [-10.0, 0])
コード例 #17
0
 def test_initial_position(self):
     container = Container(bounds=[100.0, 100.0])
     component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
     container.add(component)
     view = Viewport(component=container,
                     view_bounds=[50.0, 50.0],
                     position=[0, 0],
                     bounds=[50, 50])
     self.assertEqual(view.view_position, [0, 0])
コード例 #18
0
 def test_initial_position_hanchor_center(self):
     container = Container(bounds=[100.0, 100.0])
     component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
     container.add(component)
     view = Viewport(component=container,
                     horizontal_anchor='center',
                     view_bounds=[50.0, 50.0],
                     position=[0, 0],
                     bounds=[50, 50])
     self.assertEqual(view.view_position, [25, 0])
コード例 #19
0
    def test_basic_viewport(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_position=[10.0, 10.0],
                        view_bounds=[50.0, 50.0],
                        position=[0,0],
                        bounds=[50,50])

        self.assertEqual(view.view_position, [10, 10])
        print view.components_at(0.0, 0.0), view.view_position
        self.assert_(view.components_at(0.0, 0.0)[0] == component)
        self.assert_(view.components_at(44.9, 0.0)[0] == component)
        self.assert_(view.components_at(0.0, 44.9)[0] == component)
        self.assert_(view.components_at(44.9, 44.9)[0] == component)

        self.assert_(view.components_at(46.0, 45.0) == [])
        self.assert_(view.components_at(46.0, 0.0) == [])
        self.assert_(view.components_at(45.0, 46.0) == [])
        self.assert_(view.components_at(0.0, 46.0) == [])
コード例 #20
0
ファイル: test_viewport.py プロジェクト: alexlib/enable
 def test_initial_position_vanchor_center(self):
     container = Container(bounds=[100.0, 100.0])
     component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
     container.add(component)
     view = Viewport(
         component=container,
         vertical_anchor="center",
         view_bounds=[50.0, 50.0],
         position=[0, 0],
         bounds=[50, 50],
     )
     self.assertEqual(view.view_position, [0, 25])
コード例 #21
0
    def test_basic_viewport(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_position=[10.0, 10.0],
                        view_bounds=[50.0, 50.0],
                        position=[0, 0],
                        bounds=[50, 50])

        self.assertEqual(view.view_position, [10, 10])
        print(view.components_at(0.0, 0.0), view.view_position)
        self.assertTrue(view.components_at(0.0, 0.0)[0] == component)
        self.assertTrue(view.components_at(44.9, 0.0)[0] == component)
        self.assertTrue(view.components_at(0.0, 44.9)[0] == component)
        self.assertTrue(view.components_at(44.9, 44.9)[0] == component)

        self.assertTrue(view.components_at(46.0, 45.0) == [])
        self.assertTrue(view.components_at(46.0, 0.0) == [])
        self.assertTrue(view.components_at(45.0, 46.0) == [])
        self.assertTrue(view.components_at(0.0, 46.0) == [])
コード例 #22
0
ファイル: scrolled_canvas_demo.py プロジェクト: geggo/enable
    def _create_window(self):

        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)

        boxgridsize = 8
        boxsize = 50

        spacing = boxsize * 2
        offset = spacing / 2

        origin_color = array([0.0, 0.0, 1.0])
        x_color = array([0.0, 1.0, 0.0])
        y_color = array([1.0, 0.0, 0.0])

        for i in range(boxgridsize):
            for j in range(boxgridsize):
                color = tuple(x_color / (boxgridsize - 1) * i + y_color / (boxgridsize - 1) * j + origin_color) + (1.0,)
                box = Box(color=color, bounds=[boxsize, boxsize], resizable="")
                box.position = [i * spacing + offset - boxsize / 2 + 0.5, j * spacing + offset - boxsize / 2 + 0.5]
                canvas.add(box)

        viewport = Viewport(component=canvas, enable_zoom=True)
        viewport.view_position = [0, 0]
        viewport.tools.append(ViewportPanTool(viewport))

        # Uncomment the following to enforce limits on the zoom
        # viewport.min_zoom = 0.1
        # viewport.max_zoom = 3.0

        scrolled = Scrolled(
            canvas,
            fit_window=True,
            inside_padding_width=0,
            mousewheel_scroll=False,
            viewport_component=viewport,
            always_show_sb=True,
            continuous_drag_update=True,
        )

        return Window(self, -1, component=scrolled)
コード例 #23
0
    def test_adjust_bounds_hanchor_center_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0,0],
                        bounds=[50,50],
                        horizontal_anchor='center',
                        stay_inside=True)

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [15.0, 20])

        # resize beyond left
        view.height = 95
        view.width = 95
        self.assertEqual(view.view_position, [0.0, 5])

        # resize bigger than view
        view.bounds[0] = 120
        view.bounds[1] = 120
        self.assertEqual(view.view_position, [-10.0, 0])
コード例 #24
0
    def test_adjust_bounds_vanchor_top(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0,0],
                        bounds=[50,50],
                        vertical_anchor='top')

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [20, 10.0])

        # resize beyond bottom
        view.bounds = [80, 80]
        self.assertEqual(view.view_position, [20, -10.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [20, -50.0])
コード例 #25
0
ファイル: interface.py プロジェクト: btciavol/TechEngine
    def _create_window(self):
        self.canvas = Canvas(bgcolor='lightgrey',
                             draw_axes=True,
                             fit_window = True)


        sys,cat = load_system("datsun truck.repo")
        #        sys,cat = load_system()
#        find_technologies(sys)
        self.make_components(sys)


        viewport = Viewport(component=self.canvas,enable_zoom=True)

        max_x = 0
        max_y = 0
        for art in sys.artifacts:
            try:
                if art.drawable.x2 > max_x:
                    max_x = art.drawable.x2
                if art.drawable.y2 > max_y:
                    max_y = art.drawable.y2
            except AttributeError:
                pass

#        max_x = max([art.drawable.x2 for art in sys.artifacts])
#        max_y = max([art.drawable.y2 for art in sys.artifacts])

        viewport.view_position = [max_x/2,max_y/2]

        viewport.view_bounds = self.canvas.bounds
        viewport.zoom = 0.3
        viewport.zoom_tool.wheel_zoom_step = 1
        viewport.tools.append(ViewportPanTool(viewport))

        self.viewport = viewport
        self.fit_window()

        return Window(self, -1, component=viewport)
コード例 #26
0
    def test_adjust_bounds_hanchor_center(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0,0],
                        bounds=[50,50],
                        horizontal_anchor='center')

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [15.0, 20])

        # resize beyond left
        view.bounds = [95, 95]
        self.assertEqual(view.view_position, [-2.5, 20])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [-15.0, 20])
コード例 #27
0
    def test_adjust_bounds_vanchor_top(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0, 0],
                        bounds=[50, 50],
                        vertical_anchor='top')

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [20, 10.0])

        # resize beyond bottom
        view.bounds = [80, 80]
        self.assertEqual(view.view_position, [20, -10.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [20, -50.0])
コード例 #28
0
    def test_adjust_bounds_hanchor_center(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0, 0],
                        bounds=[50, 50],
                        horizontal_anchor='center')

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [15.0, 20])

        # resize beyond left
        view.bounds = [95, 95]
        self.assertEqual(view.view_position, [-2.5, 20])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [-15.0, 20])
コード例 #29
0
    def test_adjust_bounds_vanchor_center_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0,0],
                        bounds=[50,50],
                        vertical_anchor='center',
                        stay_inside=True)

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [20, 15.0])

        # resize beyond left
        view.bounds = [95, 95]
        self.assertEqual(view.view_position, [5, 0.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [0, -10.0])
コード例 #30
0
    def test_adjust_bounds_hanchor_top_stay_inside(self):
        container = Container(bounds=[100.0, 100.0])
        component = Component(bounds=[50.0, 50.0], position=[5.0, 5.0])
        container.add(component)
        view = Viewport(component=container,
                        view_bounds=[50.0, 50.0],
                        view_position=[20, 20],
                        position=[0,0],
                        bounds=[50,50],
                        horizontal_anchor='right',
                        stay_inside=True)

        # simple resize
        view.bounds = [60, 60]
        self.assertEqual(view.view_position, [10, 20.0])

        # resize beyond left
        view.bounds = [80, 80]
        self.assertEqual(view.view_position, [0, 20.0])

        # resize bigger than view
        view.bounds = [120, 120]
        self.assertEqual(view.view_position, [-20.0, 0])
コード例 #31
0
ファイル: canvas.py プロジェクト: zijuzhang/chaco
    def _create_viewport(self):
        # Create a container and add our plots
        canvas = PlotCanvas()
        canvas.range_controller = RangeController(cavas = canvas)

        toolbar = make_toolbar(canvas)
        toolbar.component = canvas
        canvas.overlays.append(toolbar)

        viewport = Viewport(component=canvas)
        if MULTITOUCH:
            viewport.tools.append(MPViewportPanTool(viewport))
        else:
            viewport.tools.append(ViewportPanTool(viewport, drag_button="right"))
        return viewport
コード例 #32
0
    def _create_component(self):
        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)

        boxgridsize = 8
        boxsize = 50

        spacing = boxsize * 2
        offset = spacing / 2

        origin_color = array([0.0, 0.0, 1.0])
        x_color = array([0.0, 1.0, 0.0])
        y_color = array([1.0, 0.0, 0.0])

        for i in range(boxgridsize):
            for j in range(boxgridsize):
                color = tuple(x_color / (boxgridsize - 1) * i + y_color /
                              (boxgridsize - 1) * j + origin_color) + (1.0, )
                box = Box(color=color, bounds=[boxsize, boxsize], resizable="")
                box.position = [
                    i * spacing + offset - boxsize / 2 + 0.5,
                    j * spacing + offset - boxsize / 2 + 0.5,
                ]
                canvas.add(box)

        viewport = Viewport(
            component=canvas,
            enable_zoom=True,
            vertical_anchor="center",
            horizontal_anchor="center",
        )
        # viewport.view_position = [0,0]
        viewport.tools.append(ViewportPanTool(viewport))

        # Uncomment the following to enforce limits on the zoom
        # viewport.min_zoom = 0.1
        # viewport.max_zoom = 3.0

        scrolled = Scrolled(
            canvas,
            fit_window=True,
            inside_padding_width=0,
            mousewheel_scroll=False,
            viewport_component=viewport,
            always_show_sb=True,
            continuous_drag_update=True,
        )

        return scrolled
コード例 #33
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
コード例 #34
0
    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)
コード例 #35
0
 def _component_changed(self, old, new):
     """ When the component changes, make sure our graph_updated function
         is synced with its controller's graph_updated event.
     """
     self.bgcolor = new.bgcolor
     Viewport._component_changed(self, old, new)
コード例 #36
0
 def _component_changed(self, old, new):
     """ When the component changes, make sure our graph_updated function
         is synced with its controller's graph_updated event.
     """
     self.bgcolor = new.bgcolor
     Viewport._component_changed(self, old, new)
コード例 #37
0
    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