svgui/pyjs/pyjs.py
changeset 1768 691083b5682a
parent 1767 c74815729afd
child 1771 f68a105000be
equal deleted inserted replaced
1767:c74815729afd 1768:691083b5682a
   795         if not init_method:
   795         if not init_method:
   796             init_method = ast.Function([], "__init__", ["self"], [], 0, None, [])
   796             init_method = ast.Function([], "__init__", ["self"], [], 0, None, [])
   797             #self._method(init_method, current_klass, class_name)
   797             #self._method(init_method, current_klass, class_name)
   798 
   798 
   799         # Generate a function which constructs the object
   799         # Generate a function which constructs the object
   800         clsfunc = ast.Function([],
   800         clsfunc = ast.Function(
   801            node.name,
   801             [], node.name,
   802            init_method.argnames[1:],
   802             init_method.argnames[1:],
   803            init_method.defaults,
   803             init_method.defaults,
   804            init_method.flags,
   804             init_method.flags,
   805            None,
   805             None,
   806            [ast.Discard(ast.CallFunc(ast.Name("JS"), [ast.Const(
   806             [ast.Discard(ast.CallFunc(ast.Name("JS"), [ast.Const(
   807 #            I attempted lazy initialization, but then you can't access static class members
   807                 #            I attempted lazy initialization, but then you can't access static class members
   808 #            "    if(!__"+base_class+".__was_initialized__)"+
   808                 #            "    if(!__"+base_class+".__was_initialized__)"+
   809 #            "        __" + class_name + "_initialize();\n" +
   809                 #            "        __" + class_name + "_initialize();\n" +
   810             "    var instance = new " + UU + class_name_ + "();\n" +
   810             "    var instance = new " + UU + class_name_ + "();\n" +
   811             "    if(instance.__init__) instance.__init__.apply(instance, arguments);\n" +
   811                 "    if(instance.__init__) instance.__init__.apply(instance, arguments);\n" +
   812             "    return instance;"
   812                 "    return instance;"
   813             )]))])
   813             )]))])
   814 
   814 
   815         self._function(clsfunc, False)
   815         self._function(clsfunc, False)
   816         print >>self.output, UU+class_name_ + ".__initialize__ = function () {"
   816         print >>self.output, UU+class_name_ + ".__initialize__ = function () {"
   817         print >>self.output, "    if("+UU+class_name_+".__was_initialized__) return;"
   817         print >>self.output, "    if("+UU+class_name_+".__was_initialized__) return;"