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)
Пример #2
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