wx.combo.ComboCtrl.GetButton() returns None

Hi all

I am using a wx.combo.ComboCtrl in the DateEditorAndPicker control discussed
recently.

I want to add a ToolTip to the Button portion of the control, explaining
that the user can press F4 or Space to open the Calendar.

Using dir() and help() at the python prompt, I see that there is a method
called GetButton(), which should return the dropdown button that is part of
the combobox.

However, if I try to use it, it returns None.

I could probably do it the hard way, calculate the position of the button,
test whether the mouse is hovered over it, and display the ToolTip myself.

However, I would much prefer to let wx do it for me. Is there a way to get a
reference to the underlying Button?

Version is 2.8.10.1.

Thanks

Frank Millman

IIRC, whether or not there is a real wx.Button there is an implementation detail that can vary by platform and by style of comboctrl. It may just be using the native renderer to draw a button-like image on the combo widget instead.

···

On 7/13/10 12:03 AM, Frank Millman wrote:

Hi all

I am using a wx.combo.ComboCtrl in the DateEditorAndPicker control discussed
recently.

I want to add a ToolTip to the Button portion of the control, explaining
that the user can press F4 or Space to open the Calendar.

Using dir() and help() at the python prompt, I see that there is a method
called GetButton(), which should return the dropdown button that is part of
the combobox.

However, if I try to use it, it returns None.

I could probably do it the hard way, calculate the position of the button,
test whether the mouse is hovered over it, and display the ToolTip myself.

However, I would much prefer to let wx do it for me. Is there a way to get a
reference to the underlying Button?

--
Robin Dunn
Software Craftsman

Robin Dunn wrote:

>
> I am using a wx.combo.ComboCtrl in the DateEditorAndPicker
> control discussed recently.
>
> I want to add a ToolTip to the Button portion of the control,
> explaining that the user can press F4 or Space to open the Calendar.
>

[...]

>
> Is there a way to get a reference to the underlying Button?

IIRC, whether or not there is a real wx.Button there is an
implementation detail that can vary by platform and by style of
comboctrl. It may just be using the native renderer to draw a
button-like image on the combo widget instead.

I tried to read the source on the wxWidgets site. I don't understand much of
it, but it seems that there is *something* there, called m_btn.

Here is a snippet from combo.h -
    // get the dropdown button which is part of the combobox
    // note: its not necessarily a wxButton or wxBitmapButton
    wxWindow *GetButton() const { return m_btn; }

Here is a snippet from combocmn.cpp -
    #if wxUSE_TOOLTIPS
    void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
    {
        wxControl::DoSetToolTip(tooltip);
        // Set tool tip for button and text box
        if ( tooltip )
        {
            const wxString &tip = tooltip->GetTip();
            if ( m_text ) m_text->SetToolTip(tip);
            if ( m_btn ) m_btn->SetToolTip(tip);
        }
        else
        {
            if ( m_text ) m_text->SetToolTip( NULL );
            if ( m_btn ) m_btn->SetToolTip( NULL );
        }
    }
    #endif // wxUSE_TOOLTIPS

So not only is there a button of some sort, but one should be able to set a
tooltip on it.

I tried to do it the hard way, but I hit a problem. I can calculate which
portion of the control represents the button, and if the mouse hovers over
it I can set a tooltip. When the mouse leaves the button, I want to clear
the tooltip. This works on msw, but on gtk2 the tooltip remains, no matter
what I do. I have tried setting the tooltip to an empty string, and to None,
but it makes no difference. The result is that, once it has been displayed
once, if the user hovers over the button *or* the text control part of the
control, the tooltip is displayed.

Sorry to be a nuisance, Robin, but please can you have another look at this.
It looks as if GetButton() *should* return a reference to the button portion
of the control, whether it is a wx.Button or not, and it looks as if one
should be able to set a tooltip on it.

Thanks

Frank

···

On 7/13/10 12:03 AM, Frank Millman wrote:

Did you try Andrea's SuperTooltip? You might be able to destroy that
easier...

···

On Jul 14, 7:34 am, "Frank Millman" <fr...@chagford.com> wrote:

Robin Dunn wrote:

> On 7/13/10 12:03 AM, Frank Millman wrote:

> > I am using a wx.combo.ComboCtrl in the DateEditorAndPicker
> > control discussed recently.

> > I want to add a ToolTip to the Button portion of the control,
> > explaining that the user can press F4 or Space to open the Calendar.

[...]

> > Is there a way to get a reference to the underlying Button?

> IIRC, whether or not there is a real wx.Button there is an
> implementation detail that can vary by platform and by style of
> comboctrl. It may just be using the native renderer to draw a
> button-like image on the combo widget instead.

I tried to read the source on the wxWidgets site. I don't understand much of
it, but it seems that there is *something* there, called m_btn.

