예제 #1
0
    def load(cls, file_name):
        """
        This method loads the port from XML file.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        # load the port
        if os.path.exists(file_name) is False:
            return
        parser = XMLParser(file_name)
        if parser.getTag(tag_name) is None:
            return None

        port = Port()
        port.type = parser.getTagAttr(tag_name, "type")
        port.language = parser.getTagAttr(tag_name, "language")
        port.label = parser.getTagAttr(tag_name, "label")
        port.color = parser.getTagAttr(tag_name, "color")
        port.multiple = parser.getTagAttr(tag_name, "multiple")
        port.source = parser.getTagAttr(tag_name, "source")
        port.code = parser.getTag(tag_name).getTag("code").getText()

        count = 0
        for code in port.input_codes:
            port.input_codes[count] = parser.getTag(tag_name).getTag('input_code' + str(count)).getText()
            port.output_codes[count] = parser.getTag(tag_name).getTag('output_code' + str(count)).getText()
            count = count + 1

        if port.type == "":
            return None
        return port
예제 #2
0
    def load_xml(cls, file_name):
        """
        This method loads the port from XML file.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        # load the port
        if os.path.exists(file_name) is False:
            return None
        parser = XMLParser(file_name)
        if parser.getTag(tag_name) is None:
            return None

        port = Port()
        port.type = parser.getTagAttr(tag_name, "type")
        port.language = parser.getTagAttr(tag_name, "language")
        port.hint = parser.getTagAttr(tag_name, "hint")
        port.color = parser.getTagAttr(tag_name, "color")
        port.multiple = parser.getTagAttr(tag_name, "multiple")
        port.var_name = parser.getTagAttr(tag_name, "var_name")
        port.code = parser.getTag(tag_name).getTag("code").getText()

        if port.type == "":
            return None

        return port
    def test_load_save(self):
        port = Port()
        port.label = "test"
        port.hint = "test"

        result = PortPersistence.load_xml("/this file does not exist")
        self.assertEquals(result, None)

        result = PortPersistence.save_xml(port, "/etc/")
        self.assertEquals(result, False)

        result = PortPersistence.save_xml(port, "/impossible to create")
        self.assertEquals(result, False)

        result = PortPersistence.save_xml(port, "/tmp/")
        self.assertEquals(result, True)

        file_name = "/tmp/" + port.hint + ".xml"
        result = PortPersistence.load_xml(file_name)
        os.remove(file_name)

        port.type = ""
        result = PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.hint + ".xml"
        result = PortPersistence.load_xml(file_name)
        self.assertEquals(result, None)
        os.remove(file_name)

        code_template = self.create_code_template()
        CodeTemplatePersistence.save_xml(code_template, "/tmp/")
        file_name = "/tmp/" + code_template.name + ".xml"
        result = PortPersistence.load_xml(file_name)
        os.remove(file_name)
예제 #4
0
    def test_save_python(self):

        port = Port()
        self.assertTrue(self.portpersistence.save_python(port))

        port.type = "teste_portpersistence"
        self.assertTrue(self.portpersistence.save_python(port))
예제 #5
0
 def get_element(self):
     port = Port()
     port.type = self.type.get_value()
     port.language = self.language.get_value()
     port.hint = self.hint.get_value()
     port.color = self.color.get_value()
     port.multiple = self.multiple.get_value()
     port.code = self.code.get_value()
     port.var_name = self.var_name.get_value()
     return port
 def __save(self):
     port = Port()
     port.type = self.type.get_value()
     port.language = self.language.get_value()
     port.hint = self.hint.get_value()
     port.color = self.color.get_value()
     port.multiple = self.multiple.get_value()
     port.code = self.code.get_value()
     port.var_name = self.var_name.get_value()
     self.port_manager.add_port(port)
예제 #7
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
예제 #8
0
 def create_port(self):
     port = Port()
     port.type = "Test"
     port.language = "Test"
     port.hint = "Test"
     port.color = "#000"
     port.multiple = False
     port.file = None
     port.code = ""
     port.var_name = "$block[label]$_$block[id]$_$port[name]$"
     return port
예제 #9
0
    def test_delete_port(self):

        from mosaicode.model.port import Port

        port = Port()

        port.type = "c"
        port.language = "c"
        port.source = "xml"
        port.code = "xxxx"

        self.assertIsNone(self.main_control.delete_port(port))
예제 #10
0
    def load(cls, file_name):
        """
        This method loads the port from XML file.

        Returns:

            * **Types** (:class:`boolean<boolean>`)
        """
        # load the port
        if os.path.exists(file_name) is False:
            return None

        data = ""
        port = Port()

        try:
            data_file = open(file_name, 'r')
            data = json.load(data_file)
            data_file.close()

            if data["data"] != "PORT":
                return None

            port = Port()
            port.type = data["type"]
            port.version = data["version"]
            port.type = data["type"]
            port.language = data["language"]
            port.hint = data["hint"]
            port.color = data["color"]
            port.multiple = bool(data["multiple"])
            port.var_name = data["var_name"]
            port.code = data["code"]
        except:
            return None

        if port.type == "":
            return None

        return port
예제 #11
0
    def __save(self):
        port = Port()
        port.type = self.type.get_value()
        port.language = self.language.get_value()
        port.label = self.label.get_value()
        port.color = self.color.get_value()
        port.multiple = self.multiple.get_value()
        port.code = self.code.get_value()

        count = 0
        for code_widget in self.input_code_widgets:
            port.input_codes[count] = self.input_code_widgets[count].get_value(
            )
            port.output_codes[count] = self.output_code_widgets[
                count].get_value()
            count = count + 1

        self.port_manager.add_port(port)