Hi. When I put a dialog together, I usually only want it to stay alive to provide input from the user like:
if dlg.ShowModal() == wx.ID_OK:
field_value = dlg.some_field_text_ctrl.GetValue()
# Clean up
dlg.Destroy()
# Do something with the field value
I have run into a situation where I want to keep the dialog alive until it gives a specific result, then destroy it.
I am thinking I would just show the dialog first like:
dlg.Show()
# Something to get wx.ID_OK
if ??
field_value = dlg.some_field_text_ctrl.GetValue()
# Test value
if field_value is True:
# Do something
dlg.Destroy
else:
# Leave dialog (change text attribute)
dlg.static_text = 'Not the right answer'
So I think my question is how to know if wx.ID_OK has been triggered in dialog or maybe there is a better answer.
Hi. When I put a dialog together, I usually only want it to stay alive
to provide input from the user like:
[snip]
I have run into a situation where I want to keep the dialog alive until
it gives a specific result, then destroy it.
I am thinking I would just show the dialog first like:
[snip]
So I think my question is how to know if wx.ID_OK has been triggered in
dialog or maybe there is a better answer.
I tend to use...
value = None
while <value is unacceptable>: #create dialog
rslt = dlg.ShowModal()
if rslt == wx.ID_OK:
value = dlg.GetValue()
dlg.Destroy()
if rslt != wx.ID_OK:
return
<handle acceptable value>
Hi. When I put a dialog together, I usually only want it to stay alive to provide input from the user like:
if dlg.ShowModal() == wx.ID_OK:
field_value = dlg.some_field_text_ctrl.GetValue()
# Clean up
dlg.Destroy()
# Do something with the field value
I have run into a situation where I want to keep the dialog alive until it gives a specific result, then destroy it.
One way to do this would be to use validators on the controls in the dialog such that the dialog can't be dismissed until the values all validate correctly. Another way to do it would be to catch the EVT_BUTTON event for the wx.ID_OK button and have it only call EndModal when everything checks out the way you want it to.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Many thanks Josiah and Robin for these responses. I've worked this out
using wx.ID_OK and wx.ID_CANCEL with a loop similar to Josiah's. I am
resetting the values and setting focus to first GetValue() on each loop. I was shaking my dialog back and forth (left and right) if response was incorrect using SetPosition however this stopped working for me. Should ShowModal() affect this. I can GetPosition() but not SetPostion. I am not sure why why it should be affected since dialog is still around until it is destroyed. I am trying more things to get the two things to work together.
Regards,
David
Josiah Carlson wrote:
···
David Pratt <fairwinds@eastlink.ca> wrote:
Hi. When I put a dialog together, I usually only want it to stay alive to provide input from the user like:
[snip]
I have run into a situation where I want to keep the dialog alive until it gives a specific result, then destroy it.
I am thinking I would just show the dialog first like:
[snip]
So I think my question is how to know if wx.ID_OK has been triggered in dialog or maybe there is a better answer.
I tend to use...
value = None
while <value is unacceptable>: #create dialog
rslt = dlg.ShowModal()
if rslt == wx.ID_OK:
value = dlg.GetValue()
dlg.Destroy()
if rslt != wx.ID_OK:
return
<handle acceptable value>