def load_metadata(self):
"""
Loads this node's metadata which is stored in a child comment encoded in json.
"""
for child in self:
if type(child) is NodeComment:
if child.text.startswith("<designer.metadata.do.not.edit>"):
try:
self.metadata = decode(child.text.split(maxsplit=1)[1])
except JSONDecodeError:
continue
self.model_item.setText(self.metadata.get("name", self.update_item_name()))
self.user_sort_order = self.metadata.get("user_sort", "0".zfill(7))
if not self.hidden_children:
hidden_nodes = self.metadata.get("hidden_nodes", [])
for node_string in hidden_nodes:
node_string = node_string.replace("<!- -", "<!--").replace("- ->", "-->")
node = copy_node(etree.fromstring(node_string), self) # type: _NodeElement
self.add_child(node) if node.tag is not etree.Comment else self.append(node)
node.set_hidden(True)
self.sort()
self.model_item.sortChildren(0)
评论列表
文章目录