On 24/05/2017 at 23:32, xxxxxxxx wrote:
Hello!
I'm learning about dialogs and inputs states. I'm looking into it, but there are some things I don't fully understand. In this case I want to make a basic dialog that return one string information with one "OK" button and "Cancel" button. I already wrote the code and works correctly but I don't understand the correct way to assign inputs commands to "OK" (Enter Key) and "Cancel" (esc Key).
But, If I execute a basic input states without dialogs works great. When I assign this inputs states the dialog stop working, doesn't recognize the OK and Cancel actions.
Can someone help me to understand what is happening?
Here is the code with one input state for the OK button:
import c4d
from c4d import gui
LBL_INFO = 1000
NAME = 10001
GROUP_OPTIONS = 20000
BTN_OK = 20001
BTN_CANCEL = 20002
class OptionsDialog(gui.GeDialog) :
def CreateLayout(self) :
self.SetTitle('Title')
self.AddStaticText(LBL_INFO, c4d.BFH_LEFT, name='String Name:')
self.AddEditText(NAME, c4d.BFH_SCALEFIT)
self.SetString(NAME, 'Default Name')
# Buttons
self.GroupBegin(GROUP_OPTIONS, c4d.BFH_CENTER, 2, 1)
self.AddButton(BTN_OK, c4d.BFH_SCALE, name='OK')
self.AddButton(BTN_CANCEL, c4d.BFH_SCALE, name='Cancel')
self.GroupEnd()
self.ok = False
return True
# Action Buttons Inputs
def Command(self, id, msg) :
bc = c4d.BaseContainer()
if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD,c4d.KEY_ENTER,bc) :
if bc[c4d.BFM_INPUT_VALUE]==1:
if id==BTN_CANCEL:
self.Close()
elif id==BTN_OK:
self.ok = True
self.option_find_string = self.GetString(NAME)
self.Close()
return True
def dialog_test() :
dlg = OptionsDialog()
dlg.Open(c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=50)
if not dlg.ok:
return
print "1"+dlg.option_find_string
if __name__=='__main__':
dialog_test()
---------------------------------------
Thanks for the help, cheers!