svgui/pyjs/pyjs.py
changeset 1730 64d8f52bc8c8
parent 728 e0424e96e3fd
child 1734 750eeb7230a1
equal deleted inserted replaced
1726:d51af006fa6b 1730:64d8f52bc8c8
   343             # but don't add the short name to imported_modules
   343             # but don't add the short name to imported_modules
   344             # because then the short name would be attempted to be
   344             # because then the short name would be attempted to be
   345             # added to the dependencies, and it's half way up the
   345             # added to the dependencies, and it's half way up the
   346             # module import directory structure!
   346             # module import directory structure!
   347             child_name = name[-1]
   347             child_name = name[-1]
   348             self.imported_modules_as.append(child_name) 
   348             self.imported_modules_as.append(child_name)
   349         print >> self.output, gen_mod_import(self.raw_module_name,
   349         print >> self.output, gen_mod_import(self.raw_module_name,
   350                                              strip_py(importName),
   350                                              strip_py(importName),
   351                                              self.dynamic)
   351                                              self.dynamic)
   352 
   352 
   353     def _default_args_handler(self, node, arg_names, current_klass,
   353     def _default_args_handler(self, node, arg_names, current_klass,
   425 
   425 
   426         function_args = "(" + ", ".join(declared_arg_names) + ")"
   426         function_args = "(" + ", ".join(declared_arg_names) + ")"
   427         print >>self.output, "%s = function%s {" % (function_name, function_args)
   427         print >>self.output, "%s = function%s {" % (function_name, function_args)
   428         self._default_args_handler(node, normal_arg_names, None)
   428         self._default_args_handler(node, normal_arg_names, None)
   429 
   429 
   430         local_arg_names = normal_arg_names + declared_arg_names 
   430         local_arg_names = normal_arg_names + declared_arg_names
   431 
   431 
   432         if node.varargs:
   432         if node.varargs:
   433             self._varargs_handler(node, varargname, declared_arg_names, None)
   433             self._varargs_handler(node, varargname, declared_arg_names, None)
   434             local_arg_names.append(varargname)
   434             local_arg_names.append(varargname)
   435 
   435 
   537                 star_arg_name = 'null'
   537                 star_arg_name = 'null'
   538             try: call_this, method_name = call_name.rsplit(".", 1)
   538             try: call_this, method_name = call_name.rsplit(".", 1)
   539             except ValueError:
   539             except ValueError:
   540                 # Must be a function call ...
   540                 # Must be a function call ...
   541                 return ("pyjs_kwargs_function_call("+call_name+", "
   541                 return ("pyjs_kwargs_function_call("+call_name+", "
   542                                   + star_arg_name 
   542                                   + star_arg_name
   543                                   + ", ["+fn_args+"]"
   543                                   + ", ["+fn_args+"]"
   544                                   + ")" )
   544                                   + ")" )
   545             else:
   545             else:
   546                 return ("pyjs_kwargs_method_call("+call_this+", '"+method_name+"', "
   546                 return ("pyjs_kwargs_method_call("+call_this+", '"+method_name+"', "
   547                                   + star_arg_name 
   547                                   + star_arg_name
   548                                   + ", ["+fn_args+"]"
   548                                   + ", ["+fn_args+"]"
   549                                   + ")")
   549                                   + ")")
   550         else:
   550         else:
   551             return call_name + "(" + ", ".join(call_args) + ")"
   551             return call_name + "(" + ", ".join(call_args) + ")"
   552 
   552 
   626             raise TranslationError("unsupported type (in _getattr)", v.expr)
   626             raise TranslationError("unsupported type (in _getattr)", v.expr)
   627 
   627 
   628 
   628 
   629     def modpfx(self):
   629     def modpfx(self):
   630         return strip_py(self.module_prefix)
   630         return strip_py(self.module_prefix)
   631         
   631 
   632     def _name(self, v, current_klass, top_level=False,
   632     def _name(self, v, current_klass, top_level=False,
   633                                       return_none_for_module=False):
   633                                       return_none_for_module=False):
   634 
   634 
   635         if v.name == 'ilikesillynamesfornicedebugcode':
   635         if v.name == 'ilikesillynamesfornicedebugcode':
   636             print top_level, current_klass, repr(v)
   636             print top_level, current_klass, repr(v)
   902         print >>self.output, "    "+fexpr + " = function" + function_args + " {"
   902         print >>self.output, "    "+fexpr + " = function" + function_args + " {"
   903 
   903 
   904         # default arguments
   904         # default arguments
   905         self._default_args_handler(node, normal_arg_names, current_klass)
   905         self._default_args_handler(node, normal_arg_names, current_klass)
   906 
   906 
   907         local_arg_names = normal_arg_names + declared_arg_names 
   907         local_arg_names = normal_arg_names + declared_arg_names
   908 
   908 
   909         if node.varargs:
   909         if node.varargs:
   910             self._varargs_handler(node, varargname, declared_arg_names, current_klass)
   910             self._varargs_handler(node, varargname, declared_arg_names, current_klass)
   911             local_arg_names.append(varargname)
   911             local_arg_names.append(varargname)
   912 
   912 
  1168             print "b", repr(node.expr), rhs
  1168             print "b", repr(node.expr), rhs
  1169         print >>self.output, "    " + lhs + " " + op + " " + rhs + ";"
  1169         print >>self.output, "    " + lhs + " " + op + " " + rhs + ";"
  1170 
  1170 
  1171 
  1171 
  1172     def _discard(self, node, current_klass):
  1172     def _discard(self, node, current_klass):
  1173         
  1173 
  1174         if isinstance(node.expr, ast.CallFunc):
  1174         if isinstance(node.expr, ast.CallFunc):
  1175             debugStmt = self.debug and not self._isNativeFunc(node)
  1175             debugStmt = self.debug and not self._isNativeFunc(node)
  1176             if debugStmt and isinstance(node.expr.node, ast.Name) and \
  1176             if debugStmt and isinstance(node.expr.node, ast.Name) and \
  1177                node.expr.node.name == 'import_wait':
  1177                node.expr.node.name == 'import_wait':
  1178                debugStmt = False
  1178                debugStmt = False
  1772         module_name = None
  1772         module_name = None
  1773     print translate(file_name, module_name),
  1773     print translate(file_name, module_name),
  1774 
  1774 
  1775 if __name__ == "__main__":
  1775 if __name__ == "__main__":
  1776     main()
  1776     main()
  1777