AttributeError: 'FigureCanvasWxAgg' object has no attribute 'SetInitialSize'

Hi all,

I have some trouble with matplotlib's svn version.
Any pointer would be appreciated.

Thanks in advance

                         Nils

/usr/bin/python -i nlp_3.py --verbose-helpful
$HOME=/home/nwagner
matplotlib data path /usr/lib/python2.4/site-packages/matplotlib/mpl-data
loaded rc file /home/nwagner/matplotlibrc
matplotlib version 0.98.0
verbose.level helpful
interactive is False
units is False
platform is linux2
CONFIGDIR=/home/nwagner/.matplotlib
Using fontManager instance from /home/nwagner/.matplotlib/fontManager.cache
numerix numpy 1.2.0.dev5257
backend WXAgg version 2.5.3.1
starting solver ipopt (license: CPL) with problem nlp3
[PyIPOPT] Ipopt will use Hessian approximation.
[PyIPOPT] nele_hess is 0
iter objFunVal log10(maxResidual)
     0 -1.640e+02 0.81
Traceback (most recent call last):
   File "nlp_3.py", line 65, in ?
     r = p.solve(solver)
   File "/usr/lib/python2.4/site-packages/scikits/openopt/Kernel/BaseProblem.py", line 236, in solve
     return runProbSolver(self, solvers, *args, **kwargs)
   File "/usr/lib/python2.4/site-packages/scikits/openopt/Kernel/runProbSolver.py", line 219, in runProbSolver
     solver(p)
   File "/usr/lib/python2.4/site-packages/scikits/openopt/solvers/CoinOr/ipopt_oo.py", line 70, in __solver__
     p.iterfcn(p.x0)
   File "/usr/lib/python2.4/site-packages/scikits/openopt/Kernel/BaseProblem.py", line 57, in <lambda>
     self.iterfcn = lambda *args: ooIter(self, *args)# this parameter is only for OpenOpt developers, not common users
   File "/usr/lib/python2.4/site-packages/scikits/openopt/Kernel/ooIter.py", line 78, in ooIter
     for df in p.graphics.drawFuncs: df(p)
   File "/usr/lib/python2.4/site-packages/scikits/openopt/Kernel/ooGraphics.py", line 127, in oodraw
     if self.nSubPlots>1: pylab.subplot(self.nSubPlots, 1, 1)
   File "/usr/lib/python2.4/site-packages/matplotlib/pyplot.py", line 519, in subplot
     fig = gcf()
   File "/usr/lib/python2.4/site-packages/matplotlib/pyplot.py", line 210, in gcf
     return figure()
   File "/usr/lib/python2.4/site-packages/matplotlib/pyplot.py", line 195, in figure
     FigureClass=FigureClass,
   File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_wxagg.py", line 119, in new_figure_manager
     frame = FigureFrameWxAgg(num, fig)
   File "/usr/lib/python2.4/site-packages/matplotlib/backends/backend_wx.py", line 1237, in __init__
     self.canvas.SetInitialSize(wx.Size(fig.bbox.width, fig.bbox.height))
AttributeError: 'FigureCanvasWxAgg' object has no attribute 'SetInitialSize'

This came from Stan's patch to fix figure sizing in wx. Nils, could
you report your wx version, and Stan, could you see if there is a
version problem in the SetInitialSize call?

Thanks,
JDH

···

On Sat, Jun 7, 2008 at 4:36 AM, Nils Wagner <nwagner@...425...> wrote:

Hi all,

I have some trouble with matplotlib's svn version.
Any pointer would be appreciated.
    self.canvas.SetInitialSize(wx.Size(fig.bbox.width,
fig.bbox.height))
AttributeError: 'FigureCanvasWxAgg' object has no
attribute 'SetInitialSize'

Greetings. According to http://www.wxpython.org/recentchanges.php,
SetInitialSize became available at version 2.7.2.0 (7 Nov 2006) of wxPython.
It renamed the prior SetBestFittingSize, for which I found no other mention
in the changes document. (That version history lists those methods as
belonging to wx.Window, from which wx.Panel inherits.)

Stan

···

-----Original Message-----
From: John Hunter [mailto:jdh2358@…149…]
Sent: Monday, June 09, 2008 16:05
To: Nils Wagner
Cc: matplotlib-devel@lists.sourceforge.net; Stan West
Subject: Re: [matplotlib-devel] AttributeError: 'FigureCanvasWxAgg' object
has no attribute 'SetInitialSize'

On Sat, Jun 7, 2008 at 4:36 AM, Nils Wagner <nwagner@...425...> wrote:

