Want to know the active object

Hello,

My problem is the next :

On a panel, I have :

- 1 x wxTextCtrl
- 1 x WxGrid
- 1 x wxButton (Validation)

When the user click on the button I want to know if the cursor was in the wxTextCtrl or in the wxGrid ?
Thank you for a little help on this subject.

Yours.

Hugues JEAN-BAPTISTE (hjb@agorinfo.fr)
AGORINFO
1330, route de Neufchatel
F-76230 QUINCAMPOIX
Tel. : 33.2.32.80.87.87 / Fax : 33.2.32.80.87.88
Web site : http://www.agorinfo.fr

Hugues JEAN-BAPTISTE wrote:

Hello,

My problem is the next :

On a panel, I have :

- 1 x wxTextCtrl
- 1 x WxGrid
- 1 x wxButton (Validation)

When the user click on the button I want to know if the cursor was in the wxTextCtrl or in the wxGrid ?
Thank you for a little help on this subject.

You can try with wxWindow_FindFocus()
something like:

win = wxWindow_FindFocus()

if win.GetName() == wxTextCtrlNameStr:
  # do something
elif win.GetName() == wxPanelNameStr:

You would have to change the wxTextCtrlNameStr and/or wxPanelNameStr
if you supplied your own naems on construction.

Regards
    Adi

Try keeping a reference to the last focused item.
Add a event handler for focus events like EVT_KILL_FOCUS and switch a global variable or a member of an available class then, in the event handler of the button, check to see which component modified the variable.
This is not a solution but a suggestion (never played with focus events but this is how I would try to do it)

···

On Tue, 23 Mar 2004 16:15:55 +0100, Hugues JEAN-BAPTISTE <hjb@agorinfo.fr> wrote:

Hello,

My problem is the next :

On a panel, I have :

- 1 x wxTextCtrl
- 1 x WxGrid
- 1 x wxButton (Validation)

When the user click on the button I want to know if the cursor was in the wxTextCtrl or in the wxGrid ?
Thank you for a little help on this subject.

Yours.

Hugues JEAN-BAPTISTE (hjb@agorinfo.fr)
AGORINFO
1330, route de Neufchatel
F-76230 QUINCAMPOIX
Tel. : 33.2.32.80.87.87 / Fax : 33.2.32.80.87.88
Web site : http://www.agorinfo.fr

--
Peter Damoc
Hacker Wannabe
http://www.sigmacore.net/about.html

Adi Sieker a écrit :

Hugues JEAN-BAPTISTE wrote:

Hello,

My problem is the next :

On a panel, I have :

- 1 x wxTextCtrl
- 1 x WxGrid
- 1 x wxButton (Validation)

When the user click on the button I want to know if the cursor was in the wxTextCtrl or in the wxGrid ?
Thank you for a little help on this subject.

You can try with wxWindow_FindFocus()
something like:

win = wxWindow_FindFocus()

if win.GetName() == wxTextCtrlNameStr:
    # do something
elif win.GetName() == wxPanelNameStr:

You would have to change the wxTextCtrlNameStr and/or wxPanelNameStr
if you supplied your own naems on construction.

Regards
   Adi

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Thank you for your help.

I put this code on the button to know the previous active object :

        win = wxWindow_FindFocus()
        print win.GetName()

The result is : "button" and not "Grid" or "TextCtrl"

Hi,

Hugues JEAN-BAPTISTE wrote:

  Thank you for your help.

I put this code on the button to know the previous active object :

       win = wxWindow_FindFocus()
       print win.GetName()

The result is : "button" and not "Grid" or "TextCtrl"

Duh, I really should think before posting.
Of course it is, since clicking the button will also focus it.
Then the solution from Peter is probably the best.

Regards
     Adi

Hugues JEAN-BAPTISTE wrote:

Hello,

My problem is the next :

On a panel, I have :

- 1 x wxTextCtrl
- 1 x WxGrid
- 1 x wxButton (Validation)

When the user click on the button I want to know if the cursor was in the wxTextCtrl or in the wxGrid ?
Thank you for a little help on this subject.

There is nothing built-in that can tel you where the focus *was* only where it *is*. But you can probably track it yourself by catching the focus events.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!