Exemplo n.º 1
0
    def set_entity(self, event):
        entity = event.entity

        # first do a soft clear of the tree view
        for i in range(self.activation_component_tree_view.topLevelItemCount()-1,-1,-1):
            item = self.activation_component_tree_view.takeTopLevelItem(i)
            for j in range(item.childCount()-1,-1,-1):
                child_item = item.takeChild(j)

        # repopulate the tree with the current entity's components
        tl_items = self.context['entities'][entity]['components'].keys()
        # component types represent the top level tree items
        for item in tl_items:
            components = self.context['entities'][entity]['components'][item]
            tl_tree_item = TreeWidgetItemComponent(item, components)
            self.activation_component_tree_view.addTopLevelItem(tl_tree_item)
            # the components should all be listed under their respective 
            # component type
            for component in components:
                tree_item = TreeWidgetItemComponent(component.text, component)
                tl_tree_item.addChild(tree_item)

        # now do this same stuff for the rule value component tree
        rule_value_tree = self.rule_value_component_tree_view
        # clear it out first
        for i in range(rule_value_tree.topLevelItemCount()-1,-1,-1):
            item = rule_value_tree.takeTopLevelItem(i)
            for j in range(item.childCount()-1,-1,-1):
                child_item = item.takeChild(j)
                for k in range(child_item.childCount()-1,-1,-1):
                    grand_child_item = child_item.takeChild(k)

        # then repopulate the tree with components and component properties
        tl_items = self.context['entities'][entity]['components'].keys()
        for item in tl_items:
            components = self.context['entities'][entity]['components'][item]
            tl_tree_item = TreeWidgetItemComponent(item, components)
            rule_value_tree.addTopLevelItem(tl_tree_item)
            for component in components:
                component_item = TreeWidgetItemComponent(component.text, component)
                tl_tree_item.addChild(component_item)
                # then add a child item for each non-private attribute of 
                # this component
                for name in (x for x in dir(component.component) if not x.startswith('_')):
                    # still using outer component
                    val = LambdaDef(component, name)
                    component_attr_item = TreeWidgetItemComponent(name, val)
                    component_item.addChild(component_attr_item)

        # finally, repopulate the state component list
        self.state_list_view.clear()
        for state in self.context['entities'][entity]['components']['state']:
            widget_component = WidgetItemComponent(state.text, state)
            self.state_list_view.addItem(widget_component)
Exemplo n.º 2
0
    def _find_components(self):
        # set the currently selected entity, if any
        entity = self.context['selected_entity']
        if not entity:
            return

        # repopulate the tree view
        entity_components = self.context['entities'][entity]['components']
        for comp_type in entity_components.keys():
            components = entity_components[comp_type]
            tl_item = TreeWidgetItemComponent(comp_type, components)
            self.component_tree_view.addTopLevelItem(tl_item)
            for component in components:
                # first add this component as a child item to the
                # component type top level item
                component_item = TreeWidgetItemComponent(component.text, component)
                tl_item.addChild(component_item)
                # then add each property of this component as
                # an additional nested level of child items
                for name in (x for x in dir(component.component) if not x.startswith('_')):
                    val = LambdaDef(component, name)
                    component_attr_item = TreeWidgetItemComponent(name, val)
                    component_item.addChild(component_attr_item)