December 04, 2020, 02:58:09 PM

Author Topic: How do you deselect a combobox gadget?  (Read 266 times)

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
How do you deselect a combobox gadget?
« on: October 02, 2020, 01:55:28 AM »
Code: [Select]
Import maxgui.drivers


Global window:Tgadget=CreateWindow:Tgadget("combobox",100,100,800,600,Null,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_CENTRE|WINDOW_STATUS) 

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


Global btn:Tgadget=CreateButton("click",421,302,80,40,window)


WaitEvent() ; WaitEvent()
Repeat
WaitEvent()
Select EventID()

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


' how to deselect a combobox gadget? press return to exit rather than press button


Ideally I'd like to deselect it when pressing return, but at present in this piece of code to deselect it you have to click on the button. Deselecting it = unhighlighting it. It's probably simple.

I suppose what I am asking is this: is there a way to force a gadget to lose focus?

Offline Henri

  • Sr. Member
  • ****
  • Posts: 265
Re: How do you deselect a combobox gadget?
« Reply #1 on: October 02, 2020, 12:27:15 PM »
Hi,

you probably mean "how can I display an empty readonly combobox ? "

Well, in readonly combobox you can't alter the text in "edit box" as its readonly and displays the current selection. This is so that only valid options are always selected.

What you can do is add an empty string first and select that when you want to display empty combobox.

Other alternative is to use editable combobox, but this depends on your need.


EDIT:  Readonly comboboxes do not generate key-events in OS. Edit-comboboxes generate some under the hood, but might not show in Maxgui without modification..

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

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
Re: How do you deselect a combobox gadget?
« Reply #2 on: October 03, 2020, 02:29:09 AM »
Thanks henri. Helpful as always!

"EDIT:  Readonly comboboxes do not generate key-events in OS. Edit-comboboxes generate some under the hood, but might not show in Maxgui without modification.."


What I mean is that i want to take the value that's currently selected (on the press of a key), which deselects the combobox and moves on to something else. The only way it seems that it can be done is if i select the value THEN click the button. The problem is i want to press a key rather than click a button! But as you say, it doesn't generate a keyevent.


You know, I really don't understand why you can't simply just read a key, and if that key is pressed, the combobox loses focus. I wonder if this is one of the big failings of maxgui? It does tend to make things difficult to get on with doing what you are doing. The last thing that should stand in your way is the GUI (this one isn't that intuitive). A few people I've come across don't really like maxgui. I suppose I can see why now.

Anyway, food for thought.

 

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
Re: How do you deselect a combobox gadget?
« Reply #3 on: October 03, 2020, 02:43:41 AM »
Actually, it does seem to process the arrow keys to change the value in the combobox (while the box is selected). All 4 arrows work. But that's all it seems to process.

The editable combobox allows for a return to deselect, but it's not good for what i want.

What I mean by deselection is that the selected item isn't highlighted blue. It's selected, but the combobox isn't, if you see what I mean (that is, the value is set, but the box is not selected - the button has the focus).

Offline Derron

  • Hero Member
  • *****
  • Posts: 3275
Re: How do you deselect a combobox gadget?
« Reply #4 on: October 03, 2020, 07:14:14 AM »
The OS (maxgui uses the OS libraries to create the widgets ..native widgets). Dropdowns are controllable with the keyboard (cursor keys, keyboard keys...).

Widgets can be moved along with "tab" (like in html forms) if configured correctly.

Maybe you need to create your own widget:
Readonly input field ...
On activate/focus you display a mulitline list widget ..


Bye
Ron

Offline chalky

  • Jr. Member
  • **
  • Posts: 65
Re: How do you deselect a combobox gadget?
« Reply #5 on: October 03, 2020, 08:58:16 AM »
Have you tried ActivateGadget(<required_button>) at the end of your code which processes the Combobox keypress?

Offline Henri

  • Sr. Member
  • ****
  • Posts: 265
Re: How do you deselect a combobox gadget?
« Reply #6 on: October 03, 2020, 09:34:55 AM »
You might be able to use SetHotKeyEvent(KEY_ENTER, 0) to catch enter key on any given time and then on EVENT_HOTKEY use something like "If ActiveGadget = combobox then ActivateGadget something. Not an ideal solution I'm sure.

I still don't fully understand what is your requirement and why you would need to lose focus by pressing a key. If the user selects an item from the combobox with mouse he/she would logically use the mouse to set the focus. Other option (and this is something that I use) is that user types something in a textfield and then uses TAB to set a focus to next field that might be a combobox, but without using mouse the user can press the first letter of the item text to select that item and the press TAB to set the focus to a next field in the form without ever using mouse.

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

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
Re: How do you deselect a combobox gadget?
« Reply #7 on: October 03, 2020, 10:11:23 AM »
Thanks all for your input. The only requirement that i have is that with the example i have given when i make a selection, instead of pressing the button to confirm the selection, i want to press a key instead.

So instead of pressing the key to get the "you chose" + index text, i want to press a key instead to get the message. Yes, i noticed the tab works too, but it's better that it is the return key. Losing the focus presents the message and "locks in" the chosen combogadget index.

Anyway I'll have a look at what you've all said and experiment. Thanks!

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
Re: How do you deselect a combobox gadget?
« Reply #8 on: October 03, 2020, 10:14:32 AM »
Have you tried ActivateGadget(<required_button>) at the end of your code which processes the Combobox keypress?

Hmm.. the other gadget is the button and i really don't want that there. perhaps it could be a hidden button I suppose. Might work - thanks. The problem is that without another gadget to activate, there seems to be no way to get out of the selection stage without the button (i.e. it remains selected blue). Maybe i'm just getting muddled again.

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
Re: How do you deselect a combobox gadget?
« Reply #9 on: October 03, 2020, 10:20:37 AM »
Code: [Select]
Import maxgui.drivers


Global window:Tgadget=CreateWindow:Tgadget("combobox",100,100,200,300,Null,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_CENTRE|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("select value",10,20,80,40,window)


WaitEvent() ; WaitEvent()
Repeat
WaitEvent()
Select EventID()

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

' how to deselect a combobox gadget? press return to exit rather than press button



That code is a bit more compact than the other.


Offline chalky

  • Jr. Member
  • **
  • Posts: 65
Re: How do you deselect a combobox gadget?
« Reply #10 on: October 03, 2020, 12:54:23 PM »
I think changing the button type to "BUTTON_OK" and 'hiding' it behind the ComboBox does what you want (if I've understood correctly what you're trying to do):

Code: [Select]
Import maxgui.drivers

Global window:Tgadget=CreateWindow:Tgadget("combobox",100,100,200,300,Null,WINDOW_TITLEBAR|WINDOW_MENU|WINDOW_CENTRE|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("sel",122,103,20,10,window,BUTTON_OK)
ActivateGadget(btn)

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

' how to deselect a combobox gadget? press return to exit rather than press button

Offline Juiceter

  • Jr. Member
  • **
  • Posts: 65
Re: How do you deselect a combobox gadget?
« Reply #11 on: October 04, 2020, 04:11:55 AM »
Yes it does chalky - I was nearly there. Thanks ;-)

Actually the hotkey thing henri suggested works better for what I had in mind (the code above was only a test). Thanks all for your help!

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal