コード例 #1
0
class _CheckerBoardEditor(Editor):

    scrollable = True

    def init(self, parent):
        component = self._make_component(self.value)
        self._window = Window(parent, size=(200, 200), component=component)
        self.control = self._window.control
        self._window.bgcolor = self.factory.bgcolor
        self._parent = parent

    def dispose(self):
        self._window.cleanup()
        self._window = None
        self._parent = None
        super(_CheckerBoardEditor, self).dispose()

    @on_trait_change('value')
    def update_editor(self):
        component = self._make_component(self.value)
        self._window.component = component

    def _make_component(self, model):
        component = CheckerBoardComponent(model=model)
        component.request_redraw()
        return component
コード例 #2
0
 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)
コード例 #3
0
    def control(self):
        """
		A drawable control with a color bar.
		"""

        color_map = self.plot_obj.color_mapper
        linear_mapper = LinearMapper(range=color_map.range)
        color_bar = ColorBar(index_mapper=linear_mapper,
                             color_mapper=color_map,
                             plot=self.plot_obj,
                             orientation='v',
                             resizable='v',
                             width=30)
        color_bar._axis.tick_label_formatter = self.sci_formatter
        color_bar.padding_top = self.padding_top
        color_bar.padding_bottom = self.padding_bottom
        color_bar.padding_left = 50  # Room for labels.
        color_bar.padding_right = 10

        range_selection = RangeSelection(component=color_bar)
        range_selection.listeners.append(self.plot_obj)
        color_bar.tools.append(range_selection)

        range_selection_overlay = RangeSelectionOverlay(component=color_bar)
        color_bar.overlays.append(range_selection_overlay)

        container = HPlotContainer(use_backbuffer=True)
        container.add(self)
        container.add(color_bar)

        return Window(self.parent, component=container).control
コード例 #4
0
ファイル: updating_plot3.py プロジェクト: pingleewu/ShareRoot
    def _create_window(self):
        numpoints = 50
        low = -5
        high = 15.0
        x = arange(low, high, (high - low) / numpoints)
        container = OverlayPlotContainer(bgcolor="lightgray")

        common_index = None
        index_range = None
        value_range = None
        self.animated_plots = []
        for i, color in enumerate(COLOR_PALETTE):
            if not common_index:
                animated_plot = AnimatedPlot(x, jn(i, x), color)
                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)
コード例 #5
0
    def _create_window(self):
        numpoints = 50
        low = -5
        high = 15.0
        x = arange(low, high, (high - low) / numpoints)
        container = OverlayPlotContainer(bgcolor="lightgray")

        self.animated_plots = []
        for i, color in enumerate(COLOR_PALETTE):
            animated_plot = AnimatedPlot(x, jn(i, x), color)
            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)
コード例 #6
0
    def _create_window(self):
        self._create_data()
        x = self.x_values[:self.current_index]
        y = self.y_values[:self.current_index]

        value_range = None
        index_range = None
        plot = create_line_plot((x, y), color="red", width=2.0)
        value_range = plot.value_mapper.range
        index_range = plot.index_mapper.range
        index_range.low = -5
        index_range.high = 15
        plot.padding = 50
        plot.fill_padding = True
        plot.bgcolor = "white"
        left, bottom = add_default_axes(plot)
        hgrid, vgrid = add_default_grids(plot)
        bottom.tick_interval = 2.0
        vgrid.grid_interval = 2.0

        self.plot = plot
        plot.tools.append(PanTool(component=plot))
        plot.overlays.append(
            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)
コード例 #7
0
ファイル: button_tool.py プロジェクト: pingleewu/ShareRoot
    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
コード例 #8
0
    def _create_window(self):
        """ Create an enable window. """

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

        return Window(self, component=container)
コード例 #9
0
    def _create_window(self):

        strings = array([["apple", "banana", "cherry", "durian"],
                         ["eggfruit", "fig", "grape", "honeydew"]])
        grid = TextGrid(string_array=strings)
        container = Container(bounds=size)
        container.add(grid)
        return Window(self, -1, component=container)
