[wxPython] Windows wxDialog and SetDefault of wxButton

I'd like to repeat some words I posted earlier in the year.

It is almost always a bad idea to override the normal system handling of events
like this. First, users expect the normal behavior. When an application does
something unusual, it is an invitation for people to use it incorrectly.
Confusion breeds errors.

Second, Microsoft has spent a considerable sum in user interface studies,
watching groups of users of all experience levels as they try to navigate
through various applications. The behavior of the default system controls is a
result of the lessons they learned through these studies.

There are always exceptions, of course, but overriding fundamental behavior is
usually a mistake.

···

On Mon, 15 Jul 2002 20:18:32 +0200, Andre Reitz <reitz@inworks.de> wrote:

Hy, Is it possible to get rid of the default Button behaviour under Windows,

My current approach is to catch wxEVT_CHILD_FOCUS and reset my desired
default button with wxButton.SetDefault() or wxPanel.SetDefaultItem(None)
if no defaultbutton is desired.

--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.

>
>Hy, Is it possible to get rid of the default Button behaviour under Windows,
>
>My current approach is to catch wxEVT_CHILD_FOCUS and reset my desired
>default button with wxButton.SetDefault() or wxPanel.SetDefaultItem(None)
>if no defaultbutton is desired.

I'd like to repeat some words I posted earlier in the year.

It is almost always a bad idea to override the normal system handling of events
like this. First, users expect the normal behavior. When an application does
something unusual, it is an invitation for people to use it incorrectly.
Confusion breeds errors.

Second, Microsoft has spent a considerable sum in user interface studies,
watching groups of users of all experience levels as they try to navigate
through various applications. The behavior of the default system controls is a
result of the lessons they learned through these studies.

There are always exceptions, of course, but overriding fundamental behavior is
usually a mistake.

Thank you very much, for your answer, I know that it is a bad idea to do such things,
I wanted to ask if there is a "legal" way to keep the defaultbutton,
e.g. by using wxWindow instead of wxPanel or such thing.

Did I understand those old postings correct:
- The Defaultbutton behaviour is implemented in the windows version of wxPanel
  and emulates the behaviour of MS-Windows?

Thank you for your time,

Greetings, Andre'

···

On Tue, 16 Jul 2002 09:21:03 -0700 "Tim Roberts" <timr@probo.com> wrote:

On Mon, 15 Jul 2002 20:18:32 +0200, Andre Reitz <reitz@inworks.de> wrote:

--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
_____________________________________________
inworks GmbH Andre Reitz
Magirusstrasse 44 Tel. 0731/93 80 7-21
89077 Ulm http://www.inworks.de

Well my Problem is, e.g:

···

On Tue, 16 Jul 2002 10:02:46 -0700 "Tim Roberts" <timr@probo.com> wrote:

On Tue, 16 Jul 2002 18:44:02 +0200, Andre Reitz wrote:
>
>Thank you very much, for your answer, I know that it is a bad idea to do
>such things, ...

That's what I wanted to hear. It's OK to break the rules, as long as you know
you are doing so and have a good reason. My post was for the benefit of those
folks who don't realize there is a reason for the default behaviors. So many
of the applications I see do really dumb things with their user interface...

>I wanted to ask if there is a "legal" way to keep the defaultbutton,
>e.g. by using wxWindow instead of wxPanel or such thing.
>
>Did I understand those old postings correct:
>- The Defaultbutton behaviour is implemented in the windows version of
> wxPanel and emulates the behaviour of MS-Windows?

I don't think it's even an emulation. I believe buttons in wxWindows on
Windows are really implemented as standard Windows buttons, and the "default
button" behavior you see is the standard Windows button behavior. I haven't
looked at the wxWindows code, so I could be wrong, but I think that widgets in
wxWindows use the native widgets wherever possible.

Having said that, I'm a bit confused as to what effect you are trying to get.
Are you trying to have the "Enter" key do different things based on different
conditions? Maybe it would be better not to have a default button at all, but
instead handle the Enter key directly.

--------------------------------

BUTTON1 | TEXTCTRL |*BUTTON2*|

--------------------------------

So lets say Button2 is the default Button.
If the user has the focus on Button1, then in my opinion it is
correct to "click" Button1 when hitting enter. (as is)

But when the User hits Tab and gets into TEXTCTRL then the DefaultButton
shall jump back to BUTTON2 (but doesnt)

In Fact it Button1 stays the DefaultButton, and when Clicking enter in
The TEXTCTRL, then Button1 is activated and not Button2 which originally was
the Defaultbutton!

Am I doing something wrong?

-----------------------------------------
I found something in the sources:
wxWindows/src/msw/button.cpp:
-----------------------------------------
"""
// ----------------------------------------------------------------------------
// default button handling
// ----------------------------------------------------------------------------
...
  We handle this by maintaining a permanent and a temporary default items in
   wxControlContainer (both may be NULL). When a button becomes the current
   control (i.e. gets focus) it sets itself as the temporary default which
   ensures that it has the right appearance and that Enter will be redirected
   to it. When the button loses focus, it unsets the temporary default and so
   the default item will be the permanent default -- that is the default button
   if any had been set or none otherwise, which is just what we want.
"""

