Skip to content

Commit 29246d8

Browse files
committed
load prepend.py from wrapper jar instead of prepending
1 parent a7522d7 commit 29246d8

File tree

8 files changed

+304
-136
lines changed

8 files changed

+304
-136
lines changed

build.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
<path refid="library-classpath"/>
6666
</classpath>
6767
</javac>
68+
69+
<copy file="${src}/${wrap.path}/prepend.py" tofile="${build}/${wrap.path}/prepend.py" />
70+
6871
</target>
6972

7073
<!-- - - - - - - - - - - - - - - - - - - - - - -
@@ -79,7 +82,7 @@
7982
<!-- make mode jar -->
8083
<jar jarfile="${bundle}/mode/${lib.name}.jar" basedir="build" includes="${lib.path}/*.class"/>
8184
<!-- make wrapper jar -->
82-
<jar jarfile="${bundle}/mode/${wrap.name}.jar" basedir="build" includes="${wrap.path}/*.class"/>
85+
<jar jarfile="${bundle}/mode/${wrap.name}.jar" basedir="build" includes="${wrap.path}/*"/> <!-- include prepend.py -->
8386

8487

8588
<copy todir="${bundle}">
File renamed without changes.

release/PythonMode.zip

212 Bytes
Binary file not shown.

resources/prepend.py

Lines changed: 0 additions & 74 deletions
This file was deleted.

