$1 recognizer gesture creator

gestures.svg

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->

<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   width="300"
   height="300"
   viewBox="0 0 300 300"
   id="svg2"
   version="1.1"
   inkscape:version="0.91 r13725"
   sodipodi:docname="symbols2.svg">
  <defs
     id="defs4">
    <marker
       inkscape:stockid="EmptyTriangleOutS"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="EmptyTriangleOutS"
       style="overflow:visible"
       inkscape:isstock="true">
      <path
         id="path4320"
         d="M 5.77,0.0 L -2.88,5.0 L -2.88,-5.0 L 5.77,0.0 z "
         style="fill-rule:evenodd;fill:#ffffff;stroke:#000000;stroke-width:1pt;stroke-opacity:1"
         transform="scale(0.2) translate(-3.0,0)" />
    </marker>
    <marker
       inkscape:stockid="SemiCircleOut"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="SemiCircleOut"
       style="overflow:visible"
       inkscape:isstock="true">
      <path
         id="path4335"
         d="M -2.5,-0.80913858 C -2.5,1.9508614 -4.7400000,4.1908614 -7.5,4.1908614 L -7.5,-5.8091386 C -4.7400000,-5.8091386 -2.5,-3.5691386 -2.5,-0.80913858 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.6) translate(7.125493,0.763446)" />
    </marker>
    <marker
       inkscape:stockid="DiamondS"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="DiamondS"
       style="overflow:visible"
       inkscape:isstock="true">
      <path
         id="path4239"
         d="M 0,-7.0710768 L -7.0710894,0 L 0,7.0710589 L 7.0710462,0 L 0,-7.0710768 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.2)" />
    </marker>
    <marker
       inkscape:stockid="Torso"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="Torso"
       style="overflow:visible"
       inkscape:isstock="true">
      <g
         id="g4366"
         transform="scale(0.7)"
         style="stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1">
        <path
           id="path4368"
           d="M -4.7792281,-3.2395420 C -2.4288541,-2.8736027 0.52103922,-1.3019943 0.25792722,0.38794346 C -0.0051877922,2.0778819 -2.2126741,2.6176539 -4.5630471,2.2517169 C -6.9134221,1.8857769 -8.5210350,0.75201414 -8.2579220,-0.93792336 C -7.9948090,-2.6278615 -7.1296041,-3.6054813 -4.7792281,-3.2395420 z "
           style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1.25;stroke-opacity:1" />
        <path
           id="path4370"
           d="M 4.4598789,0.088665736 C -2.5564571,-4.3783320 5.2248769,-3.9061806 -0.84829578,-8.7197331"
           style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1" />
        <path
           id="path4372"
           d="M 4.9298719,0.057520736 C -1.3872731,1.7494689 1.8027579,5.4782079 -4.9448731,7.5462725"
           style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1" />
        <rect
           id="rect4374"
           transform="matrix(0.527536,-0.849533,0.887668,0.460484,0,0)"
           y="-1.7408575"
           x="-10.391706"
           height="2.7608147"
           width="2.6366582"
           style="fill-rule:evenodd;stroke-width:1pt;stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1" />
        <rect
           id="rect4376"
           transform="matrix(0.671205,-0.741272,0.790802,0.612072,0,0)"
           y="-7.9629307"
           x="4.9587269"
           height="2.8614161"
           width="2.7327356"
           style="fill-rule:evenodd;stroke-width:1pt;stroke:#000000;stroke-opacity:1;fill:#000000;fill-opacity:1" />
        <path
           id="path4378"
           transform="matrix(0,-1.109517,1.109517,0,25.96648,19.71619)"
           d="M 16.779951 -28.685045 A 0.60731727 0.60731727 0 1 0 15.565317,-28.685045 A 0.60731727 0.60731727 0 1 0 16.779951 -28.685045 z"
           style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1" />
        <path
           id="path4380"
           transform="matrix(0,-1.109517,1.109517,0,26.82450,16.99126)"
           d="M 16.779951 -28.685045 A 0.60731727 0.60731727 0 1 0 15.565317,-28.685045 A 0.60731727 0.60731727 0 1 0 16.779951 -28.685045 z"
           style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1" />
      </g>
    </marker>
    <marker
       inkscape:stockid="Arrow1Mend"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="Arrow1Mend"
       style="overflow:visible;"
       inkscape:isstock="true">
      <path
         id="path4163"
         d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.4) rotate(180) translate(10,0)" />
    </marker>
    <marker
       inkscape:stockid="Arrow1Mstart"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="marker4608"
       style="overflow:visible"
       inkscape:isstock="true">
      <path
         id="path4610"
         d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.4) translate(10,0)" />
    </marker>
    <marker
       inkscape:stockid="DotL"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="DotL"
       style="overflow:visible"
       inkscape:isstock="true">
      <path
         id="path4215"
         d="M -2.5,-1.0 C -2.5,1.7600000 -4.7400000,4.0 -7.5,4.0 C -10.260000,4.0 -12.5,1.7600000 -12.5,-1.0 C -12.5,-3.7600000 -10.260000,-6.0 -7.5,-6.0 C -4.7400000,-6.0 -2.5,-3.7600000 -2.5,-1.0 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.8) translate(7.4, 1)" />
    </marker>
    <marker
       inkscape:stockid="Arrow1Mstart"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="Arrow1Mstart"
       style="overflow:visible"
       inkscape:isstock="true">
      <path
         id="path4160"
         d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.4) translate(10,0)" />
    </marker>
    <marker
       inkscape:stockid="Arrow1Lend"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="marker4462"
       style="overflow:visible;"
       inkscape:isstock="true">
      <path
         id="path4464"
         d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.8) rotate(180) translate(12.5,0)" />
    </marker>
    <marker
       inkscape:stockid="Arrow1Lstart"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="Arrow1Lstart"
       style="overflow:visible"
       inkscape:isstock="true">
      <path
         id="path4154"
         d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.8) translate(12.5,0)" />
    </marker>
    <marker
       inkscape:stockid="Arrow1Lend"
       orient="auto"
       refY="0.0"
       refX="0.0"
       id="Arrow1Lend"
       style="overflow:visible;"
       inkscape:isstock="true">
      <path
         id="path4157"
         d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
         style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;stroke-opacity:1;fill:#000000;fill-opacity:1"
         transform="scale(0.8) rotate(180) translate(12.5,0)" />
    </marker>
  </defs>
  <sodipodi:namedview
     id="base"
     pagecolor="#ffffff"
     bordercolor="#666666"
     borderopacity="1.0"
     inkscape:pageopacity="0.0"
     inkscape:pageshadow="2"
     inkscape:zoom="2.2711679"
     inkscape:cx="151.64526"
     inkscape:cy="135.71429"
     inkscape:document-units="px"
     inkscape:current-layer="layer2"
     showgrid="false"
     units="px"
     inkscape:window-width="1920"
     inkscape:window-height="1058"
     inkscape:window-x="1912"
     inkscape:window-y="-8"
     inkscape:window-maximized="1" />
  <metadata
     id="metadata7">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     inkscape:label="base"
     inkscape:groupmode="layer"
     id="layer1"
     transform="translate(0,-752.36216)"
     style="display:inline">
    <path
       style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:4;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
       id="path4143"
       sodipodi:type="arc"
       sodipodi:cx="150.14302"
       sodipodi:cy="902.21912"
       sodipodi:rx="140.89667"
       sodipodi:ry="140.89667"
       sodipodi:start="0"
       sodipodi:end="6.0525575"
       sodipodi:open="true"
       d="M 291.03969,902.21912 A 140.89667,140.89667 0 0 1 158.26219,1042.8817 A 140.89667,140.89667 0 0 1 10.182088,918.43048 A 140.89667,140.89667 0 0 1 125.89335,763.42494 A 140.89667,140.89667 0 0 1 287.30918,870.01172" />
  </g>
  <g
     inkscape:groupmode="layer"
     id="layer2"
     inkscape:label="levitate"
     style="display:inline">
    <path
       style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
       d="M 287.51727,157.78242 L 273.86791,207.97686 L 237.32283,255.08919 L 192.41202,280.62671 L 134.29214,286.35063 L 67.366222,261.25342 L 25.09722,210.17837 L 12.768761,160.86454 L 37.12946,140.13035 L 53.541799,126.16127 L 90.59888,94.620779 L 123.28804,66.797964 L 138.82035,53.577908 L 148.82211,45.065083 L 165.76708,59.789675 L 179.3971,71.633695 L 192.87487,83.345413 L 207.9115,96.411722 L 212.66592,100.54315"
       id="path4256"
       inkscape:connector-curvature="0"
       sodipodi:nodetypes="ccccccccccccccccccc" />
  </g>
  <g
     inkscape:groupmode="layer"
     id="layer3"
     inkscape:label="life"
     style="display:inline">
    <path
       style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
       d="M 184.92688,16.445446 L 227.19588,34.938135 L 275.18881,91.296804 L 287.51727,173.6333 L 244.80797,251.12647 L 164.67299,286.79094 L 66.045315,261.69372 L 14.089667,181.55873 L 19.373292,103.18496 L 58.56018,45.065083 L 125.0458,15.12454"
       id="path4254"
       inkscape:connector-curvature="0" />
  </g>
