dialog with cancel button only

Craig W wrote:

from the wxPython demo, under "Common Dialogs/MessageDialog"

I changed this:
        dlg = wx.MessageDialog(self, 'Hello from Python and wxPython!',
                               'A Message Box',
                               wx.OK | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
        dlg.ShowModal()
        dlg.Destroy()

TO:

        dlg = wx.MessageDialog(self, 'Hello from Python and wxPython!',
                               'A Message Box',
                               wx.CANCEL | wx.ICON_INFORMATION
                               #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL | wx.ICON_INFORMATION
                               )
        dlg.ShowModal()
        dlg.Destroy()

....I was hoping that the dialog would show a "Cancel" button instead of the "OK" button. Any idea why this doesn't work?

Not sure, but it does something similar on all the platforms so it may be some standards compliance thing that requires that the OK button be there. Please enter a bug report about it though so somebody else will take a look at it just in case I am missing something.

···

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

I looked at the 2.6.1.0 source (wxPython-src-2.6.1.0/src/gtk/msgdlg.cpp), and
found that wxCANCEL is ignored unless wxOK is set. Same thing for the msw
version.

    if (style & wxOK)
    {
        if (style & wxCANCEL)
            buttons = GTK_BUTTONS_OK_CANCEL;
        else
            buttons = GTK_BUTTONS_OK;
    }

Because I was so sure that you'd be able to have just a cancel button, I also
looked at the win32 sdk documentation, and saw that you *can't* have a
message box on windows with just a cancel button. It looks like you can with
gtk, but I'm a gtk novice, so I could be wrong.

john

···

On Tuesday 24 January 2006 03:53 pm, Robin Dunn wrote:

Craig W wrote:
> from the wxPython demo, under "Common Dialogs/MessageDialog"
>
> I changed this:
> dlg = wx.MessageDialog(self, 'Hello from Python and wxPython!',
> 'A Message Box',
> wx.OK | wx.ICON_INFORMATION
> #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL |
> wx.ICON_INFORMATION
> )
> dlg.ShowModal()
> dlg.Destroy()
>
> TO:
>
> dlg = wx.MessageDialog(self, 'Hello from Python and wxPython!',
> 'A Message Box',
> wx.CANCEL | wx.ICON_INFORMATION
> #wx.YES_NO | wx.NO_DEFAULT | wx.CANCEL |
> wx.ICON_INFORMATION
> )
> dlg.ShowModal()
> dlg.Destroy()
>
> ....I was hoping that the dialog would show a "Cancel" button instead of
> the "OK" button. Any idea why this doesn't work?

Not sure, but it does something similar on all the platforms so it may
be some standards compliance thing that requires that the OK button be
there. Please enter a bug report about it though so somebody else will
take a look at it just in case I am missing something.

> > from the wxPython demo, under "Common Dialogs/MessageDialog"
> >
> > I changed this:
> > dlg = wx.MessageDialog(self, 'Hello from Python
and wxPython!',
> > 'A Message Box',
> > wx.OK | wx.ICON_INFORMATION
> > #wx.YES_NO | wx.NO_DEFAULT |
> > wx.CANCEL | wx.ICON_INFORMATION
> > )
> > dlg.ShowModal()
> > dlg.Destroy()
> >
> > TO:
> >
> > dlg = wx.MessageDialog(self, 'Hello from Python
and wxPython!',
> > 'A Message Box',
> > wx.CANCEL | wx.ICON_INFORMATION
> > #wx.YES_NO | wx.NO_DEFAULT |
> > wx.CANCEL | wx.ICON_INFORMATION
> > )
> > dlg.ShowModal()
> > dlg.Destroy()
> >
> > ....I was hoping that the dialog would show a "Cancel" button
> > instead of the "OK" button. Any idea why this doesn't work?
>
> Not sure, but it does something similar on all the
platforms so it may
> be some standards compliance thing that requires that the
OK button be
> there. Please enter a bug report about it though so
somebody else will
> take a look at it just in case I am missing something.

I looked at the 2.6.1.0 source
(wxPython-src-2.6.1.0/src/gtk/msgdlg.cpp), and
found that wxCANCEL is ignored unless wxOK is set. Same
thing for the msw
version.

    if (style & wxOK)
    {
        if (style & wxCANCEL)
            buttons = GTK_BUTTONS_OK_CANCEL;
        else
            buttons = GTK_BUTTONS_OK;
    }

Because I was so sure that you'd be able to have just a
cancel button, I also
looked at the win32 sdk documentation, and saw that you
*can't* have a
message box on windows with just a cancel button. It looks
like you can with
gtk, but I'm a gtk novice, so I could be wrong.

I haven't really been following this thread, so forgive me if this has
already been said.

Your solution, given this, is to write your own Message Dialog. Here's the
code for one I wrote. Not brilliant flexible code, but it should get you
started. Just replace Dialog Title, the _("OK") text with _("Cancel"),
change the button ID, and choose a different icon if you want, and you
should be good to go.

David

class InfoDialog(wx.Dialog):
    """Information message dialog to the user."""

    def __init__(self, parent, msg):
        # This should be easy, right? Just use the OS MessageDialog like
so:
        # wx.MessageDialog.__init__(self, parent, msg, _("Transana
Information"), \
        # wx.OK | wx.CENTRE | wx.ICON_INFORMATION)
        # That's all there is to it, right?

···

#
        # Yeah, right. Unfortunately, on Windows, this dialog isn't TRULY
modal. It's modal to the parent window
        # it's called from, but you can still select one of the other
Transana Windows and do stuff. This message
        # can even get hidden behind other windows, and cause all kinds of
problems. According to Robin Dunn,
        # writing my own class to do this is the only solution. Here goes.

        # print "InfoDialog", msg

        wx.Dialog.__init__(self, parent, -1, _("Transana Information"),
size=(350, 150), style=wx.CAPTION | wx.CLOSE_BOX | wx.STAY_ON_TOP)

        box = wx.BoxSizer(wx.VERTICAL)
        box2 = wx.BoxSizer(wx.HORIZONTAL)

        bitmap = wx.EmptyBitmap(32, 32)
        bitmap = wx.ArtProvider_GetBitmap(wx.ART_INFORMATION,
wx.ART_MESSAGE_BOX, (32, 32))
        graphic = wx.StaticBitmap(self, -1, bitmap)

        box2.Add(graphic, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, 10)
        
        message = wx.StaticText(self, -1, msg)

        box2.Add(message, 0, wx.EXPAND | wx.ALIGN_CENTER |
wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10)
        box.Add(box2, 0, wx.EXPAND)

        btnOK = wx.Button(self, wx.ID_OK, _("OK"))

        box.Add(btnOK, 0, wx.ALIGN_CENTER | wx.BOTTOM, 10)

        self.SetAutoLayout(True)

        self.SetSizer(box)
        self.Fit()
        self.Layout()

        self.CentreOnScreen()