Skip to content

Commit 36a03c1

Browse files
committed
build now writes to a temp file
1 parent 362ba6d commit 36a03c1

File tree

5 files changed

+66
-26
lines changed

5 files changed

+66
-26
lines changed

build.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<property name="build" value="build" />
2121
<property name="bin" value="bin" />
2222
<property name="dist" value="dist" />
23+
<property name="releasedir" value="release" />
2324

2425
<property name="lib.path" value="info/sansgills/mode/python" />
2526
<property name="wrap.path" value="info/sansgills/mode/python/wrapper" />
@@ -110,7 +111,7 @@
110111
RELEASE
111112
- - - - - - - - - - - - - - - - - - - - - - - -->
112113
<target name="release" depends="package" >
113-
<zip destfile="${dist}/${lib.name}.zip" basedir="${dist}/${lib.name}" />
114+
<zip destfile="${releasedir}/${lib.name}.zip" basedir="${dist}/${lib.name}" />
114115
</target>
115116

116117
<!-- - - - - - - - - - - - - - - - - - - - - - -

release/PythonMode.zip

11.7 MB
Binary file not shown.

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

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package info.sansgills.mode.python;
22

3+
import java.io.File;
4+
import java.io.PrintWriter;
5+
36
import processing.app.Sketch;
47
import processing.app.SketchCode;
5-
import org.python.util.*;
6-
import org.python.core.*;
78

89

910
/**
@@ -17,8 +18,11 @@ public class PythonBuild {
1718
Sketch sketch;
1819
String resultProgram; //old-school
1920

21+
File binFolder;
22+
File outFile;
23+
2024
//build tracking
21-
public int buildnumber;
25+
private int buildnumber;
2226
private static int buildstotal = 0;
2327

2428

@@ -37,28 +41,67 @@ public void build() throws Exception{
3741
resultProgram = "";
3842

3943
SketchCode[] parts = sketch.getCode(); //TODO this function doesn't work properly, it returns old code for some reason
44+
4045
//concatenate code strings
4146
for(int i = parts.length-1; i >= 0; i--){ //iterate backwards... it seemed like a good idea at the time
4247
resultProgram += "\n";
4348
resultProgram += parts[i].getProgram();
4449
}
4550

46-
//System.out.println("output code: "+resultProgram);
51+
preprocess();
4752

48-
//more things?
53+
54+
//write output file
55+
binFolder = sketch.makeTempFolder();
56+
57+
outFile = new File(binFolder.getAbsolutePath()
58+
+ sketch.getName().toLowerCase()
59+
+ ".py");
60+
outFile.createNewFile();
61+
PrintWriter writer = new PrintWriter(outFile);
62+
writer.write(resultProgram+"\n");
63+
writer.close();
64+
}
65+
66+
/*
67+
* Turn .pde into valid python
68+
*/
69+
private void preprocess(){
70+
//TODO implement
4971
}
5072

5173
/*
5274
* The output code string
5375
*/
54-
public String getResults(){
76+
public String getResultString(){
5577
return resultProgram;
5678
}
5779

80+
/*
81+
* The output file path
82+
*/
83+
public String getResultFile(){
84+
return outFile.getAbsolutePath();
85+
}
86+
87+
/*
88+
*
89+
*/
90+
public int getBuildNumber(){
91+
return buildnumber;
92+
}
93+
5894
/*
5995
* The PApplet subclass to extract from the code
6096
*/
6197
public String getClassName(){
6298
return "Placeholder"; //TODO implement naming scheme
6399
}
100+
101+
/*
102+
* The name of the output object
103+
*/
104+
public String getObjName(){
105+
return "applet"; // TODO
106+
}
64107
}

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

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
package info.sansgills.mode.python;
22

3-
import info.sansgills.mode.python.wrapper.PythonPApplet;
4-
5-
import org.python.core.*;
6-
import org.python.util.InteractiveConsole;
7-
83
import processing.app.Base;
4+
import processing.core.PApplet;
95

106
/**
117
*
@@ -14,26 +10,15 @@
1410
*
1511
* TODO REPL?
1612
*
17-
* Architecture note: Processing.py has a 'PApplet Jython Driver' class that
18-
* contains a private Python interpreter. It injects the PApplet variables and
19-
* methods into this interpreter, updating whenever it needs to. It runs the
20-
* input python directly, without modification.
21-
*
22-
* I'm using a different approach, similar to vanilla Processing: preprocess the
23-
* .pde input into a valid python class inheriting from PApplet, run the
24-
* resulting code through an interpreter, and extract the class to create a
25-
* final Java object to run as a PApplet.
2613
*
2714
*/
2815

2916
public class PythonRunner {
3017
PythonBuild build; // the python source we're working with
3118
PythonEditor editor;
3219

20+
Process sketchProcess;
3321

34-
final String modeName = "PythonMode"; //for modifying python classpath
35-
final String sep = System.getProperty("file.separator");
36-
3722
public PythonRunner(PythonBuild build, PythonEditor editor) {
3823
this.build = build;
3924
this.editor = editor;
@@ -42,7 +27,8 @@ public PythonRunner(PythonBuild build, PythonEditor editor) {
4227
/*
4328
* Run the code.
4429
*/
45-
public void launch(boolean present) {
30+
public void launch(boolean present) {
31+
4632
}
4733

4834
/*

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515
*
1616
* TODO REPL?
1717
*
18+
* Architecture note: Processing.py has a 'PApplet Jython Driver' class that
19+
* contains a private Python interpreter. It injects the PApplet variables and
20+
* methods into this interpreter, updating whenever it needs to. It runs the
21+
* input python directly, without modification.
22+
*
23+
* I'm using a different approach, similar to vanilla Processing: preprocess the
24+
* .pde input into a valid python class inheriting from PApplet, run the
25+
* resulting code through an interpreter, and extract the class to create a
26+
* final Java object to run as a PApplet.
27+
*
1828
*/
1929

2030
public class ProcessingJythonWrapper {
@@ -36,7 +46,7 @@ public class ProcessingJythonWrapper {
3646
*
3747
*/
3848
public static void main(String[] args) {
39-
scriptPath = args[1];
49+
scriptPath = args[0];
4050
params = Arrays.copyOfRange(args, 1, args.length);
4151
run();
4252
}

0 commit comments

Comments
 (0)