Ejemplo n.º 1
0
    def _dispatch_to_enable(self, event, suffix):
        """ Calls Enable-level event handlers.

        Overrides PlotComponent.
        """
        Container.dispatch(self, event, suffix)
        return
Ejemplo n.º 2
0
 def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
     c = other_component
     self.do_layout(component=c)
     with gc:
         gc.clip_to_rect(c.x, c.y, c.width, c.height)
         Container._draw(self, gc, view_bounds)
     return
Ejemplo n.º 3
0
 def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
     c = other_component
     self.do_layout(component=c)
     with gc:
         gc.clip_to_rect(c.x, c.y, c.width, c.height)
         Container._draw(self, gc, view_bounds)
     return
Ejemplo n.º 4
0
 def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
     c = other_component
     self.do_layout(component=c)
     gc.save_state()
     try:
         gc.clip_to_rect(c.x, c.y, c.width, c.height)
         Container._draw(self, gc, view_bounds)
     finally:
         gc.restore_state()
     return
Ejemplo n.º 5
0
 def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
     c = other_component
     self.do_layout(component=c)
     gc.save_state()
     try:
         gc.clip_to_rect(c.x, c.y, c.width, c.height)
         Container._draw(self, gc, view_bounds)
     finally:
         gc.restore_state()
     return
Ejemplo n.º 6
0
    def _create_component(self):
        stack = VStackedContainer(
            position=[0, 0],
            halign="center",
            valign="center",  # border_visible=True,
            fit_components="hv",
            auto_size=True,
            stack_order="top_to_bottom",
            bgcolor="red",
        )

        strings = [
            "apple",
            "banana",
            "cherry",
            "durian",
            "eggfruit",
            "fig",
            "grape",
            "honeydew",
        ]

        for i, s in enumerate(strings):
            label = TextField(
                text=s,
                resizable="",
                bounds=[100 + i * 10, 20],
                bgcolor="red",  # border_visible=True,
                text_offset=1,
            )
            number = TextField(
                text=str(i + 1),
                resizable="",
                bgcolor="blue",  # border_visible=True,
                text_offset=1,
                can_edit=False,
                bounds=[20, 20],
            )
            row = HStackedContainer(
                fit_components="hv",
                auto_size=True,
                resizable="",
                valign="top",
                border_visible=True,
            )
            row.add(number)
            row.add(label)
            stack.add(row)

        container = Container(position=[20, 20], bounds=size)
        container.add(stack)
        container2 = Container(bounds=size)
        container2.add(container)
        return container2
Ejemplo n.º 7
0
 def set_slot(self, slotname, container):
     """
     Sets the named slot to use the given container. *container* can be None.
     """
     if self._frame_slots.has_key(slotname):
         old_container = self._frame_slots[slotname]
         Container.remove(self, old_container)
     if container is not None:
         self._frame_slots[slotname] = container
         Container.add(self, container)
     return
Ejemplo n.º 8
0
 def _create_window(self):
     a = Box(bounds=[75, 75], position=[50,50], fill_color=(1, 0, 0, 1))
     b = Box(bounds=[75, 75], position=[200,50], fill_color=(0, 1, 0, 1))
     c = Box(bounds=[75, 75], position=[50,200], fill_color=(0, 0, 1, 1))
     cont = Container(a, b, c, bounds=[400,400], border_visible=True, bgcolor="lightgray")
     #cont.unified_draw = True
     #cont.draw_layer = "background"
     cont2 = Container(bounds=[300,300], border_visible=True, bgcolor="cyan")
     cont.tools.append(MoveTool(cont, drag_button="left"))
     cont2.tools.append(MoveTool(cont2, drag_button="left"))
     outer = Container(cont, cont2, fit_window=True)
     return Window(self, -1, component=outer)
Ejemplo n.º 9
0
    def _create_component(self):
        text_field = TextField(position=[25, 100], width=200)

        text = "This a test with a text field\nthat has more text than\n"
        text += "can fit in it."
        text_field2 = TextField(
            position=[25, 200],
            width=200,
            height=50,
            multiline=True,
            text=text,
            font="Courier New 14",
        )

        text_field3 = TextField(
            position=[250, 50],
            height=300,
            width=200,
            multiline=True,
            font="Courier New 14",
        )

        container = Container(bounds=size, bgcolor="grey")
        container.add(text_field, text_field2, text_field3)
        return container