src/info/sansgills/mode/python/PythonBuild.java

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,15 @@ public void build() throws Exception{
7676

7777

7878
//Things we don't need to reload every build
79-
//Some small files we add to the beginning & end of sketches
80-
private static String prepend;
81-
static {
82-
try{
83-
prepend = Base.loadFile(new File(PythonMode.getModeFolder()+"prepend.py"));
84-
}catch(Exception e){
85-
System.err.println("Error instantiating Python Mode");
86-
e.printStackTrace();
87-
}
88-
}
89-
9079
//Some regexes
9180
//A hack, but much less work than a full parser, and we don't need to do very much
92-
private static Pattern getPressed; //replace mousePressed / keyPressed with
81+
private static Pattern getSpecial; //replace mousePressed / keyPressed with
9382
private static Pattern instanceVars; //replace 'mouseX' with __applet__.mouseX, etc.
9483

9584
static{
96-
getPressed = Pattern.compile("(?<!def\\s{1,100})(mousePressed|keyPressed)");
97-
instanceVars = Pattern.compile("(mouseX|mouseY|pmouseX|pmouseY|mouseButton|keyCode|key)");
85+
getSpecial = Pattern.compile("(?<!def\\s{1,1000})(mousePressed|keyPressed|frameRate)(?!\\s{0,1000}\\()");
86+
instanceVars = Pattern.compile("(mouseX|mouseY|pmouseX|pmouseY|mouseButton|"
87+
+"keyCode|key|pixels|width|height|displayWidth|displayHeight|focused|frameCount)");
9888
}
9989

10090

@@ -103,29 +93,24 @@ public void build() throws Exception{
10393
* Turn .pde into valid python
10494
*/
10595
private String preprocess(StringBuilder program){
106-
System.out.println("Preprocessing");
10796
try{
10897
String temp;
10998

110-
Matcher regex = getPressed.matcher(program);
99+
Matcher regex = getSpecial.matcher(program);
111100

112101
temp = regex.replaceAll("get$1()");
113102

114103
regex = instanceVars.matcher(temp);
115104

116105
temp = regex.replaceAll("__applet__.$1");
117106

118-
program = new StringBuilder(temp);
119-
120-
program.insert(0, prepend);
107+
return temp;
121108

122109
}catch(Exception e){
123-
124110
System.err.println("Preprocessing failed.");
125111
e.printStackTrace();
126-
112+
return null;
127113
}
128-
return program.toString();
129114
}
130115

131116

src/info/sansgills/mode/python/wrapper/ProcessingJythonWrapper.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.util.Arrays;
5+
import java.util.Scanner;
56

67
import org.python.core.*;
78
import org.python.util.InteractiveConsole;
@@ -28,7 +29,10 @@
2829
public class ProcessingJythonWrapper {
2930

3031
//EVERYTHING IS STATIC
31-
32+
33+
//Read in prepend.py from jar (this is the only one-liner to read in a stream, don't you love java)
34+
static final String prepend = new Scanner(ProcessingJythonWrapper.class.getResourceAsStream("prepend.py")).useDelimiter("\\A").next();
35+
3236
static final String[] sketchFunctions = { "setup", "draw", "mousePressed",
3337
"mouseReleased", "mouseClicked", "mouseWheel", "mouseMoved",
3438
"mouseDragged", "keyPressed", "keyReleased", "keyTyped" };
@@ -44,7 +48,7 @@ public class ProcessingJythonWrapper {
4448
* First argument is the path to the script; the rest are things to pass to PApplet.
4549
*
4650
*/
47-
public static void main(String[] args) {
51+
public static void main(String[] args) {
4852
String scriptPath = args[0];
4953
String[] params = Arrays.copyOfRange(args, 1, args.length);
5054
run(scriptPath, params);
@@ -65,6 +69,9 @@ public static void run(String scriptPath, String[] params){
6569
sys.add_package("processing.opengl");
6670

6771
try {
72+
//run prepend.py
73+
interp.exec(prepend);
74+
6875
//run the script we were given
6976
interp.execfile(scriptPath);
7077

src/info/sansgills/mode/python/wrapper/PythonPApplet.java

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class PythonPApplet extends PApplet {
2121

2222
//Accessed from prepend.py
23-
public static String[] staticMethods = { "abs", "acos", "append",
23+
public static final String[] staticMethods = { "abs", "acos", "append",
2424
"arrayCopy", "asin", "atan", "atan2", "binary", "blendColor",
2525
"ceil", "concat", "constrain", "cos", "createInput",
2626
"createOutput", "createReader", "createWriter", "day", "debug",
@@ -32,43 +32,44 @@ public class PythonPApplet extends PApplet {
3232
"saveBytes", "saveStream", "saveStrings", "second", "shorten",
3333
"sin", "sort", "splice", "split", "splitTokens", "sq", "sqrt",
3434
"subset", "tan", "trim", "unbinary", "unhex", "year" };
35-
public static String[] instanceMethods = { "alpha", "ambient",
36-
"ambientLight", "applyMatrix", "arc", "background", "beginCamera",
37-
"beginContour", "beginRaw", "beginRecord", "beginShape", "bezier",
38-
"bezierDetail", "bezierPoint", "bezierTangent", "bezierVertex",
39-
"blend", "blendMode", "blue", "box", "brightness", "camera",
40-
"clear", "color", "colorMode", "copy", "createFont",
41-
"createGraphics", "createImage", "createInput", "createOutput",
42-
"createReader", "createShape", "createWriter", "cursor", "curve",
43-
"curveDetail", "curvePoint", "curveTangent", "curveTightness",
44-
"curveVertex", "directionalLight", "ellipse",
45-
"ellipseMode", "emissive", "endCamera", "endContour", "endRaw",
46-
"endRecord", "endShape", "exit", "fill", "filter", "frameRate",
47-
"frustum", "get", "hint", "hue", "image", "imageMode", "lerpColor",
48-
"lightFalloff", "lightSpecular", "lights", "line", "loadBytes",
49-
"loadFont", "loadImage", "loadJSONArray", "loadJSONObject",
50-
"loadPixels", "loadShader", "loadShape", "loadStrings",
51-
"loadTable", "loadXML", "loop", "millis", "modelX", "modelY",
52-
"modelZ", "noCursor",
53-
"noFill", "noLights", "noLoop", "noSmooth", "noStroke", "noTint",
54-
"noise", "noiseDetail", "noiseSeed", "normal", "ortho", "parseXML",
55-
"perspective", "point", "pointLight", "popMatrix", "popStyle",
56-
"printCamera", "printMatrix", "printProjection", "pushMatrix",
57-
"pushStyle", "quad", "quadraticVertex", "random", "randomGaussian",
58-
"randomSeed", "rect", "rectMode", "red", "redraw", "requestImage",
59-
"resetMatrix", "resetShader", "rotate", "rotateX", "rotateY",
60-
"saturation", "save", "saveBytes", "saveFrame", "saveJSONArray",
61-
"saveJSONObject", "saveStream", "saveStrings", "saveTable",
62-
"saveXML", "scale", "screenX", "screenY", "screenZ",
63-
"selectFolder", "selectInput", "selectOutput", "shader", "shape",
64-
"shapeMode", "shearX", "shearY", "shininess", "size", "smooth",
65-
"specular", "sphere", "sphereDetail", "spotLight", "stroke",
66-
"strokeCap", "strokeJoin", "strokeWeight", "text", "textAlign",
67-
"textAscent", "textDescent", "textFont", "textLeading", "textMode",
68-
"textSize", "textWidth", "texture", "textureMode", "tint",
69-
"translate", "triangle", "updatePixels", "vertex" };
70-
7135

36+
public static final String[] constants = { "ADD", "ALPHA", "ALT",
37+
"AMBIENT", "ARC", "ARGB", "ARROW", "BACKSPACE", "BASELINE",
38+
"BEVEL", "BEZIER_VERTEX", "BLEND", "BLUR", "BOTTOM", "BOX",
39+
"BREAK", "BURN", "CENTER", "CHATTER", "CHORD", "CLAMP", "CLOSE",
40+
"CODED", "COMPLAINT", "CONTROL", "CORNER", "CORNERS", "CROSS",
41+
"CURVE_VERTEX", "CUSTOM", "DARKEST", "DEG_TO_RAD", "DELETE",
42+
"DIAMETER", "DIFFERENCE", "DILATE", "DIRECTIONAL",
43+
"DISABLE_DEPTH_MASK", "DISABLE_DEPTH_SORT", "DISABLE_DEPTH_TEST",
44+
"DISABLE_NATIVE_FONTS", "DISABLE_OPENGL_ERRORS",
45+
"DISABLE_OPTIMIZED_STROKE", "DISABLE_RETINA_PIXELS",
46+
"DISABLE_STROKE_PERSPECTIVE", "DISABLE_STROKE_PURE",
47+
"DISABLE_TEXTURE_MIPMAPS", "DODGE", "DOWN", "DXF", "ELLIPSE",
48+
"ENABLE_DEPTH_MASK", "ENABLE_DEPTH_SORT", "ENABLE_DEPTH_TEST",
49+
"ENABLE_NATIVE_FONTS", "ENABLE_OPENGL_ERRORS",
50+
"ENABLE_OPTIMIZED_STROKE", "ENABLE_RETINA_PIXELS",
51+
"ENABLE_STROKE_PERSPECTIVE", "ENABLE_STROKE_PURE",
52+
"ENABLE_TEXTURE_MIPMAPS", "ENTER", "EPSILON", "ERODE",
53+
"ERROR_BACKGROUND_IMAGE_FORMAT", "ERROR_BACKGROUND_IMAGE_SIZE",
54+
"ERROR_PUSHMATRIX_OVERFLOW", "ERROR_PUSHMATRIX_UNDERFLOW",
55+
"ERROR_TEXTFONT_NULL_PFONT", "ESC", "EXCLUSION", "GIF", "GRAY",
56+
"GROUP", "HALF_PI", "HAND", "HARD_LIGHT", "HINT_COUNT", "HSB",
57+
"IMAGE", "INVERT", "JAVA2D", "JPEG", "LANDSCAPE", "LEFT",
58+
"LIGHTEST", "LINE", "LINE_LOOP", "LINE_STRIP", "LINES", "LINUX",
59+
"MACOSX", "MAX_FLOAT", "MAX_INT", "MIN_FLOAT", "MIN_INT", "MITER",
60+
"MODEL", "MODELVIEW", "MOVE", "MULTIPLY", "NORMAL", "OPAQUE",
61+
"OPEN", "OPENGL", "ORTHOGRAPHIC", "OTHER", "OVERLAY", "P2D", "P3D",
62+
"PATH", "PDF", "PERSPECTIVE", "PI", "PIE", "platformNames",
63+
"POINT", "POINTS", "POLYGON", "PORTRAIT", "POSTERIZE", "PROBLEM",
64+
"PROJECT", "PROJECTION", "QUAD", "QUAD_BEZIER_VERTEX",
65+
"QUAD_STRIP", "QUADS", "QUARTER_PI", "RAD_TO_DEG", "RADIUS",
66+
"RECT", "REPEAT", "REPLACE", "RETURN", "RGB", "RIGHT", "ROUND",
67+
"SCREEN", "SHAPE", "SHIFT", "SOFT_LIGHT", "SPHERE", "SPOT",
68+
"SQUARE", "SUBTRACT", "TAB", "TARGA", "TAU", "TEXT", "THIRD_PI",
69+
"THRESHOLD", "TIFF", "TOP", "TRIANGLE", "TRIANGLE_FAN",
70+
"TRIANGLE_STRIP", "TRIANGLES", "TWO_PI", "UP", "VERTEX", "WAIT",
71+
"WHITESPACE", "WINDOWS", "X", "Y", "Z" };
72+
7273

7374
private HashMap<String, PyFunction> sketchFunctions;
7475

@@ -139,4 +140,8 @@ public boolean getmousePressed(){
139140
public boolean getkeyPressed(){
140141
return keyPressed;
141142
}
143+
144+
public float getframeRate(){
145+
return frameRate;
146+
}
142147
}

0 commit comments

Comments
 (0)