Browse files

Permit frame hacks like 2nd monitor by exposing "frame" variable and …

…calling user-defined init()
  • Loading branch information...
1 parent f96c55e commit 5b7940de2acde0c2232716201b82d4ec02263397 @jdf committed Apr 27, 2011
Showing with 16 additions and 1 deletion.
  1. +16 −1 runtime/src/jycessing/PAppletJythonDriver.java
View
17 runtime/src/jycessing/PAppletJythonDriver.java
@@ -74,7 +74,7 @@
// you have implemented a method, we save it and call it.
private final PyObject setupMeth, drawMeth, mousePressedMeth,
mouseClickedMeth, mouseReleasedMeth, mouseDraggedMeth,
- keyPressedMeth, keyReleasedMeth, keyTypedMeth, stopMeth;
+ keyPressedMeth, keyReleasedMeth, keyTypedMeth, initMeth, stopMeth;
// Adapted from Jython's PythonInterpreter.java exec(String s) to preserve
// the source file name, so that errors have the file name instead of
@@ -135,6 +135,7 @@ public PyObject __call__(final PyObject[] args, final String[] kws) {
keyPressedMeth = interp.get("keyPressed");
keyReleasedMeth = interp.get("keyReleased");
keyTypedMeth = interp.get("keyTyped");
+ initMeth = interp.get("init");
stopMeth = interp.get("stop");
addComponentListener(new ComponentAdapter() {
@Override
@@ -157,6 +158,18 @@ public void uncaughtException(Thread t, Throwable e) {
super.start();
}
+ @Override
+ public void init() {
+ try {
+ if (initMeth != null) {
+ builtins.__setitem__("frame", Py.java2py(frame));
+ initMeth.__call__();
+ }
+ } finally {
+ super.init();
+ }
+ }
+
public void blockUntilFinished() throws InterruptedException {
finishedLatch.await();
}
@@ -243,12 +256,14 @@ public void size(final int iwidth, final int iheight,
super.size(iwidth, iheight, irenderer, ipath);
setFields();
builtins.__setitem__("g", Py.java2py(g));
+ builtins.__setitem__("frame", Py.java2py(frame));
}
@Override
public void setup() {
// Put all of PApplet's globals into the Python context
setFields();
+ builtins.__setitem__("frame", Py.java2py(frame));
try {
if (isStaticMode) {

1 comment on commit 5b7940d

@CorpusCallosum

Hey, I just noticed you exposed the frame variable. Do you have an example of how to use this? I am trying to call frame.setLocation(), but getting errors. Thanks!

Please sign in to comment.