1
+ # We expose many Processing-related names as builtins, so that no imports
2
+ # are necessary, even in auxilliary modules.
1
3
import __builtin__
2
4
5
+ # PAppletJythonDriver is a PApplet that knows how to interpret a Python
6
+ # Processing sketch, and which delegates Processing callbacks (such as
7
+ # setup(), draw(), keyPressed(), etc.) to the appropriate Python code.
3
8
from jycessing import PAppletJythonDriver
4
9
10
+ # Bring all of the core Processing classes by name into the builtin namespace.
5
11
from processing .core import PApplet
6
12
from processing .core import PConstants
7
13
from processing .core import PFont
33
39
__builtin__ .PApplet = PShapeSVG
34
40
__builtin__ .PApplet = PStyle
35
41
42
+ # PVector requires special handling, because it exposes the same method names
43
+ # as static methods and instance methods.
36
44
class PVector (object ):
37
45
@classmethod
38
46
def __new__ (cls , * args ):
@@ -92,11 +100,20 @@ def __mul__(a, b):
92
100
raise TypeError ("The * operator can only be used to multiply a PVector by a scalar" )
93
101
return PVector (a .x * b , a .y * b , a .z * b )
94
102
103
+ # Now expose the funky PVector class as a builtin.
95
104
__builtin__ .PVector = PVector
96
105
106
+ # Construct the PApplet.
97
107
__papplet__ = PAppletJythonDriver (__interp__ , __path__ , __source__ )
108
+ # Make it available to sketches by the name "this", to better match existing
109
+ # Java-based documentation for third-party libraries, and such.
98
110
__builtin__ .this = __papplet__
99
111
112
+
113
+ # Expose all of the builtin Processing methods. Credit is due to
114
+ # https://github.com/kazimuth/python-mode-processing for the
115
+ # technique of exploiting Jython's bound methods, which is tidy
116
+ # and simple.
100
117
__builtin__ .alpha = __papplet__ .alpha
101
118
__builtin__ .ambient = __papplet__ .ambient
102
119
__builtin__ .ambientLight = __papplet__ .ambientLight
@@ -138,6 +155,7 @@ def __mul__(a, b):
138
155
__builtin__ .curveTangent = __papplet__ .curveTangent
139
156
__builtin__ .curveTightness = __papplet__ .curveTightness
140
157
__builtin__ .curveVertex = __papplet__ .curveVertex
158
+ __builtin__ .delay = __papplet__ .delay
141
159
__builtin__ .directionalLight = __papplet__ .directionalLight
142
160
__builtin__ .ellipse = __papplet__ .ellipse
143
161
__builtin__ .ellipseMode = __papplet__ .ellipseMode
@@ -147,9 +165,12 @@ def __mul__(a, b):
147
165
__builtin__ .endRaw = __papplet__ .endRaw
148
166
__builtin__ .endRecord = __papplet__ .endRecord
149
167
__builtin__ .endShape = __papplet__ .endShape
150
- __builtin__ .exit = __papplet__ .exit
168
+ # We provide a special exit() method.
169
+ #__builtin__.exit = __papplet__.exit
151
170
__builtin__ .fill = __papplet__ .fill
152
- __builtin__ .filter = __papplet__ .filter
171
+
172
+ # TODO: fix filter() !
173
+ #__builtin__.filter = __papplet__.filter
153
174
__builtin__ .frameRate = __papplet__ .frameRate
154
175
__builtin__ .frustum = __papplet__ .frustum
155
176
__builtin__ .get = __papplet__ .get
@@ -266,6 +287,8 @@ def __mul__(a, b):
266
287
__builtin__ .updatePixels = __papplet__ .updatePixels
267
288
__builtin__ .vertex = __papplet__ .vertex
268
289
290
+ # And these are PApplet static methods. Some are commented out to indicate
291
+ # that we prefer or require Jython's implementation.
269
292
__builtin__ .abs = PApplet .abs
270
293
__builtin__ .acos = PApplet .acos
271
294
__builtin__ .append = PApplet .append
@@ -300,7 +323,7 @@ def __mul__(a, b):
300
323
__builtin__ .loadStrings = PApplet .loadStrings
301
324
__builtin__ .log = PApplet .log
302
325
__builtin__ .mag = PApplet .mag
303
- __builtin__ .map = PApplet .map
326
+ # __builtin__.map = PApplet.map
304
327
__builtin__ .match = PApplet .match
305
328
__builtin__ .matchAll = PApplet .matchAll
306
329
#__builtin__.max = PApplet.max
@@ -317,7 +340,7 @@ def __mul__(a, b):
317
340
__builtin__ .println = PApplet .println
318
341
__builtin__ .radians = PApplet .radians
319
342
__builtin__ .reverse = PApplet .reverse
320
- __builtin__ .round = PApplet .round
343
+ # __builtin__.round = PApplet.round
321
344
__builtin__ .saveBytes = PApplet .saveBytes
322
345
__builtin__ .saveStream = PApplet .saveStream
323
346
__builtin__ .saveStrings = PApplet .saveStrings
0 commit comments