|
From: <ef...@us...> - 2010-07-16 20:45:00
|
Revision: 8562
http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8562&view=rev
Author: efiring
Date: 2010-07-16 20:44:52 +0000 (Fri, 16 Jul 2010)
Log Message:
-----------
backends: factored out most of the show() code into ShowBase class.
Also fixed various fltkagg problems.
Modified Paths:
--------------
branches/v1_0_maint/lib/matplotlib/backend_bases.py
branches/v1_0_maint/lib/matplotlib/backends/backend_cocoaagg.py
branches/v1_0_maint/lib/matplotlib/backends/backend_fltkagg.py
branches/v1_0_maint/lib/matplotlib/backends/backend_gtk.py
branches/v1_0_maint/lib/matplotlib/backends/backend_macosx.py
branches/v1_0_maint/lib/matplotlib/backends/backend_qt.py
branches/v1_0_maint/lib/matplotlib/backends/backend_qt4.py
branches/v1_0_maint/lib/matplotlib/backends/backend_tkagg.py
branches/v1_0_maint/lib/matplotlib/backends/backend_wx.py
Modified: branches/v1_0_maint/lib/matplotlib/backend_bases.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backend_bases.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backend_bases.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -21,6 +21,11 @@
pressed, x and y locations in pixel and
:class:`~matplotlib.axes.Axes` coordinates.
+:class:`ShowBase`
+ The base class for the Show class of each interactive backend;
+ the 'show' callable is then set to Show.__call__, inherited from
+ ShowBase.
+
"""
from __future__ import division
@@ -33,6 +38,8 @@
import matplotlib.widgets as widgets
#import matplotlib.path as path
from matplotlib import rcParams
+from matplotlib import is_interactive
+from matplotlib._pylab_helpers import Gcf
from matplotlib.transforms import Bbox, TransformedBbox, Affine2D
import cStringIO
@@ -49,7 +56,37 @@
_backend_d[format] = backend_class
+class ShowBase(object):
+ """
+ Simple base class to generate a show() callable in backends.
+ Subclass must override mainloop() method.
+ """
+ def __call__(self):
+ """
+ Show all figures.
+ """
+ managers = Gcf.get_all_fig_managers()
+ if not managers:
+ return
+
+ for manager in managers:
+ manager.show()
+
+ try:
+ if not self._needmain: # ipython flag
+ return
+ except AttributeError:
+ pass
+
+ if not is_interactive():
+ self.mainloop()
+
+ def mainloop(self):
+ pass
+
+
+
class RendererBase:
"""An abstract base class to handle drawing/rendering operations.
Modified: branches/v1_0_maint/lib/matplotlib/backends/backend_cocoaagg.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backends/backend_cocoaagg.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backends/backend_cocoaagg.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -30,6 +30,8 @@
import matplotlib
from matplotlib.figure import Figure
from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase
+from matplotlib.backend_bases import ShowBase
+
from backend_agg import FigureCanvasAgg
from matplotlib._pylab_helpers import Gcf
@@ -41,10 +43,24 @@
canvas = FigureCanvasCocoaAgg(thisFig)
return FigureManagerCocoaAgg(canvas, num)
-def show():
- for manager in Gcf.get_all_fig_managers():
- manager.show()
+## Below is the original show() function:
+#def show():
+# for manager in Gcf.get_all_fig_managers():
+# manager.show()
+#
+## It appears that this backend is unusual in having a separate
+## run function invoked for each figure, instead of a single
+## mainloop. Presumably there is no blocking at all.
+##
+## Using the Show class below should cause no difference in
+## behavior.
+class Show(ShowBase):
+ def mainloop(self):
+ pass
+
+show = Show()
+
def draw_if_interactive():
if matplotlib.is_interactive():
figManager = Gcf.get_active()
Modified: branches/v1_0_maint/lib/matplotlib/backends/backend_fltkagg.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backends/backend_fltkagg.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backends/backend_fltkagg.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -24,24 +24,14 @@
from matplotlib.backend_bases import \
RendererBase, GraphicsContextBase, FigureManagerBase, FigureCanvasBase,\
NavigationToolbar2, cursors
+from matplotlib.backend_bases import ShowBase
+
+
from matplotlib.figure import Figure
from matplotlib._pylab_helpers import Gcf
import matplotlib.backends.windowing as windowing
from matplotlib.widgets import SubplotTool
-
-import thread,time
-
-Fl_running=thread.allocate_lock()
-def Fltk_run_interactive():
- global Fl_running
- if Fl_running.acquire(0):
- while True:
- Fltk.Fl.check()
- time.sleep(0.005)
- else:
- print "fl loop already running"
-
# the true dots per inch on the screen; should be display dependent
# see http://groups.google.com/groups?q=screen+dpi+x11&hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&selm=7077.26e81ad5%40swift.cs.tcd.ie&rnum=5 for some info about screen dpi
PIXELS_PER_INCH = 75
@@ -75,30 +65,13 @@
if figManager is not None:
figManager.canvas.draw()
+class Show(ShowBase):
+ def mainloop(self):
+ Fltk.Fl.run()
-def ishow():
- """
- Show all the figures and enter the fltk mainloop in another thread
- This allows to keep hand in interractive python session
- Warning: does not work under windows
- This should be the last line of your script
- """
- for manager in Gcf.get_all_fig_managers():
- manager.show()
- if show._needmain:
- thread.start_new_thread(Fltk_run_interactive,())
- show._needmain = False
+show = Show()
-def show():
- """
- Show all the figures and enter the fltk mainloop
- This should be the last line of your script
- """
- for manager in Gcf.get_all_fig_managers():
- manager.show()
- Fltk.Fl.run()
-
def new_figure_manager(num, *args, **kwargs):
"""
Create a new figure manager instance
@@ -249,8 +222,9 @@
FigureCanvasBase.stop_event_loop_default(self)
stop_event_loop.__doc__=FigureCanvasBase.stop_event_loop_default.__doc__
-def destroy_figure(ptr,figman):
+def destroy_figure(ptr, figman):
figman.window.hide()
+ Fltk.Fl.wait(0) # This is needed to make the last figure vanish.
Gcf.destroy(figman._num)
class FigureManagerFltkAgg(FigureManagerBase):
@@ -301,6 +275,11 @@
self.canvas.draw()
self.window.redraw()
+ def destroy(self):
+ self.window.hide()
+ Fltk.Fl.wait(0) # This is needed to make the last figure vanish.
+ Gcf.destroy(self._num)
+
def set_window_title(self, title):
self.window_title=title
self.window.label(title)
Modified: branches/v1_0_maint/lib/matplotlib/backends/backend_gtk.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backends/backend_gtk.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backends/backend_gtk.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -20,10 +20,11 @@
_new_tooltip_api = (gtk.pygtk_version[1] >= 12)
import matplotlib
-from matplotlib import verbose
from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors, TimerBase
+from matplotlib.backend_bases import ShowBase
+
from matplotlib.backends.backend_gdk import RendererGDK, FigureCanvasGDK
from matplotlib.cbook import is_string_like, is_writable_file_like
from matplotlib.colors import colorConverter
@@ -65,17 +66,12 @@
figManager.canvas.draw_idle()
-def show(mainloop=True):
- """
- Show all the figures and enter the gtk main loop
- This should be the last line of your script
- """
- for manager in Gcf.get_all_fig_managers():
- manager.window.show()
+class Show(ShowBase):
+ def mainloop(self):
+ if gtk.main_level() == 0:
+ gtk.main()
- if mainloop and gtk.main_level() == 0 and \
- len(Gcf.get_all_fig_managers())>0:
- gtk.main()
+show = Show()
def new_figure_manager(num, *args, **kwargs):
"""
Modified: branches/v1_0_maint/lib/matplotlib/backends/backend_macosx.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backends/backend_macosx.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backends/backend_macosx.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -7,6 +7,8 @@
from matplotlib._pylab_helpers import Gcf
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
FigureManagerBase, FigureCanvasBase, NavigationToolbar2
+from matplotlib.backend_bases import ShowBase
+
from matplotlib.cbook import maxdict
from matplotlib.figure import Figure
from matplotlib.path import Path
@@ -20,19 +22,16 @@
import matplotlib
from matplotlib.backends import _macosx
-def show():
- """Show all the figures and enter the Cocoa mainloop.
- This function will not return until all windows are closed or
- the interpreter exits."""
- # Having a Python-level function "show" wrapping the built-in
- # function "show" in the _macosx extension module allows us to
- # to add attributes to "show". This is something ipython does.
- _macosx.show()
+class Show(ShowBase):
+ def mainloop(self):
+ _macosx.show()
+show = Show()
+
class RendererMac(RendererBase):
"""
The renderer handles drawing/rendering operations. Most of the renderer's
- methods forwards the command to the renderer's graphics context. The
+ methods forward the command to the renderer's graphics context. The
renderer does not wrap a C object and is written in pure Python.
"""
Modified: branches/v1_0_maint/lib/matplotlib/backends/backend_qt.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backends/backend_qt.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backends/backend_qt.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -8,6 +8,8 @@
from matplotlib.cbook import is_string_like, onetrue
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, cursors
+from matplotlib.backend_bases import ShowBase
+
from matplotlib._pylab_helpers import Gcf
from matplotlib.figure import Figure
from matplotlib.mathtext import MathTextParser
@@ -54,24 +56,14 @@
_create_qApp.qAppCreatedHere = False
-def show():
- """
- Show all the figures and enter the qt main loop
- This should be the last line of your script
- """
- for manager in Gcf.get_all_fig_managers():
- manager.window.show()
+class Show(ShowBase):
+ def mainloop(self):
+ if _create_qApp.qAppCreatedHere:
+ qt.qApp.exec_loop()
- if DEBUG: print 'Inside show'
+show = Show()
- figManager = Gcf.get_active()
- if figManager != None:
- figManager.canvas.draw()
- if _create_qApp.qAppCreatedHere:
- qt.qApp.exec_loop()
-
-
def new_figure_manager( num, *args, **kwargs ):
"""
Create a new figure manager instance
@@ -281,6 +273,9 @@
'set the canvas size in pixels'
self.window.resize(width, height)
+ def show(self):
+ self.window.show()
+
def destroy( self, *args ):
if self.window._destroying: return
self.window._destroying = True
@@ -359,6 +354,7 @@
# reference holder for subplots_adjust window
self.adj_window = None
+
def destroy( self ):
for text, tooltip_text, image_file, callback in self.toolitems:
if text is not None:
Modified: branches/v1_0_maint/lib/matplotlib/backends/backend_qt4.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backends/backend_qt4.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backends/backend_qt4.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -9,6 +9,8 @@
from matplotlib.backend_bases import RendererBase, GraphicsContextBase, \
FigureManagerBase, FigureCanvasBase, NavigationToolbar2, IdleEvent, \
cursors, TimerBase
+from matplotlib.backend_bases import ShowBase
+
from matplotlib._pylab_helpers import Gcf
from matplotlib.figure import Figure
from matplotlib.mathtext import MathTextParser
@@ -56,24 +58,14 @@
_create_qApp.qAppCreatedHere = False
-def show():
- """
- Show all the figures and enter the qt main loop
- This should be the last line of your script
- """
- for manager in Gcf.get_all_fig_managers():
- manager.window.show()
+class Show(ShowBase):
+ def mainloop(self):
+ if _create_qApp.qAppCreatedHere:
+ QtGui.qApp.exec_()
- if DEBUG: print 'Inside show'
+show = Show()
- figManager = Gcf.get_active()
- if figManager != None:
- figManager.canvas.draw()
- if _create_qApp.qAppCreatedHere:
- QtGui.qApp.exec_()
-
-
def new_figure_manager( num, *args, **kwargs ):
"""
Create a new figure manager instance
@@ -370,6 +362,9 @@
'set the canvas size in pixels'
self.window.resize(width, height)
+ def show(self):
+ self.window.show()
+
def destroy( self, *args ):
if self.window._destroying: return
self.window._destroying = True
Modified: branches/v1_0_maint/lib/matplotlib/backends/backend_tkagg.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backends/backend_tkagg.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backends/backend_tkagg.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -18,9 +18,10 @@
from matplotlib.backend_bases import RendererBase, GraphicsContextBase
from matplotlib.backend_bases import FigureManagerBase, FigureCanvasBase
from matplotlib.backend_bases import NavigationToolbar2, cursors, TimerBase
+from matplotlib.backend_bases import ShowBase
+from matplotlib._pylab_helpers import Gcf
from matplotlib.figure import Figure
-from matplotlib._pylab_helpers import Gcf
from matplotlib.widgets import SubplotTool
@@ -63,22 +64,12 @@
if figManager is not None:
figManager.show()
-
-def show():
- """
- Show all figures.
-
- """
- for manager in Gcf.get_all_fig_managers():
- manager.show()
- try:
- if not show._needmain: # might have been added by ipython
- return
- except AttributeError:
- pass
- if not matplotlib.is_interactive():
+class Show(ShowBase):
+ def mainloop(self):
Tk.mainloop()
+show = Show()
+
def new_figure_manager(num, *args, **kwargs):
"""
Create a new figure manager instance
Modified: branches/v1_0_maint/lib/matplotlib/backends/backend_wx.py
===================================================================
--- branches/v1_0_maint/lib/matplotlib/backends/backend_wx.py 2010-07-16 18:45:49 UTC (rev 8561)
+++ branches/v1_0_maint/lib/matplotlib/backends/backend_wx.py 2010-07-16 20:44:52 UTC (rev 8562)
@@ -24,6 +24,8 @@
import sys, os, os.path, math, StringIO, weakref, warnings
import numpy as np
+
+
# Debugging settings here...
# Debug level set here. If the debug level is less than 5, information
# messages (progressively more info for lower value) are printed. In addition,
@@ -117,6 +119,8 @@
from matplotlib.backend_bases import RendererBase, GraphicsContextBase,\
FigureCanvasBase, FigureManagerBase, NavigationToolbar2, \
cursors, TimerBase
+from matplotlib.backend_bases import ShowBase
+
from matplotlib._pylab_helpers import Gcf
from matplotlib.artist import Artist
from matplotlib.cbook import exception_to_str, is_string_like, is_writable_file_like
@@ -1394,24 +1398,16 @@
if figManager is not None:
figManager.canvas.draw_idle()
-def show():
- """
- Show all the figures and enter the wx main loop.
- This should be the last line of your script.
- """
- DEBUG_MSG("show()", 3, None)
+class Show(ShowBase):
+ def mainloop(self):
+ needmain = not wx.App.IsMainLoopRunning()
+ if needmain:
+ wxapp = wx.GetApp()
+ if wxapp is not None:
+ wxapp.MainLoop()
- for figwin in Gcf.get_all_fig_managers():
- figwin.frame.Show()
+show = Show()
- needmain = not wx.App.IsMainLoopRunning()
- if needmain and len(Gcf.get_all_fig_managers())>0:
- wxapp = wx.GetApp()
- if wxapp is not None:
- wxapp.MainLoop()
- # start the wxPython gui event if there is not already one running
-
-
def new_figure_manager(num, *args, **kwargs):
"""
Create a new figure manager instance
@@ -1555,6 +1551,8 @@
# attach a show method to the figure
self.canvas.figure.show = showfig
+ def show(self):
+ self.frame.Show()
def destroy(self, *args):
DEBUG_MSG("destroy()", 1, self)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|