Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
9813e43
Refactor pass 1. Refactoring Gcf out of specific backend (backend_gt…
OceanWolf Feb 21, 2015
91cbffc
Refactor Pass 2. Refactored Gcf out of all backend code.
OceanWolf Feb 22, 2015
aa3ff59
Quick fix to figure for safe unpickling.
OceanWolf Feb 25, 2015
f046e01
GTK3Agg
OceanWolf Feb 26, 2015
39ff708
Refactored making `FigureManager` a *figure* manager, plus added miss…
OceanWolf Feb 27, 2015
45c5fc2
keyword
OceanWolf Feb 27, 2015
ebf0c57
Make add_element more general, and make sure the code complies with it.
OceanWolf Feb 27, 2015
9d25441
Better destroy order.
OceanWolf Feb 27, 2015
6ae52f2
GTK simplifications
OceanWolf Feb 28, 2015
1a47d3b
Added doc and cleaned backend_managers, don't want our new file dirty.
OceanWolf Mar 3, 2015
bc17372
Improve layout!
OceanWolf Apr 6, 2015
3fb46f2
Move knowledge of the backend to the manager.
OceanWolf Apr 7, 2015
2758f3f
Incorporate MEP22 into MEP27
OceanWolf Apr 12, 2015
f354d3c
Improved new toolbar and updated tool_manager example accoridingly.
OceanWolf Apr 12, 2015
51c0598
fullscreen
OceanWolf Apr 13, 2015
6b35d85
MEP update
OceanWolf Apr 14, 2015
724b622
Finish MEP22 conversion
OceanWolf Apr 14, 2015
0b42bbe
rename window method
OceanWolf Apr 17, 2015
ef65740
Add backend anme to widgets
OceanWolf Apr 17, 2015
fb5202a
Handle FigureManager destroy internaly without pyplot.
OceanWolf Jun 4, 2015
26ce3e6
Make functionality more consistant for embedded applications
OceanWolf Jun 7, 2015
1cfebc4
Backend getter method for FigureManager
OceanWolf Jun 13, 2015
bc32fb1
Improve example after new method
OceanWolf Jun 13, 2015
81b9e69
Clean up the code a bit
OceanWolf Jun 13, 2015
85f0668
Remove old code from backend_managers
OceanWolf Jun 15, 2015
6535148
Cleanup
OceanWolf Jun 22, 2015
73e1122
Explicity get set manager as None if appropiate.
OceanWolf Jun 22, 2015
592c49b
figure attribute and canvas property
fariza Jun 22, 2015
b5d7f57
Fix FigureCanvasBase
OceanWolf Jun 23, 2015
b842bdc
super
OceanWolf Jun 25, 2015
92de15e
figure setter
fariza Jun 25, 2015
b619923
Improve MEP22 Tool Searching Structure
OceanWolf Jun 25, 2015
a07e482
adding example file
fariza Jun 25, 2015
2dd8895
super dooper
OceanWolf Jun 26, 2015
ce9c8e7
Revert old example and fix new one.
OceanWolf Jun 26, 2015
5542c5a
Improve MEP22 tool-searching method.
OceanWolf Jun 27, 2015
a975717
MEP22 Save Figure Tool
OceanWolf Jun 27, 2015
ecf1f23
pep8
OceanWolf Jun 27, 2015
4531085
Make ToolConfigureSubplots a generic tool
OceanWolf Jun 28, 2015
87fbd59
Improve flow handling and make it a lot more generic
OceanWolf Jun 28, 2015
f7eb33d
Missing resize method
OceanWolf Jun 28, 2015
0a2aa5c
Convert to new structure for finding tools
OceanWolf Jun 28, 2015
777b162
doc
OceanWolf Jun 29, 2015
468bdd7
Add ExpandableBase
OceanWolf Jun 29, 2015
209af6b
Template Backend plus fix FigManager for non-GUI backends and add gen…
OceanWolf Jun 29, 2015
06686c7
rcParam and Travis
OceanWolf Jul 19, 2015
2d93df8
test always MEP27
OceanWolf Jul 20, 2015
6b15982
Fix FigureManager to allow pyplot to work for non GUI backends
OceanWolf Jul 27, 2015
61f61f6
Fix Gcf.show_all()
OceanWolf Jul 27, 2015
71f4813
doc
OceanWolf Jul 27, 2015
d3064b6
pep8
OceanWolf Jul 27, 2015
2ca898c
remove show_popup
OceanWolf Jul 27, 2015
a567af6
AttributeError
OceanWolf Sep 22, 2015
09fc887
Fixes for MEP27
OceanWolf Aug 3, 2016
f60333d
STY: replace \ with () for line continuation
tacaswell Jun 19, 2017
072c47a
ENH: make MainLoopBase a context manager
tacaswell Jun 19, 2017
214b684
MNT: further simplify MainLoopBase
tacaswell Jun 25, 2017
35838c9
WIP:
tacaswell Jun 27, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Template Backend plus fix FigManager for non-GUI backends and add gen…
…eric focus
  • Loading branch information
OceanWolf authored and tacaswell committed Jun 19, 2017
commit 209af6b1a287960da8108b1fee7f5717e67ea0de
3 changes: 3 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1837,6 +1837,9 @@ def _idle_draw_cntx(self):
def backend(self):
return self._backend

def focus(self):
pass

def is_saving(self):
"""
Returns whether the renderer is in the process of saving
Expand Down
31 changes: 19 additions & 12 deletions lib/matplotlib/backend_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ class FigureManager(cbook.EventEmitter):
"""
def __init__(self, figure, num, **kwargs):
super(FigureManager, self).__init__(**kwargs)
self._backend = get_backend()

self.num = num
self.figure = figure

self._is_gui = hasattr(self._backend, 'Window')
if not self._is_gui:
return

self._backend = get_backend()
self._mainloop = self._backend.MainLoop()
self.window = self._backend.Window('Figure %d' % num)
self.window.mpl_connect('window_destroy_event', self.destroy)

self.figure = figure

w = int(self.figure.bbox.width)
h = int(self.figure.bbox.height)

Expand Down Expand Up @@ -137,7 +141,7 @@ def destroy(self, *args):

# Make sure we run this routine only once for the FigureManager
# This ensures the nasty __del__ fix below works.
if getattr(self, '_destroying', False):
if getattr(self, '_destroying', False) or self._is_gui is False:
return

self._destroying = True
Expand All @@ -157,7 +161,7 @@ def destroy(self, *args):
def show(self):
"""Shows the figure"""
self.window.show()
self.canvas.grab_focus()
self.canvas.focus()

def full_screen_toggle(self):
"""Toggles whether we show fullscreen, alternatively call
Expand Down Expand Up @@ -188,13 +192,16 @@ def backend(self):
return self._backend

def _get_toolbar(self):
# must be inited after the window, drawingArea and figure
# attrs are set
if rcParams['toolbar'] == 'toolmanager':
toolbar = self._backend.Toolbar(self.toolmanager)
else:
toolbar = None
return toolbar
try:
# must be inited after the window, drawingArea and figure
# attrs are set
if rcParams['toolbar'] == 'toolmanager':
toolbar = self._backend.Toolbar(self.toolmanager)
else:
toolbar = None
return toolbar
except:
return None

def show_popup(self, msg):
"""
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backend_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ def init_dialog(self):

w, h = int(tool_fig.bbox.width), int(tool_fig.bbox.height)

self.dialog.add_element(self.tool_canvas, True, 'center')
self.dialog.add_element(self.tool_canvas, 'center')
self.dialog.set_default_size(w, h)

def _window_destroy(self, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def pylab_setup(name=None):
backend_mod = get_backend(name)

# Things we pull in from all backends
new_figure_manager = backend_mod.new_figure_manager
new_figure_manager = getattr(backend_mod, 'new_figure_manager', None)

# image backends like pdf, agg or svg do not need to do anything
# for "show" or "draw_if_interactive", so if they are not defined
Expand Down
3 changes: 3 additions & 0 deletions lib/matplotlib/backends/backend_gtk3.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ def __init__(self, *args, **kwargs):
self._renderer_init()
default_context = GLib.main_context_get_thread_default() or GLib.main_context_default()

def focus(self):
self.grab_focus()

def destroy(self):
#Gtk.DrawingArea.destroy(self)
self.close_event()
Expand Down
72 changes: 24 additions & 48 deletions lib/matplotlib/backends/backend_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Copy this to backend_xxx.py and replace all instances of 'template'
with 'xxx'. Then implement the class methods and functions below, and
add 'xxx' to the switchyard in matplotlib/backends/__init__.py and
'xxx' to the backends list in the validate_backend methon in
'xxx' to the backends list in the validate_backend method in
matplotlib/__init__.py and you're off. You can use your backend with::

import matplotlib
Expand All @@ -25,14 +25,14 @@
plot([1,2,3])
show()

matplotlib also supports external backends, so you can place you can
use any module in your PYTHONPATH with the syntax::
matplotlib also supports external backends, by placing
any module in your PYTHONPATH and then using the syntax::

import matplotlib
matplotlib.use('module://my_backend')

where my_backend.py is your module name. This syntax is also
recognized in the rc file and in the -d argument in pylab, e.g.,::
recognized in the rc file and also with the -d argument in pylab, e.g.,::

python simple_plot.py -dmodule://my_backend

Expand All @@ -48,6 +48,7 @@

matplotlib/backends/backend_your_backend.py
matplotlib/backend_bases.py
matplotlib/backend_managers.py
matplotlib/backends/__init__.py
matplotlib/__init__.py
matplotlib/_pylab_helpers.py
Expand All @@ -68,9 +69,9 @@
import six

import matplotlib
from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
FigureManagerBase, FigureCanvasBase
WindowBase, FigureCanvasBase, MainLoopBase, ToolbarBase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take advantage of the fix to replace the backslash on the previous line by paretheses at the same time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might have gotten lost in my re-basing.

from matplotlib import backend_tools
from matplotlib.figure import Figure
from matplotlib.transforms import Bbox

Expand Down Expand Up @@ -178,41 +179,6 @@ def draw_if_interactive():
"""
pass

def show():
"""
For image backends - is not required
For GUI backends - show() is usually the last line of a pylab script and
tells the backend that it is time to draw. In interactive mode, this may
be a do nothing func. See the GTK backend for an example of how to handle
interactive versus batch mode
"""
for manager in Gcf.get_all_fig_managers():
# do something to display the GUI
pass


def new_figure_manager(num, *args, **kwargs):
"""
Create a new figure manager instance
"""
# if a main-level app must be created, this (and
# new_figure_manager_given_figure) is the usual place to
# do it -- see backend_wx, backend_wxagg and backend_tkagg for
# examples. Not all GUIs require explicit instantiation of a
# main-level app (egg backend_gtk, backend_gtkagg) for pylab
FigureClass = kwargs.pop('FigureClass', Figure)
thisFig = FigureClass(*args, **kwargs)
return new_figure_manager_given_figure(num, thisFig)


def new_figure_manager_given_figure(num, figure):
"""
Create a new figure manager instance for the given figure.
"""
canvas = FigureCanvasTemplate(figure)
manager = FigureManagerTemplate(canvas, num)
return manager


class FigureCanvasTemplate(FigureCanvasBase):
"""
Expand Down Expand Up @@ -258,19 +224,29 @@ def print_foo(self, filename, *args, **kwargs):
def get_default_filetype(self):
return 'foo'

class FigureManagerTemplate(FigureManagerBase):
"""
Wrap everything up into a window for the pylab interface

For non interactive backends, the base class does all the work
"""
class WindowTemplate(WindowBase):
def show(self):
pass


class RubberbandTemplate(backend_tools.RubberbandBase):
pass


class SetCursorTemplate(backend_tools.SetCursorBase):
pass

########################################################################
#
# Now just provide the standard names that backend.__init__ is expecting
# Now just provide the standard names that backend.__init__ expects
#
########################################################################

FigureCanvas = FigureCanvasTemplate
FigureManager = FigureManagerTemplate

# Needed for a GUI
MainLoop = MainLoopBase
Window = WindowTemplate
ToolRubberband = RubberbandTemplate
ToolSetCursor = SetCursorTemplate