---> I think that this doesnt work as described?
---> am I wrong?

Greetings, Andre'

--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.

--
_____________________________________________
inworks GmbH Andre Reitz
Magirusstrasse 44 Tel. 0731/93 80 7-21
89077 Ulm http://www.inworks.de

OK Here is the code:

···

On Tue, 16 Jul 2002 10:27:45 -0700 "Tim Roberts" <timr@probo.com> wrote:

On Tue, 16 Jul 2002 19:20:08 +0200, Andre Reitz wrote:
>
>Well my Problem is, e.g:
>
>--------------------------------
>> BUTTON1 | TEXTCTRL |*BUTTON2*|
>--------------------------------
>
>So lets say Button2 is the default Button.
>If the user has the focus on Button1, then in my opinion it is
>correct to "click" Button1 when hitting enter. (as is)
>
>But when the User hits Tab and gets into TEXTCTRL then the DefaultButton
>shall jump back to BUTTON2 (but doesnt)
>
>In Fact it Button1 stays the DefaultButton, and when Clicking enter in
>The TEXTCTRL, then Button1 is activated and not Button2 which originally was
>the Defaultbutton!
>
>Am I doing something wrong?
>
>---> I think that this doesnt work as described?
>---> am I wrong?

No, it should work exactly as you describe. If not, it's a wxWindows bug. I
will have to play with this to find out.

I'm surprised by the code snippet you sent along. wxWindows should never
modify the "default" status. Windows makes a clear distinction between the
"default" button and "focus" button, and they even get rendered differently.

I suggest you send an exact copy of what you sent me to the mailing list;
perhaps Robin has the answer.

--------------------------------------------------------------------------------
from wxPython.wx import *

class Frame(wxFrame):
  def __init__(self):
    wxFrame.__init__(self,None,-1,"",size=(400,400))
    p=wxPanel(self,-1,pos=(0,0),size=(400,400))
    b1=wxButton (p,-1,"B1",pos=(10,10))
    tx=wxTextCtrl(p,-1,"tx",pos=(10,40))
    b2=wxButton (p,-1,"B2",pos=(10,70))
    b2.SetDefault()
    EVT_BUTTON(self,b1.GetId(),self.OnB1)
    EVT_BUTTON(self,b2.GetId(),self.OnB2)
  def OnB1(self,event):
    print "B1"
  def OnB2(self,event):
    print "B2"

class App(wxApp):
  def OnInit(self):
    f=Frame()
    f.Show()
    return 1
    
app=App()
app.MainLoop()
--------------------------------------------------------------------------------

Please try it somebody under windows and see, that the Default Button
(when Hitting Enter in the TextField) is always the Last Focussed Button (MSW only).

In my opinion this is an evil bug....

What do you think?

Greetings, Andre'

--
- Tim Roberts, timr@probo.com
  Providenza & Boekelheide, Inc.

--
_____________________________________________
inworks GmbH Andre Reitz
Magirusstrasse 44 Tel. 0731/93 80 7-21
89077 Ulm http://www.inworks.de

Well my Problem is, e.g:

--------------------------------
> BUTTON1 | TEXTCTRL |*BUTTON2*|
--------------------------------

So lets say Button2 is the default Button.
If the user has the focus on Button1, then in my opinion it is
correct to "click" Button1 when hitting enter. (as is)

But when the User hits Tab and gets into TEXTCTRL then the DefaultButton
shall jump back to BUTTON2 (but doesnt)

In Fact it Button1 stays the DefaultButton, and when Clicking enter in
The TEXTCTRL, then Button1 is activated and not Button2 which originally

was

the Defaultbutton!

This appears to be fixed already in 2.3.3.

···

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

Thank you very much for your quick answer,
Is there a possibility to get already build binaries for
wxMSW and wxGTK with this bug fixed?

I am not able to compile it under windows. :wink:

Greetings, Andre'

···

On Wed, 17 Jul 2002 08:54:08 -0700 "Robin Dunn" <robin@alldunn.com> wrote:

> Well my Problem is, e.g:
>
> --------------------------------
> > BUTTON1 | TEXTCTRL |*BUTTON2*|
> --------------------------------
>
> So lets say Button2 is the default Button.
> If the user has the focus on Button1, then in my opinion it is
> correct to "click" Button1 when hitting enter. (as is)
>
> But when the User hits Tab and gets into TEXTCTRL then the DefaultButton
> shall jump back to BUTTON2 (but doesnt)
>
> In Fact it Button1 stays the DefaultButton, and when Clicking enter in
> The TEXTCTRL, then Button1 is activated and not Button2 which originally
was
> the Defaultbutton!

This appears to be fixed already in 2.3.3.

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

--
_____________________________________________
inworks GmbH Andre Reitz
Magirusstrasse 44 Tel. 0731/93 80 7-21
89077 Ulm http://www.inworks.de

>
> This appears to be fixed already in 2.3.3.
>

Thank you very much for your quick answer,
Is there a possibility to get already build binaries for
wxMSW and wxGTK with this bug fixed?

If you are using Python 2.2 then there is a preview release here:

···

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