G4P: Can't 'select' DropList item if there is only one item in the list

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 :frowning:

Am I missing something simple?

Thanks,

Phil.

1 Like

The GDropList creates an event when a different item is selected. If the list has a single item then it will never generate events.

Thanks Peter, I reckoned that was the case.

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.

Phil.

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 :thinking:

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:

Annotation 2020-05-08 164050

// 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; 

1 Like

Can you show the contents of the list file used

Hi Peter, I did mention that it’s only 2 lines

One
Two

and that’s it.

Annotation 2020-05-08 165447

I’ll have to do some testing and get back to you :thinking:

Cheers. I was hoping it wasn’t me being stupid!

Phil.

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 :smiley:

Hope to put out a new release tomorrow or Sunday. :+1:

2 Likes

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.

2 Likes

Excellent Peter, it’s working great now :smile:

Thanks for getting this sorted so quickly.

Phil.