コード例 #10
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)
コード例 #11
0
    def _create_window(self):
        # Create the model
        #try:
        #    self.model = model = BrainModel()
        #    cmap = bone
        #except SystemExit:
        #    sys.exit()
        #except:
        #    print "Unable to load BrainModel, using generated data cube."
        self.model = model = Model()
        cmap = jet
        self._update_model(cmap)

        datacube = self.colorcube

        # Create the plot
        self.plotdata = ArrayPlotData()
        self._update_images()

        # Center Plot
        centerplot = Plot(self.plotdata, padding=0)
        imgplot = centerplot.img_plot("xy",
                                xbounds=(model.xs[0], model.xs[-1]),
                                ybounds=(model.ys[0], model.ys[-1]),
                                colormap=cmap)[0]
        self._add_plot_tools(imgplot, "xy")
        self.center = imgplot

        # Right Plot
        rightplot = Plot(self.plotdata, width=150, resizable="v", padding=0)
        rightplot.value_range = centerplot.value_range
        imgplot = rightplot.img_plot("yz",
                                xbounds=(model.zs[0], model.zs[-1]),
                                ybounds=(model.ys[0], model.ys[-1]),
                                colormap=cmap)[0]
        self._add_plot_tools(imgplot, "yz")
        self.right = imgplot

        # Bottom Plot
        bottomplot = Plot(self.plotdata, height=150, resizable="h", padding=0)
        bottomplot.index_range = centerplot.index_range
        imgplot = bottomplot.img_plot("xz",
                                xbounds=(model.xs[0], model.xs[-1]),
                                ybounds=(model.zs[0], model.zs[-1]),
                                colormap=cmap)[0]
        self._add_plot_tools(imgplot, "xz")
        self.bottom = imgplot

        # Create Container and add all Plots
        container = GridPlotContainer(padding=20, fill_padding=True,
                                      bgcolor="white", use_backbuffer=True,
                                      shape=(2,2), spacing=(12,12))
        container.add(centerplot)
        container.add(rightplot)
        container.add(bottomplot)

        self.container = container
        return Window(self, -1, component=container)
コード例 #12
0
    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)
コード例 #13
0
 def init(self, parent):
     self.create_plot()
     self._window = Window(parent,
                           component=self.plot,
                           bgcolor=(236 / 255.0, 233 / 255.0, 216 / 255.0))
     self.control = self._window.control
     self.value.on_trait_change(self._context_items_changed,
                                'items_modified')
     return
コード例 #14
0
    def _create_window(self):
        self.model = model = Model()
        self.cmap = jet
        #self._update_model(self.cmap)

        # Create the plot
        self.plotdata = ArrayPlotData()
        self._update_images()

        # Center Plot
        centerplot = Plot(self.plotdata, padding=0)
        imgplot = centerplot.img_plot("xy",
                                      xbounds=(model.min_x, model.max_x),
                                      ybounds=(model.min_y, model.max_y),
                                      colormap=self.cmap)[0]
        self._add_plot_tools(imgplot, "xy")
        self.center = imgplot

        # Right Plot
        rightplot = Plot(self.plotdata, width=150, resizable="v", padding=0)
        rightplot.value_range = centerplot.value_range
        imgplot = rightplot.img_plot("yz",
                                     xbounds=(model.min_z, model.max_z),
                                     ybounds=(model.min_y, model.max_y),
                                     colormap=self.cmap)[0]
        self._add_plot_tools(imgplot, "yz")
        self.right = imgplot

        # Bottom Plot.  Seismic plot axis1 (depth) down into earth
        #               i.e. z is depth, to altitude.
        bottomplot = Plot(self.plotdata,
                          height=150,
                          resizable="h",
                          padding=0,
                          origin="top left")
        bottomplot.index_range = centerplot.index_range
        imgplot = bottomplot.img_plot("xz",
                                      xbounds=(model.min_x, model.max_x),
                                      ybounds=(model.min_z, model.max_z),
                                      colormap=self.cmap)[0]
        self._add_plot_tools(imgplot, "xz")
        self.bottom = imgplot

        # Create Container and add all Plots
        container = GridPlotContainer(padding=20,
                                      fill_padding=True,
                                      bgcolor="white",
                                      use_backbuffer=True,
                                      shape=(2, 2),
                                      spacing=(20, 20))
        container.add(centerplot)
        container.add(rightplot)
        container.add(bottomplot)

        self.container = container
        return Window(self, -1, component=container)
コード例 #15
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)
コード例 #16
0
        def _create_window(self):
            self.controller = TimerController()
            container = _create_plot_component(self.controller)

            # start a continuous timer
            self.timer = QtCore.QTimer()
            self.timer.timeout.connect(self.controller.onTimer)
            self.timer.start(TIMER_PERIOD)

            return Window(self, -1, component=container)
コード例 #17
0
    def create_widget(self, parent):
        if self.component is not None:
            self._window = Window(parent,
                                  component=self.component,
                                  bgcolor=self.component.bgcolor)
            enable_widget = self._window.control
        else:
            self._window = None
            enable_widget = None

        return enable_widget
コード例 #18
0
 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)
コード例 #19
0
 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)
コード例 #20
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)
コード例 #21
0
    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)
コード例 #22
0
ファイル: test_test_assistant.py プロジェクト: alexlib/enable
    def test_mouse_move_real_window(self):
        from enable.api import Window

        test_assistant = EnableTestAssistant()
        component = Component(bounds=[100, 200])
        window = Window(None, component=component)

        event = test_assistant.mouse_move(component, 10, 20, window)

        self.assertEqual(event.x, 10)
        self.assertEqual(event.y, 20)
        self.assertEqual(event.window, window)
        self.assertFalse(event.alt_down)
        self.assertFalse(event.control_down)
        self.assertFalse(event.shift_down)
コード例 #23
0
def test_mouse_move_real_window():
    from enable.api import Window

    test_assistant = EnableTestAssistant()
    component = Component(bounds=[100, 200])
    window = Window(None, component=component)

    event = test_assistant.mouse_move(component, 10, 20, window)

    nose.tools.assert_equal(event.x, 10)
    nose.tools.assert_equal(event.y, 20)
    nose.tools.assert_equal(event.window, window)
    assert not event.alt_down
    assert not event.control_down
    assert not event.shift_down
コード例 #24
0
    def create_plot(self, parent):
        # Create some line plots of some of the data
        self.plot = Plot(self.pd, padding=[40, 10, 0, 40], border_visible=True)
        self.plot.legend.visible = True

        # Attach some tools to the plot
        self.plot.tools.append(PanTool(self.plot))
        zoom = ZoomTool(component=self.plot, tool_mode="box", always_on=False)
        self.plot.overlays.append(zoom)

        # This Window object bridges the Enable and Qt4 worlds, and handles events
        # and drawing.  We can create whatever hierarchy of nested containers we
        # want, as long as the top-level item gets set as the .component attribute
        # of a Window.
        return Window(parent, -1, component=self.plot)
コード例 #25
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """

        breakpoint()

        factory = self.factory
        plotitem = factory.plotitem

        container = OverlayPlotContainer(padding=50,
                                         fill_padding=True,
                                         bgcolor=plotitem.padding_bg_color,
                                         use_backbuffer=True)

        if plotitem.title != '':
            container.overlays.append(
                PlotLabel(plotitem.title,
                          component=container,
                          overlay_position="top"))

        self._container = container
        window = Window(parent, component=container)

        # FIXME: Toolkit specifc code here. The AbstractWindow should have a
        # 'set size' method as part of its API.
        self.control = control = window.control
        if ETSConfig.toolkit == 'wx':
            control.SetSize((factory.width, factory.height))
        elif ETSConfig.toolkit == 'qt4':
            control.resize(factory.width, factory.height)
        else:
            raise NotImplementedError

        # Attach listeners to the object's traits appropriately so we can
        # update the plot when they change.  For the _update_axis_grids()
        # callback, we have to wrap it in a lambda to keep traits from
        # inferring the calling convention based on introspecting the argument
        # list.
        object = self.object
        if USE_DATA_UPDATE == 1:
            for name in (plotitem.index, plotitem.value):
                object.on_trait_change(self._update_data, name)
        for name in (plotitem.x_label_trait, plotitem.y_label_trait):
            object.on_trait_change(lambda s: self._update_axis_grids(), name)
        if plotitem.type_trait not in ("", None):
            object.on_trait_change(self.update_editor, plotitem.type_trait)
        return
コード例 #26
0
ファイル: updating_plot4.py プロジェクト: pankajp/chaco
    def _create_window(self):
        numpoints = 50
        low = -5
        high = 15.0
        x = arange(low, high, (high - low) / numpoints)
        container = OverlayPlotContainer(bgcolor="lightgray")

        common_index = None
        index_range = None
        value_range = None
        self.animated_plots = []
        for i, color in enumerate(COLOR_PALETTE):
            if not common_index:
                animated_plot = AnimatedPlot(x, jn(i, x), color)
                plot = animated_plot.plot
                common_index = plot.index
                index_range = plot.index_mapper.range
                value_range = plot.value_mapper.range
            else:
                if i % 2 == 1:
                    orientation = "v"
                else:
                    orientation = "h"
                animated_plot = AnimatedPlot(common_index,
                                             jn(i, x),
                                             color,
                                             orientation=orientation)
                plot = animated_plot.plot
                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)
コード例 #27
0
ファイル: text_field_demo.py プロジェクト: xinshuwei/enable
    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)
コード例 #28
0
ファイル: view_bounds_test.py プロジェクト: xinshuwei/enable
    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)
コード例 #29
0
    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)
コード例 #30
0
def test_mouse_move_real_window_mocked_position():
    from enable.api import Window

    test_assistant = EnableTestAssistant()
    component = Component(bounds=[100, 200])

    with mock.patch.object(Window, 'get_pointer_position', return_value=None):
        window = Window(None, component=component)
        event = test_assistant.mouse_move(component, 10, 20, window)

        nose.tools.assert_equal(event.x, 10)
        nose.tools.assert_equal(event.y, 20)
        nose.tools.assert_equal(event.window, window)
        assert not event.alt_down
        assert not event.control_down
        assert not event.shift_down
        nose.tools.assert_equal(event.window.get_pointer_position(), (10, 20))
コード例 #31
0
    def _create_window(self):

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

        boxgridsize = 8
        boxsize = 50

        spacing = boxsize * 2
        offset = spacing / 2

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

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

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

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

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

        return Window(self, -1, component=scrolled)
コード例 #32
0
 def init(self, parent):
     component = self._make_component(self.value)
     self._window = Window(parent, size=(200, 200), component=component)
     self.control = self._window.control
     self._window.bgcolor = self.factory.bgcolor
     self._parent = parent