G4P button properties and methods

I consider myself a beginner with processing. Recently I wrote a program to test ignition coils using an Arduino. The program works fine, but uses the serial monitor to control it. I have downloaded the G4P GUI tool and library. I have it installed and it works fine. What I would like to know is where can I find all the properties and methods that are associated with a control. For example the Button. The properties panel only shows a few. Then after I enter one, mouse off then later the mouse over shows up. Is there a listing somewhere that lays out all these properties for all the controls in the G4P library. Thanks Mike

I @mike_z

Is this what you are looking for?
http://www.lagers.org.uk/g4p/ref/index.html

Best regards

1 Like

I suggest that you look at these guides as well as the reference (see link above)

It is true that GUI Builder does not show all the properties and methods for a control but to be honest, for a beginner with Processing anything missing is unlikely to be useful to you.

Not sure what you mean by this.

What I mean is when the button is first placed on the grid, the properties include GUI Lock, variable name, event method, mouse off image, x, y, width and height. Then after I add a mouse off image, then there is a new property, mouse over image appears, after adding an image there then mouse pressed image (use image size and alpha mask also show up in the mix). I would like to know what all the properties are and how to make them show in the properties list. I think that there some great possibilities here, I just want to know how to work this tool. I will also investigate the guides. Thanks a million. Mike

Began watching your tutorials on youtube. The first one deals with the button. This properties panel lists some text attributes that do not show on my builder. This maybe due to me having a different version? Anyway how can I make the Text (Face Text) appear on my builder? Mike

The GUI Builder videos are over 5 years old so there will have been some changes since they were created. BTW you can also view them from the website here.

The GUI lock simply locks the control in GUI Builder to prevent it being accidentally dragged or resized in the builder - it has no effect on the final GUI in your sketch. The mouse off image, mouse over image, mouse pressed image etc are for the GImageButton control and probably don’t make a lot of sense until you see such a button in action. G4P comes with a large number of example sketches which I suggest you look at. Select Files | Examples from the menus and in the window that opens locate G4 in the Contributed Libraries section and try out th image button example.

G4P is a huge library with a large range of controls mnay of which you might never use, it is going to take a while to get used to it and GUI Builder so just take your time and experiment with it.

Thanks, I’ll give it a try. I want to experiment with the button first. Try and limit my confusion. Given enough time (a commodity in short supply) I’ll figure this old with occasional help. Mike

Well… My first minor success. I made an imageTogButton and connected it to my Arduino sketch as an ON/OFF button. It works! But… there is a noticeable delay between the switch action and the device actually turning on or off. I have the serial rate set at 9600 baud. Is that too slow? Or is there something else that could be delaying the switch action? Thanks for the help, Mike.

Well… I’ve done some investigation and this is what I know at the moment. Here is my Arduino code.
<
/*
Igntion tester
*/

int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the igntion pulse
char SwStatus = ‘0’;

void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT:
Serial.begin(38400); // Start serial communication at 9600 bps
}

void loop() {
if (Serial.available()) { // If data is available to read,
SwStatus = Serial.read(); // read it and store it in val
delay(10);
}
if (SwStatus == ‘0’) { // If 0 was received
digitalWrite(ledPin, HIGH); // turn the igntion pulse on
}
else if (SwStatus == ‘1’) {
digitalWrite(ledPin, HIGH); // turn the igntion pulse on
delay(20); // This is the frequency control
digitalWrite(ledPin, LOW); // turn the igntion pulse off:
delay(10); // This is the dwell control, wait until next pulse
}
// delay(5); // Wait 10 milliseconds for next reading
}
/>
This code will work fine with the Arduino serial monitor, by that I mean if a zero is typed on the Serial Monitor the ignition tester will turn off and a typed one will turn it on, with no delay. Here is the processing code
<
import g4p_controls.*;

import processing.serial.*;
Serial myPort; // Create object from Serial class

GImageToggleButton btnToggle0;

boolean SwState = false;

public void setup() {
String portName = Serial.list()[1]; //change the 0 to a 1 or 2 etc. to match your port
myPort = new Serial(this, portName, 38400);

size(480, 220, JAVA2D);
G4P.setGlobalColorScheme(GCScheme.ORANGE_SCHEME);
G4P.setCursor(ARROW);

// ##########################################################################
// Create default 2 state switch button
btnToggle0 = new GImageToggleButton(this, 50, 100);
background(250, 225, 200);
fill(#000000);
textSize(16);
text(“ON”, 58, 90);
text(“OFF”, 56, 175);
}

public void draw() {

if (SwState == false){
fill( #84FF03);
myPort.write(‘0’);
}
else if(SwState == true) {
fill (#FA030B);
myPort.write(‘1’);
}
circle(70, 50, 25);
}

// Event handler for image toggle buttons
public void handleToggleButtonEvents(GImageToggleButton button, GEvent event) {
//println(button + " State: " + button.getState());
if (button.getState() == 0){
println(“OFF”);
SwState = false;
}
else {println(“ON”);
SwState = true;
}
}

/>
For some reason the processing image button will turn on the ignition tester with no delay, but went the image button is turned off, the println displays off right away, but the tester will not turn off for about 2 seconds. I think there is an issue with the serial communications? Thanks Mike

Sorry about the code entries, for some reason I’m having trouble with them too. It is hell getting old!