tools: add a format toggle for switching between json and svg
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
6a1c2bb4d9
commit
723b4fec35
|
@ -40,7 +40,7 @@ logging.basicConfig(format='%(asctime)s %(levelname)s: %(name)s: %(message)s',
|
||||||
logger = logging.getLogger('tuhi') # set the pseudo-root logger to take advantage of the other loggers
|
logger = logging.getLogger('tuhi') # set the pseudo-root logger to take advantage of the other loggers
|
||||||
|
|
||||||
|
|
||||||
def parse_file(filename, tablet_model, orientation):
|
def parse_file(filename, file_format, tablet_model, orientation):
|
||||||
width = tablet_model.width
|
width = tablet_model.width
|
||||||
height = tablet_model.height
|
height = tablet_model.height
|
||||||
pressure = tablet_model.pressure
|
pressure = tablet_model.pressure
|
||||||
|
@ -81,8 +81,10 @@ def parse_file(filename, tablet_model, orientation):
|
||||||
stroke.new_abs((p.x * ps, p.y * ps), normalize(p.p))
|
stroke.new_abs((p.x * ps, p.y * ps), normalize(p.p))
|
||||||
stroke.seal()
|
stroke.seal()
|
||||||
d.seal()
|
d.seal()
|
||||||
with open(jsonname, 'w') as fd:
|
if file_format == 'json':
|
||||||
fd.write(d.to_json())
|
with open(jsonname, 'w') as fd:
|
||||||
|
fd.write(d.to_json())
|
||||||
|
return
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
js = json.load(StringIO(d.to_json()))
|
js = json.load(StringIO(d.to_json()))
|
||||||
|
@ -106,7 +108,7 @@ def main(args=sys.argv):
|
||||||
Input data is a raw log file. These are usually stored in
|
Input data is a raw log file. These are usually stored in
|
||||||
\t$XDG_DATA_HOME/tuhi/<bluetooth address>/raw/
|
\t$XDG_DATA_HOME/tuhi/<bluetooth address>/raw/
|
||||||
|
|
||||||
Pass the log file to this tool and it will convert it to a JSON file and
|
Pass the log file to this tool and it will convert it to a JSON file or
|
||||||
an SVG file. Alternatively, use --all to convert all
|
an SVG file. Alternatively, use --all to convert all
|
||||||
all log files containing pen data in the above directory.
|
all log files containing pen data in the above directory.
|
||||||
|
|
||||||
|
@ -137,6 +139,10 @@ def main(args=sys.argv):
|
||||||
help='Use defaults from the given tablet model',
|
help='Use defaults from the given tablet model',
|
||||||
default='intuos-pro',
|
default='intuos-pro',
|
||||||
choices=['intuos-pro', 'slate', 'spark'])
|
choices=['intuos-pro', 'slate', 'spark'])
|
||||||
|
parser.add_argument('--format',
|
||||||
|
help='The format to generate. Default: svg',
|
||||||
|
default='svg',
|
||||||
|
choices=['svg', 'json'])
|
||||||
|
|
||||||
ns = parser.parse_args(args[1:])
|
ns = parser.parse_args(args[1:])
|
||||||
if ns.verbose:
|
if ns.verbose:
|
||||||
|
@ -156,7 +162,7 @@ def main(args=sys.argv):
|
||||||
'spark': WacomProtocolSpark,
|
'spark': WacomProtocolSpark,
|
||||||
}
|
}
|
||||||
for f in files:
|
for f in files:
|
||||||
parse_file(f, model_map[ns.tablet_model], ns.orientation)
|
parse_file(f, ns.format, model_map[ns.tablet_model], ns.orientation)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in New Issue