Package: miniipe
Mini-IpeThis is a source-only, no-dependencies Python package to writeIpefiles.
The proper way to work with Ipe files from Python would probably be to useipepythonfromipe-tools, but this requires building a number of things from source, which may be difficult (or just time-consuming) depending on your computing environment.
Mini-Ipe is a quick way to easily write Ipe files with minimum effort, from a plain Python environment.Mini-Ipe is now on PyPI. Get it anywhere using (python3 -m)pip install miniipe.What are Ipe filesIpe is an "extensible drawing editor" that is excellent for making diagrams for scientific papers and presentations.
This makes its file format ideal as output from computational experiments.Important!An Ipe file needs a valid style file. See the remarks section below.Getting startedFirst, getminiipevisible to your interpeter, for example using pip. (No need to clone the github repository.)pip install miniipeThen try the following small program and go from there.fromminiipeimportDocument,polygondoc=Document()ps=[(100,100),(200,200),(300,100)]doc.path(polygon(ps))doc.write('simple.ipe')RemarksThis is not a complete documentation, but looking at theexampleswill get you a long way.
The best way to find out about all the methods and arguments is probably toimport miniipeand use an IDE to look around (or skim the source source); here are some general remarks.PointsMini-Ipe accesses the X and Y coordinates 2D points you give it using index[0]and[1].
This means a 2-tuple of numbers is probably the easiest way to go in many cases (see the example above).
We do not provide a class for working with 2D points/vectors: if you need to do nontrivial geometric computations, you probably already have some way to do that and we do not want to create additional API boundaries.Note.We do provide aMatrixclass for affine transformations, since this is an important concept in Ipe.Document.path(...)In Ipe,whatis drawn is mostly orthogonal tohowit it drawn.
Polygons, circles, splines: almost everything is apath.
Even filled shapes are paths with afillproperty.
This is reflected in the Mini-Ipe API: it isdocument.path( polygon(...), ...)rather thandocument.polygon( ..., ...).A path is described by a series of "path construction operators" (Ipe documentation).
TheDocument.pathmethod takes a string of such drawing instructions.
You can write these on your own, but should probably use the convenience functions likerectangle,circle,polygon, and so forth.
Under most circumstances, you can have multiple shapes be part of one "path" by concatenating these strings.LayersAll objects (path,text,use) belong to a layer.
As a consequence of the Ipe file format, if you don't specify thelayerargument, the object goes in the same layer as the previous object.MatrixMatrices occur in multiple places in Ipe, most prominently as a property of objects: when drawing something that has amatrixproperty, Ipe transforms it using the given matrix.
Use theMatrixclass for this: it supports matrix multiplication using the@operator, and helper functions for common transformations such asTranslate,ScaleandRotateare provided.
See thematrix funexample.Note.Transformation by the matrix property is not done byminiipe: it merely writes thematrixproperty in the Ipe file. To actually transform a single point in a way that is consistent with Ipe, use theMatrix.transform(p)method.
See thetransformexample to confirm that the results match.EllipseTheellipsefunction takes aMatrixargument: it draws the ellipse resulting from transforming the unit circle by this matrix.The 'parent' argumentThe methodspath,textandusetake an optional argument calledparent.
If omitted, the object is added to the default page that aminiipe.Documentstarts with.
If you make more pages, pass the page you want to add the object to instead.
To put the object in a group (miniipe.Document.group(...)), pass the group instead.Style filesIt is not clear to me that I have the rights to distribute the standard Ipe style file, so you will have to provide your own. There are several ways to go about this.Callimport_stylefile()without arguments. This tries to import~/.ipe/styles/basic.isy, which may or may not exist on your system. You get an error if this file does not exist.Callimport_stylefile(filename)with the filename of a valid style file. You can get one from Ipe as follows: make a new document, selectEdit > Style sheets, selectbasicand clickSave.Do not import a style file when you make the document withminiipeand save it anyway. Ipe may complain when you open the file - colours, symbols et cetera will be missing. You can then add thebasicstyle file after the fact. (See option 2 for how to get the basic style file.)You can also make styles using Mini-Ipe. See thestyleexample code.Bitmap imagesYou can include bitmap images in Ipe files usingadd_bitmapandimage.
Mini-Ipe does not do any bitmap processing: the image payload is entirely your own responsibility.
See thebitmapexample.