Beispiel #1
0
    def load_xml(cls, file_name):
        """
        This method loads the code_template from XML file.

        Returns:

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

        if parser.getTag(CodeTemplatePersistence.tag_name) is None:
            return None
        ct = parser.getTag(CodeTemplatePersistence.tag_name)

        code_template = CodeTemplate()
        for prop in CodeTemplatePersistence.properties:
            if hasattr(ct, prop) and hasattr(code_template, prop):
                code_template.__dict__[prop] = parser.getTagAttr(
                    CodeTemplatePersistence.tag_name, prop)

        code_parts = parser.getTag(CodeTemplatePersistence.tag_name).getTag(
            "code_parts").getChildTags("code_part")
        for code_part in code_parts:
            code_template.code_parts.append(code_part.getAttr("value"))

        if code_template.name == "":
            return None
        return code_template
Beispiel #2
0
    def load(cls, file_name):
        """
        This method loads the code_template from XML file.

        Returns:

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

        if parser.getTag(tag_name) is None:
            return None

        try:
            code_template = CodeTemplate()
            code_template.name = parser.getTagAttr(tag_name, "name")
            code_template.type = parser.getTagAttr(tag_name, "type")
            code_template.description = parser.getTagAttr(
                tag_name, "description")
            code_template.language = parser.getTagAttr(tag_name, "language")
            code_template.extension = parser.getTagAttr(tag_name, "extension")
            code_template.source = parser.getTagAttr(tag_name, "source")
            code_template.command = parser.getTag(tag_name).getTag(
                "command").getText()
            code_template.code = parser.getTag(tag_name).getTag(
                "code").getText()
        except:
            return None

        if code_template.name == "":
            return None
        return code_template
Beispiel #3
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "webaudio"
     self.language = "javascript"
     self.description = "Javascript / webaudio code template"
     self.extension = ".html"
     self.command = "chromium-browser $dir_name$$filename$$extension$\n"
     self.code = r"""<html>
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "joystick"
     self.language = "c"
     self.description = "A full template to generate joystick code"
     self.extension = ".c"
     self.command = "g++ -std=c++11 -g -Wall -pthread $dir_name$$filename$$extension$ -o $dir_name$$filename$\n"
     self.command += "$dir_name$./$filename$"
     self.code_parts = ["global", "declaration"]
     self.code = r"""
    def test_save(self):
        # NÃO TRABALHA COM None
        # code_template = None
        # self.assertTrue(self.codetemplatepersistence.save(code_template))

        code_template = CodeTemplate()
        self.assertTrue(self.codetemplatepersistence.save(code_template))

        code_template.name = "Template de teste"
        self.assertTrue(self.codetemplatepersistence.save(code_template))
Beispiel #6
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "webaudio"
     self.language = "javascript"
     self.description = "Javascript / webaudio code template"
     self.extension = ".html"
     self.command = "python -m webbrowser -t $dir_name$$filename$$extension$\n"
     self.code_parts = [
         "onload", "function", "declaration", "execution", "html"
     ]
     self.code = r"""<html>
Beispiel #7
0
    def test_add_code_template(self):
        #code_template = None
        #self.assertIsNone(self.main_control.add_code_template(code_template))
        from mosaicode.model.codetemplate import CodeTemplate

        code_template = CodeTemplate()

        code_template.type = "c"
        code_template.name = "TESTE"
        code_template.source = "xml"
        self.assertIsNone(self.main_control.add_code_template(code_template))
Beispiel #8
0
    def test_equals(self):
        code1 = CodeTemplate()
        code2 = CodeTemplate()
        self.assertEquals(code1.equals(code2), True)

        code1.language = "Test"
        self.assertEquals(code1.equals(code2), False)

        code1 = CodeTemplate()
        code1.__dict__.pop(code1.__dict__.keys()[0], None)
        self.assertEquals(code2.equals(code1), False)
 def __save(self):
     code_template = CodeTemplate()
     code_template.name = self.name.get_value()
     code_template.language = self.language.get_value()
     code_template.type = self.type.get_value()
     code_template.description = self.description.get_value()
     code_template.command = self.command.get_value()
     code_template.extension = self.extension.get_value()
     code_template.code = self.code.get_value()
     code_template.code_parts = self.code_parts.get_value().split(",")
     self.code_template_manager.add_code_template(code_template)
Beispiel #10
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "opencv"
        self.language = "c"
        self.description = "c / opencv code template"
        self.extension = '.c'
        self.command = "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/;\n"
        self.command += "export PKG_CONFIG_PATH=/lib/pkgconfig/;\n"
        self.command += "g++ $filename$$extension$  -o $filename$ `pkg-config --cflags --libs opencv`\n"
        self.command += "LD_LIBRARY_PATH=/lib/ $dir_name$./$filename$"

        self.code = r"""
