svgui/pyjs/pyjs.py
changeset 1737 a39c2918c015
parent 1736 7e61baa047f0
child 1738 d2e979738700
equal deleted inserted replaced
1736:7e61baa047f0 1737:a39c2918c015
   279                 self._function(child, False)
   279                 self._function(child, False)
   280             elif isinstance(child, ast.Class):
   280             elif isinstance(child, ast.Class):
   281                 self._class(child)
   281                 self._class(child)
   282             elif isinstance(child, ast.Import):
   282             elif isinstance(child, ast.Import):
   283                 importName = child.names[0][0]
   283                 importName = child.names[0][0]
   284                 if importName == '__pyjamas__': # special module to help make pyjamas modules loadable in the python interpreter
   284                 if importName == '__pyjamas__':  # special module to help make pyjamas modules loadable in the python interpreter
   285                     pass
   285                     pass
   286                 elif importName.endswith('.js'):
   286                 elif importName.endswith('.js'):
   287                    self.imported_js.add(importName)
   287                    self.imported_js.add(importName)
   288                 else:
   288                 else:
   289                    self.add_imported_module(strip_py(importName))
   289                    self.add_imported_module(strip_py(importName))
   290             elif isinstance(child, ast.From):
   290             elif isinstance(child, ast.From):
   291                 if child.modname == '__pyjamas__': # special module to help make pyjamas modules loadable in the python interpreter
   291                 if child.modname == '__pyjamas__':  # special module to help make pyjamas modules loadable in the python interpreter
   292                     pass
   292                     pass
   293                 else:
   293                 else:
   294                     self.add_imported_module(child.modname)
   294                     self.add_imported_module(child.modname)
   295                     self._from(child)
   295                     self._from(child)
   296             elif isinstance(child, ast.Discard):
   296             elif isinstance(child, ast.Discard):
   687                 cls_name = current_klass
   687                 cls_name = current_klass
   688                 if hasattr(cls_name, "name"):
   688                 if hasattr(cls_name, "name"):
   689                     cls_name_ = cls_name.name_
   689                     cls_name_ = cls_name.name_
   690                     cls_name = cls_name.name
   690                     cls_name = cls_name.name
   691                 else:
   691                 else:
   692                     cls_name_ = current_klass + "_" # XXX ???
   692                     cls_name_ = current_klass + "_"  # XXX ???
   693                 name = UU+cls_name_ + ".prototype.__class__." \
   693                 name = UU+cls_name_ + ".prototype.__class__." \
   694                                    + v.name
   694                                    + v.name
   695                 if v.name == 'listener':
   695                 if v.name == 'listener':
   696                     name = 'listener+' + name
   696                     name = 'listener+' + name
   697                 return name
   697                 return name
   708             #if attr_name != "__init__":
   708             #if attr_name != "__init__":
   709             attr_str = ".prototype.__class__." + attr_name
   709             attr_str = ".prototype.__class__." + attr_name
   710             call_name = UU+self.imported_classes[obj] + '.__' + obj + attr_str
   710             call_name = UU+self.imported_classes[obj] + '.__' + obj + attr_str
   711         elif obj in self.module_imports():
   711         elif obj in self.module_imports():
   712             call_name = obj + "." + attr_name
   712             call_name = obj + "." + attr_name
   713         elif obj[0] == obj[0].upper(): # XXX HACK ALERT
   713         elif obj[0] == obj[0].upper():  # XXX HACK ALERT
   714             call_name = UU + self.modpfx() + "__" + obj + ".prototype.__class__." + attr_name
   714             call_name = UU + self.modpfx() + "__" + obj + ".prototype.__class__." + attr_name
   715         else:
   715         else:
   716             call_name = UU+self._name(v, current_klass) + "." + attr_name
   716             call_name = UU+self._name(v, current_klass) + "." + attr_name
   717 
   717 
   718         return call_name
   718         return call_name
  1200 
  1200 
  1201             if debugStmt:
  1201             if debugStmt:
  1202                 print >>self.output, "sys.popstack();\n"
  1202                 print >>self.output, "sys.popstack();\n"
  1203 
  1203 
  1204         elif isinstance(node.expr, ast.Const):
  1204         elif isinstance(node.expr, ast.Const):
  1205             if node.expr.value is not None: # Empty statements generate ignore None
  1205             if node.expr.value is not None:  # Empty statements generate ignore None
  1206                 print >>self.output, self._const(node.expr)
  1206                 print >>self.output, self._const(node.expr)
  1207         else:
  1207         else:
  1208             raise TranslationError("unsupported type (in _discard)", node.expr)
  1208             raise TranslationError("unsupported type (in _discard)", node.expr)
  1209 
  1209 
  1210 
  1210 
  1394     def _mul(self, node, current_klass):
  1394     def _mul(self, node, current_klass):
  1395         return self.expr(node.left, current_klass) + " * " + self.expr(node.right, current_klass)
  1395         return self.expr(node.left, current_klass) + " * " + self.expr(node.right, current_klass)
  1396 
  1396 
  1397     def _mod(self, node, current_klass):
  1397     def _mod(self, node, current_klass):
  1398         if isinstance(node.left, ast.Const) and isinstance(node.left.value, StringType):
  1398         if isinstance(node.left, ast.Const) and isinstance(node.left.value, StringType):
  1399            self.imported_js.add("sprintf.js") # Include the sprintf functionality if it is used
  1399            self.imported_js.add("sprintf.js")  # Include the sprintf functionality if it is used
  1400            return "sprintf("+self.expr(node.left, current_klass) + ", " + self.expr(node.right, current_klass)+")"
  1400            return "sprintf("+self.expr(node.left, current_klass) + ", " + self.expr(node.right, current_klass)+")"
  1401         return self.expr(node.left, current_klass) + " % " + self.expr(node.right, current_klass)
  1401         return self.expr(node.left, current_klass) + " % " + self.expr(node.right, current_klass)
  1402 
  1402 
  1403     def _invert(self, node, current_klass):
  1403     def _invert(self, node, current_klass):
  1404         return "~" + self.expr(node.expr, current_klass)
  1404         return "~" + self.expr(node.expr, current_klass)
  1638 
  1638 
  1639     def copyFunction(self, target, source):
  1639     def copyFunction(self, target, source):
  1640         target.code = source.code
  1640         target.code = source.code
  1641         target.argnames = source.argnames
  1641         target.argnames = source.argnames
  1642         target.defaults = source.defaults
  1642         target.defaults = source.defaults
  1643         target.doc = source.doc # @@@ not sure we need to do this any more
  1643         target.doc = source.doc  # @@@ not sure we need to do this any more
  1644 
  1644 
  1645 
  1645 
  1646 def dotreplace(fname):
  1646 def dotreplace(fname):
  1647     path, ext = os.path.splitext(fname)
  1647     path, ext = os.path.splitext(fname)
  1648     return path.replace(".", "/") + ext
  1648     return path.replace(".", "/") + ext