Ejemplo n.º 1
0
    def add_comment(self, comment=None):
        """
        This method add a comment in the diagram.

            Parameters:
                * **block**
            Returns:
                * **Types** (:class:`boolean<boolean>`)
        """
        self.do("Add Comment")
        new_comment = Comment(self.diagram, comment)
        self.diagram.comments.append(new_comment)
        if comment is None:
            new_comment.is_selected = True
            self.diagram.show_comment_property(new_comment)
        self.diagram.redraw()
        return comment
Ejemplo n.º 2
0
    def test_save(self):
        file_name = get_temp_file() + ".mscd"
        diagram_control = self.create_diagram_control()

        comment = Comment(diagram_control.diagram, None)
        diagram_control.add_comment(comment)
        result = diagram_control.save(file_name)

        os.remove(file_name)

        self.assertTrue(result, "Failed to save diagram")
Ejemplo n.º 3
0
    def test_save(self):
        file_name = get_temp_file() + ".mscd"
        diagram_control = self.create_diagram_control()

        comment = Comment(diagram_control.diagram)
        comment.diagram.file_name = file_name
        DiagramControl.add_comment(comment.diagram, comment)

        result = DiagramPersistence.save(comment.diagram)

        os.remove(file_name)

        self.assertTrue(result, "Failed to save preferences")
Ejemplo n.º 4
0
    def test_load(self):
        file_name = get_temp_file() + ".mscd"
        diagram_control = self.create_diagram_control()

        comment = Comment(diagram_control.diagram)
        DiagramControl.add_comment(comment.diagram, comment)
        diagram_control.save(file_name)

        diagram_control_load = self.create_diagram_control()
        result = diagram_control_load.load(file_name)

        os.remove(file_name)

        self.assertTrue(result, "Failed to load diagram")
Ejemplo n.º 5
0
    def test_load_save(self):
        file_name = get_temp_file() + ".mscd"
        diagram_control = self.create_diagram_control()
        diagram = diagram_control.diagram

        diagram.file_name = "."
        DiagramPersistence.save(diagram)

        comment = Comment(diagram)
        diagram.file_name = file_name
        DiagramControl.add_comment(diagram, comment)

        System()
        blocks = System.get_blocks()
        for key in blocks:
            block1 = Block(diagram, blocks[key])
            DiagramControl.add_block(diagram, block1)

        source = None
        source_port = None
        for key in diagram.blocks:
            for port in diagram.blocks[key].ports:
                if not port.is_input():
                    source = diagram.blocks[key]
                    source_port = port
                    break

        sink = None
        sink_port = None
        for key in diagram.blocks:
            for port in diagram.blocks[key].ports:
                if port.is_input():
                    sink = diagram.blocks[key]
                    sink_port = port
                    break

        connection = ConnectionModel(diagram, source, source_port, sink,
                                     sink_port)
        DiagramControl.add_connection(diagram, connection)

        block0 = self.create_block(diagram_control)

        DiagramPersistence.save(diagram)

        System.remove_block(blocks.values()[0])
        result = DiagramPersistence.load(diagram)

        os.remove(file_name)
Ejemplo n.º 6
0
    def add_comment(self):
        """
        This method add a block.

        Parameters:

                * **Types** (:class:`block<>`)
        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        diagram = self.main_window.work_area.get_current_diagram()
        if diagram is None:
            return False
        comment = Comment(diagram)
        DiagramControl.add_comment(diagram, comment)
        diagram.redraw()
        return True
Ejemplo n.º 7
0
 def create_comment(self, diagram=None):
     if diagram is None:
         comment = Comment(self.create_diagram(), None)
     else:
         comment = Comment(diagram, None)
     return comment
Ejemplo n.º 8
0
 def create_comment(self):
     comment = Comment(self.create_diagram())
     comment.text = "Test"
     return comment
Ejemplo n.º 9
0
 def test_add_comment(self):
     comment = Comment(self.create_diagram(), None)
     self.diagram_control.add_comment(comment)
Ejemplo n.º 10
0
    def test_add_comment(self):
        comment = Comment(self.create_diagram())

        self.assertTrue(DiagramControl.add_comment(comment.diagram, comment),
                        "Failed to add comment")
Ejemplo n.º 11
0
    def redraw(self):
        """
        This method redraw the diagram.
        """
        # First, remove all items from the diagram
        while self.get_root_item().get_n_children() != 0:
            self.get_root_item().remove_child(0)
        self.__draw_grid()

        # Check diagram content
        # Create Block widgets
        for key in self.blocks:
            block = self.blocks[key]
            if not isinstance(block, Block):
                block = Block(self, self.blocks[key])
                self.blocks[key] = block

        # Create Connection Widgets
        i = 0
        to_remove = []

        for connector in self.connectors:

            # If it is not an instance of a connector, it is a connection model
            # Probably it it the first time we draw this diagram
            if not isinstance(connector, Connector):
                outb = self.blocks[connector.output.id]
                conn = Connector(self, outb, connector.output_port)
                conn.input = self.blocks[connector.input.id]
                conn.input_port = connector.input_port
                connector = conn
                self.connectors[i] = conn

            if connector.output:
                if  connector.output.id not in self.blocks or \
                        connector.input.id not in self.blocks:
                    to_remove.append(connector)
            i = i + 1
        for conn in to_remove:
            self.connectors.remove(conn)

        # Create Comment Widgets
        i = 0
        for comment in self.comments:
            if not isinstance(comment, Comment):
                comm = Comment(self)
                comm.move(comment.x, comment.y)
                comm.update_flow()
                self.comments[i] = comm
            i = i + 1

        # Redraw Blocks
        for key in self.blocks:
            block = self.blocks[key]
            if not isinstance(block, Block):
                block = Block(self, self.blocks[key])
                self.blocks[key] = block
            self.get_root_item().add_child(block, -1)
            block.adjust_position()
        i = 0

        # Redraw Connections
        for connector in self.connectors:
            if not isinstance(connector, Connector) and connector.output:
                outb = self.blocks[connector.output.id]
                conn = Connector(self, outb, connector.output_port)
                conn.input = self.blocks[connector.input.id]
                conn.input_port = connector.input_port
                connector = conn
                self.connectors[i] = conn
            if isinstance(connector, GooCanvas.CanvasItem):
                self.get_root_item().add_child(connector, -1)
            i = i + 1

        # Redraw Comments
        for comment in self.comments:
            self.get_root_item().add_child(comment, -1)
            comment.adjust_position()

        self.update_flows()
Ejemplo n.º 12
0
 def create_comment(self):
     comment = Comment(self.create_diagram(), None)
     return comment