Ejemplo n.º 1
0
def runmain():
        try:
            demo_main(PlotFrame, size=size, title=title)
        finally:
            if _stream is not None:
                _stream.close()
            if _wavefd is not None:
                _wavefd.close()
Ejemplo n.º 2
0
def runmain():
    try:
        demo_main(PlotFrame, size=size, title=title)
    finally:
        if _stream is not None:
            _stream.close()
        if _wavefd is not None:
            _wavefd.close()
Ejemplo n.º 3
0
                                                  container=canvas),
                                 label="Poly",
                                 toolbar=toolbar,
                                 bounds=[50, 24])
        button4 = ActivateButton(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 Window(self, -1, component=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(MyFrame, size=[700, 600])
Ejemplo n.º 4
0
        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 Window(self, -1, component=container)

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

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

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


if __name__ == "__main__":
    demo_main(MyFrame, title="Scrollbar demo", size=(250,250))

Ejemplo n.º 5
0
        from enactable.enable.enable_blob_listener import BlobWindow
        from enactable.enable.blobprovider import NetworkBlobProvider
        parser = arg_parser()
        args = parser.parse_args()
        cfg = get_global_config()
        tconf = cfg.tconf
        tconf.from_arguments(args)

        provider = NetworkBlobProvider(host=tconf.Server.host,
                                       port=tconf.Server.port)
        provider.start()
        return BlobWindow(self, -1, component=viewport, blob_provider=provider)

    def _create_window_simple(self):
        viewport = self._create_viewport()
        return Window(self, -1, component=viewport)

    def _create_window(self):
        if MULTITOUCH:
            return self._create_window_mt()
        else:
            return self._create_window_simple()


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(PlotFrame, size=(1000, 700), title="PlotCanvas")

# EOF
Ejemplo n.º 6
0

from enable.api import Canvas, Viewport, Window
from enable.tools.api import ViewportPanTool
from enable.primitives.api import Box
from enable.example_support import demo_main, DemoFrame

class MyFrame(DemoFrame):

    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)

if __name__ == "__main__":
    demo_main(MyFrame, title="Canvas example")
Ejemplo n.º 7
0
from enable.example_support import DemoFrame, demo_main
from enable.primitives.image import Image

THIS_DIR = os.path.split(__file__)[0]


class MyFrame(DemoFrame):
    def _create_window(self):
        path = os.path.join(THIS_DIR, 'deepfield.jpg')
        image = Image.from_file(path,
                                resist_width='weak',
                                resist_height='weak')

        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 Window(self, -1, component=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)
Ejemplo n.º 8
0
            elif i % 2 == 0:
                animated_plot = AnimatedPlot(common_index, jn(i,x), color)
                plot = animated_plot.plot
                plot.index_mapper.range = index_range
                plot.value_mapper.range = value_range
            else:
                animated_plot = AnimatedPlot(x, jn(i,x), color, orientation="v")
                plot = animated_plot.plot

            container.add(plot)
            self.animated_plots.append(animated_plot)

        for i, a_plot in enumerate(self.animated_plots):
            a_plot.plot.position = [50 + (i%3)*(PLOT_SIZE+50),
                                    50 + (i//3)*(PLOT_SIZE+50)]

        self.timer = Timer(100.0, self.onTimer)
        self.container = container
        return Window(self, -1, component=container)

    def onTimer(self, *args):
        for plot in self.animated_plots:
            plot.timer_tick()
        return


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(PlotFrame, size=(950, 650), title="Updating line plot")
Ejemplo n.º 9
0
        # 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


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))
Ejemplo n.º 10
0
        # Create the price plots
        price_plot, mini_plot = self._create_price_plots(time_ds, price_ds)
        price_plot.index_mapper.domain_limits = (index[0], index[-1])
        self.price_plot = price_plot
        self.mini_plot = mini_plot

        # Create the volume plot
        vol_plot = self._create_vol_plot(time_ds, vol_ds)
        vol_plot.index_mapper.domain_limits = (index[0], index[-1])

        # Set the plot's bottom axis to use the Scales ticking system
        ticker = ScalesTickGenerator(scale=CalendarScaleSystem())
        for plot in price_plot, mini_plot, vol_plot:
            bottom_axis = PlotAxis(plot, orientation="bottom",
                                   tick_generator = ticker)
            plot.overlays.append(bottom_axis)
            plot.overlays.append(PlotAxis(plot, orientation="left"))
            hgrid, vgrid = add_default_grids(plot)
            vgrid.tick_generator = bottom_axis.tick_generator

        container = VPlotContainer(bgcolor = "lightgray",
                                   spacing = 40,
                                   padding = 50,
                                   fill_padding=False)
        container.add(mini_plot, vol_plot, price_plot)

        return Window(self, -1, component=container)

if __name__ == "__main__":
    demo_main(PlotFrame, size=(800,600), title="Stock price and volume")
Ejemplo n.º 11
0
from enable.api import Container, TextField, Window
from enable.example_support import DemoFrame, demo_main

class MyFrame(DemoFrame):
    def _create_window(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=[800, 600], bgcolor='grey')
        container.add(text_field, text_field2, text_field3)
        return Window(self, -1, component=container)

if __name__ == '__main__':
    demo_main(MyFrame, size=(800, 600))
Ejemplo n.º 12
0
        self.plot = plot
        plot.tools.append(PanTool(component=plot))
        plot.overlays.append(ZoomTool(component=plot, tool_mode="box",
                                        always_on=False))

        self.timer = Timer(50.0, self.onTimer)
        return Window(self, -1, component=plot)

    def onTimer(self, *args):

        global myo
        if myo.emg:
            emgSamples = list(myo.emg)
            self.y_values.append(myo.emg[0])

        if len(self.y_values) > 100:
            self.y_values.pop(0)

        self.plot.index.set_data(self.x_values[:])
        self.plot.value.set_data(self.y_values[:])
        self.plot.request_redraw()
        return


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    plot = PlotFrame
    demo = demo_main(plot, size=(600, 500), title="Simple line plot")
    hub.shutdown()
Ejemplo n.º 13
0
                    print "skipping component:", component.__class__.__name__,
                    print "\tbounds:", component.position, component.bounds
                    continue

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


class MyFrame(DemoFrame):
    def _create_window(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 Window(self, -1, component=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(MyFrame, title=title)
Ejemplo n.º 14
0
            ZoomTool(component=plot, tool_mode="box", always_on=False))

        # Set the timer to generate events to us
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
        self.timer.Start(50.0, wx.TIMER_CONTINUOUS)
        return Window(self, -1, component=plot)

    def onTimer(self, event):
        # adjust the index and increment
        if self.current_index <= self.numpoints / 8:
            self.increment = 2
        elif self.current_index == self.numpoints:
            self.increment = -2

        self.current_index += self.increment
        if self.current_index > self.numpoints:
            self.current_index = self.numpoints

        self.plot.index.set_data(self.x_values[:self.current_index])
        self.plot.value.set_data(self.y_values[:self.current_index])
        self.plot.request_redraw()
        return


if __name__ == "__main__":
    demo_main(PlotFrame, size=(600, 500), title="Simple line plot")

# EOF
Ejemplo n.º 15
0
class PlotFrame(DemoFrame):

    def _create_window(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 Window(self, -1, component=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(PlotFrame, size=(600, 600))
Ejemplo n.º 16
0
        event.handled = True
        return


class MainFrame(DemoFrame):
    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)


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(MainFrame, size=(800, 800), title="ClipTest")
Ejemplo n.º 17
0
    def moving_mouse_move(self, event):
        self.position = [event.x - self.offset_x, event.y - self.offset_y]
        event.handled = True
        self.request_redraw()
        return

    def moving_left_up(self, event):
        self.event_state = "normal"
        event.window.set_pointer(self.normal_pointer)
        event.window.set_mouse_owner(None)
        event.handled = True
        self.request_redraw()
        return

    def moving_mouse_leave(self, event):
        self.moving_left_up(event)
        event.handled = True
        return


class MyFrame(DemoFrame):
    def _create_window(self):
        box = Box(bounds=[100, 100], position=[50, 50], padding=15)
        return Window(self, -1, component=box)


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, title="Click and drag to move the box")
Ejemplo n.º 18
0
                plot.index_mapper.range = index_range
                plot.value_mapper.range = value_range

            container.add(plot)
            self.animated_plots.append(animated_plot)


        for i, a_plot in enumerate(self.animated_plots):
            a_plot.plot.position = [50 + (i%3)*(PLOT_SIZE+50), 50 + (i//3)*(PLOT_SIZE+50)]


        # Set the timer to generate events to us
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
        self.timer.Start(100.0, wx.TIMER_CONTINUOUS)

        self.container = container
        return Window(self, -1, component=container)

    def onTimer(self, event):
        for plot in self.animated_plots:
            plot.timer_tick()
        return


if __name__ == "__main__":
    demo_main(PlotFrame, size=(1000,800), title="Updating line plot")

# EOF
Ejemplo n.º 19
0
        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(MyFrame, size=(500, 500),
                     title="Click and drag the shapes")
Ejemplo n.º 20
0
Archivo: canvas.py Proyecto: 5n1p/chaco
        from enactable.configuration import arg_parser, get_global_config
        from enactable.enable.enable_blob_listener import BlobWindow
        from enactable.enable.blobprovider import NetworkBlobProvider
        parser = arg_parser()
        args = parser.parse_args()
        cfg = get_global_config()
        tconf = cfg.tconf
        tconf.from_arguments(args)

        provider = NetworkBlobProvider(host=tconf.Server.host, port=tconf.Server.port)
        provider.start()
        return BlobWindow(self, -1, component=viewport, blob_provider=provider)

    def _create_window_simple(self):
        viewport = self._create_viewport()
        return Window(self, -1, component=viewport)

    def _create_window(self):
        if MULTITOUCH:
            return self._create_window_mt()
        else:
            return self._create_window_simple()

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(PlotFrame, size=(1000,700), title="PlotCanvas")

# EOF
Ejemplo n.º 21
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")
Ejemplo n.º 22
0
    resizable = ""

    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
        with gc:
            dx, dy = self.bounds
            x, y = self.position
            gc.set_fill_color((1.0, 0.0, 0.0, 1.0))
            gc.rect(x, y, dx, dy)
            gc.fill_path()


class MyFrame(DemoFrame):

    def _create_window(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 Window(self, -1, component=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)
Ejemplo n.º 23
0
            gc.line_to(self.size, 0)
            gc.move_to(0, -self.size)
            gc.line_to(0, self.size)
            gc.stroke_path()


class Demo(DemoFrame):
    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


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")
Ejemplo n.º 24
0
            raise

        tar_file = tarfile.open(tar_path)
        try:
            os.mkdir(voldata_path)
        except:
            pass
        tar_file.extractall(voldata_path)
        tar_file.close()
        os.unlink(tar_path)
    else:
        print 'Previously downloaded data detected.'

def cleanup_data():
    global dl_path

    answer = raw_input('Remove downloaded files? [Y/N]: ')
    if answer.lower() == 'y':
        try:
            shutil.rmtree(os.path.join(dl_path, 'voldata'))
        except:
            pass

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(PlotFrame, size=(800,700), title="Cube analyzer")
    if run_cleanup:
        cleanup_data()

Ejemplo n.º 25
0
        toolbar.canvas = canvas

        button1 = ResetButton(label="Reset", toolbar=toolbar, bounds=[50,24])
        button2 = ActivateButton(tool=DragLine(container=canvas), label="Path",
                                 toolbar=toolbar, bounds=[50,24])
        button3 = ActivateButton(tool=DragPolygon(background_color=(0,0,0.8,1),
                                 container=canvas),
                                 label="Poly", toolbar=toolbar, bounds=[50,24])
        button4 = ActivateButton(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 Window(self, -1, component=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(MyFrame, size=[700,600])
Ejemplo n.º 26
0
        event.handled = True
        self.request_redraw()
        return

    def moving_left_up(self, event):
        self.event_state = "normal"
        event.window.set_pointer(self.normal_pointer)
        event.window.set_mouse_owner(None)
        event.handled = True
        self.request_redraw()
        return

    def moving_mouse_leave(self, event):
        self.moving_left_up(event)
        event.handled = True
        return


class Demo(DemoFrame):
    def _create_component(self):
        container = Container()
        box = Box(bounds=[100, 100], position=[50, 50], padding=15)
        container.add(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(Demo)
Ejemplo n.º 27
0
            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 Window(self, -1, component=container)

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

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

    def _update_layout(self):
        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(MyFrame, title="Scrollbar demo", size=(250, 250))
Ejemplo n.º 28
0
                common_index = animated_plot.plot.index
                index_range = animated_plot.plot.index_mapper.range
                value_range = animated_plot.plot.value_mapper.range
            else:
                animated_plot = AnimatedPlot(common_index, jn(i, x), color)
                animated_plot.plot.index_mapper.range = index_range
                animated_plot.plot.value_mapper.range = value_range
            container.add(animated_plot.plot)
            self.animated_plots.append(animated_plot)

        for i, a_plot in enumerate(self.animated_plots):
            a_plot.plot.position = [
                50 + (i % 3) * (PLOT_SIZE + 50),
                50 + (i // 3) * (PLOT_SIZE + 50)
            ]

        self.timer = Timer(100.0, self.onTimer)
        self.container = container
        return Window(self, -1, component=container)

    def onTimer(self, *args):
        for plot in self.animated_plots:
            plot.timer_tick()
        return


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(PlotFrame, size=(950, 650), title="Updating line plot")
Ejemplo n.º 29
0
from enable.api import OverlayContainer, Compass, Window
from enable.example_support import demo_main, DemoFrame


class MyFrame(DemoFrame):

    def _create_window(self):
        compass = Compass(scale=2, color="blue", clicked_color="red")

        container = OverlayContainer()
        container.add(compass)

        compass.on_trait_change(self._arrow_printer, "clicked")
        self.compass = compass
        return Window(self, component=container)

    def _arrow_printer(self):
        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(MyFrame, title="Slider example")
Ejemplo n.º 30
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)
Ejemplo n.º 31
0
                    continue

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


class MyFrame(DemoFrame):
    def _create_window(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 Window(self, -1, component=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(MyFrame, title=title)
Ejemplo n.º 32
0
            x, y = self.position
            radius = min(dx/2.0, dy/2.0)
            gc.arc(x+dx/2.0, y+dy/2.0, radius, 0.0, 2*3.14159)
            gc.set_stroke_color(self.color[0:3] + (self.color[3]*0.8,))
            gc.set_line_dash(self.line_dash)
            gc.stroke_path()
        return


class MyFrame(DemoFrame):

    def _create_window(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 Window(self, -1, component=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(MyFrame, title="Click and drag to move the circles")
Ejemplo n.º 33
0
                    print "skipping component:", component.__class__.__name__,
                    print "\tbounds:", component.position, component.bounds
                    continue

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


class MyFrame(DemoFrame):
    def _create_window(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 Window(self, -1, component=scr)


if __name__ == "__main__":
    demo_main(MyFrame, title="Use the scroll bars to show and hide components")


# EOF
Ejemplo n.º 34
0
from enable.api import Canvas, Viewport, Window
from enable.tools.api import ViewportPanTool
from enable.example_support import demo_main, DemoFrame


class MyFrame(DemoFrame):

    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)


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, title="Canvas example")
Ejemplo n.º 35
0
        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


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))
Ejemplo n.º 36
0
            dx, dy = self.bounds
            x, y = self.position
            radius = min(dx / 2.0, dy / 2.0)
            gc.arc(x + dx / 2.0, y + dy / 2.0, radius, 0.0, 2 * 3.14159)
            gc.set_stroke_color(self.color[0:3] + (self.color[3] * 0.8, ))
            gc.set_line_dash(self.line_dash)
            gc.stroke_path()
        return


class Demo(DemoFrame):
    def _create_component(self):
        circle1 = Circle(bounds=[75, 75],
                         position=[50, 50],
                         shadow_type="dashed")
        circle2 = Circle(bounds=[75, 75],
                         position=[200, 50],
                         shadow_type="light")
        container = MyFilledContainer(bounds=[500, 500],
                                      bgcolor=(0.5, 0.5, 0.5, 1.0))
        container.auto_size = True
        container.add(circle1)
        container.add(circle2)
        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, title="Click and drag to move the circles")
Ejemplo n.º 37
0
                                  editor=ComponentEditor(size=size,
                                                         bgcolor=bg_color),
                                  show_label=False),
                             orientation="vertical"),
                       resizable=True,
                       title=title,
                       width=size[0],
                       height=size[1])

    def _plot_default(self):
        return _create_plot_component()


demo = Demo()


#===============================================================================
# Stand-alone frame to display the plot.
#===============================================================================
class PlotFrame(DemoFrame):
    def _create_window(self):
        # Return a window containing our plots
        return Window(self,
                      -1,
                      component=_create_plot_component(),
                      bg_color=bg_color)


if __name__ == "__main__":
    demo_main(PlotFrame, size=size, title=title)
Ejemplo n.º 38
0
                                        always_on=False))

        # Set the timer to generate events to us
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
        self.timer.Start(50.0, wx.TIMER_CONTINUOUS)
        return Window(self, -1, component=plot)

    def onTimer(self, event):
        # adjust the index and increment
        if self.current_index <= self.numpoints/8:
            self.increment = 2
        elif self.current_index == self.numpoints:
            self.increment = -2

        self.current_index += self.increment
        if self.current_index > self.numpoints:
            self.current_index = self.numpoints

        self.plot.index.set_data(self.x_values[:self.current_index])
        self.plot.value.set_data(self.y_values[:self.current_index])
        self.plot.request_redraw()
        return


if __name__ == "__main__":
    demo_main(PlotFrame, size=(600,500), title="Simple line plot")

# EOF

class MyFrame(DemoFrame):
    def _create_window(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 Window(self, -1, component=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=size)
Ejemplo n.º 40
0
        """ Updates the image data in self.plotdata to correspond to the
        slices given.
        """
        range = DataRange1D(low=self.model.minval,
                            high=self.model.maxval)
        self.colormap = self.cmap(range)


        slicexy=self.model.vals[:, :, self.slice_z]
        colorslicexy=(self.colormap.map_screen(slicexy) * 255).astype(uint8)
        # Transposed required because img_plot() expects data in row-major order
        self.plotdata.set_data("xy", transpose(colorslicexy,(1,0,2)))

        
        slicexz=self.model.vals[:, self.slice_y, :]
        colorslicexz=(self.colormap.map_screen(slicexz) * 255).astype(uint8)
        # Transposed required because img_plot() expects data in row-major order
        self.plotdata.set_data("xz", transpose(colorslicexz,(1,0,2)))


        sliceyz=self.model.vals[self.slice_x, :, :]
        colorsliceyz=(self.colormap.map_screen(sliceyz) * 255).astype(uint8)
        #print "colorsliceyz.shape=",colorsliceyz.shape
        #print "type(colorsliceyz)=",type(colorsliceyz)
        #print "type(colorsliceyz[0,0,0])=",type(colorsliceyz[0,0,0])
        self.plotdata.set_data("yz", colorsliceyz)

if __name__ == "__main__":
    demo_main(PlotFrame, size=(800,700), title="Cube analyzer")

        return


class MyFrame(DemoFrame):
    def _create_window(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 Window(self, -1, component=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(MyFrame, title="Click and drag to move the circles")
Ejemplo n.º 42
0
    def moving_mouse_move(self, event):
        self.position = [event.x-self.offset_x, event.y-self.offset_y]
        event.handled = True
        self.request_redraw()
        return

    def moving_left_up(self, event):
        self.event_state = "normal"
        event.window.set_pointer(self.normal_pointer)
        event.window.set_mouse_owner(None)
        event.handled = True
        self.request_redraw()
        return

    def moving_mouse_leave(self, event):
        self.moving_left_up(event)
        event.handled = True
        return

class MyFrame(DemoFrame):

    def _create_window(self):
        box = Box(bounds=[100,100], position=[50,50], padding=15)
        return Window(self, -1, component=box)

if __name__ == "__main__":
    demo_main(MyFrame, title="Click and drag to move the box")

# EOF
Ejemplo n.º 43
0
        self.event_state = "normal"
        event.window.set_pointer(self.normal_pointer)
        event.window.set_mouse_owner(None)
        event.handled = True
        self.request_redraw()
        return

    def moving_mouse_leave(self, event):
        self.moving_left_up(event)
        event.handled = True
        return

class MainFrame(DemoFrame):
    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)


if __name__ == "__main__":
    demo_main(MainFrame, size=(800,800), title="ClipTest")

    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
        with gc:
            gc.set_fill_color((1.0, 0.0, 0.0, 1.0))
            dx, dy = self.bounds
            x, y = self.position
            gc.rect(x, y, dx, dy)
            gc.fill_path()


class MyFrame(DemoFrame):
    def hello(self):
        print "Hello World"

    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)


if __name__ == "__main__":
    demo_main(MyFrame)

# EOF
# # Demo class that is used by the demo.py application.
#===============================================================================
class Demo(HasTraits):
    plot = Instance(Component)
   
    traits_view = View(
                    Group(
                        Item('plot', editor=ComponentEditor(size=size,
                                                            bgcolor=bg_color), 
                             show_label=False),
                        orientation = "vertical"),
                    resizable=True, title=title, 
                    width=size[0], height=size[1]
                    )
   
    def _plot_default(self):
         return _create_plot_component()
   
demo = Demo()
#===============================================================================
# Stand-alone frame to display the plot.
#===============================================================================
class PlotFrame(DemoFrame):
    def _create_window(self):
        # Return a window containing our plots
        return Window(self, -1, component=_create_plot_component(), 
                      bg_color=bg_color)
   
if __name__ == "__main__":
    demo_main(PlotFrame, size=size, title=title)
Ejemplo n.º 46
0
        for i, s in enumerate(strings):
            label = TextField(
                text=s, resizable="", bounds=[100 + i * 10, 20], bgcolor="red", text_offset=1  # border_visible=True,
            )
            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)

        # print stack.components
        container = Container(position=[20, 20], bounds=[500, 500])
        container.add(stack)
        container2 = Container(bounds=[600, 600])
        container2.add(container)
        return Window(self, -1, component=container2)


if __name__ == "__main__":
    demo_main(MyFrame, size=[600, 600])
Ejemplo n.º 47
0
            tx, ty, tdx, tdy = gc.get_text_extent(s)
            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 PlotFrame(DemoFrame):
    def _create_window(self):
        return Window(self, -1, component=container)


if __name__ == "__main__":
    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 times_and_bounds.items():
        box = Box()
        container.add(box)
        box.position = list(bounds[:2])
        box.bounds = list(bounds[2:])
        box.delay = delay

    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(PlotFrame, size=(400, 400),
                     title="Latency Test - Click a box")
Ejemplo n.º 48
0

from enable.api import OverlayContainer, Compass
from enable.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.on_trait_change(self._arrow_printer, "clicked")
        self.compass = compass
        return container

    def _arrow_printer(self):
        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")
Ejemplo n.º 49
0
            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)


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=size)
Ejemplo n.º 50
0
            gc.set_text_position(x + dx / 2 - tdx / 2, y + dy - tdy - 20)
            gc.show_text(s)


class PlotFrame(DemoFrame):
    def _create_window(self):
        return Window(self, -1, component=container)


if __name__ == "__main__":
    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

    # Save demo so that it doesn't get garbage collected when run within
    # existing event loop (i.e. from ipython).
    demo = demo_main(PlotFrame,
                     size=(400, 400),
                     title="Latency Test - Click a box")
Ejemplo n.º 51
0

class Demo(DemoFrame):
    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


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)
Ejemplo n.º 52
0
        self.plot_drawable(pn)

    def add_edge(self,source_port,sink_port,flow_element):
        edge = FlowEdge(source_port=source_port,
                              sink_port=sink_port,
                              element=flow_element)
        source_port.edges.append(edge)
        sink_port.edges.append(edge)
        if flow_element is not None:
            flow_element.drawable = edge
        self.plot_drawable(edge)

    def plot_drawable(self,drawable):
        self.canvas.add(drawable)

    def fit_window(self):
        min_x = min([c.x for c in self.canvas.components])
        max_x = max([c.x2 for c in self.canvas.components])

        min_y = min([c.y for c in self.canvas.components])
        max_y = max([c.y2 for c in self.canvas.components])
        print max_x,max_y

        self.viewport.view_bounds = (640,480)
        print self.viewport.get_preferred_size()



