python-lottie  0.6.11+deved4e6c7
A framework to work with lottie files and telegram animated stickers (tgs)
tree_view.py
Go to the documentation of this file.
1 from PyQt5 import QtWidgets
2 from PyQt5.QtGui import *
3 from PyQt5.QtCore import Qt
4 
5 from .. import objects
6 
7 
8 def lottie_theme_icon(lottie_object):
9  if isinstance(lottie_object, objects.Animation):
10  return "tool-animator"
11 
12  if isinstance(lottie_object, objects.Precomp):
13  return "folder"
14 
15  if isinstance(lottie_object, objects.ShapeLayer):
16  return "shapes"
17  if isinstance(lottie_object, objects.TextLayer):
18  return "draw-text"
19  if isinstance(lottie_object, objects.PreCompLayer):
20  return "emblem-symbolic-link"
21 
22  if isinstance(lottie_object, (objects.Rect, objects.SolidColorLayer)):
23  return "draw-rectangle"
24  if isinstance(lottie_object, objects.Ellipse):
25  return "draw-ellipse"
26  if isinstance(lottie_object, objects.Star):
27  return "draw-star"
28  if isinstance(lottie_object, objects.Path):
29  return "draw-bezier-curves"
30  if isinstance(lottie_object, (objects.Fill, objects.GradientFill)):
31  return "format-fill-color"
32  if isinstance(lottie_object, (objects.Stroke, objects.GradientStroke)):
33  return "format-stroke-color"
34  if isinstance(lottie_object, objects.Transform):
35  return "transform-scale"
36  if isinstance(lottie_object, objects.Group):
37  return "object-group"
38 
39  return None
40 
41 
42 def lottie_to_tree(tree_parent, lottie_object):
43  prop_to_tree(tree_parent, None, lottie_object)
44 
45 
46 def lottie_object_to_tree(item, lottie_object, propname, textcol):
47  if propname == "color" and isinstance(lottie_object, objects.MultiDimensional) and not lottie_object.animated:
48  item.setBackground(textcol, QBrush(QColor.fromRgbF(*lottie_object.value)))
49  else:
50  text = str(lottie_object)
51  if text != propname or textcol == 0:
52  item.setText(textcol, text)
53 
54  icon = lottie_theme_icon(lottie_object)
55  if icon:
56  item.setIcon(0, QIcon.fromTheme(icon))
57 
58  for prop in lottie_object._props:
59  propitem = prop_to_tree(item, prop.name, prop.get(lottie_object))
60  propitem.setToolTip(0, prop.lottie)
61 
62 
63 def prop_to_tree(tree_parent, propname, propval):
64  item = QtWidgets.QTreeWidgetItem(tree_parent)
65 
66  first_column = 0
67  if propname:
68  item.setText(0, propname)
69  first_column = 1
70 
71  if isinstance(propval, objects.LottieObject):
72  lottie_object_to_tree(item, propval, propname, first_column)
73  elif isinstance(propval, list):
74  for subval in propval:
75  prop_to_tree(item, type(subval).__name__, subval)
76  elif propval is None:
77  item.setText(first_column, "")
78  elif isinstance(propval, bool):
79  item.setCheckState(first_column, Qt.CheckState.Checked if propval else Qt.CheckState.Unchecked)
80  item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled)
81  else:
82  item.setText(first_column, str(propval))
83 
84  return item
Top level object, describing the animation.
Definition: animation.py:62
Base class for mapping Python classes into Lottie JSON objects.
Definition: base.py:225
Layer containing ShapeElement objects.
Definition: layers.py:193
Layer with a solid color rectangle.
Definition: layers.py:259
An animatable property that holds a NVector.
Definition: properties.py:471
Solid fill color.
Definition: shapes.py:509
ShapeElement that can contain other shapes.
Definition: shapes.py:433
Animatable Bezier curve.
Definition: shapes.py:399
A simple rectangle shape.
Definition: shapes.py:150
def prop_to_tree(tree_parent, propname, propval)
Definition: tree_view.py:63
def lottie_theme_icon(lottie_object)
Definition: tree_view.py:8
def lottie_to_tree(tree_parent, lottie_object)
Definition: tree_view.py:42
def lottie_object_to_tree(item, lottie_object, propname, textcol)
Definition: tree_view.py:46