Ejemplo n.º 10
0
    def _create_window(self):
        # create a box that changes color when clicked
        push_button_box = SelectableBox(bounds=[100, 50],
                                        position=[50, 50],
                                        color='red')

        # create a basic push button tool for it
        push_button_tool = ButtonTool(component=push_button_box)
        push_button_box.tools.append(push_button_tool)

        # print when box clicked, change color when button down
        push_button_tool.on_trait_change(self.button_clicked, 'clicked')
        push_button_tool.on_trait_change(push_button_box.select, 'down')

        # another box for a toggle button
        toggle_box = SelectableBox(bounds=[100, 50],
                                   position=[50, 125],
                                   color='lightblue',
                                   selected_color='blue')

        # a toggle button tool
        toggle_button_tool = ButtonTool(component=toggle_box, togglable=True)
        toggle_box.tools.append(toggle_button_tool)

        # change color when checked down
        toggle_button_tool.on_trait_change(toggle_box.select, 'checked')

        container = Container(bounds=[600, 600])
        container.add(push_button_box)
        container.add(toggle_box)

        window = Window(self, -1, component=container)
        return window
 def _create_window(self):
     box = Box(bounds=[100.0, 100.0], position=[50.0, 50.0])
     container = Container(bounds=[500, 500])
     container.add(box)
     drop_tool = TextDropTool(component=container)
     container.tools.append(drop_tool)
     return Window(self, -1, component=container)
Ejemplo n.º 12
0
    def _create_component(self):
        # create a box that changes color when clicked
        push_button_box = SelectableBox(bounds=[100, 50],
                                        position=[50, 50],
                                        color="red")

        # create a basic push button tool for it
        push_button_tool = ButtonTool(component=push_button_box)
        push_button_box.tools.append(push_button_tool)

        # print when box clicked, change color when button down
        push_button_tool.observe(self.button_clicked, "clicked")
        push_button_tool.observe(push_button_box.select, "down")

        # another box for a toggle button
        toggle_box = SelectableBox(
            bounds=[100, 50],
            position=[50, 125],
            color="lightblue",
            selected_color="blue",
        )

        # a toggle button tool
        toggle_button_tool = ButtonTool(component=toggle_box, togglable=True)
        toggle_box.tools.append(toggle_button_tool)

        # change color when checked down
        toggle_button_tool.observe(toggle_box.select, "checked")

        container = Container(bounds=[600, 600])
        container.add(push_button_box)
        container.add(toggle_box)

        return container
Ejemplo n.º 13
0
    def _create_component(self):
        label = Label(text="h:\nv:",
                      font="modern 16",
                      position=[20, 50],
                      bounds=[100, 100],
                      bgcolor="red",
                      color="white",
                      hjustify="center",
                      vjustify="center")

        vscroll = NativeScrollBar(orientation="vertical",
                                  bounds=[15, label.height],
                                  position=[label.x2, label.y],
                                  range=(0, 100.0, 10.0, 1.0),
                                  enabled=True)
        vscroll.on_trait_change(self._update_vscroll, "scroll_position")

        hscroll = NativeScrollBar(orientation="horizontal",
                                  bounds=[label.width, 15],
                                  position=[label.x, label.y - 15],
                                  range=(0, 100.0, 10.0, 1.0),
                                  enabled=True)
        hscroll.on_trait_change(self._update_hscroll, "scroll_position")

        container = Container(bounds=[200, 200],
                              border_visible=True,
                              padding=15)
        container.add(label, hscroll, vscroll)
        container.on_trait_change(self._update_layout, "bounds")
        container.on_trait_change(self._update_layout, "bounds_items")

        self.label = label
        self.hscroll = hscroll
        self.vscroll = vscroll
        return container
Ejemplo n.º 14
0
    def _create_component(self):

        container = Container(auto_size=False,
                              bgcolor="black",
                              *self._create_shapes())

        return container
    def test_auto_size(self):
        container = Container(bounds=[100.0, 100.0])
        self.assertTrue(container.auto_size == False)

        # Add some components
        c1 = Component(position=[10.0, 10.0], bounds=[50.0, 60.0])
        c2 = Component(position=[15.0, 15.0], bounds=[10.0, 10.0])
        container.add(c1)
        container.add(c2)
        self.assert_dims(container, x=0.0, y=0.0, width=100.0, height=100.0)

        # Turn on auto-sizing
        container.auto_size = True
        self.assert_dims(container, x=10.0, y=10.0, width=49.0, height=59.0)

        # Check that the components' positions changed appropriately
        self.assert_dims(c1, x=0.0, y=0.0)
        self.assert_dims(c2, x=5.0, y=5.0)

        # Move the second component
        c2.position = [100.0, 100.0]
        self.assert_dims(container, x=10.0, y=10.0, width=109.0, height=109.0)
        self.assert_dims(c2, x=100.0, y=100.0)

        # Delete the second component
        container.remove(c2)
        self.assert_dims(container, x=10.0, y=10.0, width=49.0, height=59.0)
        return
Ejemplo n.º 16
0
    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])
    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])
