Problem with "buttonHotKeyList" option in "YesNoDialog" (in "DirectDialog" in general)

Hello there!

I’m trying to implement the keyword “buttonHotKeyList” in the “YesNoDialog” constructor as I saw it in the Panda3D Reference. However, it does’t seem to have any affect (I still cannot use keys as replacement for the mouse). The code is taken from the example that can be found in the Panda3D manual, only adding the mentioned keyword:

dialog = YesNoDialog(dialogName="YesNoCancelDialog", text="Please choose:",buttonHotKeyList=['p','o'], command=itemSel)

Any idea of how to fix this? Thanks in advance!

Dani

I note that the manual page for DirectDialog indicates that the button in question must have focus. Presumably the keys have no effect otherwise.

If you want the hotkeys to entirely replace the mouse, perhaps you might work around this by catching the relevant key-events and responding to them?

Thanks for your answer. How does the focus property work on buttons? I have only seen it in the “DirectEntry” class, and I couldn’t find any reference to it in “DirectButton” or “DirectDialog”…

Hmm… It looks as though you can do it by accessing the button’s node and calling “setFocus” on that. Something like this:

myDirectButton = DirectButton(<params here>)
myDirectButton.node().setFocus(True)

Thanks for your help. Unfortunately, as I tried this solution I found out that it is only possible to have one button “focused” at once (that means, I can only , for example, choose “Yes” and not “Yes” or “No”). Here is the code I used:

for i in range(0,len(dialog.buttonList)):
dialog.buttonList[i].node().setFocus(True)
for i in range(0,len(dialog.buttonList)):
    print('Focus button '+ str(i+1) +': ' + str(dialog.buttonList[i].node().getFocus()))       

With the screen output:

Focus button 1: False
Focus button 2: True

I guess I’ll do the workaround you suggested before (catching key-events).

Ah yes, I perhaps didn’t think to mention that–indeed, only one object can have focus (after all, it identifies which object is “current”), I believe.

Good luck with the workaround! I hope that it works out for you! :slight_smile: