For those interested, docpicture can now display images from the web. There's also a somewhat silly example where I embedded the code for a matplotlib example inside a docstring and have it displayed as a plot when viewing the docstring via docpicture inside a web browser. In order to do so I had to exec the code which is not exactly good practice ... but it serves to highlight the need to either only allow "parsers" from the standard distribution or require the user to give permission to a parser to be able to register itself with docpicture while it is running. I chose this second approach, although if you run the demo, you will not be given the opportunity to approve or not the parser - it will be done for you. This may need to be revisited...
I just announced a new release on the Python list. You can get docpicture 0.2 from here.
Saturday, November 01, 2008
Wednesday, October 29, 2008
svg mathematical equation
Ok, it's done: mathematical equations generated dynamically and displayed as svg graphics. Only using the standard Python library ... and one "tiny" additional download: matplotlib. Here's the first result (saved as a "hard-copy"; you may have to download the page and reopen it locally using Firefox.)
Note: do not bother looking for the files in the "py-fun" repository where I had the first release of docpicture. I will clean up things a bit and do a new release from a different place.
As usual, comments & suggestions are welcome.
Note: do not bother looking for the files in the "py-fun" repository where I had the first release of docpicture. I will clean up things a bit and do a new release from a different place.
As usual, comments & suggestions are welcome.
Tuesday, October 28, 2008
docpicture and uml sequence diagrams
In a previous post about docpicture, I gave an example of a graphics generated from this site as something that would be desirable to do. (You can find more examples here.) Well, it turned out to be easy to do ... at the cost of a server connection. I used the example given to embed a graphics inside a page and ... voilà, it is done. As long as one has a live internet connection (and assuming the websequencediagram server is not down), a graphics is generated as requested.
Eventually, I still would like to implement my own parser to create svg code for uml sequence diagrams rather than relying on an external service.
Eventually, I still would like to implement my own parser to create svg code for uml sequence diagrams rather than relying on an external service.
Monday, October 27, 2008
docpicture: initial release
The subject line says it all. It's a small download: less than 22 kB, available from here. Feedback and suggestions are definitely welcome.
Sunday, October 26, 2008
docpicture: working ... and a query.
docpicture (see previous posts) is now working as a full prototype. By this, I mean that instead of doing
at the Python prompt, one can do
and some_object's docstring will be displayed in your webbrowser, with any docpicture directive being translated so as to embed a nice picture. Well, by "any", I mean any turtle directive conforming to the limited syntax I have included.
When I compare the output of help() with that of docpicture.view(), I am struck at how much more information than simply the object's docstring is included. I have tried (briefly) to play with the pydoc module to see if I could redirect the output of help() to a string that I could process with docpicture.view() ... but to no avail.
If anyone knows how I could do this simply, I would be very grateful.
docpicture is going to be released (version 0.1) as soon as I complete a decent "readme" file.
--UPDATE-- Ok, after playing some more with pydoc, I found out how to do this.
In my module, I do the following:
and use the retrieved text as I wish.
>>> help(some_object)
at the Python prompt, one can do
>>> from docpicture import view
>>> view(some_object)
and some_object's docstring will be displayed in your webbrowser, with any docpicture directive being translated so as to embed a nice picture. Well, by "any", I mean any turtle directive conforming to the limited syntax I have included.
When I compare the output of help() with that of docpicture.view(), I am struck at how much more information than simply the object's docstring is included. I have tried (briefly) to play with the pydoc module to see if I could redirect the output of help() to a string that I could process with docpicture.view() ... but to no avail.
If anyone knows how I could do this simply, I would be very grateful.
docpicture is going to be released (version 0.1) as soon as I complete a decent "readme" file.
--UPDATE-- Ok, after playing some more with pydoc, I found out how to do this.
In my module, I do the following:
import pydoc
from StringIO import StringIO
my_stdin = StringIO()
def my_pager(text):
my_stdin.write(pydoc.plain(text))
return
pydoc.pager = my_pager
pydoc.help(obj)
retrieved = my_stdin.getvalue()
my_stdin.close()
and use the retrieved text as I wish.
Friday, October 24, 2008
docpicture: getting closer


This is just a progress report for the curious among you: the previous two images were generated automatically from the docpicture code written above them. If everything goes well, by the end of the weekend I'll be ready to give a sneak preview of the code to anyone interested. Feel free to contact me.
Sunday, October 19, 2008
docpicture + svg generation: first prototype working
As outlined in a previous post, I have decided to use svg to embed pictures in html pages generated from docstrings. Of course, this could be generalized to other cases than docstrings; for example, this could be implemented as a reStructuredText directive. In the course of playing with generating such pages with inline svg code, I observed the following:
Update: The test case has been improved with styling.
Update 2: A new picture perhaps gives a better idea of a more realistic use case.
- If a file is saved locally and loaded within Firefox, it should be saved with a ".xml" (or possibly ".xhtml") extension.
- If a file is served dynamically from a server, all that is needed is that its content be identified as "application/xhtml+xml" [as I had mentioned previously].
- If the file is put on a "generic webserver" that can't be configured by the user, Firefox will ignore the svg code if the extension of the file is ".xml" or ".html". However, I did find a workaround: use a ".xhtml" extension and, when prompted by Firefox as to what application to use to open such file, select Firefox itself. The file will be downloaded locally and displayed correctly. At least, this is what happens on a Mac with Firefox 3.
Update: The test case has been improved with styling.
Update 2: A new picture perhaps gives a better idea of a more realistic use case.
Subscribe to:
Posts (Atom)