On Sat, Jul 19, 2008 at 08:05:52AM +0200, Gael Varoquaux wrote:
> On Sat, Jul 19, 2008 at 07:31:19AM +0200, Gael Varoquaux wrote:
> > - show starts a mainloop and is blocking even if there are not windows
> > open. This basically leads to a deadlock where the user cannot
> > interrupt the mainloop. This can probably be easily fixed, and I'll
> > look into it.
> It turns out it was only in the GTK backend, and quite trivial to
> correct. Attached is a new patch, including this correction.
Could somebody review this patch and possibly check it in? It is not
perfect but is, IMHO, a good start that works on everything I have thrown
at it. I have not been able to abstract in more by pushing the relevant
code in the backends, as in introduces coupling that induces the
selection of the wrong backend.
Debian freeze is close, and I would really like this to go in before. We
do need to work on a vendor registry for the long run, to allow
application builders to override this mechanism on a per-application
basis. However to be able to have a roper view of what this registry, I
need to wip up an app to use it. I am busy doing that, but it won't be
ready before Debian freeze, whereas the attached patch fixes all my
problems.
Cheers,
Gaƫl
Index: pyplot.py
===================================================================
--- pyplot.py (revision 5791)
+++ pyplot.py (working copy)
@@ -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,41 @@
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
+_backend_selection()
+
## Global ##
from matplotlib.backends import pylab_setup
Index: backends/backend_gtk.py
===================================================================
--- backends/backend_gtk.py (revision 5791)
+++ backends/backend_gtk.py (working copy)
@@ -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):
Index: rcsetup.py
===================================================================
--- rcsetup.py (revision 5791)
+++ rcsetup.py (working copy)
@@ -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],
-------------------------------------------------------------------------
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-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel