In my app I have a DropList to let the user select which Serial port (COM port) that an external device is connected to via USB. It works great if there are at least two COM ports present in the list. For example if I see COM 1 without my device connected and I see, say COM 3, when it is connected, I can select COM 3 and the device connects - all good.
The problem is when there are no COM ports before the device is plugged in. Because now the device COM port is the only port in the DropList, clicking on it does not call the COMList_click event handler so the user can never select the port
I think I may have to create a dummy first item that’s always in the drop list so the USB serial device will then become a second item that will create the event when the user clicks on it.
I’ve been trying to insert an item into the DropList and/or add an item to the end of the list by adding code to the customGUI() method. The insertItem() function always returns false no matter what index value I use and, while the addItem() function returns true, nothing gets added to the drop list.
I don’t understand why this doesn’t work
The drop list initialiser file contains two lines:
One
Two
The test program below prints:
true
true
false
to the console but the DropList does not change, it continues to just show the One and Two from the initialiser file:
// Need G4P library
import g4p_controls.*;
// You can remove the PeasyCam import if you are not using
// the GViewPeasyCam control or the PeasyCam library.
public void setup(){
size(480, 320, JAVA2D);
createGUI();
customGUI();
}
public void draw(){
background(230);
}
// Use this method to add additional statements
// to customise the GUI controls
public void customGUI(){
// Place your setup code here
boolean ok = COMList.addItem("New One");
println(ok);
COMList.addItem("New Two");
println(ok);
ok = COMList.insertItem(1,"Inserted");
println(ok);
}
The gui tab:
/* =========================================================
* ==== WARNING ===
* =========================================================
* The code in this tab has been generated from the GUI form
* designer and care should be taken when editing this file.
* Only add/edit code inside the event handlers i.e. only
* use lines between the matching comment tags. e.g.
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
// It is safe to enter your event code here
} //_CODE_:button1:12356:
* Do not rename this tab!
* =========================================================
*/
public void COMList_click(GDropList source, GEvent event) { //_CODE_:COMList:940363:
println("dropList1 - GDropList >> GEvent." + event + " @ " + millis());
} //_CODE_:COMList:940363:
// Create all the GUI controls.
// autogenerated do not edit
public void createGUI(){
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setMouseOverEnabled(false);
surface.setTitle("Sketch Window");
COMList = new GDropList(this, 128, 116, 174, 132, 3, 20);
COMList.setItems(loadStrings("list_940363"), 0);
COMList.addEventHandler(this, "COMList_click");
}
// Variable declarations
// autogenerated do not edit
GDropList COMList;
Hi done some testing and found / fixed the bugs Although insertItem and addItem work now I need to confirm it with more testing and go through the source code to make sure there is nothing else lurking in the depths
Processing 4.3.5 fixes this problem and is now available for manual installation from Sourceforge. Alternatively it will be available in Processing’s Contribution Manager in about 24 hours.