agw.ButtonPanel - How to prevent unintentional border

My agw.ButtonPanel’s always have a 2-pixel border around them. Is there a way to prevent this ?

Ray Pasco

ButtonPanel.png

Hi Ray,

My agw.ButtonPanel's always have a 2-pixel border around them. Is there a way to prevent this ?

Yes, you can just customize the ButtonPanelArt associated with
ButtonPanel. You can do it this way (where "your_bp" is your instance
of ButtonPanel):

import wx.lib.agw.buttonpanel as BP

# 0 pixels border
your_bp.GetBPArt().SetMetric(BP.BP_BORDER_SIZE, 0)
your_bp.DoLayout()

# 1 pixel border
your_bp.GetBPArt().SetMetric(BP.BP_BORDER_SIZE, 1)
your_bp.DoLayout()

HTH.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On 8 July 2011 19:52, Ray Pasco <pascor22234@gmail.com> wrote:

Thanks !

Why isn’t the border set to 0 by default like all other controls ?

There really needs to be better documentation for this very nice control. I’m writing a wxPython wiki page that will demonstrate what I think are the basic features of this control.

I think I have discovered and fixed a minor but annoying bug. When aligning to the left without text being set all the buttons are aligned on the left side, as expected. When text is defined the text is left-aligned, but the buttons get shoved to the right ! I don’t think this is what most people expect or want. The third screen shot shows what my changes do - both the text and the buttons become left-aligned.

Ray

ORIGINAL:

    # We have text, so insert the text and an expandable spacer
    # alongside it. "Standard" ButtonPanel are left or top aligned.
    if self.IsStandard():
        self._mainsizer.Insert(1, self._text, 0, wx.ALIGN_CENTER,
                                userData=self._text, realIndex=0)
        self._mainsizer.Insert(2, (0, 0), 1, wx.EXPAND)
       
    else:
        self._mainsizer.Insert(lenChildren-1, self._text, 0, wx.ALIGN_CENTER,
                               userData=self._text, realIndex=lenChildren)
        self._mainsizer.Insert(lenChildren-1, (0, 0), 1, wx.EXPAND)

NEW:

    # We have text, so insert the text and an expandable spacer
    # alongside it. "Standard" ButtonPanel are left or top aligned.
    if self.IsStandard():
        self._mainsizer.Insert(1, self._text, 0, wx.ALIGN_CENTER,
                                userData=self._text, realIndex=0)
        self._mainsizer.Insert(2, (0, 0), 0, wx.EXPAND)     ############## CHANGE
       
    else:
        self._mainsizer.Insert(lenChildren-1, self._text, 0, wx.ALIGN_CENTER,
                               userData=self._text, realIndex=lenChildren)
        self._mainsizer.Insert(lenChildren-1, (0, 0), 0, wx.EXPAND)     ############## CHANGE

1_ORIGINAL_WITHOUT_TEXT.png

2_ORIGINAL_WITH_TEXT.png

3_NEW_WITH_TEXT.png

···

Andrea does have some pretty cool documentation here: http://xoomer.virgilio.it/infinity77/AGW_Docs/buttonpanel_module.html#buttonpanel

It may not be super extensive, but it plus the demo can usually get you a ways down the road before you get stuck.

  • Mike