Help required changing style attributes from a Python extension.
I am attempting to implement the full International Orienteering Federation mapping standards (ISOM:2000 and ISSOM:2007) within Inkscape.
So far, I've created a GIMP palette containing the standard colours required, using this across the bottom of my Inkscape window. I've also written an extension to generate the required point symbols and produced many of the required fill patterns, incorporating them into patterns.svg.
I'm not happy with modifying patterns.svg as this is one of the standard files provided with Inkscape. I've seen the way that the X-moto extensions use dialog boxes for changing .jpg and .png block textures and would like to do something similar for my svg patterns, but this is a medium-term objective.
The remaining symbol type that I'm looking to implement is the lines. Different line styles from simple continuous lines of a given width and colour to complex dashed lines with superimposed symbols at regular intervals are required. Given the examples available in the current Pattern along Path and Scatter extensions, the creation of the superimposed symbols isn't seen as a problem.
The problem that I'm having is in what should be a simple task - that of changing the style attributes of an existing line. I can create new dash styles by editing the preferences.xml file in my personal user area but, for many reasons, do not see this as as a realistic option and not one that could be distributed to other users. I've been trying to write a simple Python extension that will take a selected line or number of lines and replace the style of the original with a different set of style attributes without changing its path. I've looked through the currently distributed Python extensions for clues as to how to do this, but have not been successful. I've even started looking at the 1000+ page Python 2.6.4 online manual (is this the version of Python implemented in Inkscape?) but this hasn't really helped, although I've picked up some pointers for better Python coding. I'm assuming that there is a subroutine in one of the 'helper' files - inkex.py, pathmodifier.py, ... etc. that would help with this but haven't determined which one it could be. I would be grateful if someone could point me in the right direction.
Jon
Jon wrote:
The problem that I'm having is in what should be a simple task - that of changing the style attributes of an existing line. I can create new dash styles by editing the preferences.xml file in my personal user area but, for many reasons, do not see this as as a realistic option and not one that could be distributed to other users. I've been trying to write a simple Python extension that will take a selected line or number of lines and replace the style of the original with a different set of style attributes without changing its path. I've looked through the currently distributed Python extensions for clues as to how to do this, but have not been successful. I've even started looking at the 1000+ page Python 2.6.4 online manual (is this the version of Python implemented in Inkscape?) but this hasn't really helped, although I've picked up some pointers for better Python coding. I'm assuming that there is a subroutine in one of the 'helper' files - inkex.py, pathmodifier.py, ... etc. that would help with this but haven't determined which one it could be. I would be grateful if someone could point me in the right direction.
I think this might be simpler than you expect. If I'm understanding correctly you would like to modify the style attribute of various path elements. This is as simple as using the get attribute and set attribute functionality of your favorite xml manipulation library. My favorite is LXML and this is the library most Inkscape extensions use. LXML (mostly) follows the ElementTree API:
http://effbot.org/zone/pythondoc-elementtree-ElementTree.htm#elementtree.Ele... http://effbot.org/zone/pythondoc-elementtree-ElementTree.htm#elementtree.Ele... http://effbot.org/zone/pythondoc-elementtree-ElementTree.htm#elementtree.Ele...
One little annoyance is that the style attribute is multivalued. To make this easier to work with we've made a few simple routines in simplestyle.py to break a style attribute into a python dictionary and put such a dictionary back together as a style attribute string, parseStyle() and formatStyle() respectively.
http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/annotate/head%3A/sh...
Perhaps you already know this but it is important to know how your desired change affects the XML representation. Inkscape can help you figure this out. Make a simple example file and save a copy. Now modify the line styles as you desire in Inkscape and save another copy of the file. By comparing these files in a text editor or with an XML diff tool you can learn what changes you need to make to the XML with your extension. You could also refer to the appropriate section of the SVG specification:
http://www.w3.org/TR/SVG11/painting.html#StrokeProperties
To see an example from the extensions distributed with Inkscape check:
http://bazaar.launchpad.net/~inkscape.dev/inkscape/trunk/annotate/head%3A/sh...
I hope this helps.
Aaron Spike
participants (2)
-
Aaron Spike
-
Jon