Hello,

I restate the problem :

With the attached script "test_mathtext_wx.py" :
50 functions (line 31) : the 50 bitmaps are generated correctly, by when I close the application an error appears in the console :

Assertion failed: ob_refcnt == 0, file CXX\cxx_extensions.cxx, line 1128
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

250 functions : the window never appears and the crash occurs (same message)


However, if in mathtext.py (mpl 0.98.5 win32 py2.5) line 2765 in MathTextParser, I put "self._cache = dict()" instead of "self._cache = maxdict(50)", the behavior of "test_mathtext_wx.py" is significantly different. 50 functions : error on console after closing the application (no difference here)
250 functions : NO CRASH (but error after closing the application)

And now, my questions :
Is this proof that "maxdict" is the cause of the problem ?
Is there a known way to avoid the problem?
Can someone tell me more about maxdict ?

Hoping to have been quite clear,
Cédrick



"""
Demonstrates how to convert mathtext to a wx.Bitmap for display in various
controls on wxPython.
"""

import matplotlib
matplotlib.use("WxAgg")
from numpy import arange, sin, pi, cos, log
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure

import wx

IS_GTK = 'wxGTK' in wx.PlatformInfo
IS_WIN = 'wxMSW' in wx.PlatformInfo
IS_MAC = 'wxMac' in wx.PlatformInfo

############################################################
# This is where the "magic" happens.
from matplotlib.mathtext import MathTextParser
mathtext_parser = MathTextParser("Bitmap")
def mathtext_to_wxbitmap(s):
    ftimage, depth = mathtext_parser.parse(s, 150)
    return wx.BitmapFromBufferRGBA(
        ftimage.get_width(), ftimage.get_height(),
        ftimage.as_rgba_str())
############################################################

functions = []
for i in range(250):
    functions.append((r'$\frac{x}{%d}$' % i, lambda x: x))


class CanvasFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size=(550, 350))
        self.SetBackgroundColour(wx.NamedColor("WHITE"))

        self.scroll = wx.ScrolledWindow(self, -1)
        self.scroll.SetScrollRate(20,20)

        self.sizer = wx.BoxSizer(wx.VERTICAL)
        
        for f in functions:
            self.sizer.Add(wx.StaticBitmap(self.scroll, -1, 
mathtext_to_wxbitmap(f[0])))
        self.scroll.FitInside()
        
        self.scroll.SetSizer(self.sizer)

    
class MyApp(wx.App):
    def OnInit(self):
        frame = CanvasFrame(None, "wxPython mathtext demo app")
        self.SetTopWindow(frame)
        frame.Show(True)
        return True

app = MyApp()
app.MainLoop()




------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to