Hi all,
I have been battling with something for days. I have now narrowed down my
problem enough to show it in a fairly short piece of code, which is
attached. It works perfectly in Windows, but does something horrible under
Linux.
The two platforms are -
Windows 2000, Python 2.2.2, wxPython 2.4.0.2u
Red Hat Linux 8.0, Python 2.2.2, wxPython 2.4.0.2
I have a TextCtrl (t3) with an event handler for EVT_SET_FOCUS. The handler
can decide to pass focus to another TextCtrl (t1), in which case it displays
a message box, executes t1.SetFocus(), and does not execute event.Skip(). If
t3 gains focus by tabbing into it, it works fine, but if it gains focus from
a mouse click, t1 appears to gain focus, but anything I type still appears
in t3. Under Windows, everything works as expected.
I have tried setting focus on t1 before displaying the message instead of
after. I have tried including an event.Skip(). I have tried using EVT_IDLE
and wxCallAfter to set the focus on t1. Nothing makes any difference.
The sample code is an artificial situation to illustrate the problem. What I
am actually doing is field-by-field validation, including validating fields
that the user has skipped by jumping over them with the mouse. This is why I
need to trigger the validation from an EVT_SET_FOCUS event.
Any advice will be much appreciated.
Many thanks
Frank Millman
fm.py (1.25 KB)
Frank Millman wrote:
[...]
I have a TextCtrl (t3) with an event handler for EVT_SET_FOCUS. The handler
can decide to pass focus to another TextCtrl (t1), in which case it displays
a message box, executes t1.SetFocus(), and does not execute event.Skip(). If
t3 gains focus by tabbing into it, it works fine, but if it gains focus from
a mouse click, t1 appears to gain focus, but anything I type still appears
in t3. Under Windows, everything works as expected.
[...]
Hi Frank,
Under windows you may get troubles with text selection in OnSetFocus - due to wrong (?) order of instructions in msc/window.cpp wxWindowMSW::SetFocusFromKbd() where selection is made after setting focus to control - if you move focus to another control which can have selection (textctrl) you will get two controls with selected text.
···
--
Pozdrawiam,
Grzegorz Makarewicz
---------------------------------------------------------------------
-- "Linux is more compatible with Windows than Windows with Windows."
---------------------------------------------------------------------
Frank Millman wrote:
[...]
> I have a TextCtrl (t3) with an event handler for EVT_SET_FOCUS. The
handler
> can decide to pass focus to another TextCtrl (t1), in which case it
displays
> a message box, executes t1.SetFocus(), and does not execute
event.Skip(). If
> t3 gains focus by tabbing into it, it works fine, but if it gains focus
from
> a mouse click, t1 appears to gain focus, but anything I type still
appears
> in t3. Under Windows, everything works as expected.
>
[...]
Hi Frank,
Under windows you may get troubles with text selection in OnSetFocus -
due to wrong (?) order of instructions in msc/window.cpp
wxWindowMSW::SetFocusFromKbd() where selection is made after setting
focus to control - if you move focus to another control which can have
selection (textctrl) you will get two controls with selected text.
--
Pozdrawiam,
Grzegorz Makarewicz
---------------------------------------------------------------------
-- "Linux is more compatible with Windows than Windows with Windows."
---------------------------------------------------------------------
Thanks for the reply, Grzegorz
You seem to be saying that the problem is in the Windows version, but in
fact my Windows version works perfectly - it is my Linux version that has
the problem.
Do you have any suggestions for a workaround?
Thanks
Frank
···
----- Original Message -----
From: "Grzegorz Makarewicz" <mak@trisoft.com.pl>
To: <wxPython-users@lists.wxwindows.org>
Sent: Monday, March 17, 2003 10:41 AM
Subject: Re: [wxPython-users] SetFocus() problem with Linux
Frank Millman wrote:
Thanks for the reply, Grzegorz
You seem to be saying that the problem is in the Windows version, but in
fact my Windows version works perfectly - it is my Linux version that has
the problem.
Do you have any suggestions for a workaround?
Sorry i'm newbie in gtk world , but i'm sure it is stored in window.cpp and depends on instructions order, elsewhere in gtk_window_focus_in_callback.
caret is positioned ok so code until if ( win->m_hasFocus ) is executed correctly, the rest (last 7 lines) is black magic for me.
mak
I think you have to execute event.Skip() to work well in Linux in handlers for EVT_SET_FOCUS or EVT_KILL_FOCUS
josu.
···
On Tue, 18 Mar 2003 16:12:09 +0200 "Frank Millman" <frank@chagford.com> wrote:
----- Original Message -----
From: "Grzegorz Makarewicz" <mak@trisoft.com.pl>
To: <wxPython-users@lists.wxwindows.org>
Sent: Monday, March 17, 2003 10:41 AM
Subject: Re: [wxPython-users] SetFocus() problem with Linux
> Frank Millman wrote:
> [...]
> > I have a TextCtrl (t3) with an event handler for EVT_SET_FOCUS. The
handler
> > can decide to pass focus to another TextCtrl (t1), in which case it
displays
> > a message box, executes t1.SetFocus(), and does not execute
event.Skip(). If
> > t3 gains focus by tabbing into it, it works fine, but if it gains focus
from
> > a mouse click, t1 appears to gain focus, but anything I type still
appears
> > in t3. Under Windows, everything works as expected.
> >
> [...]
>
> Hi Frank,
>
> Under windows you may get troubles with text selection in OnSetFocus -
> due to wrong (?) order of instructions in msc/window.cpp
> wxWindowMSW::SetFocusFromKbd() where selection is made after setting
> focus to control - if you move focus to another control which can have
> selection (textctrl) you will get two controls with selected text.
>
> --
>
> Pozdrawiam,
> Grzegorz Makarewicz
>
> ---------------------------------------------------------------------
> -- "Linux is more compatible with Windows than Windows with Windows."
> ---------------------------------------------------------------------
>
Thanks for the reply, Grzegorz
You seem to be saying that the problem is in the Windows version, but in
fact my Windows version works perfectly - it is my Linux version that has
the problem.
Do you have any suggestions for a workaround?
Thanks
Frank
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
Josu Oyanguren wrote:
I think you have to execute event.Skip() to work well in Linux in handlers for EVT_SET_FOCUS or EVT_KILL_FOCUS
After adding event.Skip() instead of message box, t3 is blocker forever - the window (t3) itself think that it has the focus.
mak
it was only a supossition. Can you send a minimal example?
···
On Tue, 18 Mar 2003 15:57:08 +0100 Grzegorz Makarewicz <mak@trisoft.com.pl> wrote:
After adding event.Skip() instead of message box, t3 is blocker forever
- the window (t3) itself think that it has the focus.
Josu Oyanguren wrote:
it was only a supossition. Can you send a minimal example?
try with:
1. different order of message box and set focus
2. invoke Skip(False)
3. remove message box
4. remove event.Skip()
just nothing special - 2 carets and t3 has focus or t3 is blind and wont accept focus
def OnGotFocus(self,event):
self.MessageBox("Skip","Moving to t1",wxOK)
self.t1.SetFocus()
event.Skip()
fm.py (1.29 KB)
···
--
Pozdrawiam,
Grzegorz Makarewicz
---------------------------------------------------------------------
-- "Linux is more compatible with Windows than Windows with Windows."
---------------------------------------------------------------------
Grzegorz Makarewicz wrote:
try with:
1. different order of message box and set focus
2. invoke Skip(False)
3. remove message box
4. remove event.Skip()
The bad news - none of the above worked.
1. Makes no difference with Linux, causes a loop in Windows - t3 regains
focus after the message box is closed, which triggers the got focus event,
which displays the message box, which ....
2. No difference
3. It works correctly without the message box. Unfortunately this does not
help me. This is part of a validation framework - I have to call a message
box to display an error message.
4, No difference.
The good news - I have found a workaround. It is as ugly as sin, but the
users do not have to know what goes on under the hood
I have set up a "mouse left down" event on t3. This gets called before the
got focus event. If detected, I set focus on t1, I display the message box,
and I do *not* call event.Skip(). I have to do some more testing, but at
this stage it looks as if the problem is solved.
I would still like to hear from anyone who knows a more "correct" solution.
But in the meantime I can continue with my development. A big thank you to
all those who responded.
Frank Millman
Frank Millman wrote:
I have set up a "mouse left down" event on t3. This gets called before the
got focus event. If detected, I set focus on t1, I display the message box,
and I do *not* call event.Skip(). I have to do some more testing, but at
this stage it looks as if the problem is solved.
What about other (double)clicks (right,midle) in next 10 fields ?
As windows user i have found wxCallAfter usefull - but not on linux.
def OnSetFocus3(self,event):
self.t1.SetFocus()
wxCallAfter(self.OnCallAfter)
def OnCallAfter(self):
self.MessageBox("Skip","Moving to t1",wxOK)
···
--
Pozdrawiam,
Grzegorz Makarewicz
---------------------------------------------------------------------
-- "Linux is more compatible with Windows than Windows with Windows."
---------------------------------------------------------------------