November 28, 2020, 02:57:06 AM

Author Topic: combogadgets: event on selection rather than change?  (Read 183 times)

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
combogadgets: event on selection rather than change?
« on: October 12, 2020, 05:18:22 PM »
Code: [Select]

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.

Offline Kryzon

  • Full Member
  • ***
  • Posts: 237
Re: combogadgets: event on selection rather than change?
« Reply #1 on: October 13, 2020, 12:33:33 AM »
The closest thing would be to remove that hidden button and instead use... 
Code: [Select]
SetGadgetSensitivity(c1, SENSITIZE_MOUSE) 
But at least on my Windows system the combobox starts behaving weird with this turned on. 

Offline Henri

  • Sr. Member
  • ****
  • Posts: 265
Re: combogadgets: event on selection rather than change?
« Reply #2 on: October 13, 2020, 02:38:17 PM »
Hi,

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

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

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
Re: combogadgets: event on selection rather than change?
« Reply #3 on: October 13, 2020, 04:09:38 PM »
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.

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
Re: combogadgets: event on selection rather than change?
« Reply #4 on: October 13, 2020, 04:49:48 PM »
Code: [Select]
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.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal