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 i == 0: 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 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) ] # 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 _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)
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))
def _create_window(self): # Create the data and datasource objects # In order for the date axis to work, the index data points need to # be in units of seconds since the epoch. This is because we are using # the CalendarScaleSystem, whose formatters interpret the numerical values # as seconds since the epoch. numpoints = 500 index = create_dates(numpoints) returns = random.lognormal(0.01, 0.1, size=numpoints) price = 100.0 * cumprod(returns) volume = abs(random.normal(1000.0, 1500.0, size=numpoints) + 2000.0) time_ds = ArrayDataSource(index) vol_ds = ArrayDataSource(volume, sort_order="none") price_ds = ArrayDataSource(price, sort_order="none") # 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)
def _create_window(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 Window(self, -1, component=scrolled)
def _create_window(self): self.controller = TimerController() container = _create_plot_component(self.controller) # Bind the exit event to the onClose function which will force the # example to close. The PyAudio package causes problems that normally # prevent the user from closing the example using the 'X' button. # NOTE: I believe it is sufficient to just stop the timer-Vibha. self.Bind(wx.EVT_CLOSE, self.onClose) # Set the timer to generate events to us timerId = wx.NewId() self.timer = wx.Timer(self, timerId) self.Bind(wx.EVT_TIMER, self.controller.onTimer, id=timerId) self.timer.Start(TIMER_PERIOD, wx.TIMER_CONTINUOUS) # Return a window containing our plots return Window(self, -1, component=container)
def _create_window(self): stack = VStackedContainer( position=[0, 0], halign='center', valign='center', #border_visible=True, fit_components='hv', auto_size=True, stack_order='top_to_bottom', bgcolor='red') strings = [ "apple", "banana", "cherry", "durian", "eggfruit", "fig", "grape", "honeydew" ] for i, s in enumerate(strings): label = TextField( text=s, resizable='', bounds=[100 + i * 10, 20], bgcolor='red', #border_visible=True, text_offset=1) number = TextField( text=str(i + 1), resizable='', bgcolor='blue', #border_visible=True, text_offset=1, can_edit=False, bounds=[20, 20]) row = HStackedContainer(fit_components='hv', auto_size=True, resizable='', valign='top', border_visible=True) row.add(number) row.add(label) stack.add(row) container = Container(position=[20, 20], bounds=size) container.add(stack) container2 = Container(bounds=size) container2.add(container) return Window(self, -1, component=container2)
def _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) ] self.timer = Timer(100.0, self.onTimer) self.container = container return Window(self, -1, component=container)
def _create_window(self): canvas = DrawingCanvas(bounds=[500, 500]) toolbar = DrawingCanvasToolbar( width=500, height=32, fit_window=False, bgcolor="lightgrey") canvas.toolbar = toolbar 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)
def test_mouse_move_real_window_mocked_position(self): from enable.api import Window test_assistant = EnableTestAssistant() component = Component(bounds=[100, 200]) patch = mock.patch.object(Window, "get_pointer_position", return_value=None) with patch: 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) self.assertEqual(event.window.get_pointer_position(), (10, 20))
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 _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)
def init(self, parent): """ Finishes initializing the editor by creating the underlying toolkit widget. """ canvas = self.value viewport = CanvasViewport(component=canvas, view_position=[0, 0]) viewport.tools.append(ViewportPanTool(viewport, drag_button='right')) viewport.max_zoom = 1.0 viewport.min_zoom = 0.2 self.canvas_view = viewport self.scrolled = Scrolled(canvas, fit_window=True, inside_padding_width=0, mousewheel_scroll=False, always_show_sb=True, continuous_drag_update=True, viewport_component=viewport) self._window = Window(parent, -1, component=self.scrolled) self.control = self._window.control
def _create_window(self): self._create_data() x = self.x_values[:self.current_index] y = self.y_values[:self.current_index] plot = create_line_plot((x, y), color="red", width=2.0) 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)) self.timer = Timer(50.0, self.onTimer) return Window(self, -1, component=plot)
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)
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)
def _create_window(self): label = Label( text="h:\nv:", font="modern 16", position=[20, 50], bounds=[100, 100], bgcolor="red", color="white", hjustify="center", vjustify="center") vscroll = NativeScrollBar( orientation="vertical", bounds=[15, label.height], position=[label.x2, label.y], range=(0, 100.0, 10.0, 1.0), enabled=True) vscroll.on_trait_change(self._update_vscroll, "scroll_position") hscroll = NativeScrollBar( orientation="horizontal", bounds=[label.width, 15], position=[label.x, label.y - 15], range=(0, 100.0, 10.0, 1.0), enabled=True) hscroll.on_trait_change(self._update_hscroll, "scroll_position") container = Container( bounds=[200, 200], border_visible=True, padding=15) container.add(label, hscroll, vscroll) container.on_trait_change(self._update_layout, "bounds") container.on_trait_change(self._update_layout, "bounds_items") self.label = label self.hscroll = hscroll self.vscroll = vscroll return Window(self, -1, component=container)
def _create_canvas(self, parent): '''Create canvas for chaco plots ''' panel = wx.Panel(parent, -1, style=wx.CLIP_CHILDREN) # self.panel = panel container_panel = Window(panel, component=self.plot_container) a = self.adapter if a.max_size: panel.SetMaxSize(a.max_size) if a.min_size: panel.SetMinSize(a.min_size) print('size', panel.GetSize()) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(wx.StaticLine(parent, -1, style=wx.LI_HORIZONTAL), 0, wx.EXPAND | wx.BOTTOM, 5) sizer.Add(self._create_toolbar(panel), 0, wx.EXPAND) sizer.Add(container_panel.control, 1, wx.EXPAND) sizer.Add(wx.StaticLine(parent, -1, style=wx.LI_HORIZONTAL), 0, wx.EXPAND | wx.BOTTOM, 5) panel.SetSizer(sizer) if a.padding: for side, pad in list(a.padding.items()): if side == 'right' or side == 'top': padd = int((1 - pad) * 200) setattr(self.plot_container, 'padding_' + side, padd) else: padd = int(pad * 200) setattr(self.plot_container, 'padding_' + side, padd) return panel