예제 #1
0
    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
예제 #2
0
 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())
예제 #3
0
    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
예제 #4
0
    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))
예제 #5
0
    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))
예제 #6
0
 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)
예제 #7
0
    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"
예제 #8
0
    def setUp(self):
        """Do the test basic setup."""
        win = MainWindow()
        self.diagram = Diagram(win)

        blockmodel = BlockModel()
        self.block = Block(self.diagram, blockmodel)
예제 #9
0
    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
예제 #10
0
 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)
예제 #11
0
 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()
예제 #12
0
    def setUp(self):
        """Do the test basic setup."""
        win = MainWindow()
        self.blockmanager = BlockManager(win)

        diagram = Diagram(MainWindow())
        blockmodel = BlockModel()
        self.block = Block(diagram, blockmodel)
예제 #13
0
    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
예제 #14
0
 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()
예제 #15
0
    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)
예제 #16
0
    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)
예제 #18
0
    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()
예제 #19
0
    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)
예제 #20
0
 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()
예제 #21
0
    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))
예제 #22
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)
예제 #23
0
    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
예제 #24
0
 def setUp(self):
     """Do the test basic setup."""
     diagram = Diagram(MainWindow())
     block = Block(diagram, None)
     self.blockmodel = BlockModel(block)
예제 #25
0
 def setUp(self):
     """Do the test basic setup."""
     win = MainWindow()
     diagram = Diagram(win)
     block = Block()
     self.code_generator = CodeGenerator(diagram)
예제 #26
0
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())
예제 #27
0
 def test_set_block(self):
     diagram = Diagram(MainWindow())
     blockmodel = BlockModel()
     block = Block(diagram, blockmodel)
     self.assertIsNone(self.property_box.set_block(block))
예제 #28
0
    def test_delete_block(self):

        diagram = Diagram(MainWindow())
        blockmodel = BlockModel()
        block = Block(diagram, blockmodel)
        self.assertIsNone(self.main_control.delete_block(block))
예제 #29
0
 def test_show_block_property(self):
     diagram = Diagram(MainWindow())
     blockmodel = BlockModel()
     block = Block(diagram, blockmodel)
     self.assertIsNone(self.main_control.show_block_property(block))
예제 #30
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()