Revision: 5798
          http://matplotlib.svn.sourceforge.net/matplotlib/?rev=5798&view=rev
Author:   jdh2358
Date:     2008-07-21 09:50:36 +0000 (Mon, 21 Jul 2008)

Log Message:
-----------
Added Gael's backend fallback patch

Modified Paths:
--------------
    trunk/matplotlib/examples/pylab_examples/scatter_demo.py
    trunk/matplotlib/lib/matplotlib/backends/__init__.py
    trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py
    trunk/matplotlib/lib/matplotlib/pyplot.py
    trunk/matplotlib/lib/matplotlib/rcsetup.py
    trunk/matplotlib/matplotlibrc.template

Modified: trunk/matplotlib/examples/pylab_examples/scatter_demo.py
===================================================================
--- trunk/matplotlib/examples/pylab_examples/scatter_demo.py    2008-07-21 
00:22:19 UTC (rev 5797)
+++ trunk/matplotlib/examples/pylab_examples/scatter_demo.py    2008-07-21 
09:50:36 UTC (rev 5798)
@@ -6,5 +6,6 @@
 y = 0.9*rand(N)
 area = pi*(10 * rand(N))**2 # 0 to 10 point radiuses
 scatter(x,y,s=area, marker='^', c='r')
-
+savefig('test.ps')
+savefig('test.pdf')
 show()

Modified: trunk/matplotlib/lib/matplotlib/backends/__init__.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/__init__.py        2008-07-21 
00:22:19 UTC (rev 5797)
+++ trunk/matplotlib/lib/matplotlib/backends/__init__.py        2008-07-21 
09:50:36 UTC (rev 5798)
@@ -23,7 +23,9 @@
     # Things we pull in from all backends
     new_figure_manager = backend_mod.new_figure_manager
 
-
+    # 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
+    # by the backend, just do nothing
     def do_nothing(*args, **kwargs): pass
     backend_version = getattr(backend_mod,'backend_version', 'unknown')
     show = getattr(backend_mod, 'show', do_nothing)

Modified: trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py     2008-07-21 
00:22:19 UTC (rev 5797)
+++ trunk/matplotlib/lib/matplotlib/backends/backend_gtk.py     2008-07-21 
09:50:36 UTC (rev 5798)
@@ -67,7 +67,8 @@
     for manager in Gcf.get_all_fig_managers():
         manager.window.show()
 
-    if mainloop and gtk.main_level() == 0:
+    if mainloop and gtk.main_level() == 0 and \
+                            len(Gcf.get_all_fig_managers())>0:
         gtk.main()
 
 def new_figure_manager(num, *args, **kwargs):

Modified: trunk/matplotlib/lib/matplotlib/pyplot.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/pyplot.py   2008-07-21 00:22:19 UTC (rev 
5797)
+++ trunk/matplotlib/lib/matplotlib/pyplot.py   2008-07-21 09:50:36 UTC (rev 
5798)
@@ -1,12 +1,13 @@
 import sys
 
 import matplotlib
-from matplotlib import _pylab_helpers
+from matplotlib import _pylab_helpers, interactive
 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
 from matplotlib.figure import Figure, figaspect
 from matplotlib.backend_bases import FigureCanvasBase
 from matplotlib.image import imread as _imread
 from matplotlib import rcParams, rcParamsDefault, get_backend
+from matplotlib.rcsetup import interactive_bk as _interactive_bk
 from matplotlib.artist import getp, get, Artist
 from matplotlib.artist import setp as _setp
 from matplotlib.axes import Axes
@@ -32,7 +33,42 @@
            MaxNLocator
 
 
+## Backend detection ##
+def _backend_selection():
+    """ If rcParams['backend_fallback'] is true, check to see if the
+        current backend is compatible with the current running event
+        loop, and if not switches to a compatible one.
+    """
+    backend = rcParams['backend']
+    if not rcParams['backend_fallback'] or \
+                     backend not in _interactive_bk:
+        return
+    is_agg_backend = rcParams['backend'].endswith('Agg')
+    if 'wx' in sys.modules and not backend in ('WX', 'WXAgg'):
+        import wx
+        if wx.App.IsMainLoopRunning():
+            rcParams['backend'] = 'wx' + 'Agg' * is_agg_backend
+    elif 'qt' in sys.modules and not backend == 'QtAgg':
+        import qt
+        if not qt.qApp.startingUp():
+            # The mainloop is running.
+            rcParams['backend'] = 'qtAgg'
+    elif 'PyQt4.QtCore' in sys.modules and not backend == 'Qt4Agg':
+        import PyQt4.QtGui
+        if not PyQt4.QtGui.qApp.startingUp():
+            # The mainloop is running.
+            rcParams['backend'] = 'qt4Agg'
+    elif 'gtk' in sys.modules and not backend in ('GTK', 'GTKAgg',
+                                                            'GTKCairo'):
+        import gobject
+        if gobject.MainLoop().is_running():
+            rcParams['backend'] = 'gtk' + 'Agg' * is_agg_backend
+    elif 'Tkinter' in sys.modules and not backend == 'TkAgg':
+        #import Tkinter
+        pass #what if anything do we need to do for tkinter?
 
+_backend_selection()
+
 ## Global ##
 
 from matplotlib.backends import pylab_setup

Modified: trunk/matplotlib/lib/matplotlib/rcsetup.py
===================================================================
--- trunk/matplotlib/lib/matplotlib/rcsetup.py  2008-07-21 00:22:19 UTC (rev 
5797)
+++ trunk/matplotlib/lib/matplotlib/rcsetup.py  2008-07-21 09:50:36 UTC (rev 
5798)
@@ -305,6 +305,7 @@
 # a map from key -> value, converter
 defaultParams = {
     'backend'           : ['Agg', validate_backend], # agg is certainly present
+    'backend_fallback'  : [True, validate_bool], # agg is certainly present
     'numerix'           : ['numpy', validate_numerix],
     'maskedarray'       : [False, validate_bool],
     'toolbar'           : ['toolbar2', validate_toolbar],

Modified: trunk/matplotlib/matplotlibrc.template
===================================================================
--- trunk/matplotlib/matplotlibrc.template      2008-07-21 00:22:19 UTC (rev 
5797)
+++ trunk/matplotlib/matplotlibrc.template      2008-07-21 09:50:36 UTC (rev 
5798)
@@ -26,6 +26,11 @@
 # to the module name (which must be in the PYTHONPATH) as
 # 'module://my_backend'
 backend      : %(backend)s
+
+# if you are runing pyplot inside a GUI and your backend choice
+# conflicts, we will automatically try and find a compatible one for
+# you if backend_fallback is True
+#backend_fallback: True
 numerix      : %(numerix)s  # numpy, Numeric or numarray
 #maskedarray : False       # True to use external maskedarray module
                            # instead of numpy.ma; this is a temporary


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins

Reply via email to