Re: [Inkscape-devel] The death of PyXML
Justin Barca wrote:
My software project also relies on PyXML, and it is because of this dependency that I can use it in the creation of extensions. I find it puzzling that an internal python library for something as important as xml proc just went to the wayside. Can you explain to me what happened with this project ? Are there major bugs with it right now ? If necessary, I hope the conversion to another xml api can be done with regular expressions or other string processing.
Yeah, I think I kinda talked you into PyXML. Though you can certainly write extensions for Inkscape without it. I had no idea that people would let something so important, ie one of the only python libraries that supported some of the more advanced XML features, go defunct. PyXML was not internal to the python distribution. It was an extension layer on top of the core DOM functionality available in the python distribution. I don't know what happened to PyXML. I asked several acquaintances who are closer with the Python community and no one knew. Everyone I spoke with is quite happy with the ElementTree api that is now part of the standard Python 1.5 distribution. ElementTree looks reasonable to me, but again like the core dom module in the standard library it doesn't support functionality that is important to me especially XPath. Thankfully I think I may have found the best of both worlds in lxml. Someone has implemented the popular ElementTree API on top of libxml2 and extended it by exposing libxml2's support for XPath and other technologies that are important for working with XML.
Could one convert the code from PyXML to lxml using regex and string processing, I suppose. The translation is pretty simple. You could probably do a 1:1 substitution automatically. For me it is going to be easier to edit the relatively few scripts in the Inkscape distribution by hand. And that will help me learn the API a bit better. This is how I translated the XML portion of gear.py:
With PyXML: path = points_to_svgd( points )
# Create SVG Path for gear gear = self.document.createElement( 'svg:path' ) style = { 'stroke': '#000000', 'fill': 'none' } gear.setAttribute( 'style', simplestyle.formatStyle(style) ) gear.setAttribute( 'd', path )
# Embed gear in group to make animation easier: # Translate group, Rotate path. g=self.document.createElement('g')
g.setAttribute( 'inkscape:label', 'Gear' + str( teeth ) ) t = 'translate(' + str( self.view_center[0] ) + ',' + str( self.view_center[1] ) + ')' g.setAttribute( 'transform', t ) self.current_layer.appendChild( g ) g.appendChild( gear )
With lxml: path = points_to_svgd( points )
# Embed gear in group to make animation easier: # Translate group, Rotate path. t = 'translate(' + str( self.view_center[0] ) + ',' + str( self.view_center[1] ) + ')' g_attribs = {'inkscape:label':'Gear' + str( teeth ), 'transform':t } g = inkex.etree.SubElement(self.current_layer, 'g', g_attribs)
# Create SVG Path for gear style = { 'stroke': '#000000', 'fill': 'none' } gear_attribs = {'style':simplestyle.formatStyle(style), 'd':path} gear = inkex.etree.SubElement(g, 'svg:path', gear_attribs )
I think I'm going to hold off on the full conversion until I get more feedback from other people in the community. I would especially like to hear from our Mac OSX users and packagers about how easy it would be to distribute and install lxml with Inkscape. (Jiho could you please give it a try?) Some version of lxml has been available in Ubuntu universe since at least Breezy. Is lxml available for other distros?
Aaron Spike
Aaron Spike wrote:
I think I'm going to hold off on the full conversion until I get more feedback from other people in the community. I would especially like to hear from our Mac OSX users and packagers about how easy it would be to distribute and install lxml with Inkscape. (Jiho could you please give it a try?) Some version of lxml has been available in Ubuntu universe since at least Breezy. Is lxml available for other distros?
Cedric Gemy put me in contact with Olivier Grisel. Olivier assures me that distributing lxml for OSX is super easy and offered his help if we need it. I plan to replace PyXML with lxml in SVN as soon as I am able unless someone can give me reason not to do so.
Aaron Spike
I think I'm going to hold off on the full conversion until I get more feedback from other people in the community. I would especially like to hear from our Mac OSX users and packagers about how easy it would be to distribute and install lxml with Inkscape. (Jiho could you please give it a try?)
I cannot test it right now. It does not seem to be in DarwinPorts (there is only py-libxml2 http://xmlsoft.org/) but if it behaves as numpy or pyXML formerly it is straightforward to install and distribute (on OS 10.4 at least. we are encountering problems on 10.3 but these should be solved soon). Good luck with the translation.
JiHO
participants (2)
-
Aaron Spike
-
jiho