S'identifier - S'inscrire - Contact

CommunityWiki
Jam session in wikilandia

Visually Programming Python

Source :

I did something today I’ve been wanting to do for a long time: I finally got around to rendering a Python program in Inkscape. I took the findit program, which I wrote about in my last blog entry, and rerendered it in Inkscape. You can see the results in one of two ways:

Get Inkscape, and look at findit.svg. Look at findit.png, a rendered out image of the SVG.

Warning: It’s a huge .PNG file. But more: You don’t really get a sense of the program, looking at the PNG. You can’t arbitrarily zoom in, zoom out, and so on, and so forth. It’s not nearly as interactive an experience, as it is, looking at it in SVG. In Inkscape, hit “5″ to see the whole diagram at once. Then select something, or multiple somethings, and hit “3.” It’ll zoom in on just them. One thing you don’t get from just looking at it, is just how structured it is.

Green text is comment, and ignored. Boxes, lines, arrows, and so on, are also “comments,” and also ignored. Navy text is titles, names. Like, names of classes, functions, variables. Red text is ordering information. BASIC makes a comeback! All class icons have label “#CLASS”, all function icons (the lambda) have label “#FUNCTION.” Grouping is done by… well, “grouping.” That is, I used SVG grouping (the “g” element) to put things together into a structural unit.

A bit more about grouping: Suppose you have a group of:

red “210″ navy “LineObject” the group labelled “#CLASS” some other groups, defining functions

What this means is that, at rank “210″ in the ordering of the output file, define the class “LineObject,” and give it the functions defined in the subgroups. The actual graphic within the group labelled “#CLASS” is unimportant for programmatic interpretation. But for us humans, I always used the same graphic to represent a class. (No-brainer, here.) So, if you look at this, and you look at the structure, you should be able to see: It shouldn’t be impossible to decode this, and write out an “.SVG -> .PY” compiler. I wrote a very simple one, as a proof of concept. It only did a little “Hello, World.” But I may just actually up and write the whole thing. We’ll see how it goes. It might be possible, even, to write an import hook, such that Python automatically transforms the .svg into .py, or some other transformation, so that you don’t have to do anything special. I don’t quite remember all the Python module hackery stuff, but I may check it out [..]

Lion le 08.10.06 à 00:56 dans Mind - Version imprimable
Article précédent - Commenter - Article suivant -