| 22 | |
| 23 | |
| 24 | class InstancesTree(gui.TreeView): |
| 25 | def __init__(self, **kwargs): |
| 26 | super(InstancesTree, self).__init__(**kwargs) |
| 27 | |
| 28 | def append_instance(self, instance, parent): |
| 29 | item = gui.TreeItem(instance.variable_name) |
| 30 | if parent == None: |
| 31 | parent = self |
| 32 | item.instance = instance |
| 33 | item.onclick.do(self.on_tree_item_selected, js_stop_propagation=True) |
| 34 | parent.append(item) |
| 35 | return item |
| 36 | |
| 37 | def select_instance(self, node, instance): |
| 38 | if not hasattr(node, 'attributes'): |
| 39 | return |
| 40 | if node.identifier != self.identifier: |
| 41 | if hasattr(node, 'instance'): |
| 42 | if node.instance.identifier == instance.identifier: |
| 43 | node.style['background-color'] = 'lightblue' |
| 44 | else: |
| 45 | node.style['background-color'] = 'white' |
| 46 | node.attributes['treeopen'] = 'true' |
| 47 | for item in node.children.values(): |
| 48 | self.select_instance(item, instance) |
| 49 | |
| 50 | @gui.decorate_event |
| 51 | def on_tree_item_selected(self, emitter): |
| 52 | self.select_instance(self, emitter.instance) |
| 53 | return (emitter.instance,) |
| 54 | |
| 55 | def append_instances_from_tree(self, node, parent=None): |
| 56 | if not hasattr(node, 'attributes'): |
| 57 | return |
| 58 | if not (hasattr(node, 'variable_name') and not node.variable_name is None): |
| 59 | return |
| 60 | nodeTreeItem = self.append_instance(node, parent) |
| 61 | for child in node.children.values(): |
| 62 | self.append_instances_from_tree(child, nodeTreeItem) |
| 63 | |
| 64 | |
| 65 | class InstancesWidget(gui.VBox): |