From 2f7b402527b256159756fd19e1fbd288d71cd51b Mon Sep 17 00:00:00 2001 From: Joris Vankerschaver Date: Sat, 18 May 2019 16:53:25 +0100 Subject: [PATCH 1/3] MAINT: Replace deprecated .set by .trait_set[q] --- chaco/barplot.py | 2 +- chaco/base_1d_mapper.py | 4 ++-- chaco/base_2d_plot.py | 2 +- chaco/base_xy_plot.py | 2 +- chaco/grid_mapper.py | 8 ++++---- chaco/plot_containers.py | 2 +- chaco/plotscrollbar.py | 5 ++--- chaco/serializable.py | 4 ++-- chaco/shell/commands.py | 4 ++-- .../scalar_image_function_inspector.py | 2 +- .../scalar_image_function_inspector_old.py | 2 +- examples/demo/basic/bounded_grids.py | 20 ++++++++++--------- examples/demo/basic/draw_layers.py | 9 ++++++--- examples/demo/basic/grid_container.py | 6 ++++-- examples/demo/basic/horizon_plot.py | 3 ++- examples/demo/basic/inset_plot.py | 14 ++++++------- examples/demo/basic/scatter_inspector.py | 3 ++- examples/demo/vtk/cmap_scatter.py | 2 +- examples/demo/vtk/spectrum.py | 13 +++++++----- examples/user_guide/grid_plot_container.py | 4 ++-- .../user_guide/overlay_container_inset.py | 9 ++++----- 21 files changed, 65 insertions(+), 55 deletions(-) diff --git a/chaco/barplot.py b/chaco/barplot.py index 579e3a2fc..7470ade86 100644 --- a/chaco/barplot.py +++ b/chaco/barplot.py @@ -147,7 +147,7 @@ def __init__(self, *args, **kw): super(BarPlot, self).__init__(*args, **kw) # Set any keyword Traits that were postponed. - self.set(**postponed) + self.trait_set(**postponed) def map_screen(self, data_array): diff --git a/chaco/base_1d_mapper.py b/chaco/base_1d_mapper.py index bfddf57a4..e6cb03b55 100644 --- a/chaco/base_1d_mapper.py +++ b/chaco/base_1d_mapper.py @@ -97,8 +97,8 @@ def _set_screen_bounds(self, new_bounds): return if not self.stretch_data: self._adjust_range((self.low_pos, self.high_pos), new_bounds) - self.set(low_pos = new_bounds[0], trait_change_notify=False) - self.set(high_pos = new_bounds[1], trait_change_notify=False) + self.trait_setq(low_pos = new_bounds[0]) + self.trait_setq(high_pos = new_bounds[1]) self._cache_valid = False self._low_bound_initialized = True self._high_bound_initialized = True diff --git a/chaco/base_2d_plot.py b/chaco/base_2d_plot.py index ecb25f6c8..dede6b599 100644 --- a/chaco/base_2d_plot.py +++ b/chaco/base_2d_plot.py @@ -86,7 +86,7 @@ def __init__(self, **kwargs): for trait_name in ("index", "value"): if trait_name in kwargs: kwargs_tmp[trait_name] = kwargs.pop(trait_name) - self.set(**kwargs_tmp) + self.trait_set(**kwargs_tmp) super(Base2DPlot, self).__init__(**kwargs) if self.index is not None: self.index.on_trait_change(self._update_index_data, diff --git a/chaco/base_xy_plot.py b/chaco/base_xy_plot.py index d4d5a4567..ecfa2c061 100644 --- a/chaco/base_xy_plot.py +++ b/chaco/base_xy_plot.py @@ -183,7 +183,7 @@ def __init__(self, **kwtraits): for trait_name in ("index", "value", "index_mapper", "value_mapper"): if trait_name in kwtraits: kwargs_tmp[trait_name] = kwtraits.pop(trait_name) - self.set(**kwargs_tmp) + self.trait_set(**kwargs_tmp) AbstractPlotRenderer.__init__(self, **kwtraits) if self.index is not None: self.index.on_trait_change(self._either_data_changed, "data_changed") diff --git a/chaco/grid_mapper.py b/chaco/grid_mapper.py index 43f1bd7c1..1519c9c5e 100644 --- a/chaco/grid_mapper.py +++ b/chaco/grid_mapper.py @@ -210,10 +210,10 @@ def _set_screen_bounds(self, new_bounds): # TODO: figure out a way to not need to do this check: if self.screen_bounds == new_bounds: return - self.set(x_low_pos=new_bounds[0], trait_change_notify=False) - self.set(x_high_pos=new_bounds[1], trait_change_notify=False) - self.set(y_low_pos=new_bounds[2], trait_change_notify=False) - self.set(y_high_pos=new_bounds[3], trait_change_notify=False) + self.trait_setq(x_low_pos=new_bounds[0]) + self.trait_setq(x_high_pos=new_bounds[1]) + self.trait_setq(y_low_pos=new_bounds[2]) + self.trait_setq(y_high_pos=new_bounds[3]) self._update_bounds() def _get_screen_bounds(self): diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 7b0e75f9b..95b14b0c2 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -722,7 +722,7 @@ def _set_component_grid(self, val): component.container.remove(component) component.container = self - self.set(shape=grid.shape, trait_change_notify=False) + self.trait_setq(shape=grid.shape) self._components = list(grid.flatten()) if self._should_compact(): diff --git a/chaco/plotscrollbar.py b/chaco/plotscrollbar.py index aba698e45..89a8b269a 100644 --- a/chaco/plotscrollbar.py +++ b/chaco/plotscrollbar.py @@ -104,9 +104,8 @@ def _handle_dataspace_update(self): ticksize = 1 foo = (totalmin, totalmax, view, ticksize) print("scrollrange:", foo) - self.set(range = foo, - scroll_position = max(min(self.scroll_position, totalmax-view), totalmin), - trait_change_notify=False) + self.trait_setq(range = foo, + scroll_position = max(min(self.scroll_position, totalmax-view), totalmin)) self._scroll_updated = True self.request_redraw() return diff --git a/chaco/serializable.py b/chaco/serializable.py index fdf8fd8a3..bc879c1d5 100644 --- a/chaco/serializable.py +++ b/chaco/serializable.py @@ -71,8 +71,8 @@ def _do_setstate(self, state): because we need Serializable's implementation to call _post_load() after all the _do_setstate() have returned.) """ - # Quietly all the attributes - self.set(trait_change_notify=False, **state) + # Quietly set all the attributes + self.trait_setq(**state) return #------------------------------------------------------------------------ diff --git a/chaco/shell/commands.py b/chaco/shell/commands.py index c0bd42054..41271c37f 100644 --- a/chaco/shell/commands.py +++ b/chaco/shell/commands.py @@ -627,7 +627,7 @@ def xaxis(**kwds): p = curplot() if p: if kwds: - p.x_axis.set(**kwds) + p.x_axis.trait_set(**kwds) else: p.x_axis.visible ^= True p.request_redraw() @@ -655,7 +655,7 @@ def yaxis(**kwds): p = curplot() if p: if kwds: - p.y_axis.set(**kwds) + p.y_axis.trait_setq(**kwds) else: p.y_axis.visible ^= True p.request_redraw() diff --git a/examples/demo/advanced/scalar_image_function_inspector.py b/examples/demo/advanced/scalar_image_function_inspector.py index e022b3dea..469ffea42 100644 --- a/examples/demo/advanced/scalar_image_function_inspector.py +++ b/examples/demo/advanced/scalar_image_function_inspector.py @@ -101,7 +101,7 @@ def compute_model(self): self.model_changed = True self._function = self.function except: - self.set(function = self._function, trait_change_notify=False) + self.trait_setq(function=self._function) def _anytrait_changed(self, name, value): if name in ['function', 'npts_x', 'npts_y', diff --git a/examples/demo/advanced/scalar_image_function_inspector_old.py b/examples/demo/advanced/scalar_image_function_inspector_old.py index 83cc4ab1b..34f0b6d2b 100644 --- a/examples/demo/advanced/scalar_image_function_inspector_old.py +++ b/examples/demo/advanced/scalar_image_function_inspector_old.py @@ -89,7 +89,7 @@ def compute_model(self): self.model_changed = True self._function = self.function except: - self.set(function = self._function, trait_change_notify=False) + self.trait_setq(function=self._function) def _anytrait_changed(self, name, value): if name in ['function', 'npts_x', 'npts_y', diff --git a/examples/demo/basic/bounded_grids.py b/examples/demo/basic/bounded_grids.py index b3dddacb5..c7be93a1f 100644 --- a/examples/demo/basic/bounded_grids.py +++ b/examples/demo/basic/bounded_grids.py @@ -37,13 +37,15 @@ def _create_plot_component(): plot.y_grid.line_color = "black" xmin, xmax = 1.0, 6.0 ymin, ymax = 0.2, 0.80001 - plot.x_grid.set(data_min = xmin, data_max = xmax, - transverse_bounds = (ymin, ymax), - transverse_mapper = plot.y_mapper) + plot.x_grid.data_min = xmin + plot.x_grid.data_max = xmax + plot.x_grid.transverse_bounds = (ymin, ymax) + plot.x_grid.transverse_mapper = plot.y_mapper - plot.y_grid.set(data_min = ymin, data_max = ymax, - transverse_bounds = (xmin, xmax), - transverse_mapper = plot.x_mapper) + plot.y_grid.data_min = ymin + plot.y_grid.data_max = ymax + plot.y_grid.transverse_bounds = (xmin, xmax) + plot.y_grid.transverse_mapper = plot.x_mapper # Attach some tools to the plot plot.tools.append(PanTool(plot)) @@ -58,9 +60,9 @@ def my_bounds_func(ticks): func_plot = Plot(pd, padding=50, border_visible=True) func_plot.plot(("index", "y3"), color="red") - func_plot.x_grid.set(transverse_bounds = my_bounds_func, - transverse_mapper = func_plot.y_mapper, - line_color="black") + func_plot.x_grid.transverse_bounds = my_bounds_func + func_plot.x_grid.transverse_mapper = func_plot.y_mapper + func_plot.x_grid.line_color = "black" func_plot.tools.append(PanTool(func_plot)) container = HPlotContainer() diff --git a/examples/demo/basic/draw_layers.py b/examples/demo/basic/draw_layers.py index 2285f6cba..78f9c341e 100644 --- a/examples/demo/basic/draw_layers.py +++ b/examples/demo/basic/draw_layers.py @@ -40,21 +40,24 @@ def _create_plot_component(): y_name = "struve" + str(i) pd.set_data(y_name, struve(i, x)) renderer = plot.plot(("x", y_name), color="blue", name=y_name, line_width=2)[0] - renderer.set(draw_layer = "struve", unified_draw=True) + renderer.draw_layer = "struve" + renderer.unified_draw = True # Draw bessels for i in range(3): y_name = "bessel" + str(i) pd.set_data(y_name, jn(i,x)) renderer = plot.plot(("x", y_name), color="green", name=y_name, line_width=2)[0] - renderer.set(draw_layer = "bessel", unified_draw=True) + renderer.draw_layer = "bessel" + renderer.unified_draw = True # Draw sines for i in range(3): y_name = "sine" + str(i) pd.set_data(y_name, sin(x * (i+1) / 1.5)) renderer = plot.plot(("x", y_name), color="red", name=y_name, line_width=2)[0] - renderer.set(draw_layer="sine", unified_draw=True) + renderer.draw_layer = "sine" + renderer.unified_draw = True # Attach some tools to the plot plot.tools.append(PanTool(plot)) diff --git a/examples/demo/basic/grid_container.py b/examples/demo/basic/grid_container.py index fe5b1f312..a056fbf21 100644 --- a/examples/demo/basic/grid_container.py +++ b/examples/demo/basic/grid_container.py @@ -70,7 +70,8 @@ def _create_plot_component(): # Set the upper-left plot to only be resizable vertically, and to have a # fixed horizontal width. This also constrains the width of the first column. ul_plot = container.components[0] - ul_plot.set(resizable="v", width=200) + ul_plot.resizable = "v" + ul_plot.width = 200 ul_plot.overlays.append(PlotLabel("Not horizontally resizable", component=ul_plot)) @@ -78,7 +79,8 @@ def _create_plot_component(): # This also constrains the height of the bottom row and the width of # the middle column. cplot = container.components[4] - cplot.set(resizable="", bounds=[400,400]) + cplot.resizable = "" + cplot.bounds = [400,400] cplot.overlays.append(PlotLabel("Not resizable", component=cplot)) container.padding_top = 50 diff --git a/examples/demo/basic/horizon_plot.py b/examples/demo/basic/horizon_plot.py index b81368904..e9b6894d5 100644 --- a/examples/demo/basic/horizon_plot.py +++ b/examples/demo/basic/horizon_plot.py @@ -142,7 +142,8 @@ class Demo(HasTraits): if __name__ == "__main__": filled, horizon = _create_plot_components() - demo.set(horizon=horizon, filled=filled) + demo.horizon = horizon + demo.filled = filled demo.configure_traits() #--EOF--- diff --git a/examples/demo/basic/inset_plot.py b/examples/demo/basic/inset_plot.py index e6b990f51..350512736 100644 --- a/examples/demo/basic/inset_plot.py +++ b/examples/demo/basic/inset_plot.py @@ -47,13 +47,13 @@ def _create_plot_component(): # range to the first plot plot2 = Plot(pd, range2d=plot1.range2d, padding=50) plot2.plot(('index', 'y3'), type="scatter", color="blue", marker="circle") - plot2.set(resizable = "", - bounds = [250, 250], - position = [550,150], - bgcolor = "white", - border_visible = True, - unified_draw = True - ) + plot2.resizable = "" + plot2.bounds = [250, 250] + plot2.position = [550,150] + plot2.bgcolor = "white" + plot2.border_visible = True + plot2.unified_draw = True + plot2.tools.append(PanTool(plot2)) plot2.tools.append(MoveTool(plot2, drag_button="right")) zoom = ZoomTool(component=plot2, tool_mode="box", always_on=False) diff --git a/examples/demo/basic/scatter_inspector.py b/examples/demo/basic/scatter_inspector.py index b78a4c5f6..394b6b37a 100644 --- a/examples/demo/basic/scatter_inspector.py +++ b/examples/demo/basic/scatter_inspector.py @@ -33,7 +33,8 @@ def _create_plot_component(): scatter = plot.plot(("x", "y"), type="scatter", color="lightblue")[0] # Tweak some of the plot properties - plot.set(title="Scatter Inspector Demo", padding=50) + plot.title = "Scatter Inspector Demo" + plot.padding = 50 # Attach some tools to the plot plot.tools.append(PanTool(plot)) diff --git a/examples/demo/vtk/cmap_scatter.py b/examples/demo/vtk/cmap_scatter.py index 076e2c60c..98bde807a 100644 --- a/examples/demo/vtk/cmap_scatter.py +++ b/examples/demo/vtk/cmap_scatter.py @@ -67,7 +67,7 @@ def create_plot(): # Set colors #plot.title_color = "white" #for axis in plot.x_axis, plot.y_axis: - # axis.set(title_color="white", tick_label_color="white") + # axis.trait_set(title_color="white", tick_label_color="white") # Right now, some of the tools are a little invasive, and we need the # actual ColomappedScatterPlot object to give to them diff --git a/examples/demo/vtk/spectrum.py b/examples/demo/vtk/spectrum.py index 01a08afd1..81958772d 100644 --- a/examples/demo/vtk/spectrum.py +++ b/examples/demo/vtk/spectrum.py @@ -134,16 +134,19 @@ def main(): specplot, timeplot, spectrogram = plots for i, p in enumerate(plots): - p.set(resizable = "", bounds = [200,200], outer_x = 0, - bgcolor = "transparent", - ) + p.resizable = "" + p.bgcolor = "transparent" + p.bounds = [200,200] + p.outer_x = 0 p.outer_y = i*250 p.tools.append(MoveTool(p, drag_button="right")) p.tools.append(PanTool(p)) p.tools.append(ZoomTool(p)) - spectrogram.tools[-1].set(tool_mode="range", axis="value") - spectrogram.tools[-2].set(constrain=True, constrain_direction="y") + spectrogram.tools[-1].tool_mode = "range" + spectrogram.tools[-1].axis = "value" + spectrogram.tools[-2].constrain = True + spectrogram.tools[-2].constrain_direction = "y" container = OverlayPlotContainer(bgcolor = "transparent", fit_window = True) diff --git a/examples/user_guide/grid_plot_container.py b/examples/user_guide/grid_plot_container.py index e24dee6dd..6a2b7943d 100644 --- a/examples/user_guide/grid_plot_container.py +++ b/examples/user_guide/grid_plot_container.py @@ -41,8 +41,8 @@ def _plot_default(self): line_width=3.0) # Set each plot's aspect based on its position in the grid - plot.set(height=((i % 3) + 1) * 50.0, - resizable='h') + plot.height = ((i % 3) + 1) * 50.0 + plot.resizable = 'h' # Add to the grid container container.add(plot) diff --git a/examples/user_guide/overlay_container_inset.py b/examples/user_guide/overlay_container_inset.py index b821ae955..39984e976 100644 --- a/examples/user_guide/overlay_container_inset.py +++ b/examples/user_guide/overlay_container_inset.py @@ -38,11 +38,10 @@ def _plot_default(self): # Create a second inset plot, not resizable, not zoom-able inset_plot = Plot(pd) inset_plot.plot(('index', 'value'), color='blue') - inset_plot.set(resizable = '', - bounds = [250, 150], - position = [450, 350], - border_visible = True - ) + inset_plot.resizable = '' + inset_plot.bounds = [250, 150] + inset_plot.position = [450, 350] + inset_plot.border_visible = True # Create a container and add our plots container = OverlayPlotContainer() From ab6cedfd51f9a25701367085aeb7acee2114bce5 Mon Sep 17 00:00:00 2001 From: Joris Vankerschaver Date: Sat, 18 May 2019 17:42:03 +0100 Subject: [PATCH 2/3] MAINT: Use tuple slices --- chaco/color_spaces.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/chaco/color_spaces.py b/chaco/color_spaces.py index b5434f8d4..ac8262a2e 100644 --- a/chaco/color_spaces.py +++ b/chaco/color_spaces.py @@ -79,11 +79,11 @@ def separate_colors(xyz, axis=-1): axis = n + axis slices = makeslices(n) slices[axis] = 0 - x = xyz[slices] + x = xyz[tuple(slices)] slices[axis] = 1 - y = xyz[slices] + y = xyz[tuple(slices)] slices[axis] = 2 - z = xyz[slices] + z = xyz[tuple(slices)] return x, y, z, axis From d2493fb52074d055bd1613d82ef301867b0213b4 Mon Sep 17 00:00:00 2001 From: Joris Vankerschaver Date: Fri, 31 May 2019 05:31:30 +0100 Subject: [PATCH 3/3] FIX: Undo .trait_setq --- chaco/shell/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chaco/shell/commands.py b/chaco/shell/commands.py index 41271c37f..ccfeee66a 100644 --- a/chaco/shell/commands.py +++ b/chaco/shell/commands.py @@ -655,7 +655,7 @@ def yaxis(**kwds): p = curplot() if p: if kwds: - p.y_axis.trait_setq(**kwds) + p.y_axis.trait_set(**kwds) else: p.y_axis.visible ^= True p.request_redraw()