How to use the enable.example_support.DemoFrame function in enable

To help you get started, we’ve selected a few enable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github enthought / chaco / examples / demo / financial / stock_prices.py View on Github external
""" Returns **numpoints** number of dates that evenly bracket the current
    date and time.  **units** should be one of "weeks", "days", "hours"
    "minutes", or "seconds".
    """
    units_map = { "weeks" : 7*24*3600,
                  "days" : 24*3600,
                  "hours" : 3600,
                  "minutes" : 60,
                  "seconds" : 1 }
    now = time.time()
    dt = units_map[units]
    dates = linspace(now, now+numpoints*dt, numpoints)
    return dates


class PlotFrame(DemoFrame):

    def _create_price_plots(self, times, prices, mini_height=75):
        """ Creates the two plots of prices and returns them.  One of the
        plots can be zoomed and panned, and the other plot (smaller) always
        shows the full data.

        *dates* and *prices* are two data sources.
        """

        # Create the price plot
        price_plot = FilledLinePlot(index = times, value = prices,
                        index_mapper = LinearMapper(range=DataRange1D(times)),
                        value_mapper = LinearMapper(range=DataRange1D(prices)),
                        edge_color = "blue",
                        face_color = "paleturquoise",
                        bgcolor = "white",
github enthought / enable / examples / enable / filled_container_demo.py View on Github external
resizable = ""

    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
        with gc:
            gc.set_fill_color(self.color)
            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 MyFrame(DemoFrame):

    def _create_window(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 Window(self, -1, component=container)


if __name__ == "__main__":
    # Save demo so that it doesn't get garbage collected when run within
github enthought / enable / examples / enable / scrolled_canvas_demo.py View on Github external
from numpy import array

from enable.api import Canvas, Viewport, Window, Scrolled
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)

        boxgridsize = 8
        boxsize = 50

        spacing = boxsize * 2
        offset = spacing / 2

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

        for i in range(boxgridsize):
github enthought / enable / examples / enable / scrolled_demo.py View on Github external
line_dash = array([2.0, 2.0])

    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
        with gc:
            gc.set_fill_color(self.color)
            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 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)
github enthought / enable / examples / enable / basic_draw.py View on Github external
from enable.example_support import DemoFrame, demo_main
from enable.api import Component, Container, Window

class Box(Component):

    resizable = ""

    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 _create_window(self):
        box = Box(bounds=[100.0, 100.0], position=[50.0, 50.0])
        container = Container(bounds=[500,500])
        container.add(box)
        return Window(self, -1, component=container)

if __name__ == "__main__":
    demo_main(MyFrame)
github enthought / enable / examples / enable / compass_example.py View on Github external
from __future__ import print_function

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__":
github enthought / chaco / examples / demo / advanced / data_cube.py View on Github external
if event.left_down or event.right_down:
            self._update_slices(event)

    def _update_slices(self, event):
            plot = self.component
            ndx = plot.map_index((event.x, event.y),
                                 threshold=5.0, index_only=True)
            if ndx:
                self.callback(self, *ndx)

    def normal_mouse_wheel(self, event):
        if self.wheel_cb is not None:
            self.wheel_cb(self, event.mouse_wheel)


class PlotFrame(DemoFrame):

    # These are the indices into the cube that each of the image plot views
    # will show; the default values are non-zero just to make it a little
    # interesting.
    slice_x = 10
    slice_y = 10
    slice_z = 10

    num_levels = Int(15)
    colormap = Any
    colorcube = Any

    #---------------------------------------------------------------------------
    # Private Traits
    #---------------------------------------------------------------------------
github enthought / enable / examples / enable / tools / pyface / context_menu.py View on Github external
from pyface.action.api import MenuManager, Action

class Box(Component):

    resizable = ""

    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)
github enthought / enable / examples / enable / tools / drop_tool.py View on Github external
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_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)

if __name__ == "__main__":
    demo_main(MyFrame)
github enthought / enable / examples / enable / latency_demo.py View on Github external
class MyContainer(Container):
    text_color = black_color_trait

    def _draw_container_mainlayer(self, gc, view_bounds=None, mode="default"):
        s = "Hold down the mouse button on the boxes."
        with gc:
            gc.set_font(font)
            gc.set_fill_color(self.text_color_)
            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 list(times_and_bounds.items()):
        box = Box()
        container.add(box)
        box.position = list(bounds[:2])
        box.bounds = list(bounds[2:])