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()
class TestBlock(TestCase): def setUp(self): """Do the test basic setup.""" diagram = Diagram(MainWindow()) blockmodel = BlockModel() self.block = Block(diagram, blockmodel) # ----------------------------------------------------------------------x def test_rebuild(self): self.assertIsNone(self.block.rebuild()) # ----------------------------------------------------------------------x def test_build(self): self.assertIsNone(self.block.build()) # ----------------------------------------------------------------------x def test_get_input_pos(self): input_id = 2 self.assertIsNotNone(self.block.get_input_pos(input_id)) #self.assertEqual((int, int), self.block.get_input_pos(input_id)) # ----------------------------------------------------------------------x def test_get_output_pos(self): output_id = 2 self.assertIsNotNone(self.block.get_output_pos(output_id)) #self.assertEqual((int, int), self.block.get_output_pos(output_id)) # ----------------------------------------------------------------------x def test_move(self): x = 3 y = 5 self.assertIsNone(self.block.move(x, y)) x = 0 y = 0 self.assertIsNone(self.block.move(x, y)) # NÃO SUPORTA X, Y = NONE #x = None #y = None #self.assertIsNone(self.block.move(x, y)) # ----------------------------------------------------------------------x def test_adjust_position(self): self.assertIsNone(self.block.adjust_position()) # ----------------------------------------------------------------------x def test_delete(self): self.assertIsNone(self.block.delete()) # ----------------------------------------------------------------------x def test_get_position(self): self.assertIsNotNone(self.block.get_position()) # ----------------------------------------------------------------------x def test_set_properties(self): data = {"label": ("Type"), "name": "type", "value": "255:255:255:255"} self.assertIsNone(self.block.set_properties(data)) data = {"label": "", "name": "", "value": ""} self.assertIsNone(self.block.set_properties(data)) data = {"label": None, "name": "type", "value": "255:255:255:255"} self.assertIsNone(self.block.set_properties(data)) # ----------------------------------------------------------------------x def test_get_properties(self): self.assertIsNotNone(self.block.get_properties()) # ----------------------------------------------------------------------x def test_update_flow(self): self.assertIsNotNone(self.block.update_flow())