def create_block(self, diagram_control=None): if diagram_control is None: diagram_control = self.create_diagram_control() block_model = BlockModel() block_model.maxIO = 2 block = Block(diagram_control.diagram, block_model) block.language = "language" block.properties = [{"name": "test", "label": "Test", "type": "Test"}] block.ports = [{ "type": "Test", "label": "Input", "conn_type": "Input", "name": "input" }, { "type": "Test", "label": "Output", "conn_type": "Outpu", "name": "output" }] BlockControl.load_ports(block, System.get_ports()) DiagramControl.add_block(diagram_control.diagram, block) return block
def setUp(self): """Do the test basic setup.""" diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) blockmodel = BlockModel(None) self.blockcodeeditor = BlockCodeEditor(BlockEditor(), Block())
def create_block(self, diagram_control=None): if diagram_control is None: diagram_control = self.create_diagram_control() block_model = BlockModel() block_model.maxIO = 2 block = Block(diagram_control.diagram, block_model) block.language = "language" DiagramControl.add_block(diagram_control.diagram, block) return block
def test_save(self): # NÃO TRABALHA COM None # block = None # self.assertTrue(self.blockpersistence.save(block)) diagram = Diagram(MainWindow()) block = Block(diagram, None) self.assertTrue(self.blockpersistence.save(block)) diagram = Diagram(MainWindow()) blockmodel = BlockModel(None) block = Block(diagram, blockmodel) block.type = "teste_blockpersistence" self.assertTrue(self.blockpersistence.save(block))
def test_add_block(self): # QUALQUER UMA DAS FORMAS ABAIXO APRESENTARÁ NONE # self.assertIsNone(self.blockmanager.add_block(self.block)) # self.assertIsNone(self.blockmanager.add_block(None)) # self.block.label = "Teste" # self.assertIsNone(self.blockmanager.add_block(self.block)) diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) block.label = "Teste Block manager" self.assertIsNone(self.blockmanager.add_block(block))
def setUp(self): """Do the test basic setup.""" win = MainWindow() diagram = Diagram(MainWindow()) blockmodel = BlockModel() self.block = Block(diagram, blockmodel) self.blockmenu = BlockMenu(self.block, None)
def add_block(self, block): """ This method add a block in the diagram. Parameters: * **block** Returns: * **Types** (:class:`boolean<boolean>`) """ if self.diagram is None: return False, "This diagram is None, you can not add a block." if block is None: return False, "Houston, we have a problem! Is ir an empty block?" if self.diagram.language is None or self.diagram.language == 'None': self.diagram.language = block.language if self.diagram.language != block.language: return False, "Block language is different from diagram language." self.do("Add Block") new_block = BlockModel(block) new_block = deepcopy(new_block) new_block = Block(self.diagram, new_block) self.diagram.last_id = max(int(self.diagram.last_id), int(block.id)) if block.id < 0: block.id = self.diagram.last_id self.diagram.last_id += 1 self.diagram.blocks[block.id] = block self.diagram.redraw() return True, "Success"
def setUp(self): """Do the test basic setup.""" win = MainWindow() self.diagram = Diagram(win) blockmodel = BlockModel() self.block = Block(self.diagram, blockmodel)
def add_block(self, block): """ 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 new_block = BlockModel(block) new_block = deepcopy(new_block) new_block = Block(diagram, new_block) if not DiagramControl(diagram).add_block(new_block): message = "Block language is different from diagram language.\n" +\ "Diagram is expecting to generate " + diagram.language + \ " code while block is writen in " + block.language Dialog().message_dialog("Error", message, self.main_window) return None diagram.redraw() return new_block
def setUp(self): port = Port() self.source_block = self.create_block() self.source_block.ports.append(port) self.source_block = Block(self.create_diagram(), self.create_block()) self.diagram = self.create_diagram() self.connector = Connector(self.diagram, self.source_block, port)
def test_set_block(self): block = Block(self.create_diagram(), self.create_block()) block.properties = [{"name": "curve", "label": "Curve", "type": MOSAICODE_FLOAT, "value": 800 } ] self.propertybox.set_block(block) block.properties = [{"name": "curve", "label": "Curve", "type": MOSAICODE_OPEN_FILE, "value": "800" } ] self.propertybox.set_block(block) self.propertybox.notify_block()
def setUp(self): """Do the test basic setup.""" win = MainWindow() self.blockmanager = BlockManager(win) diagram = Diagram(MainWindow()) blockmodel = BlockModel() self.block = Block(diagram, blockmodel)
def create_block(self, diagram_control=None): if diagram_control is None: diagram_control = self.create_diagram_control() System() block_model = BlockModel() System.add_port(self.create_port()) block_model.ports = [{ "type": "Test", "label": "Click", "conn_type": "Input", "name": "0" }, { "type": "Test", "label": "Click", "conn_type": "Output", "name": "1" }, { "type": "Test", "label": "Click", "conn_type": "Input", "name": "2" }, { "type": "Test", "label": "Click", "conn_type": "Output", "name": "3" }] block_model.help = "Test" block_model.label = "Test" block_model.color = "200:200:25:150" block_model.group = "Test" block_model.codes = {"code0": "Test", "Code1": "Test", "Code2": "Test"} block_model.type = "Test" block_model.language = "Test" block_model.properties = [{ "name": "test", "label": "Test", "value": "0", "type": MOSAICODE_FLOAT }] block_model.extension = "Test" block_model.file = None result = BlockControl.load_ports(block_model, System.get_ports()) System.add_block(block_model) self.assertEquals(result[1], "Success") self.assertEquals(result[0], True) self.assertEquals(len(block_model.ports), 4) block = Block(diagram_control.diagram, block_model) self.assertEquals(len(block.ports), 4) return block
def test_update_flow(self): self.connector.input = None self.connector.update_flow() point = (0, 0) self.connector.update_flow(point) self.connector.input = Block(self.create_diagram(), self.create_block()) self.connector.input.move(100, 100) self.connector.input_port = Port() self.connector.update_flow()
def setUp(self): """Do the test basic setup.""" win = MainWindow() diagram = Diagram(win) blockmodel = BlockModel() block = Block(diagram, blockmodel) block_manager = BlockManager(win) self.blockporteditor = BlockPortEditor (block_manager, block)
def test_set_block(self): # from mosaicode.GUI.block import Block # from mosaicode.GUI.diagram import Diagram as Diagram # from mosaicode.model.blockmodel import BlockModel as BlockModel # # block = Block(Diagram, BlockModel) # self.assertIsNone(self.main_control.set_block(block)) diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) self.assertIsNone(self.main_control.set_block(block))
def setUp(self): """Do the test basic setup.""" win = MainWindow diagram = Diagram(win) blockmodel = BlockModel() block = Block(diagram, blockmodel) block_manager = BlockManager(win) block_editor = BlockEditor(block_manager, block) self.block_property_editor = BlockPropertyEditor(block_editor, block)
def paste(self): """ This method paste a block. """ if self.diagram is None: return False replace = {} self.diagram.deselect_all() # interact into blocks, add blocks and change their id clipboard = self.diagram.main_window.main_control.get_clipboard() for widget in clipboard: if not isinstance(widget, BlockModel): continue block = BlockModel(widget) block.x += 20 block.y += 20 block.id = -1 new_block = BlockModel(block) new_block = deepcopy(new_block) new_block = Block(self.diagram, new_block) if not self.add_block(new_block): continue replace[widget.id] = new_block new_block.is_selected = True # interact into connections changing block ids for widget in clipboard: if not isinstance(widget, ConnectionModel): continue # if a connector is copied without blocks if widget.output.id not in replace \ or widget.input.id not in replace: continue output_block = replace[widget.output.id] output_port = widget.output_port input_block = replace[widget.input.id] input_port = widget.input_port self.diagram.start_connection(output_block, output_port) self.diagram.curr_connector.is_selected = True self.diagram.end_connection(input_block, input_port) for widget in clipboard: if not isinstance(widget, CommentModel): continue comment = CommentModel(widget) comment.x += 20 comment.y += 20 comment.is_selected = True comment = self.diagram.main_window.main_control.add_comment(comment) self.diagram.update_flows()
def setUp(self): """Do the test basic setup.""" win = MainWindow() diagram = Diagram(win) blockmodel = BlockModel() source = Block(diagram, blockmodel) # NAO TRATA NONE # source = None source_port = 0 conn_type = None self.connector = Connector(diagram, source, source_port, conn_type)
def test_update_flow(self): self.connector.input = None self.connector.update_flow() point = (0,0) self.connector.update_flow(point) self.connector.input = Block(self.create_diagram(), self.create_block()) self.connector.input.move(100,100) self.connector.input_port = Port() System.get_preferences().connection = "Curve" self.connector.update_flow() System.get_preferences().connection = "Line" self.connector.update_flow() System.get_preferences().connection = "Square" self.connector.update_flow()
def test_delete_connection(self): from mosaicode.GUI.connector import Connector blockmodel = BlockModel() source = Block(self.diagram, blockmodel) # NOTE: NAO TRATA None # source = None source_port = 0 conn_type = None connection = Connector(self.diagram, source, source_port, conn_type) self.assertIsNone(self.diagram.delete_connection(connection))
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)
def create_block(self, diagram_control=None): if diagram_control is None: diagram_control = self.create_diagram_control() block_model = BlockModel() port0 = Port() port0.label = "Test0" port0.conn_type = Port.OUTPUT port0.name = "Test0" port0.type = "Test" port1 = Port() port1.label = "Test1" port1.conn_type = Port.INPUT port1.name = "Test1" port1.type = "Test" block_model.ports = [port0, port1] block_model.help = "Test" block_model.label = "Test" block_model.color = "200:200:25:150" block_model.group = "Test" block_model.codes = {"code0":"Test", "Code1":"Test", "Code2":"Test"} block_model.type = "Test" block_model.maxIO = 2 block_model.language = "language" block_model.properties = [{"name": "test", "label": "Test", "type": MOSAICODE_FLOAT }] block_model.extension = "Test" block_model.file = None block = Block(diagram_control.diagram, block_model) return block
def setUp(self): """Do the test basic setup.""" diagram = Diagram(MainWindow()) block = Block(diagram, None) self.blockmodel = BlockModel(block)
def setUp(self): """Do the test basic setup.""" win = MainWindow() diagram = Diagram(win) block = Block() self.code_generator = CodeGenerator(diagram)
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())
def test_set_block(self): diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) self.assertIsNone(self.property_box.set_block(block))
def test_delete_block(self): diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) self.assertIsNone(self.main_control.delete_block(block))
def test_show_block_property(self): diagram = Diagram(MainWindow()) blockmodel = BlockModel() block = Block(diagram, blockmodel) self.assertIsNone(self.main_control.show_block_property(block))
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()