Re: [matplotlib-devel] setupext.py chooses tk on mac OS X incorrectly
Hi all, I agree with JDH. Unfortunately, work has been exceptionally hectic so I haven't begun the patch (if you don't count the hack job I did to install it for myself). Hi Adam, As noted above, I haven't started a patch yet but I would be up for working with you on one. It sounds like we can get this tested pretty well. Thanks, and talk to you soon, Jayson On Sat, Feb 7, 2009 at 7:44 AM, John Hunter wrote: > On Wed, Feb 4, 2009 at 5:08 PM, Jayson Barr wrote: > >> 4). I don't mind helping write the patch. I am only worried about >> not knowing the intricacies of all the random supported platforms that >> you all look out for. For example: I know jack about Windows linking. >> Either way, I'll update it if you have someone look at it. I'll work >> on it sometimes this week when I'm not too busy at work and send it >> in. > > > The problem is that the code is already messy, and Adam describes his > solution as messy, and it is difficult if not impossible to get people > to test on all the required platforms. I can test on OS X w/o > macports and a linux box, Charlie would probably be able to test on > win32, and Adam can test on macports. Perhaps you and Adam can > collaborate on a patch and we'll see if we can get it properly tested. > There are lots of tcl/tk combinations out there on different > platforms, so it is a trick issue. > > JDH > -- Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Interactive wx/pylab with no threads (PyOS_InputHook)
Hi Brian, I wrote the code in PyGTK that uses PyOS_InputHook for interactivity, as well as the Mac OS X native backend for matplotlib that uses PyOS_InputHook in exactly the same way. PyQT and Tkinter also use PyOS_InputHook, though the code is a bit kludgy on Windows. So I definitely agree that PyOS_InputHook is the right way to go. Your current code should work, but there's a better way to do it. If I understand the code correctly, you rely on the fact that PyOS_InputHook is called repeatedly by readline, and you use PyOS_InputHook to process wx events that need to be processed at that time. A better way is to use PyOS_InputHook to start the wx event loop, but have this event loop check stdin. As soon as some input is available on stdin, you exit the event loop, which means that PyOS_InputHook returns, and Python can proceed to handle the command that was just entered by the user on stdin. Essentially, think of wx's event loop as sitting in a call to select(), waiting for the next wx event to arrive. You want to add fileno(stdin) to the set of file descriptors watched by select(). There are two advantages to this approach. First, it does not rely on readline calling PyOS_InputHook repeatedly. This is important, since Python may not be using readline at all, and if it is, depending on the Python version and how readline was installed it may call PyOS_InputHook only once. Second, this approach is more efficient (not wasting processor cycles going back and forth between readline and PyOS_InputHook), and gives a better response time (essentially immediate). The best place to put this code is in wxPython. Hopefully (I haven't checked this), wx exposes enough of the event loop to allow you to have it watch stdin. This may be an issue, since for example qt4 does not on Windows, which is why the event loop is kludgy with PyQT on Windows. You could have a look at the PyOS_InputHook code in PyGTK (you'll need to get the developer's version of PyGTK, since this code is not yet in an official release). It's actually quite straightforward and you may be able to modify it directly for wx. It's actually unfortunate that we have to use PyOS_InputHook; all this would be a lot easier if Python itself supported event loops. --Michiel --- On Sun, 2/8/09, Brian Granger wrote: > From: Brian Granger > Subject: [matplotlib-devel] Interactive wx/pylab with no threads > (PyOS_InputHook) > To: matplotlib-devel@lists.sourceforge.net, "IPython Development list" > > Date: Sunday, February 8, 2009, 7:08 PM > IPython and matplotlib devs, > > Over the weekend I have been playing around to see if it is > possible > to do interactive GUI work with wx from IPython *without > using > threads*. The idea here is to use PyOS_InputHook. > Currently, recent > versions of PyQt4 and PyGTK do this and if we can get wx > working, we > can probably get rid of IPython's subtle threaded > shells that > currently allow interactive GUIs to work. > > I am attaching a Cython module that mostly works. Here is > a simple > example that works in IPython (without the -wthread > option!) > > In [1]: import pyximport > > In [2]: pyximport.install() > > In [3]: import inputhook > > In [4]: inputhook.set_input_hook() > > In [5]: import wx > > In [6]: app = wx.PySimpleApp() > > In [7]: app.MainLoop() > > In [8]: f = wx.Frame(None,-1,"Look mom, no > threads!") > > In [9]: f.Show() > Out[9]: True > > The docstring of the module also has a matplotlib example. > This > really does work and I am pretty sure it will also work in > plain > vanilla python as well. There are a few issues to work > out: > > * When frame are closed by clicking the red button or the > "X", the > Windows don't close. In addition, in matplotlib, this > causes further > problems. > > * In the current matplotlib backend wx.Yield() is called in > a way that > is not safe as far as protecting against recursive calls to > Yield. I > think it should be called in this way: > > app = wx.GetApp() > if app is not None: > app.Yield(True) > > * I don't think that interupts work yet, but I > haven't tested this > thoroughly yet. > > I don't have any more time to work on this right now, > but I at least > wanted to share my findings with both IPython and > matplotlib devs. It > would be great if someone familiar with wx could try to > figure out the > remaining issues. If there are no takers here, I might > eventually see > if wxpython itself is interested in this code (that is > probably where > it really belongs anyway). > > Cheers, > > Brian > -- > Create and Deploy Rich Internet Apps outside the browser > with Adobe(R)AIR(TM) > software. With Adobe AIR, Ajax developers can use existing > skills and code to > build responsive, highly engaging applications that combine > the power of local > resources and data with the reach of the web. Download the > Adobe AIR SD
[matplotlib-devel] Request: only left and bottom border in figure frame
Dear all, I asked in the user list for a way to have only left and bottom border in figure frame (http://sourceforge.net/mailarchive/forum.php?thread_name=1233927942.20817.1.camel%40mineat2.hmi.de&forum_name=matplotlib-users) Tony S Yu has kindly give a solution and a implementation that maybe it will be nice to integrate the trunk. I think this is a very nice feature. Also, it would be good it this could be configured from de rcParam. Regards, Zunbeltz -- Dr. Zunbeltz Izaola Helmholtz-Zentrum Berlin für Materialien und Energie GmbH Methods and Instruments (SF1) Glienicker Str. 100 D-14109 Berlin Tel (030) 8062-3179 Fax (030) 8062-2523 Room A 349 -- Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] setupext.py chooses tk on mac OS X incorrectly
On Mon, Feb 9, 2009 at 17:08, Jayson Barr wrote: > I agree with JDH. Likewise. > Unfortunately, work has been exceptionally hectic so I haven't begun > the patch (if you don't count the hack job I did to install it for > myself). Same here, I'm really busy with work and don't have much time to look into this at the moment. > Hi Adam, > As noted above, I haven't started a patch yet but I would be up for > working with you on one. It sounds like we can get this tested pretty > well. Its on my todo list, so when I get chance I'm going to investigate a better solution. I'll keep you posted. Cheers Adam -- Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Interactive wx/pylab with no threads (PyOS_InputHook)
Michiel, Thanks for jumping into the discussion. > I wrote the code in PyGTK that uses PyOS_InputHook for interactivity, as well > as the Mac OS X native backend for matplotlib that uses PyOS_InputHook in > exactly the same way. PyQT and Tkinter also use PyOS_InputHook, though the > code is a bit kludgy on Windows. So I definitely agree that PyOS_InputHook is > the right way to go. Great, I was wondering how the Mac OS X backend works - now I know. I will have a look at the code for both PyGTK and OS X. Hopefully that will show me more of the best way of handling this. > Your current code should work, but there's a better way to do it. If I > understand the code correctly, you rely on the fact that PyOS_InputHook is > called repeatedly by readline, and you use PyOS_InputHook to process wx > events that need to be processed at that time. Yes, at least that is my understanding. I put in some debug statements and you could see that it was being called repeatedly. A better way is to use PyOS_InputHook to start the wx event loop, but have this event loop check stdin. As soon as some input is available on stdin, you exit the event loop, which means that PyOS_InputHook returns, and Python can proceed to handle the command that was just entered by the user on stdin. > > Essentially, think of wx's event loop as sitting in a call to select(), > waiting for the next wx event to arrive. You want to add fileno(stdin) to the > set of file descriptors watched by select(). I have seen that this is how the PyQt4 implementation handles it. > There are two advantages to this approach. First, it does not rely on > readline calling PyOS_InputHook repeatedly. This is important, since Python > may not be using readline at all, and if it is, depending on the Python > version and how readline was installed it may call PyOS_InputHook only once. OK, I was wondering about this. But, what happens if PyOS_InputHook is called repeatedly. Are you not then starting the event loop multiple times. Can you say more about what happens in this case? Second, this approach is more efficient (not wasting processor cycles going back and forth between readline and PyOS_InputHook), and gives a better response time (essentially immediate). That would be very nice as my implementation is less responsive. > The best place to put this code is in wxPython. Hopefully (I haven't checked > this), wx exposes enough of the event loop to allow you to have it watch > stdin. This may be an issue, since for example qt4 does not on Windows, which > is why the event loop is kludgy with PyQT on Windows. You could have a look > at the PyOS_InputHook code in PyGTK (you'll need to get the developer's > version of PyGTK, since this code is not yet in an official release). It's > actually quite straightforward and you may be able to modify it directly for > wx. Yes, I fully agree with this. I might end up contacting the wx devs to get their help on this. I actually don't know wx at all, so I am amazed that I got this far. I will have a look at the PyGTK implementation. > It's actually unfortunate that we have to use PyOS_InputHook; all this would > be a lot easier if Python itself supported event loops. Yes, that would be nice!!! Cheers, Brian > --Michiel > > --- On Sun, 2/8/09, Brian Granger wrote: > >> From: Brian Granger >> Subject: [matplotlib-devel] Interactive wx/pylab with no threads >> (PyOS_InputHook) >> To: matplotlib-devel@lists.sourceforge.net, "IPython Development list" >> >> Date: Sunday, February 8, 2009, 7:08 PM >> IPython and matplotlib devs, >> >> Over the weekend I have been playing around to see if it is >> possible >> to do interactive GUI work with wx from IPython *without >> using >> threads*. The idea here is to use PyOS_InputHook. >> Currently, recent >> versions of PyQt4 and PyGTK do this and if we can get wx >> working, we >> can probably get rid of IPython's subtle threaded >> shells that >> currently allow interactive GUIs to work. >> >> I am attaching a Cython module that mostly works. Here is >> a simple >> example that works in IPython (without the -wthread >> option!) >> >> In [1]: import pyximport >> >> In [2]: pyximport.install() >> >> In [3]: import inputhook >> >> In [4]: inputhook.set_input_hook() >> >> In [5]: import wx >> >> In [6]: app = wx.PySimpleApp() >> >> In [7]: app.MainLoop() >> >> In [8]: f = wx.Frame(None,-1,"Look mom, no >> threads!") >> >> In [9]: f.Show() >> Out[9]: True >> >> The docstring of the module also has a matplotlib example. >> This >> really does work and I am pretty sure it will also work in >> plain >> vanilla python as well. There are a few issues to work >> out: >> >> * When frame are closed by clicking the red button or the >> "X", the >> Windows don't close. In addition, in matplotlib, this >> causes further >> problems. >> >> * In the current matplotlib backend wx.Yield() is called in >> a way that >> is not safe as far as protecting against recu
[matplotlib-devel] Patch for the PDF backend when setting pdf.use14corefonts=True is used
The PDF backend breaks when the setting pdf.use14corefonts=True is used. You'll find a test case reproducing this bug in the attached file 'test_pdf_use14corefonts.py'. This setting is very useful because it produces very lightweight PDF files. The files are lightweight because they only use the 14 core fonts built in every PDF viewers (like Helvetica and Times). Attached to this email is a patch against the current trunk containing the bug fix and the related test case. Do you agree to commit it? Thanks, Nicolas Grilly Index: unit/test_pdf_use14corefonts.py === --- unit/test_pdf_use14corefonts.py (révision 0) +++ unit/test_pdf_use14corefonts.py (révision 0) @@ -0,0 +1,25 @@ +# encoding: utf-8 + +import matplotlib +matplotlib.use('PDF') + +from matplotlib import rcParams +import pylab + +rcParams['pdf.use14corefonts'] = True +rcParams['font.family'] = 'sans-serif' +rcParams['font.size'] = 8 +rcParams['font.sans-serif'] = ['Helvetica'] + +title = u'Test PDF backend with option use14corefonts=True' + +text = u'''A three lines text positionned just above a blue line +and containing some french characters and the euro symbol: +"Merci pépé pour les 10 €"''' + +pylab.figure(figsize=(6, 4)) +pylab.title(title) +pylab.text(0.5, 0.5, text, horizontalalignment='center') +pylab.axhline(0.5, linewidth=0.5) +pylab.savefig('test.pdf') +pylab.close() Index: CHANGELOG === --- CHANGELOG (révision 6903) +++ CHANGELOG (copie de travail) @@ -1,3 +1,7 @@ +2009-02-10 Fixed a bug in backend_pdf so it doesn't break when the setting + pdf.use14corefonts=True is used. Added test case in + unit/test_pdf_use14corefonts.py. - NGR + 2009-02-08 Added a new imsave function to image.py and exposed it in the pyplot interface - GR Index: lib/matplotlib/backends/backend_pdf.py === --- lib/matplotlib/backends/backend_pdf.py (révision 6903) +++ lib/matplotlib/backends/backend_pdf.py (copie de travail) @@ -1465,7 +1465,7 @@ self.draw_path(boxgc, path, mytrans, gc._rgb) def encode_string(self, s, fonttype): -if fonttype == 3: +if fonttype in (1, 3): return s.encode('cp1252', 'replace') return s.encode('utf-16be', 'replace') @@ -1492,7 +1492,7 @@ font = self._get_font_afm(prop) l, b, w, h = font.get_str_bbox(s) descent = -b * fontsize / 1000 -fonttype = 42 +fonttype = 1 else: font = self._get_font_ttf(prop) self.track_characters(font, s) @@ -1627,9 +1627,9 @@ font = self._get_font_afm(prop) l, b, w, h, d = font.get_str_bbox_and_descent(s) scale = prop.get_size_in_points() -w *= scale -h *= scale -d *= scale +w *= scale / 1000 +h *= scale / 1000 +d *= scale / 1000 else: font = self._get_font_ttf(prop) font.set_text(s, 0.0, flags=LOAD_NO_HINTING) # encoding: utf-8 import matplotlib matplotlib.use('PDF') from matplotlib import rcParams import pylab rcParams['pdf.use14corefonts'] = True rcParams['font.family'] = 'sans-serif' rcParams['font.size'] = 8 rcParams['font.sans-serif'] = ['Helvetica'] title = u'Test PDF backend with option use14corefonts=True' text = u'''A three lines text positionned just above a blue line and containing some french characters and the euro symbol: "Merci pépé pour les 10 â¬"''' pylab.figure(figsize=(6, 4)) pylab.title(title) pylab.text(0.5, 0.5, text, horizontalalignment='center') pylab.axhline(0.5, linewidth=0.5) pylab.savefig('test.pdf') pylab.close() -- Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Patch for the PDF backend when setting pdf.use14corefonts=True is used
Nicolas Grilly writes: > The PDF backend breaks when the setting pdf.use14corefonts=True is > used. You'll find a test case reproducing this bug in the attached > file 'test_pdf_use14corefonts.py'. You're right. I committed your patch, but there is another bug that makes this a little difficult to test: the font cache doesn't record whether it was build with pdf.use14corefonts enabled or not, and the font name "Helvetica" happens to match "Helvetica Narrow", whose metrics are included with matplotlib, and using that afm file without including the font itself breaks the output. I'm too busy with other things to fix this now, but patches are welcome. As a workaround, deleting ~/.matplotlib/fontList.cache helps if anyone wants to alternate between enabling and disabling use14corefonts. > This setting is very useful because it produces very lightweight PDF > files. The files are lightweight because they only use the 14 core > fonts built in every PDF viewers (like Helvetica and Times). Unfortunately, this functionality is deprecated in the PDF standard as of PDF 1.5, and many publishers require embedding all fonts in PDF files. Apparently not all substitutes for the standard fonts are similar enough. (The real fonts need to be licensed, so many Linux distributions ship with free look-alike substitutes, and who knows what fonts are installed on some publisher's systems.) Thanks for the patch! -- Jouni K. Seppänen http://www.iki.fi/jks -- Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Interactive wx/pylab with no threads (PyOS_InputHook)
> I will have a look at the code for both PyGTK and OS X. > Hopefully that will show me more of the best way of > handling this. The code in PyGTK is a bit easier to understand than the code for OS X. The OS X code also includes stuff to handle SIGINTs (keyboard interrupts by ctrl-c), which is nice but not really essential. > But, what happens if PyOS_InputHook is called > repeatedly. Are you not then starting the event loop > multiple times. Can you say more about what happens in > this case? On the first call to PyOS_InputHook, you start the event loop, and you stay in the event loop until some input is available on stdin. So Python never gets the chance to call PyOS_InputHook repeatedly. Depending on if and how readline is installed, it is possible that once input is available on stdin and PyOS_InputHook exits, PyOS_InputHook is called a second time. But that doesn't do any real damage: the event loop is restarted, but it exits immediately because input is available on stdin. It's good to double-check that that works on wx though. Another option is to write your hook function as follows: check if any input is available on stdin; if so, return add fileno(stdin) to the set of file descriptors to be watched by the event loop start the event loop; if input is available on stdin, exit the event loop and return --Michiel. -- Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM) software. With Adobe AIR, Ajax developers can use existing skills and code to build responsive, highly engaging applications that combine the power of local resources and data with the reach of the web. Download the Adobe AIR SDK and Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel