Changing labels on standard dialog buttons

I have posted the question at wxwidgets forum in the following thread:
http://forums.wxwidgets.org/viewtopic.php?f=27&t=32219&p=135736#p135736

and eventually was referred to this mailing list.

So what I want to do is use a standard dialog (e.g. a MessageDialog),
but modify the labels of the OK/CANCEL buttons.

It was suggested that I use the FindWindowById, but when I do
    dialog = wx.MessageDialog(self, "message", "title", wx.OK|
wx.CANCEL)
    print dialog.FindWindowById(wx.ID_OK)

I get None.
The same result with FindWindowByName and ByLabel

I'd appreciate any idea on how to modify the standard labels, or on
how to get FindWindow to work in python.

What would the new labels be - in other words can you explain a bit more what your reasons are to change the labels of a standard dialog. As the name "standard" implies the use of these dialogs is pretty well defined and the buttons match pretty well the intended use.

If you need it for non standard dialogs, i.e. a dialog you create then the label is totally up to you (see attached).

If you haven't already done so have a look at the wxPython demo, bottom left search for "dialog" and for "stock", the first search will show you all the available dialogs and the second gives you the available stock buttons.

Werner

acustomdialog.py (882 Bytes)

···

On 11/07/2011 04:47 PM, dbbd wrote:

I have posted the question at wxwidgets forum in the following thread:
changing button labels on standard dialog - wxWidgets Discussion Forum

and eventually was referred to this mailing list.

So what I want to do is use a standard dialog (e.g. a MessageDialog),
but modify the labels of the OK/CANCEL buttons.

It was suggested that I use the FindWindowById, but when I do
     dialog = wx.MessageDialog(self, "message", "title", wx.OK|
wx.CANCEL)
     print dialog.FindWindowById(wx.ID_OK)

I get None.
The same result with FindWindowByName and ByLabel

I'd appreciate any idea on how to modify the standard labels, or on
how to get FindWindow to work in python.

What I want is for the ok button to say ‘Add’, cancel can stay :slight_smile:
i know how to build my own dialog, but see no harm in having the ability to access my buttons.
That was what FindWindowById supposed to do, and I know it works from C++
Any reason it does not work from python?

Dan

···

On Monday, November 7, 2011, werner wbruhin@free.fr wrote:

On 11/07/2011 04:47 PM, dbbd wrote:

I have posted the question at wxwidgets forum in the following thread:
http://forums.wxwidgets.org/viewtopic.php?f=27&t=32219&p=135736#p135736

and eventually was referred to this mailing list.

So what I want to do is use a standard dialog (e.g. a MessageDialog),
but modify the labels of the OK/CANCEL buttons.

It was suggested that I use the FindWindowById, but when I do
dialog = wx.MessageDialog(self, “message”, “title”, wx.OK|
wx.CANCEL)
print dialog.FindWindowById(wx.ID_OK)

I get None.
The same result with FindWindowByName and ByLabel

I’d appreciate any idea on how to modify the standard labels, or on
how to get FindWindow to work in python.

What would the new labels be - in other words can you explain a bit more what your reasons are to change the labels of a standard dialog. As the name “standard” implies the use of these dialogs is pretty well defined and the buttons match pretty well the intended use.

If you need it for non standard dialogs, i.e. a dialog you create then the label is totally up to you (see attached).

If you haven’t already done so have a look at the wxPython demo, bottom left search for “dialog” and for “stock”, the first search will show you all the available dialogs and the second gives you the available stock buttons.

Werner


To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

As I recall, we don’t always have access to every widget in a wx.MessageDialog because the OS itself doesn’t allow it. Remember, wxPython wraps the native widgets where ever possible. This may be one of those cases. If so, then rolling your own wx.Dialog is the way to go. It’s really not that hard.

···

Mike Driscoll

Blog: http://blog.pythonlibrary.org

That’s how I think of it, too. What I’m surprised about is that the wxWidgets API shows a method, SetOKLabel(ButtonLabel), which “Overrides the default label of the OK button.” wxPython doesn’t have this method.

Also, I’m surprised you could find the msgDialog by ID by searching for wx.OK, as I thought that was just a style flag.

Che

···

On Mon, Nov 7, 2011 at 2:26 PM, Mike Driscoll kyosohma@gmail.com wrote:

As I recall, we don’t always have access to every widget in a wx.MessageDialog because the OS itself doesn’t allow it. Remember, wxPython wraps the native widgets where ever possible. This may be one of those cases. If so, then rolling your own wx.Dialog is the way to go. It’s really not that hard.