Beispiel #11
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "opengl"
     self.language = "c"
     self.description = "A full template to generate opengl code"
     self.extension = ".c"
     self.command = "g++ -Wall -g $dir_name$$filename$$extension$ -o $dir_name$$filename$ -lGL -lGLU -lglut -lm\n"
     self.command += "$dir_name$./$filename$"
     self.code_parts = [
         "global", "function", "call", "idle", "declaration", "execution"
     ]
     self.code = r"""
Beispiel #12
0
 def __init__(self):
     CodeTemplate.__init__(self)
     self.name = "gtk"
     self.language = "c"
     self.description = "A full template to generate gtk code"
     self.extension = ".c"
     self.command = "g++ -o $dir_name$$filename$ $dir_name$$filename$$extension$ `pkg-config --cflags --libs gtk+-3.0`\n"
     self.command += "$dir_name$./$filename$"
     self.code_parts = [
         "destroy", "windows", "function", "declaration", "configuration",
         "show", "struct", "callback"
     ]
     self.code = r"""
    def test_add_code_template(self):
        code_template = CodeTemplate()
        self.assertIsNone(
            self.codetemplatemanager.add_code_template(code_template))

        code_template.type = "Language Test"
        code_template.name = "Testando Code Template"
        code_template.description = "Um teste para code template em Add Code Template"
        code_template.language = ""
        code_template.command = ""
        code_template.extension = "teste"
        code_template.code = "Testando 1 2 3"
        code_template.source = "python"
        self.assertIsNone(
            self.codetemplatemanager.add_code_template(code_template))
Beispiel #14
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "opencv"
        self.language = "c"
        self.description = "A full template to generate OpenCV code"
        self.extension = '.c'
        self.command = "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib/;\n"
        self.command += "export PKG_CONFIG_PATH=/lib/pkgconfig/;\n"
        self.command += "g++ $filename$$extension$  -o $filename$ `pkg-config --cflags --libs opencv`\n"
        self.command += "LD_LIBRARY_PATH=/lib/ $dir_name$./$filename$"
        self.code_parts = [
            "include", "function", "declaration", "execution", "deallocation"
        ]

        self.code = r"""
Beispiel #15
0
 def get_code_template(self):
     code_template = CodeTemplate()
     for key in System.code_templates:
         if System.code_templates[key].language == self.diagram.language:
             code_template = System.code_templates[key]
             break
     generator = CodeGenerator(self.diagram, code_template)
     return generator
    def load(cls, file_name):
        """
        This method loads the code_template from XML file.

        Returns:

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

        code_template = CodeTemplate()
        data = ""

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

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

            code_template.version = data["version"]
            code_template.name = data["name"]
            code_template.type = data["type"]
            code_template.description = data["description"]
            code_template.language = data["language"]
            code_template.command = data["command"]

            props = data["properties"]
            for prop in props:
                code_template.properties.append(prop)

            codes = data["codes"]
            if codes:
                for key in codes:
                    code_template.codes[key] = codes[key]

            parts = data["code_parts"]
            for part in parts:
                code_template.code_parts.append(part.strip())
        except Exception as e:
            print(e)
            return None

        if code_template.name == "":
            return None
        return code_template
    def test_run(self):
        self.code = None
        self.assertIsNone(self.code_generator.run(self.code))

        self.code = CodeTemplate()
        self.assertIsNone(self.code_generator.run(self.code))

        self.code = "Teste()"
        self.assertIsNone(self.code_generator.run(self.code))
    def __init__(self, main_window):
        Manager.__init__(self, main_window, "Code Template Manager")

        self.element = CodeTemplate()
        self.get_items = System.get_code_templates
        self.editor = CodeTemplateEditor
        self.update()
        self.show_all()
        self.show()
    def test_set_properties(self):
        code = CodeTemplate()
        code.properties  = [{"name": "test",
                             "label": "test",
                             "value": "test",
                             "type": "test"}]

        code.set_properties({"out": "SET"})
        code.set_properties({"test": "SET"})
        assert code.properties[0]["value"] == "SET"
