File indexing completed on 2025-01-19 03:59:52
0001 from PyQt5 import QtWidgets 0002 from PyQt5.QtGui import * 0003 from PyQt5.QtCore import Qt 0004 0005 from .. import objects 0006 0007 0008 def lottie_theme_icon(lottie_object): 0009 if isinstance(lottie_object, objects.Animation): 0010 return "tool-animator" 0011 0012 if isinstance(lottie_object, objects.Precomp): 0013 return "folder" 0014 0015 if isinstance(lottie_object, objects.ShapeLayer): 0016 return "shapes" 0017 if isinstance(lottie_object, objects.TextLayer): 0018 return "draw-text" 0019 if isinstance(lottie_object, objects.PreCompLayer): 0020 return "emblem-symbolic-link" 0021 0022 if isinstance(lottie_object, (objects.Rect, objects.SolidColorLayer)): 0023 return "draw-rectangle" 0024 if isinstance(lottie_object, objects.Ellipse): 0025 return "draw-ellipse" 0026 if isinstance(lottie_object, objects.Star): 0027 return "draw-star" 0028 if isinstance(lottie_object, objects.Path): 0029 return "draw-bezier-curves" 0030 if isinstance(lottie_object, (objects.Fill, objects.GradientFill)): 0031 return "format-fill-color" 0032 if isinstance(lottie_object, (objects.Stroke, objects.GradientStroke)): 0033 return "format-stroke-color" 0034 if isinstance(lottie_object, objects.Transform): 0035 return "transform-scale" 0036 if isinstance(lottie_object, objects.Group): 0037 return "object-group" 0038 0039 return None 0040 0041 0042 def lottie_to_tree(tree_parent, lottie_object): 0043 prop_to_tree(tree_parent, None, lottie_object) 0044 0045 0046 def lottie_object_to_tree(item, lottie_object, propname, textcol): 0047 if propname == "color" and isinstance(lottie_object, objects.MultiDimensional) and not lottie_object.animated: 0048 item.setBackground(textcol, QBrush(QColor.fromRgbF(*lottie_object.value))) 0049 else: 0050 text = str(lottie_object) 0051 if text != propname or textcol == 0: 0052 item.setText(textcol, text) 0053 0054 icon = lottie_theme_icon(lottie_object) 0055 if icon: 0056 item.setIcon(0, QIcon.fromTheme(icon)) 0057 0058 for prop in lottie_object._props: 0059 propitem = prop_to_tree(item, prop.name, prop.get(lottie_object)) 0060 propitem.setToolTip(0, prop.lottie) 0061 0062 0063 def prop_to_tree(tree_parent, propname, propval): 0064 item = QtWidgets.QTreeWidgetItem(tree_parent) 0065 0066 first_column = 0 0067 if propname: 0068 item.setText(0, propname) 0069 first_column = 1 0070 0071 if isinstance(propval, objects.LottieObject): 0072 lottie_object_to_tree(item, propval, propname, first_column) 0073 elif isinstance(propval, list): 0074 for subval in propval: 0075 prop_to_tree(item, type(subval).__name__, subval) 0076 elif propval is None: 0077 item.setText(first_column, "") 0078 elif isinstance(propval, bool): 0079 item.setCheckState(first_column, Qt.CheckState.Checked if propval else Qt.CheckState.Unchecked) 0080 item.setFlags(Qt.ItemFlag.ItemIsSelectable | Qt.ItemFlag.ItemIsEnabled) 0081 else: 0082 item.setText(first_column, str(propval)) 0083 0084 return item