if __name__ == '__main__':
    demo_main(GraphFrame,size=(640,480))
Ejemplo n.º 53
0
                animated_plot = AnimatedPlot(common_index, jn(i,x), color)
                animated_plot.plot.index_mapper.range = index_range
                animated_plot.plot.value_mapper.range = value_range
            container.add(animated_plot.plot)
            self.animated_plots.append(animated_plot)


        for i, a_plot in enumerate(self.animated_plots):
            a_plot.plot.position = [50 + (i%3)*(PLOT_SIZE+50), 50 + (i//3)*(PLOT_SIZE+50)]


        # Set the timer to generate events to us
        timerId = wx.NewId()
        self.timer = wx.Timer(self, timerId)
        self.Bind(wx.EVT_TIMER, self.onTimer, id=timerId)
        self.timer.Start(100.0, wx.TIMER_CONTINUOUS)

        self.container = container
        return Window(self, -1, component=container)

    def onTimer(self, event):
        for plot in self.animated_plots:
            plot.timer_tick()
        return


if __name__ == "__main__":
    demo_main(PlotFrame, size=(1000,800), title="Updating line plot")

# EOF
Ejemplo n.º 54
0
            for i in range(old, new):
                self._add_column(i)
        else:
            for i in range(new, old):
                self._remove_column(i)
        self.request_redraw()

    def _cells_changed(self, new):
        self.request_redraw()



# Test
if __name__ == '__main__':
    from enable.wx_backend.api import Window
    from enable.api import Container
    from enable.example_support import DemoFrame, demo_main

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

    demo_main(MyFrame)
Ejemplo n.º 55
0
    def _create_window(self):
        slider = Slider()
        slider.set_slider_pixels(10)
        slider.slider_thickness = 5
        slider.set_endcap_percent(0.1)
        slider.min = 0
        slider.max = 100
        slider.value = 40
        slider.padding = 25
        slider.slider = "cross"
        slider.orientation = "h"
        slider.num_ticks = 4
        slider.set_tick_percent(0.05)

        container = OverlayContainer()
        container.add(slider)

        slider.on_trait_change(self.val_changed, "value")
        self.slider = slider
        return Window(self, component=container)

    def val_changed(self):
        print(self.slider.value)


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, title="Slider example")
        price_plot.index_mapper.domain_limits = (index[0], index[-1])
        self.price_plot = price_plot
        self.mini_plot = mini_plot

        # Create the volume plot
        vol_plot = self._create_vol_plot(time_ds, vol_ds)
        vol_plot.index_mapper.domain_limits = (index[0], index[-1])

        # Set the plot's bottom axis to use the Scales ticking system
        ticker = ScalesTickGenerator(scale=CalendarScaleSystem())
        for plot in price_plot, mini_plot, vol_plot:
            bottom_axis = PlotAxis(
                plot, orientation="bottom", tick_generator=ticker)
            plot.overlays.append(bottom_axis)
            plot.overlays.append(PlotAxis(plot, orientation="left"))
            hgrid, vgrid = add_default_grids(plot)
            vgrid.tick_generator = bottom_axis.tick_generator

        container = VPlotContainer(
            bgcolor="lightgray", spacing=40, padding=50, fill_padding=False)
        container.add(mini_plot, vol_plot, price_plot)

        return Window(self, -1, component=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(
        PlotFrame, size=(800, 600), title="Stock price and volume")
Ejemplo n.º 57
0
class PlotFrame(DemoFrame):

    def _create_window(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 Window(self, -1, component=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(PlotFrame, size=(600, 600))
Ejemplo n.º 58
0
        box1 = Box(bounds=[100, 100],
                   position=[50, 50],
                   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(MyFrame,
                     size=(500, 500),
                     title="Click and drag the shapes")
Ejemplo n.º 59
0
from numpy import array

from enable.example_support import DemoFrame, demo_main

from enable.api import Container, Window
from enable.text_grid import TextGrid

class MyFrame(DemoFrame):
    def _create_window(self):

        strings = array([["apple", "banana", "cherry", "durian"],
                         ["eggfruit", "fig", "grape", "honeydew"]])
        grid = TextGrid(string_array=strings)
        container = Container(bounds=[500,100])
        container.add(grid)
        return Window(self, -1, component=container)

if __name__ == "__main__":
    demo_main(MyFrame, size=[500,100])