Permalink
Browse files

Fix #13: PVector doesn't work in imported modules.

  • Loading branch information...
1 parent e6884b0 commit 9eba479c587ce00009d47aac81bc6b2aab0610dd @jdf jdf committed with Jun 7, 2013
View
@@ -5,7 +5,7 @@
<classpathentry kind="src" path="runtime/generated"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
- <classpathentry kind="lib" path="buildtime/lib/jython/jython.jar" sourcepath="/jython-trunk"/>
+ <classpathentry kind="lib" path="buildtime/lib/jython/jython.jar" sourcepath="buildtime/lib/jython/jython-2.5.3-sources.jar"/>
<classpathentry kind="lib" path="buildtime/lib/processing/core.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file not shown.
@@ -30,7 +30,19 @@
import processing.core.PApplet;
import processing.core.PConstants;
+import processing.core.PFont;
+import processing.core.PGraphics;
+import processing.core.PGraphicsJava2D;
import processing.core.PImage;
+import processing.core.PMatrix2D;
+import processing.core.PMatrix3D;
+import processing.core.PShape;
+import processing.core.PShapeSVG;
+import processing.core.PStyle;
+import processing.opengl.PGraphics2D;
+import processing.opengl.PGraphics3D;
+import processing.opengl.PGraphicsOpenGL;
+import processing.opengl.PShader;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
@@ -120,6 +132,21 @@ public PyObject __call__(final PyObject[] args, final String[] kws) {
return Py.None;
}
});
+ builtins.__setitem__("PApplet", Py.java2py(PApplet.class));
+ builtins.__setitem__("PConstants", Py.java2py(PConstants.class));
+ builtins.__setitem__("PFont", Py.java2py(PFont.class));
+ builtins.__setitem__("PGraphics", Py.java2py(PGraphics.class));
+ builtins.__setitem__("PGraphics2D", Py.java2py(PGraphics2D.class));
+ builtins.__setitem__("PGraphics3D", Py.java2py(PGraphics3D.class));
+ builtins.__setitem__("PGraphicsJava2D", Py.java2py(PGraphicsJava2D.class));
+ builtins.__setitem__("PGraphicsOpenGL", Py.java2py(PGraphicsOpenGL.class));
+ builtins.__setitem__("PImage", Py.java2py(PImage.class));
+ builtins.__setitem__("PMatrix2D", Py.java2py(PMatrix2D.class));
+ builtins.__setitem__("PMatrix3D", Py.java2py(PMatrix3D.class));
+ builtins.__setitem__("PShader", Py.java2py(PShader.class));
+ builtins.__setitem__("PShape", Py.java2py(PShape.class));
+ builtins.__setitem__("PShapeSVG", Py.java2py(PShapeSVG.class));
+ builtins.__setitem__("PStyle", Py.java2py(PStyle.class));
if (!isStaticMode) {
// Executing the sketch will bind method names ("draw") to PyCode
@@ -1,19 +1,5 @@
-from processing.core import PApplet
-from processing.core import PConstants
-from processing.core import PFont
-from processing.core import PGraphics
-from processing.opengl import PGraphics2D
-from processing.opengl import PGraphics3D
-from processing.core import PGraphicsJava2D
-from processing.opengl import PGraphicsOpenGL
-from processing.core import PImage
-from processing.core import PMatrix
-from processing.core import PMatrix2D
-from processing.core import PMatrix3D
-from processing.opengl import PShader
-from processing.core import PShape
-from processing.core import PShapeSVG
-from processing.core import PStyle
+import __builtin__
+
from processing.core import PVector as RealPVector
# Thanks, Guido!
@@ -75,11 +61,11 @@ def __mul__(a, b):
raise TypeError("The * operator can only be used to multiply a PVector by a scalar")
return PVector(a.x * b, a.y * b, a.z * b)
-
+__builtin__.PVector = PVector
# Extra helper functions go here
def pwd(name = ""):
"""Returns the script's path, or the path for some data close to the script."""
import java.lang.System as System
return System.getProperty("python.main.root") + "/" + name
-
+__builtin__.pwd = pwd
@@ -0,0 +1,2 @@
+def sayok():
+ print("OK!")
@@ -0,0 +1,5 @@
+def sayok():
+ a = PVector(5, 7, 11)
+ b = PVector(13, 17, 23)
+ assert a - b == PVector(-8.0, -10.0, -12.0)
+ print "OK!"
@@ -0,0 +1,4 @@
+import imported_module
+
+imported_module.sayok()
+exit()
@@ -0,0 +1,5 @@
+start = millis()
+delay(2)
+print millis() > 2
+# expect True
+exit()
@@ -0,0 +1,4 @@
+import imported_module_with_pvector as m
+
+m.sayok()
+exit()
@@ -126,6 +126,16 @@ public void millis() throws Exception {
assertEquals("True\n", run("millis"));
}
+ @Test
+ public void imports() throws Exception {
+ assertEquals("OK!\n", run("import"));
+ }
+
+ @Test
+ public void pvector_import() throws Exception {
+ assertEquals("OK!\n", run("pvector_in_imported_module"));
+ }
+
public static void main(final String[] args) {
JUnitCore.runClasses(JycessingTests.class);
}

0 comments on commit 9eba479

Please sign in to comment.