Hello all,
I have a dialog-driven program. A typical case might be:
the program starts, popping up the main dialog.
the user selects the "new search" button, popping up a "new search" dialog.
the user searches, so a "search results" dialog appears.
the user closes the "search results" dialog, calling its Destroy()
method, and the "new search" dialog is shown again.
the user escapes that one, and it is destroyed, now showing the main dialog.
My question is whether or not I can know when any of these dialogs
gets focus, specifically after it re-appears after another dialog is
destroyed. For example, maybe the user was focused on the "search"
button of the "new search" dialog, but when they escape from the
results, I want to automatically call SetFocus() on the search text
control. Another example is that, in some dialogs, the user could add
to a list of items held in a config file. That list is shown in the
main dialog, so I want to re-draw the list each time the main dialog
comes back into focus. Googling for this sort of thing only tells me
about widget focus events, and those for frames, but nothing for
dialogs. Is what I am trying to do even possible? Thanks in advance,
and please let me know if anything did not make sense.
Try EVT_ACTIVATE. I assume it will work for dialogs as it does for Frames. Otherwise if your dialogs are modal then you should be able to keep track of who's in control since you are directing the program flow when ShowModal returns. If they are not modal then you could switch them to frames with a wx.Panel in them.
···
On 10/19/11 8:59 PM, Alex Hall wrote:
Hello all,
I have a dialog-driven program. A typical case might be:
the program starts, popping up the main dialog.
the user selects the "new search" button, popping up a "new search" dialog.
the user searches, so a "search results" dialog appears.
the user closes the "search results" dialog, calling its Destroy()
method, and the "new search" dialog is shown again.
the user escapes that one, and it is destroyed, now showing the main dialog.
My question is whether or not I can know when any of these dialogs
gets focus, specifically after it re-appears after another dialog is
destroyed. For example, maybe the user was focused on the "search"
button of the "new search" dialog, but when they escape from the
results, I want to automatically call SetFocus() on the search text
control. Another example is that, in some dialogs, the user could add
to a list of items held in a config file. That list is shown in the
main dialog, so I want to re-draw the list each time the main dialog
comes back into focus. Googling for this sort of thing only tells me
about widget focus events, and those for frames, but nothing for
dialogs. Is what I am trying to do even possible? Thanks in advance,
and please let me know if anything did not make sense.
Hello all,
I have a dialog-driven program. A typical case might be:
the program starts, popping up the main dialog.
the user selects the "new search" button, popping up a "new search"
dialog.
the user searches, so a "search results" dialog appears.
the user closes the "search results" dialog, calling its Destroy()
method, and the "new search" dialog is shown again.
the user escapes that one, and it is destroyed, now showing the main
dialog.
My question is whether or not I can know when any of these dialogs
gets focus, specifically after it re-appears after another dialog is
destroyed. For example, maybe the user was focused on the "search"
button of the "new search" dialog, but when they escape from the
results, I want to automatically call SetFocus() on the search text
control. Another example is that, in some dialogs, the user could add
to a list of items held in a config file. That list is shown in the
main dialog, so I want to re-draw the list each time the main dialog
comes back into focus. Googling for this sort of thing only tells me
about widget focus events, and those for frames, but nothing for
dialogs. Is what I am trying to do even possible? Thanks in advance,
and please let me know if anything did not make sense.
Try EVT_ACTIVATE. I assume it will work for dialogs as it does for
Frames. Otherwise if your dialogs are modal then you should be able to
keep track of who's in control since you are directing the program flow
when ShowModal returns. If they are not modal then you could switch
them to frames with a wx.Panel in them.
They are modal, but I am not sure how to know which dialog gets focus
when another dies. Each dialog is a class with its own event handler
method, and each one can call others. For instance, a search results
dialog can call either a download dialog or a more information dialog,
or it could be destroyed. How would I tell the search results dialog
to do something when one of its two possible spawned dialogs is
escaped from? How would the results dialog know about the destruction
at all? That's why I was hoping for a way to see when a dialog was
activated. I did try evt_activate, but it somehow gets called twice. I
am just doing:
self.Bind(wx.EVT_ACTIVATE, self.onActivate)
...
def onActive(self, evt): print "main dialog active"
and it prints "main dialog active" twice each time I run the program.
This is not a huge problem, but I would rather avoid doing activation
things twice if I can. Any idea why this would happen? Main is
actually the third dialog called (the first two are a login dialog,
which I cancel, and a "this is beta software" warning), but that
shouldn't make a difference. Thanks!
···
On 10/20/11, Robin Dunn <robin@alldunn.com> wrote:
When a modal dialog is closed it is supposed to transfer activation/focus back to the widget that had it before the dialog was shown. It's possible for something the dialog does to disrupt that, but in the general case is should work. Also, you can always force it yourself in your code that is run after ShowModal returns. You're already making decisions about whether to show another dialog, right? This is what I meant by directing the program flow. So something like this pseudo code could work:
if dlgA.ShowModal() == wx.ID_OK:
doStuff()
dlgA.Destroy()
if someCondition:
createAndShowDlgB()
else:
mainDlg.Raise()
mainDlg.doStuffForReactivation()
The Raise() may not be needed, especially if control is naturally returning to mainDlg's event loop after this code completes. In other words, you should be able to assume that a dialog is being reactivated when its event handler that spawned other modal dialog(s) is returning after those dialog(s) have returned from their ShowModals.
···
On 10/20/11 8:03 AM, Alex Hall wrote:
On 10/20/11, Robin Dunn<robin@alldunn.com> wrote:
On 10/19/11 8:59 PM, Alex Hall wrote:
Hello all,
I have a dialog-driven program. A typical case might be:
the program starts, popping up the main dialog.
the user selects the "new search" button, popping up a "new search"
dialog.
the user searches, so a "search results" dialog appears.
the user closes the "search results" dialog, calling its Destroy()
method, and the "new search" dialog is shown again.
the user escapes that one, and it is destroyed, now showing the main
dialog.
My question is whether or not I can know when any of these dialogs
gets focus, specifically after it re-appears after another dialog is
destroyed. For example, maybe the user was focused on the "search"
button of the "new search" dialog, but when they escape from the
results, I want to automatically call SetFocus() on the search text
control. Another example is that, in some dialogs, the user could add
to a list of items held in a config file. That list is shown in the
main dialog, so I want to re-draw the list each time the main dialog
comes back into focus. Googling for this sort of thing only tells me
about widget focus events, and those for frames, but nothing for
dialogs. Is what I am trying to do even possible? Thanks in advance,
and please let me know if anything did not make sense.
Try EVT_ACTIVATE. I assume it will work for dialogs as it does for
Frames. Otherwise if your dialogs are modal then you should be able to
keep track of who's in control since you are directing the program flow
when ShowModal returns. If they are not modal then you could switch
them to frames with a wx.Panel in them.
They are modal, but I am not sure how to know which dialog gets focus
when another dies.
Thanks for the responses. I still am not sure why it is activating
twice, but I can live with it. The structure of my code is such that
the full control is not centralized, so using the event handlers to
figure out activation would be difficult at best. I'll also be looking
more into Dialog.Bind(), which I had forgotten about until you all
reminded me of it.
···
On 10/20/11, Robin Dunn <robin@alldunn.com> wrote:
On 10/20/11 8:03 AM, Alex Hall wrote:
On 10/20/11, Robin Dunn<robin@alldunn.com> wrote:
On 10/19/11 8:59 PM, Alex Hall wrote:
Hello all,
I have a dialog-driven program. A typical case might be:
the program starts, popping up the main dialog.
the user selects the "new search" button, popping up a "new search"
dialog.
the user searches, so a "search results" dialog appears.
the user closes the "search results" dialog, calling its Destroy()
method, and the "new search" dialog is shown again.
the user escapes that one, and it is destroyed, now showing the main
dialog.
My question is whether or not I can know when any of these dialogs
gets focus, specifically after it re-appears after another dialog is
destroyed. For example, maybe the user was focused on the "search"
button of the "new search" dialog, but when they escape from the
results, I want to automatically call SetFocus() on the search text
control. Another example is that, in some dialogs, the user could add
to a list of items held in a config file. That list is shown in the
main dialog, so I want to re-draw the list each time the main dialog
comes back into focus. Googling for this sort of thing only tells me
about widget focus events, and those for frames, but nothing for
dialogs. Is what I am trying to do even possible? Thanks in advance,
and please let me know if anything did not make sense.
Try EVT_ACTIVATE. I assume it will work for dialogs as it does for
Frames. Otherwise if your dialogs are modal then you should be able to
keep track of who's in control since you are directing the program flow
when ShowModal returns. If they are not modal then you could switch
them to frames with a wx.Panel in them.
They are modal, but I am not sure how to know which dialog gets focus
when another dies.
When a modal dialog is closed it is supposed to transfer
activation/focus back to the widget that had it before the dialog was
shown. It's possible for something the dialog does to disrupt that, but
in the general case is should work. Also, you can always force it
yourself in your code that is run after ShowModal returns. You're
already making decisions about whether to show another dialog, right?
This is what I meant by directing the program flow. So something like
this pseudo code could work:
if dlgA.ShowModal() == wx.ID_OK:
doStuff()
dlgA.Destroy()
if someCondition:
createAndShowDlgB()
else:
mainDlg.Raise()
mainDlg.doStuffForReactivation()
The Raise() may not be needed, especially if control is naturally
returning to mainDlg's event loop after this code completes. In other
words, you should be able to assume that a dialog is being reactivated
when its event handler that spawned other modal dialog(s) is returning
after those dialog(s) have returned from their ShowModals.