From e24f127622c8211a4a96c5f92f572fce5d5da218 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 9 Apr 2017 03:14:13 -0700 Subject: [PATCH 1/2] Stylistic cleanup to backend_bases.py. --- lib/matplotlib/backend_bases.py | 141 ++++++++++---------------------- 1 file changed, 43 insertions(+), 98 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 294543b4ed54..3ddc4ce6f6c0 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -222,14 +222,12 @@ def open_group(self, s, gid=None): *gid* as the id of the group. Is only currently used by :mod:`~matplotlib.backends.backend_svg`. """ - pass def close_group(self, s): """ Close a grouping element with label *s* Is only currently used by :mod:`~matplotlib.backends.backend_svg` """ - pass def draw_path(self, gc, path, transform, rgbFace=None): """ @@ -772,7 +770,6 @@ def start_rasterizing(self): """ Used in MixedModeRenderer. Switch to the raster renderer. """ - pass def stop_rasterizing(self): """ @@ -780,14 +777,12 @@ def stop_rasterizing(self): and draw the contents of the raster renderer as an image on the vector renderer. """ - pass def start_filter(self): """ Used in AggRenderer. Switch to a temporary renderer for image filtering effects. """ - pass def stop_filter(self, filter_func): """ @@ -796,7 +791,6 @@ def stop_filter(self, filter_func): *filter_func* and is drawn on the original renderer as an image. """ - pass class GraphicsContextBase(object): @@ -850,7 +844,6 @@ def restore(self): Restore the graphics context from the stack - needed only for backends that save graphics contexts on a stack """ - pass def get_alpha(self): """ @@ -1315,12 +1308,10 @@ def remove_callback(self, func, *args, **kwargs): self.callbacks.pop(funcs.index(func)) def _timer_set_interval(self): - 'Used to set interval on underlying timer object.' - pass + """Used to set interval on underlying timer object.""" def _timer_set_single_shot(self): - 'Used to set single shot on underlying timer object.' - pass + """Used to set single shot on underlying timer object.""" def _on_timer(self): ''' @@ -1368,7 +1359,6 @@ class IdleEvent(Event): An event triggered by the GUI backend when it is idle -- useful for passive animation """ - pass class DrawEvent(Event): @@ -1710,7 +1700,6 @@ class FigureCanvasBase(object): 'Joint Photographic Experts Group') register_backend('jpeg', 'matplotlib.backends.backend_agg', 'Joint Photographic Experts Group') - # TIFF support register_backend('tif', 'matplotlib.backends.backend_agg', 'Tagged Image File Format') @@ -1742,7 +1731,7 @@ def _idle_draw_cntx(self): def is_saving(self): """ - Returns `True` when the renderer is in the process of saving + Returns whether the renderer is in the process of saving to a file, rather than rendering for an on-screen buffer. """ return self._is_saving @@ -1779,41 +1768,26 @@ def pick(self, mouseevent): self.figure.pick(mouseevent) def blit(self, bbox=None): - """ - blit the canvas in bbox (default entire canvas) - """ - pass + """Blit the canvas in bbox (default entire canvas).""" def resize(self, w, h): - """ - set the canvas size in pixels - """ - pass + """Set the canvas size in pixels.""" def draw_event(self, renderer): - """ - This method will be call all functions connected to the - 'draw_event' with a :class:`DrawEvent` - """ - + """Pass a `DrawEvent` to all functions connected to ``draw_event``.""" s = 'draw_event' event = DrawEvent(s, self, renderer) self.callbacks.process(s, event) def resize_event(self): + """Pass a `ResizeEvent` to all functions connected to ``resize_event``. """ - This method will be call all functions connected to the - 'resize_event' with a :class:`ResizeEvent` - """ - s = 'resize_event' event = ResizeEvent(s, self) self.callbacks.process(s, event) def close_event(self, guiEvent=None): - """ - This method will be called by all functions connected to the - 'close_event' with a :class:`CloseEvent` + """Pass a `CloseEvent` to all functions connected to ``close_event``. """ s = 'close_event' try: @@ -1828,9 +1802,7 @@ def close_event(self, guiEvent=None): # with an open window; 'callbacks' attribute no longer exists. def key_press_event(self, key, guiEvent=None): - """ - This method will be call all functions connected to the - 'key_press_event' with a :class:`KeyEvent` + """Pass a `KeyEvent` to all functions connected to ``key_press_event``. """ self._key = key s = 'key_press_event' @@ -1840,8 +1812,7 @@ def key_press_event(self, key, guiEvent=None): def key_release_event(self, key, guiEvent=None): """ - This method will be call all functions connected to the - 'key_release_event' with a :class:`KeyEvent` + Pass a `KeyEvent` to all functions connected to ``key_release_event``. """ s = 'key_release_event' event = KeyEvent( @@ -1886,7 +1857,6 @@ def button_press_event(self, x, y, button, dblclick=False, guiEvent=None): This method will be call all functions connected to the 'button_press_event' with a :class:`MouseEvent` instance. - """ self._button = button s = 'button_press_event' @@ -1996,7 +1966,7 @@ def grab_mouse(self, ax): another axes. """ if self.mouse_grabber not in (None, ax): - raise RuntimeError('two different attempted to grab mouse input') + raise RuntimeError("Another Axes already grabs mouse input") self.mouse_grabber = ax def release_mouse(self, ax): @@ -2010,10 +1980,7 @@ def release_mouse(self, ax): self.mouse_grabber = None def draw(self, *args, **kwargs): - """ - Render the :class:`~matplotlib.figure.Figure` - """ - pass + """Render the :class:`~matplotlib.figure.Figure`.""" def draw_idle(self, *args, **kwargs): """ @@ -2028,7 +1995,6 @@ def draw_cursor(self, event): Draw a cursor in the event.axes if inaxes is not None. Use native GUI drawing for efficiency if possible """ - pass def get_width_height(self): """ @@ -2682,8 +2648,7 @@ def full_screen_toggle(self): pass def resize(self, w, h): - """"For gui backends, resize the window (in pixels).""" - pass + """"For GUI backends, resize the window (in pixels).""" def key_press(self, event): """ @@ -2694,24 +2659,20 @@ def key_press(self, event): key_press_handler(event, self.canvas, self.canvas.toolbar) def show_popup(self, msg): - """ - Display message in a popup -- GUI only - """ - pass + """Display message in a popup -- GUI only.""" def get_window_title(self): - """ - Get the title text of the window containing the figure. - Return None for non-GUI backends (e.g., a PS backend). + """Get the title text of the window containing the figure. + + Return None for non-GUI (e.g., PS) backends. """ return 'image' def set_window_title(self, title): + """Set the title text of the window containing the figure. + + This has no effect for non-GUI (e.g., PS) backends. """ - Set the title text of the window containing the figure. Note that - this has no effect for non-GUI backends (e.g., a PS backend). - """ - pass cursors = tools.cursors @@ -2806,8 +2767,7 @@ def __init__(self, canvas): self.set_history_buttons() def set_message(self, s): - """Display a message on toolbar or in status bar""" - pass + """Display a message on toolbar or in status bar.""" def back(self, *args): """move back up the view lim stack""" @@ -2820,22 +2780,20 @@ def dynamic_update(self): pass def draw_rubberband(self, event, x0, y0, x1, y1): - """Draw a rectangle rubberband to indicate zoom limits""" - pass + """Draw a rectangle rubberband to indicate zoom limits.""" def remove_rubberband(self): - """Remove the rubberband""" - pass + """Remove the rubberband.""" def forward(self, *args): - """Move forward in the view lim stack""" + """Move forward in the view lim stack.""" self._views.forward() self._positions.forward() self.set_history_buttons() self._update_view() def home(self, *args): - """Restore the original view""" + """Restore the original view.""" self._views.home() self._positions.home() self.set_history_buttons() @@ -2940,10 +2898,9 @@ def pan(self, *args): def press(self, event): """Called whenver a mouse button is pressed.""" - pass def press_pan(self, event): - """the press mouse button in pan/zoom mode callback""" + """Callback for mouse button press in pan/zoom mode.""" if event.button == 1: self._button_pressed = 1 @@ -2972,7 +2929,7 @@ def press_pan(self, event): self.press(event) def press_zoom(self, event): - """the press mouse button in zoom to rect mode callback""" + """Callback for mouse button press in zoom to rect mode.""" # If we're already in the middle of a zoom, pressing another # button works to "cancel" if self._ids_zoom != []: @@ -3025,7 +2982,7 @@ def _switch_off_zoom_mode(self, event): self.mouse_move(event) def push_current(self): - """push the current view limits and position onto the stack""" + """Push the current view limits and position onto the stack.""" views = [] pos = [] for a in self.canvas.figure.get_axes(): @@ -3039,11 +2996,10 @@ def push_current(self): self.set_history_buttons() def release(self, event): - """this will be called whenever mouse button is released""" - pass + """Callback for mouse button release.""" def release_pan(self, event): - """the release mouse button callback in pan/zoom mode""" + """Callback for mouse button release in pan/zoom mode.""" if self._button_pressed is None: return @@ -3061,8 +3017,7 @@ def release_pan(self, event): self.draw() def drag_pan(self, event): - """the drag callback in pan/zoom mode""" - + """Callback for dragging in pan/zoom mode.""" for a, ind in self._xypress: #safer to use the recorded button at the press than current button: #multiple button can get pressed during motion... @@ -3070,8 +3025,7 @@ def drag_pan(self, event): self.dynamic_update() def drag_zoom(self, event): - """the drag callback in zoom mode""" - + """Callback for dragging in zoom mode.""" if self._xypress: x, y = event.x, event.y lastx, lasty, a, ind, view = self._xypress[0] @@ -3091,7 +3045,7 @@ def drag_zoom(self, event): self.draw_rubberband(event, x, y, lastx, lasty) def release_zoom(self, event): - """the release mouse button callback in zoom to rect mode""" + """Callback for mouse button release in zoom to rect mode.""" for zoom_id in self._ids_zoom: self.canvas.mpl_disconnect(zoom_id) self._ids_zoom = [] @@ -3146,7 +3100,7 @@ def release_zoom(self, event): self.release(event) def draw(self): - """Redraw the canvases, update the locators""" + """Redraw the canvases, update the locators.""" for a in self.canvas.figure.get_axes(): xaxis = getattr(a, 'xaxis', None) yaxis = getattr(a, 'yaxis', None) @@ -3164,7 +3118,7 @@ def draw(self): def _update_view(self): """Update the viewlim and position from the view and - position stack for each axes + position stack for each axes. """ views = self._views() @@ -3182,24 +3136,21 @@ def _update_view(self): self.canvas.draw_idle() def save_figure(self, *args): - """Save the current figure""" + """Save the current figure.""" raise NotImplementedError def set_cursor(self, cursor): + """Set the current cursor to one of the :class:`Cursors` enums values. """ - Set the current cursor to one of the :class:`Cursors` - enums values - """ - pass def update(self): - """Reset the axes stack""" + """Reset the axes stack.""" self._views.clear() self._positions.clear() self.set_history_buttons() def zoom(self, *args): - """Activate zoom to rect mode""" + """Activate zoom to rect mode.""" if self._active == 'ZOOM': self._active = None else: @@ -3229,8 +3180,7 @@ def zoom(self, *args): self.set_message(self.mode) def set_history_buttons(self): - """Enable or disable back/forward button""" - pass + """Enable or disable the back/forward button.""" class ToolContainerBase(object): @@ -3282,11 +3232,11 @@ def add_tool(self, tool, group, position=-1): self.toggle_toolitem(tool.name, True) def _remove_tool_cbk(self, event): - """Captures the 'tool_removed_event' signal and removes the tool""" + """Captures the 'tool_removed_event' signal and removes the tool.""" self.remove_toolitem(event.tool.name) def _get_image_filename(self, image): - """Find the image based on its name""" + """Find the image based on its name.""" # TODO: better search for images, they are not always in the # datapath basedir = os.path.join(rcParams['datapath'], 'images') @@ -3303,8 +3253,7 @@ def trigger_tool(self, name): Parameters ---------- name : String - Name(id) of the tool triggered from within the container - + Name (id) of the tool triggered from within the container """ self.toolmanager.trigger_tool(name, sender=self) @@ -3336,7 +3285,6 @@ def add_toolitem(self, name, group, position, image, description, toggle): * `False` : The button is a normal button (returns to unpressed state after release) """ - raise NotImplementedError def toggle_toolitem(self, name, toggled): @@ -3364,9 +3312,7 @@ def remove_toolitem(self, name): ---------- name : string Name of the tool to remove - """ - raise NotImplementedError @@ -3390,5 +3336,4 @@ def set_message(self, s): s : str Message text """ - pass From fd59a34b3cc762ac09fe415aea08fec8d2870b16 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 9 Apr 2017 03:17:06 -0700 Subject: [PATCH 2/2] Deprecate FigureCanvasBase.idle_event. The corresponding event had been deprecated since 1.5. --- examples/event_handling/idle_and_timeout.py | 37 --------------------- lib/matplotlib/backend_bases.py | 2 ++ 2 files changed, 2 insertions(+), 37 deletions(-) delete mode 100644 examples/event_handling/idle_and_timeout.py diff --git a/examples/event_handling/idle_and_timeout.py b/examples/event_handling/idle_and_timeout.py deleted file mode 100644 index e89d0b696141..000000000000 --- a/examples/event_handling/idle_and_timeout.py +++ /dev/null @@ -1,37 +0,0 @@ -from __future__ import print_function -""" -Demonstrate/test the idle and timeout API - -WARNING: idle_event is deprecated. Use the animations module instead. - -This is only tested on gtk so far and is a prototype implementation -""" -import numpy as np -import matplotlib.pyplot as plt - -fig, ax = plt.subplots() - -t = np.arange(0.0, 2.0, 0.01) -y1 = np.sin(2*np.pi*t) -y2 = np.cos(2*np.pi*t) -line1, = ax.plot(y1) -line2, = ax.plot(y2) - -N = 100 - - -def on_idle(event): - on_idle.count += 1 - print('idle', on_idle.count) - line1.set_ydata(np.sin(2*np.pi*t*(N - on_idle.count)/float(N))) - event.canvas.draw() - # test boolean return removal - if on_idle.count == N: - return False - return True -on_idle.cid = None -on_idle.count = 0 - -fig.canvas.mpl_connect('idle_event', on_idle) - -plt.show() diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 3ddc4ce6f6c0..01b41e419f11 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1354,6 +1354,7 @@ def __init__(self, name, canvas, guiEvent=None): self.guiEvent = guiEvent +@cbook.deprecated("2.1") class IdleEvent(Event): """ An event triggered by the GUI backend when it is idle -- useful @@ -1952,6 +1953,7 @@ def enter_notify_event(self, guiEvent=None, xy=None): event = Event('figure_enter_event', self, guiEvent) self.callbacks.process('figure_enter_event', event) + @cbook.deprecated("2.1") def idle_event(self, guiEvent=None): """Called when GUI is idle.""" s = 'idle_event'