combogadgets: event on selection rather than change?

Started by Juiceter, October 12, 2020, 17:18:22

Previous topic - Next topic

Juiceter



Import maxgui.drivers
Strict

Global window:Tgadget=CreateWindow:Tgadget("combobox",100,100,200,300,Null,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_CENTER|WINDOW_STATUS) 

Global c1:Tgadget=CreateComboBox(121,102,40,50,window)
AddGadgetItem c1,"1" ; AddGadgetItem c1,"2"  ; AddGadgetItem c1,"3"  ; AddGadgetItem c1,"4"
SelectGadgetItem c1,0

Global btn:Tgadget=CreateButton("",121,102,20,20,window,BUTTON_OK) ' hidden button.

Repeat
WaitEvent()
Select EventID()

Case EVENT_GADGETACTION
Select EventSource()
Case c1
ActivateGadget c1
Print "value changed"
Default
    ActivateGadget(btn)
Print "you chose: " + GadgetItemText(c1,SelectedGadgetItem(c1))
Exit
End Select
Case EVENT_WINDOWCLOSE Exit
End Select
Forever


' when a gadget is SELECTED an event is not emitted, only when it is CHANGED! But we want the first.




Regarding the code above, I was wondering if it is possible to signal that the gadget has been SELECTED rather than CHANGED.

Nothing happens unless you change the value in the gadget. Do you have to use an eventhook to do this or something? Can it even be done? As soon as I click on the gadget I want to display a message to that effect.

Kryzon

The closest thing would be to remove that hidden button and instead use... 
SetGadgetSensitivity(c1, SENSITIZE_MOUSE) 
But at least on my Windows system the combobox starts behaving weird with this turned on. 

Henri

Hi,

it should be possible to get the selected event at least in Windows..

-Henri
- Got 01100011 problems, but the bit ain't 00000001

Juiceter

#3
Thanks lads. A lot of the time maxgui doesn't seem to behave logically (at least to my logic).

For instance, it's perfectly logical to me to click on a gadget to activate it so that you can, for instance, display a message in the window ribbon as to what the gadget and its values represent. The way it actually works is that you have to select a different value before you can do this (hope I'm not being unfair and missing something).

If you remove the hidden button then it wont exit on a return, but looking at that (experimental) command it looks like there is a way around it.

Juiceter


Import maxgui.drivers
Strict

Global window:Tgadget=CreateWindow:Tgadget("combobox",100,100,200,300,Null,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_CENTER|WINDOW_STATUS) 

Global c1:Tgadget=CreateComboBox(121,102,40,50,window)
AddGadgetItem c1,"1" ; AddGadgetItem c1,"2"  ; AddGadgetItem c1,"3"  ; AddGadgetItem c1,"4"
SelectGadgetItem c1,0

Global btn:Tgadget=CreateButton("",121,102,20,20,window,BUTTON_OK) ' hidden button.

SetGadgetSensitivity(c1,SENSITIZE_MOUSE)

Repeat
WaitEvent()
Select EventID()
Case EVENT_MOUSEDOWN
SetStatusText window,"c1 selected"
Case EVENT_GADGETACTION
Select EventSource()
Case c1
ActivateGadget c1
SetStatusText window,"value changed"
Default
    ActivateGadget(btn)
SetStatusText window,"you chose: " + GadgetItemText(c1,SelectedGadgetItem(c1))
Delay 1000
Exit
End Select
Case EVENT_WINDOWCLOSE Exit
End Select
Forever


This seems to work just fine for me as to my desires (posting it in the hope it will help others). Thanks for both your input.