Ejemplo n.º 1
0
 def addNode(self, title, inputs, outputs, posx, posy):
     try:
         node1 = Node(self.scene, title=title, inputs=inputs, outputs=outputs)
         node1.setPos(posx, posy)
     except Exception as ex:
         print("Exception caught in EditorWidget - addNode()")
         print(ex)
         handleError(ex)
Ejemplo n.º 2
0
    def categoryCreated(self, cat):
        try:
            print("slot in EditorWidget, categoryCreated")
            # print(str(cat))
            # print("category id: " + str(cat.id))
            self.aiml.append(cat)
            thatToCheck = self.getLastSentence(cat)
            print("got last sentence of category")
            title = "Category: " + cat.id
            aNode = Node(self.scene, title, cat)
            print("created node")
            aNode.content.wdg_label.displayVisuals(cat)
            print("displayed contents on node")

            for that in thatToCheck:
                self.findChildNodes(aNode, that)
            self.findParentNodes(aNode)

            self.placeNodes(self.scene.nodes)

            for node in self.scene.nodes:
                node.updateConnectedEdges()

            aNode.content.catClicked.connect(
                self.categoryClicked
            )  # connecting signals coming from Content Widget
            print("trying to connect addChild button")
            aNode.content.childClicked.connect(
                self.addChildClicked
            )  # connecting signals coming from Content Widget
        except Exception as ex:
            print("Exception caught in EditorWidget when creating category!")
            print(ex)
            handleError(ex)
Ejemplo n.º 3
0
    def deserialize(self, data, hashmap={}, restore_id=True):
        if DEBUG: print("Deserializing scene")
        self.clear()
        hashmap = {}

        if restore_id: self.objId = data['id']

        # create nodes
        for node_data in data['nodes']:
            Node(self).deserialize(node_data, hashmap, restore_id)

        # create edges
        for edge_data in data['edges']:
            Edge(self).deserialize(edge_data, hashmap, restore_id)

        return True
Ejemplo n.º 4
0
    def deserializeFromClipboard(self, data):

        hashmap = {}

        # calculate mouse pointer - scene position
        view = self.scene.grScene.views()[0]
        mouse_scene_pos = view.last_scene_mouse_position

        # calculate selected objects bbox and center
        minx, maxx, miny, maxy = 0, 0, 0, 0
        for node_data in data['nodes']:
            x, y = node_data['pos_x'], node_data['pos_y']
            if x < minx: minx = x
            if x > maxx: maxx = x
            if y < miny: miny = y
            if y > maxy: maxy = y
        bbox_center_x = (minx + maxx) / 2
        bbox_center_y = (miny + maxy) / 2

        # center = view.mapToScene(view.rect().center())

        # calculate tehe offset of the newly creating nodes
        offset_x = mouse_scene_pos.x() - bbox_center_x
        offset_y = mouse_scene_pos.y() - bbox_center_y

        # create each node
        for node_data in data['nodes']:
            new_node = Node(self.scene)
            new_node.deserialize(node_data, hashmap, restore_id=False)

            # readjust the new node's position
            pos = new_node.pos
            new_node.setPos(pos.x() + offset_x, pos.y() + offset_y)

        # create each edge
        if 'edges' in data:
            for edge_data in data['edges']:
                new_edge = Edge(self.scene)
                new_edge.deserialize(edge_data, hashmap, restore_id=False)

        # store history
        self.scene.history.storeHistory("Pasted elements in scene",
                                        setModified=True)
Ejemplo n.º 5
0
 def addNode(self, title, inputs, outputs, posx, posy):
     node1 = Node(self.scene, title=title, inputs=inputs, outputs=outputs)
     node1.setPos(posx, posy)
Ejemplo n.º 6
0
    def addNodes(self):
        node1 = Node(self.scene,
                     "My Awesome Node 1",
                     inputs=[0, 0, 0],
                     outputs=[1])
        node2 = Node(self.scene,
                     "My Awesome Node 2",
                     inputs=[3, 3, 3],
                     outputs=[1])
        node3 = Node(self.scene,
                     "My Awesome Node 3",
                     inputs=[2, 2, 2],
                     outputs=[1])
        node4 = Node(
            self.scene,
            "A Category",
            inputs=[1, 1],
            outputs=[2, 2],
        )
        node1.setPos(-350, -250)
        node2.setPos(-75, 0)
        node3.setPos(200, -150)
        node4.setPos(200, -50)

        edge1 = Edge(self.scene,
                     node1.outputs[0],
                     node2.inputs[0],
                     edge_type=EDGE_TYPE_BEZIER)
        edge2 = Edge(self.scene,
                     node2.outputs[0],
                     node3.inputs[0],
                     edge_type=EDGE_TYPE_BEZIER)
Ejemplo n.º 7
0
    def create_category_graph_view(self, cat):
        try:
            if cat.type == "topic":
                # Iterate through topic and place categories
                for category in cat.tags:
                    thatToCheck = self.graphview.getLastSentence(category)
                    if DEBUG: print("got last sentence of category")
                    title = "Category: " + category.cat_id
                    aNode = Node(self.graphview.scene, title, category)
                    if DEBUG: print("created node")
                    aNode.content.wdg_label.displayVisuals(category)
                    if DEBUG: print("displayed contents on node")

                    if thatToCheck is not None:
                        for that in thatToCheck:
                            self.graphview.findChildNodes(aNode, that)

                    # FIXME: Nodes only get placed if there are <that> tags otherwise get stacked in default place.
                    self.graphview.findParentNodes(aNode)
                    self.graphview.placeNodes(self.graphview.scene.nodes)

                    for node in self.graphview.scene.nodes:
                        node.updateConnectedEdges()

                    aNode.content.catClicked.connect(
                        self.graphview.categoryClicked
                    )  # connecting signals coming from Content Widget

                    # NOTE: When addChildClicked has been implemented then this can be uncommented
                    # if DEBUG: print("trying to connect addChild button")
                    # aNode.content.childClicked.connect(self.graphview.addChildClicked) # connecting signals coming from Content Widget
            elif cat.type == "comment":
                print("Comment found, don't display comments on graphview.")
            else:
                thatToCheck = self.graphview.getLastSentence(cat)
                if DEBUG: print("got last sentence of category")
                title = "Category: " + cat.cat_id
                aNode = Node(self.graphview.scene, title, cat)
                if DEBUG: print("created node")
                aNode.content.wdg_label.displayVisuals(cat)
                if DEBUG: print("displayed contents on node")

                if thatToCheck is not None:
                    for that in thatToCheck:
                        self.graphview.findChildNodes(aNode, that)

                self.graphview.findParentNodes(aNode)
                self.graphview.placeNodes(self.graphview.scene.nodes)

                for node in self.graphview.scene.nodes:
                    node.updateConnectedEdges()

                aNode.content.catClicked.connect(
                    self.graphview.categoryClicked
                )  # connecting signals coming from Content Widget
        except Exception as ex:
            print(
                "Exception caught in TabController - create_category_graph_view()"
            )
            print(ex)
            handleError(ex)