Here is a snippet from combo.h -
// get the dropdown button which is part of the combobox
// note: its not necessarily a wxButton or wxBitmapButton
wxWindow *GetButton() const { return m_btn; }

Here is a snippet from combocmn.cpp -
#if wxUSE_TOOLTIPS
void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
{
wxControl::DoSetToolTip(tooltip);
// Set tool tip for button and text box
if ( tooltip )
{
const wxString &tip = tooltip->GetTip();
if ( m_text ) m_text->SetToolTip(tip);
if ( m_btn ) m_btn->SetToolTip(tip);
}
else
{
if ( m_text ) m_text->SetToolTip( NULL );
if ( m_btn ) m_btn->SetToolTip( NULL );
}
}
#endif // wxUSE_TOOLTIPS

So not only is there a button of some sort, but one should be able to set a
tooltip on it.

I tried to do it the hard way, but I hit a problem. I can calculate which
portion of the control represents the button, and if the mouse hovers over
it I can set a tooltip. When the mouse leaves the button, I want to clear
the tooltip. This works on msw, but on gtk2 the tooltip remains, no matter
what I do. I have tried setting the tooltip to an empty string, and to None,
but it makes no difference. The result is that, once it has been displayed
once, if the user hovers over the button *or* the text control part of the
control, the tooltip is displayed.

Sorry to be a nuisance, Robin, but please can you have another look at this.
It looks as if GetButton() *should* return a reference to the button portion
of the control, whether it is a wx.Button or not, and it looks as if one
should be able to set a tooltip on it.

Thanks

Frank

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Frank Millman wrote:

Sorry to be a nuisance, Robin, but please can you have
another look at this.
It looks as if GetButton() *should* return a reference to the
button portion
of the control, whether it is a wx.Button or not, and it
looks as if one
should be able to set a tooltip on it.

Cancel that request. I seem to have found a workaround using wx.TipWindow.

I will do some more testing tomorrow, and if it works ok I will update the
wiki page with a revised version.

Thanks

Frank

Robin Dunn wrote:

I am using a wx.combo.ComboCtrl in the DateEditorAndPicker
control discussed recently.

I want to add a ToolTip to the Button portion of the control,
explaining that the user can press F4 or Space to open the Calendar.

[...]

Is there a way to get a reference to the underlying Button?

IIRC, whether or not there is a real wx.Button there is an
implementation detail that can vary by platform and by style of
comboctrl. It may just be using the native renderer to draw a
button-like image on the combo widget instead.

I tried to read the source on the wxWidgets site. I don't understand much of
it, but it seems that there is *something* there, called m_btn.

Here is a snippet from combo.h -
     // get the dropdown button which is part of the combobox
     // note: its not necessarily a wxButton or wxBitmapButton
     wxWindow *GetButton() const { return m_btn; }

Here is a snippet from combocmn.cpp -
     #if wxUSE_TOOLTIPS
     void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip)
     {
         wxControl::DoSetToolTip(tooltip);
         // Set tool tip for button and text box
         if ( tooltip )
         {
             const wxString&tip = tooltip->GetTip();
             if ( m_text ) m_text->SetToolTip(tip);
             if ( m_btn ) m_btn->SetToolTip(tip);
         }
         else
         {
             if ( m_text ) m_text->SetToolTip( NULL );
             if ( m_btn ) m_btn->SetToolTip( NULL );
         }
     }
     #endif // wxUSE_TOOLTIPS

So not only is there a button of some sort, but one should be able to set a
tooltip on it.

Notice how it always uses "if (m_btn) ..." everywhere? That's because it's possible for the pointer to be NULL. If you look at a ComboCtrl in the WIT you'll be able to see that there isn't a child widget that is a button. In fact, I don't see any code where m_btn is assigned, so I'm beginning to wonder if it is left over from a previous implementation, or perhaps it is there in case a new implementation on another platform needs it...

I tried to do it the hard way, but I hit a problem. I can calculate which
portion of the control represents the button, and if the mouse hovers over
it I can set a tooltip. When the mouse leaves the button, I want to clear
the tooltip. This works on msw, but on gtk2 the tooltip remains, no matter
what I do. I have tried setting the tooltip to an empty string, and to None,
but it makes no difference. The result is that, once it has been displayed
once, if the user hovers over the button *or* the text control part of the
control, the tooltip is displayed.

Sorry to be a nuisance, Robin, but please can you have another look at this.
It looks as if GetButton() *should* return a reference to the button portion
of the control, whether it is a wx.Button or not, and it looks as if one
should be able to set a tooltip on it.

Only if an actual widget is used rather than painting the button area itself, otherwise it will return NULL. When a NULL pointer is returned SWIG turns it into None.

···

On 7/14/10 5:34 AM, Frank Millman wrote:

On 7/13/10 12:03 AM, Frank Millman wrote:

--
Robin Dunn
Software Craftsman