Another question about dropdown lists in G4P

I’ve noticed that if I click on a dropdown list and select the current selection, no event is triggered. Is this the intended behaviour? In most cases, this is OK because no action needs to be taken, but in some cases I may want to trigger an event even if the user clicks on the same selection as the one already selected.What’s the best way to handle this, any suggestions?

Thanks.

1 Like

Hmm. is hasFocus() when the list is opened? Maybe on hasFocus() you could setSelected(0) to default / 0 – essentially deselecting your option when the list is opened, so that the user is forced to reselect. that might then trigger a new event (untested brainstorming!)

Yes this is the intended behaviour.

When the user opens the drop list there are 3 options

  1. Select a new list item
  2. Select the currently selected item
  3. Click the mouse outside the drop list control

In all three cases the list box would disappear but only the first option generates an event.

To me this makes perfect sense because the selected item in the droplist should reflect the current state of the sketch. Generating an event when the selection hasn’t changed should therefore have no effect.

I would not recommend the solution from @jeremydouglas (nice try :wink:) for several reasons

  1. If the currently selected item is already 0 then setSelected(0) will have no effect. If the user then selects item 0 with the mouse no event would not generated anyway.
  2. If the currently selected item is not 0 then setSelected(0) will change the selected item but then no event is fired if the user selects item 0 with the mouse.
  3. If the currently selected item is not 0 then setSelected(0) will change the selected item but if the user clicks outside the list then no event will be fired and the droplist shows the wrong selection.

TBH I can’t imagine why you might want to do that if the droplist selection reflects the current state of the sketch.

1 Like

In the vast majority of cases, you’re probably correct. I was just a little surprised, I expected an event to be triggered even when the user selects the choice that is already selected. I don’t know if that’s how other GUI toolkits work, like the Java AWT or Swing toolkits. But I’m sure I can figure out a way to work around it.

I’m using dropdown lists in four places:

  1. Selecting an “effect” to be loaded into one of the 8 “slots”.
  2. Selecting a MIDI device.
  3. Selecting an audio device.
  4. Selecting an IP address to send OSC messages to.

In the first two cases, “none” is an appropriate option, so I made that the default. In the third case (selecting an audio I/O device), “none” doesn’t really work. Pure Data allows the user to select “none” for a MIDI device if no MIDI device is available or Midi isn’t required by the app, but it always expects an audio device to be selected, "none"isn’t an option. Pure Data was designed specifically for audio processing. I suppose it could be used to develop apps that don’t involve audio at all, but I’ve never heard of any.

When my program starts up, it polls the other computer (which defaults to “localhost”, 127.0.0.1) to load the audio and MIDI dropdown lists with available devices. This seems appropriate as a default choice for the OSC destination. It’s the third case, selecting an audio device, that’s a bit problematic. I don’t want to make “none” the default, or even include it in the list at all, since Pure Data won’t accept it. So I have to arbitrarily choose one of the devices returned by Pure Data as the default audio device. When the user chooses an audio (or MIDI) device, I send an OSC message to Pure Data to tell it that this device has been chosen. It appears in my testing that the first device in the list sent back by Pure Data is also the default device in Pure Data, but I don’t know that this is always the case. So I wanted to send an OSC message to Pure Data, even if the user chooses the device that has already been chosen. This is only an issue when the program first starts up, because if the first device in the list, the default device, isn’t in fact the device that was chosen by Pure Data at startup, the user is liable to think that the default device is being used by Pure Data, when in fact some other device is being used, which could be confusing (Pure Data won’t complain, but no sound will be heard).

I hope all this makes sense. I’m not asking you to change the behaviour, I just wanted confirmation that this is the way your library was designed to work. I think I can find a work-around for it.

1 Like

I found a solution. The first time the user opens to window to select audio devices, I send messages to Pure Data to arbitrarily select the first item in the list for audio in and audio out, before the user can even click on the dropdowns. That way, I know the first item in the list is currently selected by Pure Data. If that’s what the user wants, fine, I don’t need to do anything. Otherwise, the user will click on some other item on the list and an event will be triggered.

1 Like

I was just about to reply suggesting something similar but I have deleted it.

That is a good solution because the control reflects the current state of the sketch

1 Like