Beispiel #20
0
    def load_xml(cls, file_name):
        """
        This method loads the code_template from XML file.

        Returns:

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

        if parser.getTag(tag_name) is None:
            return None
        ct = parser.getTag(tag_name)

        code_template = CodeTemplate()
        code_template.name = parser.getTagAttr(tag_name, "name")
        code_template.type = parser.getTagAttr(tag_name, "type")
        code_template.description = parser.getTagAttr(tag_name, "description")
        code_template.language = parser.getTagAttr(tag_name, "language")
        code_template.command = parser.getTagAttr(tag_name, "command")

        parts = parser.getTag(tag_name)
        parts = parts.getTag("code_parts")
        if parts:
            parts = parts.getChildTags("code_part")
            for part in parts:
                code_template.code_parts.append(part.getAttr("value"))

        parts = parser.getTag(tag_name)
        parts = parts.getTag("files")
        if parts:
            parts = parts.getChildTags("file")
            for part in parts:
                code_template.files[part.getAttr("name_")] = part.getAttr(
                    "value")

        parts = parser.getTag(tag_name)
        parts = parts.getTag("properties")
        if parts:
            parts = parts.getChildTags("property")
            for part in parts:
                code_template.properties.append(
                    ast.literal_eval(part.getAttr("value")))

        if code_template.name == "":
            return None
        return code_template
    def load(cls, file_name):
        """
        This method loads the code_template from XML file.

        Returns:

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

        if parser.getTag(tag_name) is None:
            return None

        try:
            code_template = CodeTemplate()
            code_template.name = parser.getTagAttr(tag_name, "name")
            code_template.type = parser.getTagAttr(tag_name, "type")
            code_template.description = parser.getTagAttr(
                tag_name, "description")
            code_template.language = parser.getTagAttr(tag_name, "language")
            code_template.command = parser.getTag(tag_name).getTag(
                "command").getText()
            code_template.extension = parser.getTagAttr(tag_name, "extension")
            code_template.code = parser.getTag(tag_name).getTag(
                "code").getText()

            code_parts = parser.getTag(tag_name).getTag(
                "code_parts").getChildTags("code_part")
            for code_part in code_parts:
                code_template.code_parts.append(code_part.getAttr("value"))

        except Exception as e:
            print e
            return None

        if code_template.name == "":
            return None
        return code_template