Hi all,

I have some trouble with matplotlib's svn version.
Any pointer would be appreciated.
    self.canvas.SetInitialSize(wx.Size(fig.bbox.width,
fig.bbox.height))
AttributeError: 'FigureCanvasWxAgg' object has no attribute
'SetInitialSize'

This came from Stan's patch to fix figure sizing in wx. Nils, could you
report your wx version, and Stan, could you see if there is a version
problem in the SetInitialSize call?

Thanks,
JDH

OK, I committed a change to svn using:

        def do_nothing(*args, **kwargs):
            warnings.warn('could not find a SetSizeFunc for
backend_wx; please report your wxpython version=%s to the matplotlib
developers list'%backend_version)
            pass

        # try to find the set size func across wx versions
        self.SetSizeFunc = getattr(self.canvas, 'SetInitialSize',
                                   getattr(self.canvas,
'SetBestFittingSize', do_nothing))
        self.SetSizeFunc(wx.Size(fig.bbox.width, fig.bbox.height))

Could you guys test from svn on your respective wx versions and/or
check that the logic looks correct here?

Thanks,
JDH

···

On Tue, Jun 10, 2008 at 9:21 AM, Stan West <stan.west@...595...> wrote:

Greetings. According to http://www.wxpython.org/recentchanges.php,
SetInitialSize became available at version 2.7.2.0 (7 Nov 2006) of wxPython.
It renamed the prior SetBestFittingSize, for which I found no other mention
in the changes document. (That version history lists those methods as
belonging to wx.Window, from which wx.Panel inherits.)

Hi, John. With the change, "fig = figure(figsize=(w, h))" properly creates
a figure window with a correctly-sized canvas, but "fig.set_size_inches((w,
h), forward=True)" raises

    AttributeError: 'FigureCanvasWxAgg' object has no attribute
'SetSizeFunc'

in FigureManagerWx.resize. Previously, the SetInitialSize called by
FigureFrameWx.__init__ and FigureManagerWx.resize was an attribute of the
canvas, but the new code makes SetSizeFunc an attribute of the frame
instead. FigureManagerWx.resize was still looking under the canvas.

Would you please look over the attached patch? During
FigureCanvasWx.__init__, it connects FigureCanvasWx.SetInitialSize to
SetBestFittingSize or do_nothing if it isn't already inherited from
wx.Panel. FigureFrameWx.__init__ and FigureManagerWx.resize just call
FigureCanvasWx.SetInitialSize.

Stan

backend_wx.patch (2.13 KB)

···

-----Original Message-----
From: John Hunter [mailto:jdh2358@…149…]
Sent: Tuesday, June 10, 2008 10:31
To: Stan West
Cc: Nils Wagner; matplotlib-devel@lists.sourceforge.net
Subject: Re: [matplotlib-devel] AttributeError: 'FigureCanvasWxAgg' object
has no attribute 'SetInitialSize'

On Tue, Jun 10, 2008 at 9:21 AM, Stan West <stan.west@...595...> wrote:

Greetings. According to http://www.wxpython.org/recentchanges.php,
SetInitialSize became available at version 2.7.2.0 (7 Nov 2006) of

wxPython.

It renamed the prior SetBestFittingSize, for which I found no other
mention in the changes document. (That version history lists those
methods as belonging to wx.Window, from which wx.Panel inherits.)

OK, I committed a change to svn using:

        def do_nothing(*args, **kwargs):
            warnings.warn('could not find a SetSizeFunc for backend_wx;
please report your wxpython version=%s to the matplotlib developers
list'%backend_version)
            pass

        # try to find the set size func across wx versions
        self.SetSizeFunc = getattr(self.canvas, 'SetInitialSize',
                                   getattr(self.canvas,
'SetBestFittingSize', do_nothing))
        self.SetSizeFunc(wx.Size(fig.bbox.width, fig.bbox.height))

Could you guys test from svn on your respective wx versions and/or check
that the logic looks correct here?

Thanks,
JDH

OK, I applied this. Nils, could you test again with wxagg.

Thanks,
JDH

···

On Wed, Jun 11, 2008 at 4:34 PM, Stan West <stan.west@...595...> wrote:

Would you please look over the attached patch? During
FigureCanvasWx.__init__, it connects FigureCanvasWx.SetInitialSize to
SetBestFittingSize or do_nothing if it isn't already inherited from
wx.Panel. FigureFrameWx.__init__ and FigureManagerWx.resize just call
FigureCanvasWx.SetInitialSize.