We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have been experimenting with PApplet.runSketch to create multiple windows with limited success.
My main question is :- Is it appropriate for a library, such as G4P, to use this method to create multiple windows in a PS3 sketch? If not what is?
In the following code I have been experimenting with the args argument to this method. Based on my research the code below should open the secondary window in the top left corner but it uses the default screen centre instead. Any thoughts?
EDIT this problem was solved thanks to GoToLoop's PS3 code below
EDIT this code has been corrected for PS3
// Main sketch (first) tab
void settings(){
size(600, 200);
}
void setup() {
String[] args = {"--location=0,0", "Foo"};
Foo sa = new Foo(320, 240);
PApplet.runSketch(args, sa);
}
void draw() {
background(0);
ellipse(50, 50, 10, 10);
}
// Foo.java tab
import processing.core.*;
public class Foo extends PApplet {
private final int w, h;
public Foo() {
w = 200;
h = 200;
}
public Foo(int w, int h) {
this.w = w;
this.h = h;
}
public void settings() {
size(w, h);
}
public void draw() {
background(255);
fill(0);
ellipse(100, 50, 10, 10);
}
}
Answers
I guess it depends why you want to display multiple windows.
If the window is for the library itself, I would assume you'd use the underlying Java code instead of relying on Processing.
I did some extra experiments based on my example code from:
http://forum.Processing.org/two/discussion/11304/multiple-monitors-primary-dragable-secondary-fullscreen
1st the Processing 1.5.1 version:
And now Processing 2.2.1 version:
But I couldn't make size() inside settings() to accept any variable in Processing 3.0b5!Be that some explicitly declared field initialized inside the constructor.
Or relying on
args[]
passed from runSketch()! ~X(w>>1
to field aaa.0
! @-)size(aaa = w>>1, h>>1, JAVA2D);
ends up as
width = 100
&height = 100
! :-&P.S.: I had to create an explicit settings() for the main sketch for v2.1 b/c PDE's pre-processor didn't!
Perhaps b/c ProjectorSketch nested class already had settings() in it! 8-}
@KevinWorkman
Sorry didn't make myself clear. I am trying to make G4P compatible with PS3. G4P provides an easy to use GUI with a wide variety of controls incl buttons, sliders, droplists, textfields and many more. One of the more powerful features of G4P was support for additional windows, thus enabling the user/sketcher to easily create multi-window sketches. These secondary windows could be used to hold other G4P controls to create 'control windows' or simply for graphic display. For instance the Mandelbrot example that comes with G4P creates a new window for every view on the set, when trying it out I must have had 20-30 windows open.
PS1 & 2 didn't have any native support for multiple windows so the G4P code had to be pretty complex to get it to work smoothly. This is why there will not be a single version of G4P that works in both PS2 & PS3
The reason that I asked the question
is because PS3 appears to offer some limited support for multiple windows using the runSketch method, but I don't think this is what the PS developers had in mind so I hope they will respond and provide more information on this topic.
@GoToLoop
Thanks for the examples unfortunately again I didn't make myself clear. I am only interested in PS3 sketches so although your code was interesting only the last post was useful. Very useful as it turns out because it highlighted a couple of mistakes in my code. First I didn't include the settings method and secondly the order of the arguments was wrong.
I have gone back and corrected the code above and changed the title to reflect that I am interested in PS3.
Thanks guys I think I will raise another question aimed primarily at the developers of PS3 to get more info about this topic.
The path you're exploring right now, runSketch(), is compatible w/ Processing 1 and forward!
I'm just re-highlighting that fact to you! O:-)
I was only able to help you this time b/c I've been using main() & runSketch() since previous forum! :P
All of those 3 versions (ea. 1 for ea. Processing series) are very similar to each other.
Only main diff. is that for Processing 3, we've got that "pesky" setup() new "cousin": settings()! :O)
Neither Processing 3! No matter which Processing version, multiple instances is an undocumented "feature", made possible via PApplet's main() & runSketch()
static
methods. :-BNot Processing 3, but Processing 1 has always had limited support for multi windows via runSketch()! :-\"
G4P provided sophisticated multiple window support (for PS1 & PS2) using documented Processing methods only. This was possible because PApplet inherited from a windowed component so I was not reliant on runSketch. With PS3 this is not the case so I am forced to look at alternatives such as runSketch.
All thus talk about PS1 and PS2, although interesting, does not help me find a way of updating G4P for Processing 3. Unfortunately runSketch doesn't look like it will give me the level of control I have at the moment with PS2 but I havn't given up on it yet.
Thanks for the replies,.
The problem I experienced with the
args
parameter to runSketch to set the window location was solved based on the Accepted Answer.I still need to do more research and experiments with runSketch to see the extent of what is possible.
I know this is an old post but I just wanted to say thanks for the solution to the problem I was having with incorporating a robot arm sim into the G4P GUI to control the arm. Was struggling with creating a second window using P3D or OpenGL and no joy - spent hours/days. Your solution had it working within a few minutes. Only error I am getting is the following:
Unknown cursor type: 0 Unknown cursor type: 12
Error gets thrown when I start the sketch but everything remains operational. Any ideas would be appreciated. No other messages appear.
Thanks again. Mike
There was a problem with cursor in early releases of PS3 it was fixed in later releases. Don't if that was the cause of your particular problem.
Hi @quark thanks for the info. By the way I did an instructable on the robot arm and gui you an @GoToLoop helped me with. Gave both of you all credit, Thanks again.
Glad I could help and thanks for giving credit, much appreciated.
Hi, This is an important question to me too, the multiple window handling. I have some Processing relying software with uses 2 views on different windows. I had it solved with the old schema JFrame with added PApplets.
Thanks to this post I'm able to swtich to PApplet.runSketch and no JFrames but there are some issues I cannot make work: 1) When I have 2+ PApplets running with runSketch and close one, all of them close (does not happen when, e.g. minimizing) 2) How do I change the window name? That was done in the JFrame and I cannot see any arg in runSketch for that 3) Related to 1, how to I replace a running PApplet with another one? This is not so important as I can just change the view without replacing.
In the end, the question I guess it's: "to what extent runSketch replaces JFrame". One expects it to be fully, or it should not have been removed as an option.
Very insightful thread anyways, thanks!
It does not replace JFrame rather runSketch will create the JFrame for you but only for JAVA2D renderer. Using runSketch with P2D and P3D creates an OpenGL window rather than a JFrame. Whichever type of window is created clicking on the red cross terminates the application so closes ALL open windows. Processing has done this by adding its own WindowAdapter(s) the solution is to remove them and add your own, or in the case of JFrame change the defaultActionOnClose
You can look at the G4P library source code for GWindow and its subclasses to see how I overcame these issues.
Ok, understood, thanks quark! However, I had to dig more than expected/desired into Processing code for all this Processing 3 update with different windows. Actually, to get into the JFrame and change the defaultAction is not working. With this change:
((JFrame)((SmoothCanvas)myPApplet.getSurface().getNative()).getFrame()).setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
it keeps exiting. Actually, the default behavior is HIDE_ON_CLOSE, and it also exits the whole application.
I added a WindowListener and actually enters in the Activated and Opened event handlers, but not in Closed or Deactivated! Quite strange...
((JFrame)((SmoothCanvas)myPApplet.getSurface().getNative()).getFrame()).addWindowListener(new MyWindowListener());
WindowAdapters are addative so you need to remove the existing ones first.
Wohooo! Worked! Bowing after you again quark. I always had assumed Listeners were unique. In case someone might find the code helpful, these two lines are enough to make PApplets 'hide on close' instead of exiting the whole app:
Hi efialto
Are you saying that just using those two lines of code you are able to get the PApplet.runSketch to hide on close. I been going nuts over trying to figure it out especially since I am very JAVA impaired. Will you be willing to share exactly how you accomplished it. Where exactly do you put the windowlistener in the PApplet. I tried a couple of places and it complained about SmoothCanvas or too many {, etc.
This would temporarily solve my other issue that I posted: https://forum.processing.org/two/discussion/15095/g4p-second-window-how-to-include-gwoptics-library-in-second-window#latest
Thanks awful much Mike
@CyberMerln, here's a more refined tweaked version of @efialto's solution: :ar!
Also, I've redone my previous "Multi-Monitor Sketch" example to include removeExitEvent() too: :bz
@GoToLoop: You are absolutely great for putting this together. Can not tell you how much I appreciate it. Just tried it and it works like a charm.
Thanks again. Mike
Nice explanation GoToLoop! Glad it was helpful for CyberMerln :)