User:Silviolorusso/mipsum: Difference between revisions
(Created page with "== MIPSUM, an Inkscape "lorem ipsum" plugin for learning while practicing == '''WHAT?''' <br/> A plugin that generates placeholder text randomly taken from the [http://flossma...") |
|||
(11 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[Category: Cookbook]] | |||
== MIPSUM, an Inkscape "lorem ipsum" plugin for learning while practicing == | == MIPSUM, an Inkscape "lorem ipsum" plugin for learning while practicing == | ||
[[File:mipsum-before.png]] [[File:mipsum-after.png]]<br/><br/> | |||
'''WHAT?''' <br/> | '''WHAT?''' <br/> | ||
A plugin that generates | A plugin that generates place-holder text randomly taken from the [http://flossmanuals.net/Inkscape/ FLOSS Manual for Inkscape]. | ||
'''HOW?''' <br/> | '''HOW?''' <br/> | ||
1. Install the plugin putting the files contained in the following .zip in your Inkscape extension folder ($HOME/.config/inkscape/extensions/ or /usr/share/inkscape/extensions): | |||
[[Media:mipsum.zip]] <br/> | |||
2. Create a textbox (or more) and write the word "mipsum" followed (without any space) by the number of characters you want to generate. | |||
3. In your Inkscape, go to Extensions>Python>Mipsum. It will generate text taken from the manual for Inkscape. | |||
4. Learn new tricks and techniques. | |||
<br/> | |||
'''CODE''' <br/> | |||
helloworld.inx describes your extensions to Inkscape. | |||
<source lang="xml"> | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension"> | |||
<_name>Mipsum</_name> | |||
<id>pzi.helloworld</id> | |||
<dependency type="executable" location="extensions">mipsum.py</dependency> | |||
<effect> | |||
<object-type>all</object-type> | |||
<effects-menu> | |||
<submenu _name="Python"/> | |||
</effects-menu> | |||
</effect> | |||
<script> | |||
<command reldir="extensions" interpreter="python">mipsum.py</command> | |||
</script> | |||
</inkscape-extension> | |||
</source> | |||
mipsum.py is the actual extension. | |||
<source lang="python"> | |||
import os | |||
import random | |||
import sys, codecs | |||
from lxml import etree | |||
f = codecs.open(sys.argv[-1], encoding="utf-8") | |||
# open the file and parse into an etree file | |||
t = etree.parse(f) | |||
# modify the tree | |||
NS = {"svg": "http://www.w3.org/2000/svg"} | |||
# get the inkscape manual from flossmanuals.net | |||
lynxcmd = "lynx -dump -nolist http://en.flossmanuals.net/inkscape/_all/ | tr '\n' ' ' | sed 's/ */\ /g'" | |||
data = os.popen(lynxcmd).read() | |||
for flowPara in t.xpath("//svg:flowPara", namespaces=NS): | |||
if flowPara.text[0:6] == "mipsum" : | |||
# get the number of charachters to generate | |||
charnum = int(flowPara.text[6:]) | |||
# takes a random part of the text inside the manual | |||
charnumend = random.randint(0,239605) | |||
charnumbegin = charnumend - charnum | |||
flowPara.text = data[charnumbegin:charnumend] | |||
# output tree | |||
sys.stdout.write(etree.tostring(t, encoding="utf-8", xml_declaration=True)) | |||
</source> |
Latest revision as of 18:26, 11 December 2011
MIPSUM, an Inkscape "lorem ipsum" plugin for learning while practicing
WHAT?
A plugin that generates place-holder text randomly taken from the FLOSS Manual for Inkscape.
HOW?
1. Install the plugin putting the files contained in the following .zip in your Inkscape extension folder ($HOME/.config/inkscape/extensions/ or /usr/share/inkscape/extensions):
2. Create a textbox (or more) and write the word "mipsum" followed (without any space) by the number of characters you want to generate.
3. In your Inkscape, go to Extensions>Python>Mipsum. It will generate text taken from the manual for Inkscape.
4. Learn new tricks and techniques.
CODE
helloworld.inx describes your extensions to Inkscape.
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>Mipsum</_name>
<id>pzi.helloworld</id>
<dependency type="executable" location="extensions">mipsum.py</dependency>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="Python"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">mipsum.py</command>
</script>
</inkscape-extension>
mipsum.py is the actual extension.
import os
import random
import sys, codecs
from lxml import etree
f = codecs.open(sys.argv[-1], encoding="utf-8")
# open the file and parse into an etree file
t = etree.parse(f)
# modify the tree
NS = {"svg": "http://www.w3.org/2000/svg"}
# get the inkscape manual from flossmanuals.net
lynxcmd = "lynx -dump -nolist http://en.flossmanuals.net/inkscape/_all/ | tr '\n' ' ' | sed 's/ */\ /g'"
data = os.popen(lynxcmd).read()
for flowPara in t.xpath("//svg:flowPara", namespaces=NS):
if flowPara.text[0:6] == "mipsum" :
# get the number of charachters to generate
charnum = int(flowPara.text[6:])
# takes a random part of the text inside the manual
charnumend = random.randint(0,239605)
charnumbegin = charnumend - charnum
flowPara.text = data[charnumbegin:charnumend]
# output tree
sys.stdout.write(etree.tostring(t, encoding="utf-8", xml_declaration=True))