From 89435dd8e8beaab4ed2a808786c8d827b897f076 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Thu, 16 Sep 2010 00:17:09 +0000 Subject: [PATCH] Removed unused _wxagg extension. svn path=/trunk/matplotlib/; revision=8702 --- CHANGELOG | 2 + lib/matplotlib/backends/backend_wxagg.py | 101 +-------- setup.cfg.template | 8 - setup.py | 15 +- setupext.py | 115 ---------- src/_wxagg.cpp | 273 ----------------------- 6 files changed, 6 insertions(+), 508 deletions(-) delete mode 100644 src/_wxagg.cpp diff --git a/CHANGELOG b/CHANGELOG index 3f941a010454..471a9d55194d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +2010-09-15 Remove unused _wxagg extension. - EF + 2010-08-25 Add new framework for doing animations with examples.- RM 2010-08-21 Remove unused and inappropriate methods from Tick classes: diff --git a/lib/matplotlib/backends/backend_wxagg.py b/lib/matplotlib/backends/backend_wxagg.py index a1f406f0fb74..de2b016bb319 100644 --- a/lib/matplotlib/backends/backend_wxagg.py +++ b/lib/matplotlib/backends/backend_wxagg.py @@ -128,78 +128,12 @@ def new_figure_manager(num, *args, **kwargs): return figmgr -# -# agg/wxPython image conversion functions (wxPython <= 2.6) -# - -def _py_convert_agg_to_wx_image(agg, bbox): - """ - Convert the region of the agg buffer bounded by bbox to a wx.Image. If - bbox is None, the entire buffer is converted. - - Note: agg must be a backend_agg.RendererAgg instance. - """ - image = wx.EmptyImage(int(agg.width), int(agg.height)) - image.SetData(agg.tostring_rgb()) - - if bbox is None: - # agg => rgb -> image - return image - else: - # agg => rgb -> image => bitmap => clipped bitmap => image - return wx.ImageFromBitmap(_clipped_image_as_bitmap(image, bbox)) - - -def _py_convert_agg_to_wx_bitmap(agg, bbox): - """ - Convert the region of the agg buffer bounded by bbox to a wx.Bitmap. If - bbox is None, the entire buffer is converted. - - Note: agg must be a backend_agg.RendererAgg instance. - """ - if bbox is None: - # agg => rgb -> image => bitmap - return wx.BitmapFromImage(_py_convert_agg_to_wx_image(agg, None)) - else: - # agg => rgb -> image => bitmap => clipped bitmap - return _clipped_image_as_bitmap( - _py_convert_agg_to_wx_image(agg, None), - bbox) - - -def _clipped_image_as_bitmap(image, bbox): - """ - Convert the region of a wx.Image bounded by bbox to a wx.Bitmap. - """ - l, b, width, height = bbox.bounds - r = l + width - t = b + height - - srcBmp = wx.BitmapFromImage(image) - srcDC = wx.MemoryDC() - srcDC.SelectObject(srcBmp) - - destBmp = wx.EmptyBitmap(int(width), int(height)) - destDC = wx.MemoryDC() - destDC.SelectObject(destBmp) - - destDC.BeginDrawing() - x = int(l) - y = int(image.GetHeight() - t) - destDC.Blit(0, 0, int(width), int(height), srcDC, x, y) - destDC.EndDrawing() - - srcDC.SelectObject(wx.NullBitmap) - destDC.SelectObject(wx.NullBitmap) - - return destBmp - # # agg/wxPython image conversion functions (wxPython >= 2.8) # -def _py_WX28_convert_agg_to_wx_image(agg, bbox): +def _convert_agg_to_wx_image(agg, bbox): """ Convert the region of the agg buffer bounded by bbox to a wx.Image. If bbox is None, the entire buffer is converted. @@ -216,7 +150,7 @@ def _py_WX28_convert_agg_to_wx_image(agg, bbox): return wx.ImageFromBitmap(_WX28_clipped_agg_as_bitmap(agg, bbox)) -def _py_WX28_convert_agg_to_wx_bitmap(agg, bbox): +def _convert_agg_to_wx_bitmap(agg, bbox): """ Convert the region of the agg buffer bounded by bbox to a wx.Bitmap. If bbox is None, the entire buffer is converted. @@ -262,34 +196,3 @@ def _WX28_clipped_agg_as_bitmap(agg, bbox): return destBmp - -def _use_accelerator(state): - """ - Enable or disable the WXAgg accelerator, if it is present and is also - compatible with whatever version of wxPython is in use. - """ - global _convert_agg_to_wx_image - global _convert_agg_to_wx_bitmap - - if getattr(wx, '__version__', '0.0')[0:3] < '2.8': - # wxPython < 2.8, so use the C++ accelerator or the Python routines - if state and _wxagg is not None: - _convert_agg_to_wx_image = _wxagg.convert_agg_to_wx_image - _convert_agg_to_wx_bitmap = _wxagg.convert_agg_to_wx_bitmap - else: - _convert_agg_to_wx_image = _py_convert_agg_to_wx_image - _convert_agg_to_wx_bitmap = _py_convert_agg_to_wx_bitmap - else: - # wxPython >= 2.8, so use the accelerated Python routines - _convert_agg_to_wx_image = _py_WX28_convert_agg_to_wx_image - _convert_agg_to_wx_bitmap = _py_WX28_convert_agg_to_wx_bitmap - - -# try to load the WXAgg accelerator -try: - import _wxagg -except ImportError: - _wxagg = None - -# if it's present, use it -_use_accelerator(True) diff --git a/setup.cfg.template b/setup.cfg.template index 6ea8cfe73565..1dd1ca1cbb14 100644 --- a/setup.cfg.template +++ b/setup.cfg.template @@ -58,7 +58,6 @@ tag_svn_revision = 1 #gtk = False #gtkagg = False #tkagg = False -#wxagg = False #macosx = False [rc_options] @@ -74,10 +73,3 @@ tag_svn_revision = 1 # #backend = Agg # -# The numerix module was historically used to provide -# compatibility between the Numeric, numarray, and NumPy array -# packages. Now that NumPy has emerge as the universal array -# package for python, numerix is not really necessary and is -# maintained to provide backward compatibility. Do not change -# this unless you have a compelling reason to do so. -#numerix = numpy diff --git a/setup.py b/setup.py index b23499033542..6510f2538472 100644 --- a/setup.py +++ b/setup.py @@ -33,12 +33,12 @@ import glob from distutils.core import setup -from setupext import build_agg, build_gtkagg, build_tkagg, build_wxagg,\ +from setupext import build_agg, build_gtkagg, build_tkagg,\ build_macosx, build_ft2font, build_image, build_windowing, build_path, \ build_contour, build_delaunay, build_nxutils, build_gdk, \ build_ttconv, print_line, print_status, print_message, \ print_raw, check_for_freetype, check_for_libpng, check_for_gtk, \ - check_for_tk, check_for_wx, check_for_macosx, check_for_numpy, \ + check_for_tk, check_for_macosx, check_for_numpy, \ check_for_qt, check_for_qt4, check_for_cairo, \ check_provide_pytz, check_provide_dateutil,\ check_for_dvipng, check_for_ghostscript, check_for_latex, \ @@ -156,17 +156,6 @@ def chop_package(fname): build_tkagg(ext_modules, packages) rc['backend'] = 'TkAgg' -if options['build_wxagg']: - if check_for_wx() or (options['build_wxagg'] is True): - options['build_agg'] = 1 - import wx - if getattr(wx, '__version__', '0.0')[0:3] < '2.8' : - build_wxagg(ext_modules, packages) - wxagg_backend_status = "yes" - else: - print_message("WxAgg extension not required for wxPython >= 2.8") - rc['backend'] = 'WXAgg' - hasgtk = check_for_gtk() if options['build_gtk']: if hasgtk or (options['build_gtk'] is True): diff --git a/setupext.py b/setupext.py index 2c6418850b27..9ee3453e9932 100644 --- a/setupext.py +++ b/setupext.py @@ -102,7 +102,6 @@ BUILT_IMAGE = False BUILT_MACOSX = False BUILT_TKAGG = False -BUILT_WXAGG = False BUILT_WINDOWING = False BUILT_CONTOUR = False BUILT_DELAUNAY = False @@ -127,7 +126,6 @@ 'build_gtk': 'auto', 'build_gtkagg': 'auto', 'build_tkagg': 'auto', - 'build_wxagg': 'auto', 'build_macosx': 'auto', 'build_image': True, 'build_windowing': True, @@ -166,9 +164,6 @@ try: options['build_tkagg'] = config.getboolean("gui_support", "tkagg") except: options['build_tkagg'] = 'auto' - try: options['build_wxagg'] = config.getboolean("gui_support", "wxagg") - except: options['build_wxagg'] = 'auto' - try: options['build_macosx'] = config.getboolean("gui_support", "macosx") except: options['build_macosx'] = 'auto' @@ -710,97 +705,6 @@ def add_pygtk_flags(module): if sys.platform == 'win32' and win32_compiler == 'msvc' and 'm' in module.libraries: module.libraries.remove('m') - -def check_for_wx(): - gotit = False - explanation = None - try: - import wx - except ImportError: - explanation = 'wxPython not found' - else: - if getattr(wx, '__version__', '0.0')[0:3] >= '2.8': - print_status("wxPython", wx.__version__) - return True - elif sys.platform == 'win32' and win32_compiler == 'mingw32': - explanation = "The wxAgg extension can not be built using the mingw32 compiler on Windows, since the default wxPython binary is built using MS Visual Studio" - else: - wxconfig = find_wx_config() - if wxconfig is None: - explanation = """ -WXAgg's accelerator requires `wx-config'. - -The `wx-config\' executable could not be located in any directory of the -PATH environment variable. If you want to build WXAgg, and wx-config is -in some other location or has some other name, set the WX_CONFIG -environment variable to the full path of the executable like so: - -export WX_CONFIG=/usr/lib/wxPython-2.6.1.0-gtk2-unicode/bin/wx-config -""" - elif not check_wxpython_broken_macosx104_version(wxconfig): - explanation = 'WXAgg\'s accelerator not building because a broken wxPython (installed by Apple\'s Mac OS X) was found.' - else: - gotit = True - - if gotit: - module = Extension("test", []) - add_wx_flags(module, wxconfig) - if not find_include_file( - module.include_dirs, - os.path.join("wx", "wxPython", "wxPython.h")): - explanation = ("Could not find wxPython headers in any of %s" % - ", ".join(["'%s'" % x for x in module.include_dirs])) - - if gotit: - print_status("wxPython", wx.__version__) - else: - print_status("wxPython", "no") - if explanation is not None: - print_message(explanation) - return gotit - -def find_wx_config(): - """If the WX_CONFIG environment variable has been set, returns it value. - Otherwise, search for `wx-config' in the PATH directories and return the - first match found. Failing that, return None. - """ - - wxconfig = os.getenv('WX_CONFIG') - if wxconfig is not None: - return wxconfig - - path = os.getenv('PATH') or '' - for dir in path.split(':'): - wxconfig = os.path.join(dir, 'wx-config') - if os.path.exists(wxconfig): - return wxconfig - - return None - -def check_wxpython_broken_macosx104_version(wxconfig): - """Determines if we're using a broken wxPython installed by Mac OS X 10.4""" - if sys.platform == 'darwin': - if wxconfig == '/usr/bin/wx-config': - version_full = getoutput(wxconfig + ' --version-full') - if version_full == '2.5.3.1': - return False - return True - -def add_wx_flags(module, wxconfig): - """ - Add the module flags to build extensions which use wxPython. - """ - - if sys.platform == 'win32': # just added manually - wxlibs = ['wxexpath', 'wxjpegh', 'wxmsw26uh', - 'wxmsw26uh_animate', 'wxmsw26uh_gizmos', 'wxmsw26uh_gizmos_xrc', - 'wxmsw26uh_gl', 'wxmsw26uh_stc', 'wxpngh', 'wxregexuh', 'wxtiffh', 'wxzlibh'] - module.libraries.extend(wxlibs) - module.libraries.extend(wxlibs) - return - - get_pkgconfig(module, '', flags='--cppflags --libs', pkg_config_exec='wx-config') - # Make sure you use the Tk version given by Tkinter.TkVersion # or else you'll build for a wrong version of the Tcl # interpreter (leading to nasty segfaults). @@ -1200,25 +1104,6 @@ def build_tkagg(ext_modules, packages): BUILT_TKAGG = True -def build_wxagg(ext_modules, packages): - global BUILT_WXAGG - if BUILT_WXAGG: - return - - deps = ['src/_wxagg.cpp', 'src/mplutils.cpp'] - deps.extend(glob.glob('CXX/*.cxx')) - deps.extend(glob.glob('CXX/*.c')) - - module = Extension('matplotlib.backends._wxagg', deps) - - add_agg_flags(module) - add_ft2font_flags(module) - wxconfig = find_wx_config() - add_wx_flags(module, wxconfig) - - ext_modules.append(module) - BUILT_WXAGG = True - def build_macosx(ext_modules, packages): global BUILT_MACOSX if BUILT_MACOSX: return # only build it if you you haven't already diff --git a/src/_wxagg.cpp b/src/_wxagg.cpp deleted file mode 100644 index 1586c4f96081..000000000000 --- a/src/_wxagg.cpp +++ /dev/null @@ -1,273 +0,0 @@ -// File: _wxagg.cpp -// Purpose: Accelerate WXAgg by doing the agg->wxWidgets conversions in C++. -// Author: Ken McIvor -// -// Copyright 2005 Illinois Institute of Technology -// Derived from `_gtkagg.cpp', Copyright 2004-2005 John Hunter -// -// See the file "LICENSE" for information on usage and redistribution -// of this file, and for a DISCLAIMER OF ALL WARRANTIES. - - -// TODO: -// * Better type checking. -// -// * Make the `bbox' argument optional. -// -// * Determine if there are any thread-safety issues with this implementation. -// -// * Perform some AGG kung-fu to let us slice a region out of a -// rendering_buffer and convert it from RGBA to RGB on the fly, rather than -// making itermediate copies. This could be of use in _gtkagg and _tkagg as -// well. -// -// * Write an agg_to_wx_bitmap() that works more like agg_to_gtk_drawable(), -// drawing directly to a bitmap. -// -// This was the initial plan, except that I had not idea how to take a -// wx.Bitmap Python shadow class and turn it into a wxBitmap pointer. -// -// It appears that this is the way to do it: -// bool success = wxPyConvertSwigPtr(pyBitmap, (void**)&bitmap, -// _T("wxBitmap")); -// -// I'm not sure this will speed things up much, since wxWidgets requires you -// to go AGG->wx.Image->wx.Bitmap before you can blit using a MemoryDC. - - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "agg_basics.h" -#include "_backend_agg.h" -#include "agg_pixfmt_rgba.h" -#include "util/agg_color_conv_rgb8.h" -#include "agg_py_transforms.h" - -#include -#include -#include - - -// forward declarations -static wxImage *convert_agg2image(RendererAgg *aggRenderer, Py::Object clipbox); -static wxBitmap *convert_agg2bitmap(RendererAgg *aggRenderer, Py::Object clipbox); - - -// the extension module -class _wxagg_module : public Py::ExtensionModule<_wxagg_module> -{ -public: - - _wxagg_module() - : Py::ExtensionModule<_wxagg_module>("_wxkagg") - { - add_varargs_method("convert_agg_to_wx_image", - &_wxagg_module::convert_agg_to_wx_image, - "Convert the region of the agg buffer bounded by bbox to a wx.Image." - " If bbox\nis None, the entire buffer is converted.\n\nNote: agg must" - " be a backend_agg.RendererAgg instance."); - - add_varargs_method("convert_agg_to_wx_bitmap", - &_wxagg_module::convert_agg_to_wx_bitmap, - "Convert the region of the agg buffer bounded by bbox to a wx.Bitmap." - " If bbox\nis None, the entire buffer is converted.\n\nNote: agg must" - " be a backend_agg.RendererAgg instance."); - - initialize("The _wxagg module"); - } - - virtual ~_wxagg_module() {} - -private: - - Py::Object convert_agg_to_wx_image(const Py::Tuple &args) - { - args.verify_length(2); - - RendererAgg* aggRenderer = static_cast( - args[0].getAttr("_renderer").ptr()); - - Py::Object clipbox = args[1]; - - // convert the buffer - wxImage *image = convert_agg2image(aggRenderer, clipbox); - - // wrap a wx.Image around the result and return it - PyObject *pyWxImage = wxPyConstructObject(image, _T("wxImage"), 1); - if (pyWxImage == NULL) - { - throw Py::MemoryError( - "_wxagg.convert_agg_to_wx_image(): could not create the wx.Image"); - } - - return Py::asObject(pyWxImage); - } - - - Py::Object convert_agg_to_wx_bitmap(const Py::Tuple &args) - { - args.verify_length(2); - - RendererAgg* aggRenderer = static_cast( - args[0].getAttr("_renderer").ptr()); - - Py::Object clipbox = args[1]; - - // convert the buffer - wxBitmap *bitmap = convert_agg2bitmap(aggRenderer, clipbox); - - // wrap a wx.Bitmap around the result and return it - PyObject *pyWxBitmap = wxPyConstructObject(bitmap, _T("wxBitmap"), 1); - if (pyWxBitmap == NULL) - { - throw Py::MemoryError( - "_wxagg.convert_agg_to_wx_bitmap(): could not create the wx.Bitmap"); - } - - return Py::asObject(pyWxBitmap); - } -}; - - -// -// Implementation Functions -// - -static wxImage *convert_agg2image(RendererAgg *aggRenderer, Py::Object clipbox) -{ - int srcWidth = 1; - int srcHeight = 1; - int srcStride = 1; - - bool deleteSrcBuffer = false; - agg::int8u *srcBuffer = NULL; - - double l, b, r, t; - - if (!py_convert_bbox(clipbox.ptr(), l, b, r, t)) - { - // Convert everything: rgba => rgb -> image - srcBuffer = aggRenderer->pixBuffer; - srcWidth = (int) aggRenderer->get_width(); - srcHeight = (int) aggRenderer->get_height(); - srcStride = (int) aggRenderer->get_width() * 4; - } - else - { - // Convert a region: rgba => clipped rgba => rgb -> image - srcWidth = (int)(r - l); - srcHeight = (int)(t - b); - srcStride = srcWidth * 4; - - deleteSrcBuffer = true; - srcBuffer = new agg::int8u[srcStride*srcHeight]; - if (srcBuffer == NULL) - { - throw Py::MemoryError( - "_wxagg::convert_agg2image(): could not allocate `srcBuffer'"); - } - - int h = (int) aggRenderer->get_height(); - agg::rect_base region( - (int) l, // x1 - h - (int) t, // y1 - (int) r, // x2 - h - (int) b); // y2 - - agg::rendering_buffer rbuf; - rbuf.attach(srcBuffer, srcWidth, srcHeight, srcStride); - pixfmt pf(rbuf); - renderer_base rndr(pf); - rndr.copy_from(aggRenderer->renderingBuffer, ®ion, - (int) - l, (int)(t - h)); - } - - // allocate the RGB data array - - // use malloc(3) because wxImage will use free(3) - agg::int8u *destBuffer = (agg::int8u *) malloc( - sizeof(agg::int8u) * srcWidth * 3 * srcHeight); - - if (destBuffer == NULL) - { - if (deleteSrcBuffer) - { - delete [] srcBuffer; - } - - throw Py::MemoryError( - "_wxagg::convert_agg2image(): could not allocate `destBuffer'"); - } - - // convert from RGBA to RGB - agg::rendering_buffer rbSource; - rbSource.attach(srcBuffer, srcWidth, srcHeight, srcStride); - - agg::rendering_buffer rbDest; - rbDest.attach(destBuffer, srcWidth, srcHeight, srcWidth*3); - - agg::color_conv(&rbDest, &rbSource, agg::color_conv_rgba32_to_rgb24()); - - // Create a wxImage using the RGB data - wxImage *image = new wxImage(srcWidth, srcHeight, destBuffer); - if (image == NULL) - { - if (deleteSrcBuffer) - { - delete [] srcBuffer; - } - - free(destBuffer); - throw Py::MemoryError( - "_wxagg::convert_agg2image(): could not allocate `image'"); - } - - if (deleteSrcBuffer) - { - delete [] srcBuffer; - } - - return image; -} - - -static wxBitmap *convert_agg2bitmap(RendererAgg *aggRenderer, Py::Object clipbox) -{ - // Convert everything: rgba => rgb -> image => bitmap - // Convert a region: rgba => clipped rgba => rgb -> image => bitmap - wxImage *image = convert_agg2image(aggRenderer, clipbox); - wxBitmap *bitmap = new wxBitmap(*image); - - image->Destroy(); - delete image; - - if (bitmap == NULL) - { - throw Py::MemoryError( - "_wxagg::convert_agg2bitmap(): could not allocate `bitmap'"); - } - - return bitmap; -} - - -// -// Module Initialization -// - -extern "C" - DL_EXPORT(void) - init_wxagg(void) -{ - wxPyCoreAPI_IMPORT(); - //suppress an unused variable warning by creating _wxagg_module in two lines - static _wxagg_module* _wxagg = NULL; - _wxagg = new _wxagg_module; -};