Beispiel #22
0
    def create_code_template(self):
        code_template = CodeTemplate()
        code_template.name = "webaudio"
        code_template.type = "Test"
        code_template.language = "Test"
        code_template.command = "python\n"
        code_template.description = "Javascript / webaudio code template"

        code_template.code_parts = [
            "onload", "function", "declaration", "execution", "html"
        ]
        code_template.properties = [{
            "name": "title",
            "label": "Title",
            "value": "Title",
            "type": MOSAICODE_STRING
        }]

        code_template.files["index.html"] = r"""
<html>
    <head>
        <meta http-equiv="Cache-Control" content="no-store" />
        <!-- $author$ $license$ -->
        <title>$prop[title]$</title>
        <link rel="stylesheet" type="text/css" href="theme.css">
        <script src="functions.js"></script>
        <script>
        $single_code[function]$
        function loadme(){
        $single_code[onload]$
        return;
        }
        var context = new (window.AudioContext || window.webkitAudioContext)();
        //declaration block
        $code[declaration]$

        //execution
        $code[execution]$

        //connections
        $connections$
        </script>
    </head>

    <body onload='loadme();'>
        $code[html]$
    </body>
</html>
"""

        code_template.files["theme.css"] = r"""
/*
Developed by: $author$
*/
html, body {
  background: #ffeead;
  color: #ff6f69;
}
h1, p {
  color: #ff6f69;
}
#navbar a {
  color: #ff6f69;
}
.item {
  background: #ffcc5c;
}
button {
  background: #ff6f69;
  color: #ffcc5c;
}
"""

        code_template.files["functions.js"] = r"""
/*
Developed by: $author$
*/
$single_code[function]$
"""
        System.add_code_template(code_template)
        return code_template
    def __init__(self, code_template_manager, code_template_name):
        Gtk.Dialog.__init__(self, _("Code Template Editor"),
                            code_template_manager,
                            0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        self.code_template_manager = code_template_manager
        system_code_template = System.get_code_templates()
        if code_template_name is not None:
            self.code_template = system_code_template[code_template_name]
        else:
            self.code_template = CodeTemplate()

        self.main_control = self
        self.set_default_size(800, 300)

        self.tabs = Gtk.Notebook()
        self.tabs.set_scrollable(True)
        box = self.get_content_area()
        box.pack_start(self.tabs, True, True, 0)

        common_tab = Gtk.VBox()
        code_tab = Gtk.VBox()
        command_tab = Gtk.VBox()

        self.tabs.append_page(common_tab, Gtk.Label(_("Common")))
        self.tabs.append_page(code_tab, Gtk.Label(_("Code")))
        self.tabs.append_page(command_tab, Gtk.Label(_("Command")))

        # First Tab: Common properties
        self.name = StringField({"label": _("Name")}, self.__edit)
        self.language = StringField({"label": _("Language")}, self.__edit)
        self.extension = StringField({"label": _("Extension")}, self.__edit)
        self.type = StringField({"label": _("Type")}, None)
        self.description = StringField({"label": _("Description")}, None)
        self.code_parts = StringField({"label": _("Code Parts")}, None)

        common_tab.pack_start(self.language, False, False, 0)
        common_tab.pack_start(self.name, False, False, 0)
        common_tab.pack_start(self.extension, False, False, 0)
        common_tab.pack_start(self.type, False, False, 0)
        common_tab.pack_start(self.description, False, False, 0)
        common_tab.pack_start(self.code_parts, False, False, 0)

        # Second Tab: Code properties

        # Button bar
        button_bar = Gtk.HBox()
        code_tab.pack_start(button_bar, False, False, 0)
        self.__populate_combos(button_bar)

        self.code = CodeField({"label": _("")}, None)
        code_tab.pack_end(self.code, True, True, 0)

        # Third Tab: Command properties
        self.command = CodeField({"label": _("")}, None)
        command_tab.pack_start(self.command, True, True, 0)

        if code_template_name is not None:
            System()
            self.name.set_value(self.code_template.name)
            self.type.set_value(self.code_template.type)
            self.description.set_value(self.code_template.description)
            self.language.set_value(self.code_template.language)
            self.command.set_value(self.code_template.command)
            self.extension.set_value(self.code_template.extension)
            self.code.set_value(self.code_template.code)
            code_parts_string = ', '.join(self.code_template.code_parts)
            self.code_parts.set_value(code_parts_string)

        self.show_all()
        result = self.run()
        if result == Gtk.ResponseType.OK:
            self.__save()
        self.close()
        self.destroy()
Beispiel #24
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "opencv"
        self.language = "c"
        self.description = "c / opencv code template"
        self.command = "make run\n"
        self.code_parts = [
            "include", "function", "declaration", "execution", "deallocation"
        ]

        self.files["main.c"] = r"""
        
/*
* Generated by Mosaicode
*	$name$
*	$description$
*	Developed by: $author$
*	Using $license$
*/

#ifdef _CH_
#pragma package <opencv>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include "opencv2/core.hpp"
#include "opencv2/opencv.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/features2d/features2d.hpp"

using namespace cv;
using namespace std;
$single_code[include]$

$single_code[function]$

#define FRAMERATE 1000.0 / 25.0

int main(int argc, char ** argv){
    char key = ' ';
    $code[declaration]$
    while((key = (char)waitKey(FRAMERATE)) != 27){
        $code[execution, connection]$
        $code[deallocation]$
    }

    destroyAllWindows();
    return 0;
}
"""

        self.files["function.c"] = r"""
#include "opencv2/core.hpp"
using namespace cv;
"""

        self.files["Makefile"] = r"""
Beispiel #25
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "Mosaicode-Sound"
        self.language = "c"
        self.command = "make && ./main\n"
        self.description = "mosaicode-c-sound"
        self.code_parts = ["declaration", "execution", "setup"]
        self.properties = [{
            "name": "title",
            "label": "Title",
            "value": "Title",
            "type": MOSAICODE_STRING
        }]

        self.files["main.c"] = \
r"""
#include <mosaic-sound.h>
#include <portaudio.h>
#include <alsa/asoundlib.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <time.h>
#include <math.h>

#define NUM_SECONDS 12
#define SAMPLE_RATE 44100
#define FRAMES_PER_BUFFER 256

$code[declaration]$

static int mscsound_callback(const void *inputBuffer, void *outputBuffer,
                             unsigned long framesPerBuffer,
                             const PaStreamCallbackTimeInfo *timeInfo,
                             PaStreamCallbackFlags statusFlags,
                             void *userData) {
  float *in = (float *)inputBuffer;
  float *out = (float *)outputBuffer;

  (void)timeInfo; /* Prevent unused variable warnings. */
  (void)statusFlags;
  (void)userData;
  (void)in;
  (void)out;

  $code[execution]$

  return paContinue;
}

/*
 * This routine is called by mscsound when mscsound_callback is done.
 */
static void mscsound_finished(void *data) { printf("Stream Completed!\n"); }

/*******************************************************************/
int main(int argc, char *argv[]) {
  time_t t;

  /* Intializes random number generator */
  srand((unsigned) time(&t));

  $code[setup]$

  $connections$

  void *stream = mscsound_initialize(SAMPLE_RATE, FRAMES_PER_BUFFER);

  printf("Playing until the Enter key is pressed.\n");
  getchar();

  mscsound_terminate(stream);

  return 0;
}
"""

        self.files["Makefile"] = \
r"""CC := gcc
Beispiel #26
0
 def test_init(self):
     CodeTemplate()
    def setUp(self):
        """Do the test basic setup."""
        self.blockmodel = BlockModel()

        self.blockmodel.id = 1
        self.blockmodel.x = 2
        self.blockmodel.y = 2

        self.blockmodel.language = "c"
        self.blockmodel.framework = "opencv"
        self.blockmodel.help = "Adiciona bordas na imagem."
        self.blockmodel.label = "Add Border"
        self.blockmodel.color = "0:180:210:150"
        self.blockmodel.in_ports = [{
            "type": "mosaicode_c_opencv.extensions.ports.image",
            "name": "input_image",
            "label": "Input Image"
        }, {
            "type": "mosaicode_c_opencv.extensions.ports.int",
            "name": "border_size",
            "label": "Border Size"
        }]
        self.blockmodel.out_ports = [{
            "type": "mosaicode_c_opencv.extensions.ports.image",
            "name": "output_image",
            "label": "Output Image"
        }]
        self.blockmodel.group = "Experimental"
        self.blockmodel.properties = [{
            "label": "Color",
            "name": "color",
            "type": MOSAICODE_COLOR,
            "value": "#FF0000"
        }, {
            "name":
            "type",
            "label":
            "Type",
            "type":
            MOSAICODE_COMBO,
            "value":
            "IPL_BORDER_CONSTANT",
            "values": [
                "IPL_BORDER_CONSTANT", "IPL_BORDER_REPLICATE",
                "IPL_BORDER_REFLECT", "IPL_BORDER_WRAP"
            ]
        }, {
            "label": "Border Size",
            "name": "border_size",
            "type": MOSAICODE_INT,
            "value": "50"
        }]
        self.blockmodel.codes[0] = \
            "CvScalar get_scalar_color(const char * rgbColor){\n" + \
            "   if (strlen(rgbColor) < 13 || rgbColor[0] != '#')\n" + \
            "       return cvScalar(0,0,0,0);\n" + \
            "   char r[4], g[4], b[4];\n" + \
            "   strncpy(r, rgbColor+1, 4);\n" + \
            "   strncpy(g, rgbColor+5, 4);\n" + \
            "   strncpy(b, rgbColor+9, 4);\n" + \
            "\n" + \
            "   int ri, gi, bi = 0;\n" + \
            "   ri = (int)strtol(r, NULL, 16);\n" + \
            "   gi = (int)strtol(g, NULL, 16);\n" + \
            "   bi = (int)strtol(b, NULL, 16);\n" + \
            "\n" + \
            "   ri /= 257;\n" + \
            "   gi /= 257;\n" + \
            "   bi /= 257;\n" + \
            "   \n" + \
            "   return cvScalar(bi, gi, ri, 0);\n" + \
            "}\n"
        self.blockmodel.codes[1] = \
            "IplImage * block$id$_img_i0 = NULL;\n" + \
            "int block$id$_int_i1 = $prop[border_size]$;\n" + \
            "IplImage * block$id$_img_o0 = NULL;\n"
        self.blockmodel.codes[2] = \
            'if(block$id$_img_i0){\n' + \
            '\tCvSize size$id$ = cvSize(block$id$_img_i0->width +' + \
            ' block$id$_int_i1 * 2, block$id$_img_i0->height' + \
            ' + block$id$_int_i1 * 2);\n' + \
            '\tblock$id$_img_o0 = cvCreateImage(size$id$,' + \
            ' block$id$_img_i0->depth,block$id$_img_i0->nChannels);\n' + \
            '\tCvPoint point$id$ = cvPoint' + \
            '(block$id$_int_i1, block$id$_int_i1);\n' + \
            '\tCvScalar color = get_scalar_color("$prop[color]$");\n' + \
            '\tcvCopyMakeBorder(block$id$_img_i0, block$id$_img_o0,' + \
            ' point$id$, $prop[type]$, color);\n' + \
            '}\n'

        win = MainWindow()
        self.diagram = Diagram(win)
        self.codetemplate = CodeTemplate()
        #block = Block(diagram, blockmodel)
        #diagram.language = None
        self.code_generator = CodeGenerator(None, None)
        self.diagram.language = None
        self.code_generator = CodeGenerator(self.diagram, None)
        self.diagram.language = ""
        self.code_generator = CodeGenerator(self.diagram, None)
        self.code_generator = CodeGenerator(self.diagram, self.codetemplate)
Beispiel #28
0
    def __init__(self):
        CodeTemplate.__init__(self)
        self.name = "gtk"
        self.language = "c"
        self.description = "A full template to generate gtk code"
        self.command = "make && $dir_name$./main\n"
        self.code_parts = ["declaration", "setup"]
        self.properties = [{"name": "title",
                            "label": "Title",
                            "value": "Title",
                            "type": MOSAICODE_STRING
                            },
                            {"name": "border",
                            "label": "Border",
                            "value": 50,
                            "type": MOSAICODE_INT
                            },
                            {"name": "width",
                            "label": "Width",
                            "value": 800,
                            "type": MOSAICODE_INT
                            },
                            {"name": "height",
                            "label": "Height",
                            "value": 600,
                            "type": MOSAICODE_INT
                            }
                           ]

        self.files["callback.h"] = r"""
typedef void (*string_callback)(const char * value);
typedef void (*float_callback)(float value);
typedef void (*int_callback)(int value);
typedef void (*char_callback)(char value);
"""

        self.files["main.c"] = r"""
#include <gtk/gtk.h>
#include <limits.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include "callback.h"

GtkWidget * window;
GtkWidget * fixed_layout;
$code[declaration]$

void destroy(void){
    gtk_main_quit ();
}

int main(int argc, char *argv[]){
    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "$prop[title]$");
    g_signal_connect(window, "destroy",G_CALLBACK(destroy), NULL);
    gtk_window_resize(GTK_WINDOW(window), $prop[width]$, $prop[height]$);
    gtk_container_set_border_width(GTK_CONTAINER(window), $prop[border]$);

    fixed_layout = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(window), fixed_layout);


    $code[setup]$
    $connections$

    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}
"""

        self.files["Makefile"] = \
r"""CC := gcc
 def setUp(self):
     self.code_template = CodeTemplate()
     self.code_template.code_parts = ["test"]
Beispiel #30
0
 def test_str(self):
     code = CodeTemplate()
     string = code.__str__()
     assert isinstance(string, str)
     assert string == str(code.__class__.__module__)