</svg>

main.py

#  $1 Gesture creator
#  Author: falldeaf
#  Site: falldeaf.com
#  Email: [email protected]
#  Instructions: 1.) Create an Vector file with a single line/Path on layers 2 and up
#                2.) Export as SVG, make sure coordinates are set to Absolute *BEFORE* creating your lines (tested in inkscape)
#                3.) add XML/SVG to gesture.svg file and place in same directory

from xml.dom import minidom
import re

xmldoc = minidom.parse('gestures.svg')
layers = xmldoc.getElementsByTagName('g')

for g in layers:
  if g.attributes['id'].value.startswith('layer') and g.attributes['id'].value != "layer1":
    name = g.attributes['inkscape:label'].value
    
    print("[" + g.attributes['id'].value.upper() + "] - (" + name + ")")
    
    path = g.getElementsByTagName('path')[0]
    xylist = re.sub('[A-Za-z]', '', path.attributes['d'].value)
    #print(xylist)
    
    print('this.Templates.Push( new Template("' + name + '", new Array(', end='')
    
    points = []
    for xys in xylist.split():
      xy = xys.split(',')
      np = 'new Point(' + xy[0] + ',' + xy[1] + ')'
      points.append(np)

    print(",".join(points), end='')
    print(')));')
    print(" ");