FindFocus()

Hi

I'm new to wxPython, well to GUI programming in general, perhaps you can help me.

I have a panel with 3 TextCtrl's and I need to put accented characters into the TextCtrl into which the user has put the caret.

I can do this successfully using a menu (and a toolbar since this also uses EVT_MENU) and identifying the relevant TextCtrl using wx.Window.FindFocus in this manner

ctrl=wx.Window.FindFocus()
ctrl.WriteText("whatever")

However the situation has arisen where I really could do with using a block of Bitmap buttons to do the job, but of course the button click 'hijacks' the focus so FindFocus no longer refers to one of the TextCtrls.

Any ideas how I can overcome this

regards

John

You need to define your criteria for "relevant text control" better.
If it's just "the window whcih last had focus", you'll need to track
focus. I suspect that you can come up with a better definition than
that if you take a step back from the mechanics of your UI code and
focus on the UI process, though.

···

On 1/8/07, John Lockett <john@lockettpots.co.uk> wrote:

Hi

I'm new to wxPython, well to GUI programming in general, perhaps you can
help me.

I have a panel with 3 TextCtrl's and I need to put accented characters
into the TextCtrl into which the user has put the caret.

I can do this successfully using a menu (and a toolbar since this also
uses EVT_MENU) and identifying the relevant TextCtrl using
wx.Window.FindFocus in this manner

ctrl=wx.Window.FindFocus()
ctrl.WriteText("whatever")

However the situation has arisen where I really could do with using a
block of Bitmap buttons to do the job, but of course the button click
'hijacks' the focus so FindFocus no longer refers to one of the TextCtrls.

Any ideas how I can overcome this

regards

John

Hi John,

However the situation has arisen where I really could do with using a
block of Bitmap buttons to do the job, but of course the button click
'hijacks' the focus so FindFocus no longer refers to one of the TextCtrls.

I see 2 ways of doing that (but maybe someone else will point to a
better solution). Warning: I didn't test them, so they might not work:

1) Instead of a standard wx.Button, use a wx.lib.buttons.GenButton (or
GenBitmapButton), overriding its ability to accept focus:

def AcceptFocus(self):
    return False

2) You might keep track of the focus changing using a property, like:

self.widgetWithFocus = None

in the __init__ method, then binding the wx.EVT_SET_FOCUS for the
textctrls and the button:

textctrl1.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
textctrl2.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
...
self.myButton.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)

def OnSetFocus(self, event):

    widget = event.GetEventObject()

    if widget == self.myButton:
        self.widgetWithFocus.SetFocus()
        return

    self.widgetWithFocus = event.GetEventObject()

It seems a very ugly code and there is an high probability that it
won't work ;-). But you could try. I am sure others will come up with
better solutions.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

···

On 1/8/07, John Lockett wrote:

OK "relevant text control"

On the panel the user has three textCrl.

1. an word/phrase in English
2. a translation in a foreign language
3. a short note about the translation

User clicks in one of the boxes and starts to enter text. Needs to enter a foreign/accented character. Clicks on bitmapButton to do so.

So the 'relevant text control' is the one that the user was entering text in at the time of clicking on the button.

So I guess it is "the window whcih last had focus" so what does "track focus" mean please?

John

Chris Mellon wrote:

···

You need to define your criteria for "relevant text control" better.
If it's just "the window whcih last had focus", you'll need to track
focus. I suspect that you can come up with a better definition than
that if you take a step back from the mechanics of your UI code and
focus on the UI process, though.

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

See the wx.EVT_SET_FOCUS and wx.EVT_KILL_FOCUS event bindings.

- Josiah

···

John <john@monakmore.co.uk> wrote:

OK "relevant text control"

On the panel the user has three textCrl.

1. an word/phrase in English
2. a translation in a foreign language
3. a short note about the translation

User clicks in one of the boxes and starts to enter text. Needs to enter
a foreign/accented character. Clicks on bitmapButton to do so.

So the 'relevant text control' is the one that the user was entering
text in at the time of clicking on the button.

So I guess it is "the window whcih last had focus" so what does "track
focus" mean please?

John

Chris Mellon wrote:

>
> You need to define your criteria for "relevant text control" better.
> If it's just "the window whcih last had focus", you'll need to track
> focus. I suspect that you can come up with a better definition than
> that if you take a step back from the mechanics of your UI code and
> focus on the UI process, though.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>
>

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