python-lottie  0.6.11+devcecd248
A framework to work with lottie files and telegram animated stickers (tgs)
pretty_print.py
Go to the documentation of this file.
1 import sys
2 
3 from ..objects.base import LottieObject, LottieBase
4 from ..objects.properties import MultiDimensional, Value, ShapeProperty
5 from ..objects.layers import Layer
6 
7 
8 def _prettyprint_scalar(lottie_object, out=sys.stdout):
9  if isinstance(lottie_object, float) and lottie_object == round(lottie_object):
10  lottie_object = int(lottie_object)
11  return str(lottie_object)
12 
13 
14 def prettyprint(lottie_object, out=sys.stdout, indent=" ", _i=""):
15  if isinstance(lottie_object, LottieObject):
16  out.write(lottie_object.__class__.__name__)
17  out.write('\n')
18  _i += indent
19  maxk = max(map(lambda x: len(x.name), lottie_object._props))
20  for k in lottie_object._props:
21  out.write(_i)
22  out.write(k.name.ljust(maxk))
23  out.write(' : ')
24  prettyprint(k.get(lottie_object), out, indent, _i)
25  elif isinstance(lottie_object, (list, tuple)):
26  if not lottie_object or (not isinstance(lottie_object[0], LottieBase) and len(lottie_object) < 16):
27  out.write("[")
28  out.write(", ".join(map(_prettyprint_scalar, lottie_object)))
29  out.write("]\n")
30  else:
31  out.write("[\n")
32  for k in lottie_object:
33  out.write(_i + indent)
34  prettyprint(k, out, indent, _i + indent)
35  out.write(_i)
36  out.write(']\n')
37  else:
38  out.write(_prettyprint_scalar(lottie_object, out))
39  out.write('\n')
40 
41 
42 def _prettyprint_summary_printable(obj):
43  if isinstance(obj, LottieObject):
44  return not isinstance(obj, (MultiDimensional, Value, ShapeProperty))
45  return obj and isinstance(obj, (list, tuple)) and isinstance(obj[0], LottieObject)
46 
47 
48 def prettyprint_summary(lottie_object, out=sys.stdout, indent=" ", _i=""):
49  if isinstance(lottie_object, LottieObject):
50  out.write(lottie_object.__class__.__name__)
51  name = getattr(lottie_object, "name", None)
52  if name:
53  out.write(" %r" % name)
54  if isinstance(lottie_object, Layer):
55  out.write(" %s -> %s" % (lottie_object.index, lottie_object.parent_index))
56  out.write('\n')
57  _i += indent
58  for k in lottie_object._props:
59  val = k.get(lottie_object)
60  if _prettyprint_summary_printable(val):
61  out.write(_i)
62  out.write(k.name)
63  out.write(' : ')
64  prettyprint_summary(val, out, indent, _i)
65  elif _prettyprint_summary_printable(lottie_object):
66  out.write("[\n")
67  for k in lottie_object:
68  out.write(_i + indent)
69  prettyprint_summary(k, out, indent, _i + indent)
70  out.write(_i)
71  out.write(']\n')
lottie.exporters.pretty_print.prettyprint_summary
def prettyprint_summary(lottie_object, out=sys.stdout, indent=" ", _i="")
Definition: pretty_print.py:48
lottie.exporters.pretty_print.prettyprint
def prettyprint(lottie_object, out=sys.stdout, indent=" ", _i="")
Definition: pretty_print.py:14