The problem is that wx.MessageDialog is not a real wx.Dialog, it is just a wrapper around a native API function. So there is no wx.Button that can be found with one of the Find methods. There is a generic message dialog class in wx.lib.agw that you can use instead that is a real wx.Dialog and is also implemented in Python code, so it is easy to override behavior as needed. I also recently added a MultiMessageDialog class in wx.lib.dialogs that is much like a wx.MessageDialog but it is able to have an extra block of text that is scrollable and it explicitly supports changing the labels of the stock buttons.

···

On 11/7/11 7:47 AM, dbbd wrote:

I have posted the question at wxwidgets forum in the following thread:
changing button labels on standard dialog - wxWidgets Discussion Forum

and eventually was referred to this mailing list.

So what I want to do is use a standard dialog (e.g. a MessageDialog),
but modify the labels of the OK/CANCEL buttons.

It was suggested that I use the FindWindowById, but when I do
     dialog = wx.MessageDialog(self, "message", "title", wx.OK|
wx.CANCEL)
     print dialog.FindWindowById(wx.ID_OK)

I get None.
The same result with FindWindowByName and ByLabel

I'd appreciate any idea on how to modify the standard labels, or on
how to get FindWindow to work in python.

--
Robin Dunn
Software Craftsman

    As I recall, we don't always have access to every widget in a
    wx.MessageDialog because the OS itself doesn't allow it. Remember,
    wxPython wraps the native widgets where ever possible. This may be
    one of those cases. If so, then rolling your own wx.Dialog is the
    way to go. It's really not that hard.

That's how I think of it, too. What I'm surprised about is that the
wxWidgets API shows a method, SetOKLabel(ButtonLabel), which "Overrides
the default label of the OK button." wxPython doesn't have this method.

It does in 2.9, it's a new feature. I don't think I've actually tried it however so I'm not sure if it's implemented for all platforms.

Also, I'm surprised you could find the msgDialog by ID by searching for
wx.OK, as I thought that was just a style flag.

Yeah, that should have been wx.ID_OK.

···

On 11/7/11 11:32 AM, C M wrote:

On Mon, Nov 7, 2011 at 2:26 PM, Mike Driscoll <kyosohma@gmail.com > <mailto:kyosohma@gmail.com>> wrote:

--
Robin Dunn
Software Craftsman

Hi,

As I recall, we don't always have access to every widget in a
wx.MessageDialog because the OS itself doesn't allow it. Remember,
wxPython wraps the native widgets where ever possible. This may be
one of those cases. If so, then rolling your own wx.Dialog is the
way to go. It's really not that hard.

That's how I think of it, too. What I'm surprised about is that the
wxWidgets API shows a method, SetOKLabel(ButtonLabel), which "Overrides
the default label of the OK button." wxPython doesn't have this method.

It does in 2.9, it's a new feature. I don't think I've actually tried it
however so I'm not sure if it's implemented for all platforms.

Haven't tried it on all platforms yet but it does work on Windows (wx2.9):

There appears to be a method for each possible enumeration of buttons
supported by the dialog.
SetOKCancelLabels("OK Button String", "Cancel Button string")
SetOkLabel("Ok Label String")
SetYesNoCancelLabels(...,...,...)
...

Cody

···

On Mon, Nov 7, 2011 at 1:40 PM, Robin Dunn <robin@alldunn.com> wrote:

On 11/7/11 11:32 AM, C M wrote:

On Mon, Nov 7, 2011 at 2:26 PM, Mike Driscoll <kyosohma@gmail.com >> <mailto:kyosohma@gmail.com>> wrote:

Hi guys,
I am new to wx.Python framework.
I want to set custom labels for button in wx.TextEntryDialog, wx.MessageBox and wx.FileDialogue.
Is there any way that I can set custom label for ok , cancel, save, open button?
I want to set the custom label since I am implementing a internationalization, which supports different language.
so obviously ok text will be ‘some chinese translated ok text’ in chinese.

Thanks

Hi!
The standard buttons should get localized by wx itself.
E.g. the standard OK button is typically created by wx.Button(self, wx.ID_OK), i.e. without the need to provide a label.
The standard dialogs are creating the buttons like this.

On my german Windows, I get german labels by default.

To change the language, try something like self.locale = wx.Locale(wx.LANGUAGE_DEFAULT) or self.locale = wx.Locale(wx.LANGUAGE_CHINESE).