@falldeaf/$1 recognizer gesture creator
Python3

No description

I built🔨
THIS
Files
  • main.py
  • gestures.svg
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#  $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(" ");
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux