Cédrick FAURY wrote:
Hello,
I did an application that uses bitmaps constructed with MathTextParser
as described in the example
http://matplotlib.sourceforge.net/examples/user_interfaces/mathtext_wx.html
(I work with Windows XP, python 2.5, Matplotlib 0.98.5 and wxPython
2.8.10.1)
After making a lot of these bitmaps (from about 50 to 150...) the
program crash as described in the thread
[matplotlib-devel] Fontcache problem on windows
<http://www.mail-archive.com/matplotlib-de...@lists.sourceforge.net/msg02353.html>.
I don't think these problems are related. One is a cache of math
expression images, the other is a cache of fonts.
I am unable to reproduce this on Matplotlib 0.98.5.3 on Linux (don't
have a Windows box handy). Can you run the attached script (which is
just a modification of mathtext_wx.py to generate 60 different math
expressions, and let me know if that crashes for you? If not, we need
to track down the difference between what this script does and what
yours does that causes the crash. Can you share a minimal script that
reproduces the bug? It would also be useful to see a traceback (you may
need to run your script from the commandline in Windows rather than
double-clicking, in order to get the full traceback output).
Thanks,
Mike
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA
"""
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(150):
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.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.change_plot(0)
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.add_buttonbar()
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.add_toolbar() # comment this out for no toolbar
menuBar = wx.MenuBar()
# File Menu
menu = wx.Menu()
menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit this simple sample")
menuBar.Append(menu, "&File")
if IS_GTK or IS_WIN:
# Equation Menu
menu = wx.Menu()
for i, (mt, func) in enumerate(functions):
bm = mathtext_to_wxbitmap(mt)
item = wx.MenuItem(menu, 1000 + i, "")
item.SetBitmap(bm)
menu.AppendItem(item)
self.Bind(wx.EVT_MENU, self.OnChangePlot, item)
menuBar.Append(menu, "&Functions")
self.SetMenuBar(menuBar)
self.SetSizer(self.sizer)
self.Fit()
def add_buttonbar(self):
self.button_bar = wx.Panel(self)
self.button_bar_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(self.button_bar, 0, wx.LEFT | wx.TOP | wx.GROW)
for i, (mt, func) in enumerate(functions):
bm = mathtext_to_wxbitmap(mt)
button = wx.BitmapButton(self.button_bar, 1000 + i, bm)
self.button_bar_sizer.Add(button, 1, wx.GROW)
self.Bind(wx.EVT_BUTTON, self.OnChangePlot, button)
self.button_bar.SetSizer(self.button_bar_sizer)
def add_toolbar(self):
"""Copied verbatim from embedding_wx2.py"""
self.toolbar = NavigationToolbar2Wx(self.canvas)
self.toolbar.Realize()
if IS_MAC:
self.SetToolBar(self.toolbar)
else:
tw, th = self.toolbar.GetSizeTuple()
fw, fh = self.canvas.GetSizeTuple()
self.toolbar.SetSize(wx.Size(fw, th))
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
self.toolbar.update()
def OnPaint(self, event):
self.canvas.draw()
def OnChangePlot(self, event):
self.change_plot(event.GetId() - 1000)
def change_plot(self, plot_number):
t = arange(1.0,3.0,0.01)
s = functions[plot_number][1](t)
self.axes.clear()
self.axes.plot(t, s)
self.Refresh()
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