I am using wxPython to prototype some display interfaces for a project that will eventually become an embedded design. Since we are iterating with a graphics designer, it is much easier to let them work in a WYSIWYG editor like Inkscape than constantly rewrite 2D graphics drawing calls. For elements that need animation or dynamic text, the SVG elements are easily identifiable by ID so that they can be programatically updated before rendering. The rendering flow looks like this:
Inkscape SVG as XML --> Python modification of XML --> Drawing onto wxPython buffered canvas using Cairo and pyRSVG
I'd like to animate a pivoting needle around a fixed axis for a gauge. To define a needle, the graphics designer draws the graphical "needle" and a "needle_axis" element which is a small circle. Then, I thought I could set the transform property using the desired angle and the center coordinates of the "needle_axis." However, since the relative positions could have been affected because of other transforms, determining the absolute location of the rotation axis is non-trivial.
I cannot seem to find a Python library for determining absolute coordinates of an element, and it feels like reinventing the wheel to try an implement the part of the SVG spec. necessary to calculate it. The rsvg API mentions rsvg_handle_get_dimensions_sub
and arsvg_handle_get_position_sub
functions to get the dimensions and positions of elements, but I can't find an API for pyRSVG.
Is there a better way to find the rotation axis than manually calculating it? An example Inkscape SVG file and test snippet are available as a gist.
simpletransform.py
- but it's in the Deprecated folder of my installed InkScape, and couldn't be imported (without a lot of work).