Ejemplo n.º 18
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])
Ejemplo n.º 19
0
def main():
    from basic_move import Box
    from enable.api import Container
    container = Container()
    box = Box(bounds=[30, 30], position=[20, 20], padding=5)
    container.add(box)

    # Create the mlab test mesh and get references to various parts of the
    # VTK pipeline
    m = mlab.test_mesh()
    scene = mlab.gcf().scene
    render_window = scene.render_window
    renderer = scene.renderer
    rwi = scene.interactor

    # Create the Enable Window
    window = EnableVTKWindow(
        rwi,
        renderer,
        component=container,
        #istyle_class = tvtk.InteractorStyleSwitch,
        istyle_class=tvtk.InteractorStyle,
        resizable="v",
        bounds=[100, 100],
        padding_top=20,
        padding_bottom=20,
        padding_left=20,
    )

    #rwi.render()
    #rwi.start()
    mlab.show()
    return window, render_window
Ejemplo n.º 20
0
 def _create_component(self):
     strings = array([["apple", "banana", "cherry", "durian"],
                      ["eggfruit", "fig", "grape", "honeydew"]])
     grid = TextGrid(string_array=strings)
     container = Container(bounds=size)
     container.add(grid)
     return container
    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])
Ejemplo n.º 22
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])
Ejemplo n.º 23
0
    def _create_window(self):
        """ Create an enable window. """

        container = Container(auto_size=False,
                              bgcolor='black',
                              *self._create_shapes())

        return Window(self, component=container)
Ejemplo n.º 24
0
        def _create_window(self):
            input = InputVariable(name='foo', default=3)

            box = IOField(input, position=[50, 300], bounds=[150, 15])

            container = Container(bounds=[800, 600])
            container.add(box)
            return Window(self, -1, size=[800, 600], component=container)
 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])
Ejemplo n.º 26
0
        def _create_window(self):
            box1 = TextFieldGrid(4, 2, position=[50, 300])

            box1.set_cell(1, 1, "apple")
            box1.set_cell(0, 3, "pear")

            container = Container(bounds=[800, 600], use_backbuffer=False)
            container.add(box1)
            return Window(self, -1, size=[800, 600], component=container)
    def _create_window(self):

        stack = VStackedContainer(
            position=[0, 0],
            halign='center',
            valign='center',  #border_visible=True,
            fit_components='hv',
            auto_size=True,
            stack_order='top_to_bottom',
            bgcolor='red')

        strings = [
            "apple", "banana", "cherry", "durian", "eggfruit", "fig", "grape",
            "honeydew"
        ]

        for i, s in enumerate(strings):
            label = TextField(
                text=s,
                resizable='',
                bounds=[100 + i * 10, 20],
                bgcolor='red',  #border_visible=True,
                text_offset=1)
            number = TextField(
                text=str(i + 1),
                resizable='',
                bgcolor='blue',  #border_visible=True,
                text_offset=1,
                can_edit=False,
                bounds=[20, 20])
            row = HStackedContainer(fit_components='hv',
                                    auto_size=True,
                                    resizable='',
                                    valign='top',
                                    border_visible=True)
            row.add(number)
            row.add(label)
            stack.add(row)

        container = Container(position=[20, 20], bounds=size)
        container.add(stack)
        container2 = Container(bounds=size)
        container2.add(container)
        return Window(self, -1, component=container2)
 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])
    def _create_window(self):
        box = Box(bounds=[100.0, 100.0], position=[50.0, 50.0])
        menu = MenuManager()
        menu.append(Action(name="Hello World", on_perform=self.hello))
        context_menu = ContextMenuTool(component=box, menu_manager=menu)

        box.tools.append(context_menu)
        container = Container(bounds=[500, 500])
        container.add(box)
        return Window(self, -1, component=container)
Ejemplo n.º 30
0
    def _create_component(self):
        container = Container(bounds=[800, 600], bgcolor=(0.9, 0.7, 0.7, 1.0),
                              auto_size=False, fit_window=False)
        circle1 = Circle(bounds=[75,75], position=[100,100],
                         shadow_type="dashed")
        container.add(circle1)

        scr = Scrolled(container, bounds=[200,200], position=[50,50],
                       stay_inside=True, vertical_anchor='top',
                       horizontal_anchor='left', fit_window=False)
        return scr
Ejemplo n.º 31
0
 def _create_component(self):
     box = Box(bounds=[100.0, 100.0], position=[50.0, 50.0])
     box.tools.append(
         ResizeTool(component=box,
                    hotspots=set([
                        "top", "left", "right", "bottom", "top left",
                        "top right", "bottom left", "bottom right"
                    ])))
     container = Container(bounds=[500, 500])
     container.add(box)
     return container
Ejemplo n.º 32
0
 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])
Ejemplo n.º 33
0
 def _dispatch_draw(self, layer, gc, view_bounds, mode):
     self._position_cells()
     Container._dispatch_draw(self, layer, gc, view_bounds, mode)
     self._draw_grid(gc, view_bounds, mode)
Ejemplo n.º 34
0
 def _dispatch_stateful_event(self, event, suffix):
     Container._dispatch_stateful_event(self, event, suffix)
     if not event.handled:
         if self.is_in(event.x, event.y):
             event.handled = True
     return