.
Aurium.Colivre.Coop.br Esse site é Legal Demais para Internet Explorer

Aurium :: WritingInkscapeExtensionsInJavascript

Últimas blogadas:

%HEADLINES{"http://softwarelivre.org/aurium/blog/feed" refresh="600" header="SoftwareLivre.org" limit="15" format=" * $title" }% %HEADLINES{"http://cirandas.net/aurium/blog/feed" refresh="600" header="Cirandas.net" limit="15" format=" * $title" }%



Before you read how to do an Javascript extension for Inkscape, is a good idea to read the "Scripting HOW TO" and "Making an INX" tutorials.

There is a lot of things to do… but…
Now you can be a beta-tester of the InkMoz - the Bridge from Inkscape to Mozilla

Well, now you know there is two files to define an Inkscape extension: an executable (script or binary) and the INX file, to say for the Inkscape what this extension need and how to call that.

You can put this files into one of this directories:

So… Staring to make your first effect in Javascript:

Create the my-test.inx file with this content:
<inkscape-extension>

  <_name>my InkMoz test</_name>
  <id>org.inkmoz.filter.mytest</id>
  
  <dependency type="executable" location="path">xulrunner</dependency>
  <dependency type="executable" location="extensions">/InkMoz/runInkMoz.py</dependency>
  <dependency type="file" location="extensions">my-inkmoz-test.py</dependency>
  
  <param name="fill" type="string" _gui-text="Fill Color">blue</param>
  
  <effect>
    <object-type>all</object-type>
    <effects-menu>
      <submenu _name="Testing"/>
    </effects-menu>                   
  </effect>
  
  <script>
    <command reldir="extensions">my-inkmoz-test.py</command>
  </script>

</inkscape-extension>

What? Why the extension is a Python file???

For now we need a system executable file, so a little piece of python code will do the work. I will put a Bug report for Inkscape developers and we will not need that on the future.

This little mixed script is needed becose we can't send extra arguments for the executable by the INX file when it is on the extensions dir. See the example:
<command reldir="extensions">testing_inkmoz.py --s=script.js</command>
It can do what the InkMoz need but it wil be not right understanded by the Inkscape. I think the inkscape can add the type hidden for effects parameters, like this:
<param name="occult" type="hidden">my static arg value</param>
Whith that we can call directly /InkMoz/runInkMoz.py without mix script. But… Don't worry with that now.

Now, create the my-inkmoz-test.py script file with this content:
#!/usr/bin/env python

# This little Python code must work every where.
# ...where exists Python and Inkscape. ;-)
# This will allow to start the InkMoz.
import os, imp
inkExtDir = os.popen( 'inkscape -x' ).read().strip()
imp.load_source( 'runInkMoz', inkExtDir+'/InkMoz/runInkMoz.py' )

'''
START_JAVASCRIPT_CODE

alert( "Hello World!\nThis is my first Javascript efect for Inkscape!" );

// Convert the color of selected elements:
for ( var i=0; i < inkMoz.args.id.length; i++ ) {
  var elem = inkMoz.svgDoc.getElementById( inkMoz.args.id[i] );
  if ( elem.nodeName == "g" ) {
    alert("Group painting is not implemented on this test script,\n"+
          "because we need to paint the childs recursively.");
  }
  elem.style.setProperty( "fill", inkMoz.args.fill, "" )
}

inkMoz.workDone();
// You must call the workDone() to tell that you finish.
// It is important for who want to make some thing interactive or asynchronous.

END_JAVASCRIPT_CODE
'''

The lines where only exists START_JAVASCRIPT_CODE and END_JAVASCRIPT_CODE will tell for the InkMoz where is the javascript code area.

The '''''' is a python multiline string, and with that the javascript code will not fight with the little python.

DiggThis

Copyright © 2004 - 2019 Aurélio A. Heckert
Conteúdo licenciado sob Creative Commons by-nc-sa