Пример #1
0
    def test_load(self):
        # First condition
        result = CodeTemplatePersistence.load_xml("This file does not exist")
        self.assertEquals(result, None)

        # Second condition
        port = Port()
        port.label = "test"
        PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        self.assertNotEquals(result, True)
        os.remove(file_name)

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

        self.code_template.name = "Test"
        CodeTemplatePersistence.save_xml(self.code_template, "/tmp/")
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        self.assertEquals(result.equals(self.code_template), True)
        os.remove(file_name)
Пример #2
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))
    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 __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.hint = "FLOW"
     self.color = "#2c63F4"
     self.multiple = False
     self.var_name = "$block[label]$_$block[id]$_$port[name]$"
    def test_save_xml(self):

        # Second condition
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.save_xml(self.code_template,
                                                  file_name)
        #        self.assertEquals(result, False)

        # Second condition
        port = Port()
        port.label = "test"
        PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        #        self.assertNotEquals(result, True)
        #        os.remove(file_name)

        CodeTemplatePersistence.save_xml(self.code_template, "/tmp/")
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
        self.assertEquals(result, None)
        #        os.remove(file_name)

        self.code_template.name = "Test"
        CodeTemplatePersistence.save_xml(self.code_template, "/tmp/")
        file_name = "/tmp/" + self.code_template.type + ".xml"
        result = CodeTemplatePersistence.load_xml(file_name)
Пример #6
0
 def __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.hint = "FLOAT"
     self.color = "#fc2300"
     self.multiple = False
     self.code = "$input$ = $output$;\n"
     self.var_name = "$port[name]$$block[id]$"
Пример #7
0
 def __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.hint = "COLOR"
     self.color = "#2c6300"
     self.multiple = False
     self.code = "memcpy($output$, $input$,  sizeof($input$));\n"
     self.var_name = "$block[label]$_$block[id]$_$port[name]$"
Пример #8
0
 def __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.hint = "RCT"
     self.color = "#00F"
     self.multiple = False
     self.var_name = "$block[label]$_$block[id]$_$port[name]$"
     self.code = "$input$ = $output$;\n"
Пример #9
0
 def __init__(self):
     Port.__init__(self)
     self.language = "javascript"
     self.hint = "MIDI"
     self.color = "#F0F"
     self.multiple = True
     self.code = "$output$.push($input$);\n"
     self.var_name = "$block[label]$_$block[id]$_$port[name]$"
 def test_load_wrong_file(self):
     port = Port()
     port.hint = "test"
     PortPersistence.save_xml(port, path="/tmp/")
     file_name = "/tmp/" + port.hint + ".xml"
     result = CodeTemplatePersistence.load_xml(file_name)
     self.assertNotEquals(result, True)
     os.remove(file_name)
Пример #11
0
 def __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.hint = "FLOAT"
     self.color = "#fc2300"
     self.multiple = False
     self.code = "$output$.push_back($input$);\n"
     self.var_name = "$block[label]$_$port[name]$_$block[id]$"
Пример #12
0
 def __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.label = "POINT"
     self.color = "#0FF"
     self.multiple = False
     self.code = "block$sink$_point_i$sink_port$ = block$source$_point_o$source_port$;// POINT conection\n"
     self.input_codes[1] = "CvPoint block$id$_point_i$port_number$;\n"
     self.output_codes[1] = "CvPoint block$id$_point_o$port_number$;\n"
Пример #13
0
 def __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.label = "DOUBLE"
     self.color = "#000"
     self.multiple = False
     self.code = "block$sink$_double_i$sink_port$ = block$source$_double_o$source_port$;// DOUBLE conection\n"
     self.input_codes[1] = "double block$id$_double_i$port_number$;\n"
     self.output_codes[1] = "double block$id$_double_o$port_number$;\n"
Пример #14
0
 def __init__(self):
     Port.__init__(self)
     self.language = "javascript"
     self.label = "SOUND"
     self.color = "#F00"
     self.multiple = True
     self.code = "block_$source$.connect(block_$sink$_i$sink_port$);"
     self.input_codes[1] = "var block_$id$_i$port_number$ = null;\n"
     self.output_codes[1] = "var block_$id$_o$port_number$ = null; // It must be an object with a connect method\n"
     self.var_name = "block_$id$_$conn_type$$port_number$"
Пример #15
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
Пример #16
0
    def __init__(self):
        Port.__init__(self)
        self.language = "c"
        self.hint = "COLOR"
        self.color = "#2c6300"
        self.multiple = False
        self.code = """
        free($input$);
        $input$ = $output$;
"""
        self.var_name = "$block[label]$_$block[id]$_$port[name]$"
 def __init__(self):
     Port.__init__(self)
     self.language = "javascript"
     self.label = "CHAR"
     self.color = "#00F"
     self.multiple = True
     self.code = "block_$source$_o$source_port$.push(block_$sink$_i$sink_port$);"
     self.input_codes[
         1] = "var block_$id$_i$port_number$ = function(value){\n//Put your code here\n};\n"
     self.output_codes[1] = "var block_$id$_o$port_number$ = [];\n"
     self.var_name = "block_$id$_$conn_type$$port_number$"
