Exemple #1
0
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
from enable.api import Canvas, Viewport
from enable.examples._example_support import demo_main, DemoFrame
from enable.tools.api import ViewportPanTool


class Demo(DemoFrame):
    def _create_component(self):
        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)
        from enable.examples.demo.enable.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


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, title="Canvas example")
Exemple #2
0
            "canvas",
            editor=ComponentEditor(),
            show_label=False,
            width=200,
            height=200,
        ),
        resizable=True,
    )

    def _canvas_default(self):
        image = stars()

        container = ConstraintsContainer(bounds=[500, 500])
        container.add(image)
        ratio = float(image.data.shape[1]) / image.data.shape[0]
        container.layout_constraints = [
            image.left == container.contents_left,
            image.right == container.contents_right,
            image.top == container.contents_top,
            image.bottom == container.contents_bottom,
            image.layout_width == ratio * image.layout_height,
        ]

        return container


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo)
Exemple #3
0

class Demo(DemoFrame):
    def _create_component(self):
        rect1 = Region("orchid", position=[50, 50])
        rect2 = Region("cornflowerblue", position=[200, 50])
        rect1.overlays.append(Overlay("One", component=rect1))
        rect2.overlays.append(Overlay("Two", component=rect2))
        container1 = OverlayPlotContainer(bounds=[400, 400], resizable="")
        container1.add(rect1, rect2)
        container1.bgcolor = (0.60, 0.98, 0.60, 0.5)  # "palegreen"

        rect3 = Region("purple", position=[50, 50])
        rect4 = Region("teal", position=[200, 50])
        rect3.overlays.append(Overlay("Three", component=rect3))
        rect4.overlays.append(Overlay("Four", component=rect4))
        container2 = OverlayPlotContainer(bounds=[400, 400], resizable="")
        container2.add(rect3, rect4)
        container2.bgcolor = "navajowhite"
        container2.position = [200, 200]

        top_container = OverlayPlotContainer()
        top_container.add(container1, container2)
        return top_container


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, size=(600, 600))
Exemple #4
0
        container = Container(
            bounds=[200, 200], border_visible=True, padding=15
        )
        container.add(label, hscroll, vscroll)
        container.observe(self._update_layout, "bounds.items")

        self.label = label
        self.hscroll = hscroll
        self.vscroll = vscroll
        return container

    def _update_hscroll(self, event):
        text = self.label.text.split("\n")
        text[0] = "h: " + str(self.hscroll.scroll_position)
        self.label.text = "\n".join(text)

    def _update_vscroll(self, event):
        text = self.label.text.split("\n")
        text[1] = "v: " + str(self.vscroll.scroll_position)
        self.label.text = "\n".join(text)

    def _update_layout(self, event):
        self.vscroll._widget_moved = True
        self.hscroll._widget_moved = True


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, title="Scrollbar demo", size=(250, 250))
Exemple #5
0
                    print("\tbounds:", component.position, component.bounds)
                    continue

                with gc:
                    component.draw(gc, new_bounds, mode)


class Demo(DemoFrame):
    def _create_component(self):
        container = VerboseContainer(auto_size=False, bounds=[800, 800])
        a = Box(bounds=[50.0, 50.0], position=[50.0, 50.0])
        b = Box(bounds=[50.0, 50.0], position=[200.0, 50.0])
        c = Box(bounds=[50.0, 50.0], position=[50.0, 200.0])
        d = Box(bounds=[50.0, 50.0], position=[200.0, 200.0])
        container.add(a)
        container.add(b)
        container.add(c)
        container.add(d)
        scr = Scrolled(container,
                       bounds=[300, 300],
                       position=[50, 50],
                       fit_window=False)
        return scr


if __name__ == "__main__":
    title = "Use the scroll bars to show and hide components"
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, title=title)
Exemple #6
0
#
# This software is provided without warranty under the terms of the BSD
# license included in LICENSE.txt and may be redistributed only under
# the conditions described in the aforementioned license. The license
# is also available online at http://www.enthought.com/licenses/BSD.txt
#
# Thanks for using Enthought open source!
from enable.api import OverlayContainer, Compass
from enable.examples._example_support import demo_main, DemoFrame


class Demo(DemoFrame):
    def _create_component(self):
        compass = Compass(scale=2, color="blue", clicked_color="red")

        container = OverlayContainer()
        container.add(compass)

        compass.observe(self._arrow_printer, "clicked")
        self.compass = compass
        return container

    def _arrow_printer(self, event):
        print("Clicked:", self.compass.clicked)


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, title="Slider example")
Exemple #7
0
            x, y = self.position
            dx, dy = self.bounds
            gc.set_text_position(x + dx / 2 - tdx / 2, y + dy - tdy - 20)
            gc.show_text(s)


class Demo(DemoFrame):
    def _create_component(self):
        times_and_bounds = {
            0.5: (60, 200, 100, 100),
            0.33: (240, 200, 100, 100),
            0.25: (60, 50, 100, 100),
            0.10: (240, 50, 100, 100),
        }

        container = MyContainer(auto_size=False)
        for delay, bounds in list(times_and_bounds.items()):
            box = Box()
            container.add(box)
            box.position = list(bounds[:2])
            box.bounds = list(bounds[2:])
            box.delay = delay
        return container


if __name__ == "__main__":

    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, size=(400, 400), title="Latency Test - Click a box")
            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


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, size=size)
Exemple #9
0
class Demo(DemoFrame):
    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


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, title="Click and drag to move the circles")
Exemple #10
0
            tool=PointLine(container=canvas),
            label="Polyline",
            toolbar=toolbar,
            bounds=[70, 24],
        )
        button5 = ActivateButton(
            tool=DragSegment(container=canvas),
            label="Line",
            toolbar=toolbar,
            bounds=[50, 24],
        )
        button6 = ActivateButton(
            tool=PointPolygon(container=canvas),
            label="PointPoly",
            toolbar=toolbar,
            bounds=[80, 24],
        )
        toolbar.add_button(button1)
        toolbar.add_button(button2)
        toolbar.add_button(button3)
        toolbar.add_button(button4)
        toolbar.add_button(button5)
        toolbar.add_button(button6)
        return canvas


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, size=[700, 600])
Exemple #11
0
class TextDropTool(BaseDropTool):
    """ Example implementation of a drop tool """
    def accept_drop(self, location, obj):
        return True

    def handle_drop(self, location, objs):
        if not isinstance(objs, list):
            objs = [objs]
        x, y = location
        for obj in objs:
            label = Label(text=str(obj), position=[x, y], bounds=[100, 50])
            self.component.add(label)
            self.component.request_redraw()
            y += 15


class MyFrame(DemoFrame):
    def _create_component(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 container


if __name__ == "__main__":
    demo_main(MyFrame)
Exemple #12
0
        # 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


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(MyFrame, size=(600, 600))
Exemple #13
0
            fill_color="lightpink",
            text="Box 1",
        )

        box2 = Box(
            bounds=[100, 100],
            position=[150, 150],
            fill_color="greenyellow",
            text="Box 2",
        )

        circle1 = Circle(
            radius=50,
            position=[250, 250],
            fill_color="cornflowerblue",
            text="Circle 1",
        )

        circle2 = Circle(radius=50,
                         position=[350, 350],
                         fill_color="khaki",
                         text="Circle 2")

        return box1, box2, circle1, circle2


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(Demo, size=(500, 500), title="Click and drag the shapes")