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
def add_comment(self, comment=None): """ This method add a comment in the diagram. Parameters: * **block** Returns: * **Types** (:class:`boolean<boolean>`) """ if self.diagram is None: return False 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
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, None) diagram.file_name = file_name diagram_control.add_comment(comment) System() blocks = System.get_blocks() for key in blocks: block1 = Block(diagram, blocks[key]) diagram_control.add_block(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) diagram_control.add_connection(connection)
def create_comment(self, diagram=None): if diagram is None: comment = Comment(self.create_diagram(), None) else: comment = Comment(diagram, None) return comment
def create_comment(self): comment = Comment(self.create_diagram()) comment.text = "Test" return comment
def test_add_comment(self): comment = Comment(self.create_diagram(), None) self.diagram_control.add_comment(comment)
def test_add_comment(self): comment = Comment(self.create_diagram()) self.assertTrue(DiagramControl.add_comment(comment.diagram, comment), "Failed to add comment")
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()
def create_comment(self): comment = Comment(self.create_diagram(), None) return comment