Пример #18
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
Пример #19
0
 def __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.label = "IMG"
     self.color = "#F0F"
     self.multiple = False
     self.code = "block$sink$_img_i$sink_port$ = cvCloneImage(block$source$_img_o$source_port$);// IMG conection\n"
     self.input_codes[1] = "IplImage * block$id$_img_i$port_number$ = NULL;\n"
     self.output_codes[1] = "IplImage * block$id$_img_o$port_number$ = NULL;\n"
     self.input_codes[3] = "cvReleaseImage(&block$id$_img_i$port_number$);\n"
     self.output_codes[3] = "cvReleaseImage(&block$id$_img_o$port_number$);\n"
Пример #20
0
 def __init__(self):
     Port.__init__(self)
     self.language = "c"
     self.label = "RCT"
     self.color = "#00F"
     self.multiple = False
     self.code = "block$sink$_rect_i$sink_port$ = block$source$_rect_o$source_port$;// RECT conection\n"
     self.input_codes[
         1] = "CvRect block$id$_rect_i$port_number$ = cvRect( 0, 0, 1, 1);\n"
     self.output_codes[
         1] = "CvRect block$id$_rect_o$port_number$ = cvRect( 0, 0, 1, 1);\n"
Пример #21
0
    def __init__(self):
        Port.__init__(self)
        self.language = "c"
        self.hint = "IMG"
        self.color = "#F0F"
        self.multiple = False
        self.var_name = "$block[label]$_$block[id]$_$port[name]$"
        self.code = \
"""        
        if(!$output$.empty()) 
        	$input$ = $output$.clone();
"""        	
 def __init__(self):
     Port.__init__(self)
     self.language = "javascript"
     self.label = "FLOAT"
     self.color = "#000"
     self.multiple = True
     self.code = "block_$source$_o$source_port$.push(block_$sink$_i$sink_port$);\n"
     self.input_codes[
         1] = "var block_$id$_i$port_number$ = function(value){\n//Put your code here\n};\n"
     self.output_codes[
         1] = "var block_$id$_o$port_number$ = [];\nfunction update_block_$id$_o$port_number$(value){\nfor (var i = 0; i &lt; block_$id$_o$port_number$.length ; i++){\n        block_$id$_o$port_number$[i](value);\n    }\n}\n"
     self.var_name = "block_$id$_$conn_type$$port_number$"
    def test_load_save(self):
        port = Port()
        port.label = "test"

        PortPersistence.save_python(port, "/tmp/")
        file_name = "/tmp/" + port.label.lower().replace(' ', '_') + ".py"
        os.remove(file_name)

        PortPersistence.save_xml(port, "/tmp/")
        file_name = "/tmp/" + port.type + ".xml"

        result = PortPersistence.load_xml(file_name)
    def test_load_wrong_diagram(self):
        port = Port()
        port.hint = "test"
        PortPersistence.save_xml(port, path="/tmp/")
        file_name = "/tmp/" + port.hint + ".xml"
        result = DiagramPersistence.load(file_name)
        self.assertNotEquals(result, True)

        diagram = self.create_full_diagram()
        diagram.file_name = file_name
        result = DiagramPersistence.load(diagram)
        self.assertNotEquals(result, True)
        os.remove(file_name)
Пример #25
0
    def __init__(self):
        Port.__init__(self)
        self.language = "c"
        self.type = "mosaicode_lib_c_base.extensions.ports.integer"
        self.hint = "INT"
        self.color = "#fc2300"
        self.multiple = True
        self.code = """
    $output$ = realloc($output$, ($output$_size + 1 ) * sizeof(void *));
    $output$[$output$_size] = &$input$;
    $output$_size++;
"""
        self.var_name = "$block[label]$_$block[id]$_$port[name]$"
 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)
Пример #27
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
Пример #28
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)
Пример #29
0
    def __on_save(self, widget=None, data=None):
        new_port = Port()
        for widget in self.side_panel.get_children():
            try:
                new_port.__dict__[widget.get_name()] = widget.get_value()
            except:
                pass

        if new_port.type == "":
            message = "Type can not be empty"
            MessageDialog("Error", message, self.get_toplevel()).run()
            return
        if new_port.label == "":
            message = "Label can not be empty"
            MessageDialog("Error", message, self.get_toplevel()).run()
            return
        if new_port.name == "":
            message = "Name can not be empty"
            MessageDialog("Error", message, self.get_toplevel()).run()
            return
        contains = False
        i = 0
        for port in self.block.ports:
            if port.label == new_port.label:
                self.block.ports[i] = new_port
                contains = True
            i += 1
        if not contains:
            self.block.ports.append(new_port)
        self.__populate_list()
        self.__clean_side_panel()
Пример #30
0
 def test_init(self):
     model = Port()
     self.assertEqual(model.is_input(), False)
     model.conn_type = Port.INPUT
     self.assertEqual(model.is_input(), True)
     model.conn_type = Port.OUTPUT
     self.assertEqual(model.is_input(), False)