Help required with Python extensions

Post questions on how to use or achieve an effect in Inkscape.
JonE
Posts: 6
Joined: Tue Feb 02, 2010 8:14 am
Location: UK

Help required with Python extensions

Postby JonE » Mon Mar 15, 2010 2:39 am

As you may have gathered from my previous posts, I am attempting to implement the full International Orienteering Federation mapping standards (ISOM:2000 and ISSOM:2007) within Inkscape.

In order to realise this objective, work is required in four main areas and I have made significant progress in three of them:

Colours. I have created a GIMP palette containing all the standard colours required and have replaced the default palette across the bottom of Inkscape with my own.

Area Fill Patterns. I have created a large number of the required fill patterns, writing these into the patterns.svg file and its just a matter of time to create the rest. I'm not happy with this approach, due to the number of different fills and because I'm modifying one of the standard files provided with Inkscape. I've seen the way that the X-moto extensions use dialog boxes for changing block textures and hope to implement something similar at a later stage (when I've worked out how they've done it and how to modify it to work with SVG patterns rather than .jpg and .png files). Any help in this direction would be appreciated.

Point Symbols. I've written an extension to generate the required symbols, placing them at the centre of the current canvas view. Not all of the symbols have been created yet, but its just a matter of time.

Line Symbols. 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 of an existing line, including its style:, stroke-width:, stroke-dasharray: and stroke-dashoffset: attributes. 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. For the last few days I've been trying to write a Python extension that will take a line or number of lines selected by the user and to replace the style of the original lines with a different set of style attributes. I've been looking through all of the currently distributed Python extensions but so far I've not been able to fathom out how to do this. I've even tried 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. I'm assuming that there is a subroutine in one of the 'helper' files - inkex.py, pathmodifier.py, ... etc. to help with this but haven't determined which one it could be.

So if anyone could help, I'd be most grateful.

turquoise
Posts: 20
Joined: Mon Feb 04, 2008 6:48 am

Will "Paste Style" do what you need?

Postby turquoise » Sat Mar 20, 2010 12:30 am

hi,
I don't know how to do this in Python but there is a regular menu item "Paste Style" which may do what you want. Select a line which has the current style that you want and Edit->Copy or Ctrl+c. Select a line or multiple lines which are to receive the style and Edit->Paste Style or Shift+Ctrl+V. If you can manually select the lines which need to be changed could be the easiest method instead of writing a python program.
Hope this helps.

User avatar
RobA
Posts: 335
Joined: Fri Aug 10, 2007 1:22 am

Re: Help required with Python extensions

Postby RobA » Sat Mar 20, 2010 12:44 am

As far as I know, to change an attribute like the line style you have to parse the dom of the SVG (XML), and just change it.

It is the "style" attribute.

If you want to just set the whole stylem you can just access the node with .set('style', whatever)

To make more complicated styles up use the simplestyle library to access it using simplestyle.parseStyle and simplestyle.formatStyle

Look at markers_strokepaint.py where it changes the style of markers to match the line style.

-Rob A>


Return to “Help with using Inkscape”