Changing labels on standard dialog buttons

651 views
Skip to first unread message

dbbd

unread,
Nov 7, 2011, 10:47:20 AM11/7/11
to wxPython-users
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.

werner

unread,
Nov 7, 2011, 1:21:01 PM11/7/11
to wxpytho...@googlegroups.com
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

Dan Bar Dov

unread,
Nov 7, 2011, 1:53:42 PM11/7/11
to wxpytho...@googlegroups.com
What I want is for the ok button to say 'Add', cancel can stay :-)
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
> --
> To unsubscribe, send email to wxPython-user...@googlegroups.com
> or visit http://groups.google.com/group/wxPython-users?hl=en

Mike Driscoll

unread,
Nov 7, 2011, 2:26:01 PM11/7/11
to wxpytho...@googlegroups.com
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

C M

unread,
Nov 7, 2011, 2:32:32 PM11/7/11
to wxpytho...@googlegroups.com
On Mon, Nov 7, 2011 at 2:26 PM, Mike Driscoll <kyos...@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.

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

Robin Dunn

unread,
Nov 7, 2011, 2:33:49 PM11/7/11
to wxpytho...@googlegroups.com


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.

--
Robin Dunn
Software Craftsman
http://wxPython.org

Robin Dunn

unread,
Nov 7, 2011, 2:40:34 PM11/7/11
to wxpytho...@googlegroups.com
On 11/7/11 11:32 AM, C M wrote:
>
>
> On Mon, Nov 7, 2011 at 2:26 PM, Mike Driscoll <kyos...@gmail.com
> <mailto:kyos...@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.
>
>
> 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.

Cody

unread,
Nov 7, 2011, 2:48:57 PM11/7/11
to wxpytho...@googlegroups.com
Hi,

On Mon, Nov 7, 2011 at 1:40 PM, Robin Dunn <ro...@alldunn.com> wrote:
> On 11/7/11 11:32 AM, C M wrote:
>>
>>
>> On Mon, Nov 7, 2011 at 2:26 PM, Mike Driscoll <kyos...@gmail.com
>> <mailto:kyos...@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.
>>
>>
>> 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

Reply all
Reply to author
Forward
0 new messages