Help with custom button

I am trying to make a custom flat button that has a bitmap to the left and some label text to the right all of which need to be clickable and give some sort of feedback.

I have an implementation that I think should work but is giving me some trouble that can be seen in the attached test file. Basically I thought that by creating a bitmap on the fly that combined the desired icon and drawing a label next to it in a new bitmap then putting it into a bitmap button using the wx.NO_BORDER style would do it but when using the NO_BORDER style the button turns into a white and black square.

The test file contains 5 test cases.

1) what the desired button should look like, (using a staticbitmap and static text to show appearance)

2) What I have now that is giving the problem, (my custom bitmapbutton with icon and text drawn into button)

3) The same code as number 2 but not using the NO_BORDER style shows that the bitmap is made correctly

4) Using GetBitmapLabel to get the bitmap used in the button from #2 shows that the bitmap in there is correct as well

5) Only putting the desired bitmap without label in a bitmap button and using NO_BORDER creates a flat button that gives the desired feedback and shows that the NO_BORDER style works in this case when there is no drawn text in the icon. But since the text is not part of the button it is not clickable. This is what I have settled with for now, but would really like to get #2 working.

This is on Mac OS X using wxpython 2.8.4.2 / python 2.5

Any help on this is much appreciated,

Cody

flatbmpbtn.py (5.44 KB)

I am trying to make a custom flat button that has a bitmap to the

left and some label text to the right all of which need to be
clickable and give some sort of feedback.

Have you tried the existing wx.lib.buttons.GenBitmapTextButton?
That seems like it maybe does what you need.

CM

Doh!, Didn't notice that one. It is pretty close to what I am looking for and may use it. I would still however rather get it to work with the BitmapButton if possible so that it gets the native highlighting when pressed/selected. Also the GenBitmapTextButton seems to miss allot of clicks when toggling in between its selected and unselected state, and it doesn't grey itself out into an disabled state when the window looses focus like the rest of the controls.

thanks,

Cody

···

On Sep 24, 2007, at 1:32 AM, C M wrote:

I am trying to make a custom flat button that has a bitmap to the
left and some label text to the right all of which need to be
clickable and give some sort of feedback.

Have you tried the existing wx.lib.buttons.GenBitmapTextButton?
That seems like it maybe does what you need.

CM

Hello:
Im new at this, but I have a frame and on this frame
is a smaller subframe with a box resizer in it. In
the box is a static label and a wx.grid widget. Im
using boa Constructor. I can specify how many rows
and columns I want in the table and it all works fine,
except that the subframe and box resizer do not shrink
to fit the wx.grid if there are only a few rows and
columns in it. This leaves a large white blank on the
running GUI, which is not pretty. Can anyone tell me
how to have the subframe and sizer automatically
shrink to fit whatever number of rows/columns I have
in the wx.grid? Do you use bestFittingSize or
clientSize of the subframe or box sizer or wx.grid?

Thanks, JJ

···

____________________________________________________________________________________
Be a better Heartthrob. Get better relationship answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545433

Doh!, Didn't notice that one. It is pretty close to what I am looking
for and may use it. I would still however rather get it to work with
the BitmapButton if possible so that it gets the native highlighting
when pressed/selected.

GenThemedBitmapTextButton

Also the GenBitmapTextButton seems to miss
allot of clicks when toggling in between its selected and unselected
state, and it doesn't grey itself out into an disabled state when the
window looses focus like the rest of the controls.

If you're rapidly clicking to toggle the button, you're probably
clicking fast enough to trip double clicks, and a double click doesn't
toggle the button. This means that you lose every other click. I'm not
sure what you mean about the disabled state, losing focus isn't the
same as disabled.

···

On 9/24/07, Cody Precord <codyprecord@gmail.com> wrote:

JJ wrote:

Hello:
Im new at this, but I have a frame and on this frame
is a smaller subframe with a box resizer in it. In
the box is a static label and a wx.grid widget. Im
using boa Constructor. I can specify how many rows
and columns I want in the table and it all works fine,
except that the subframe and box resizer do not shrink
to fit the wx.grid if there are only a few rows and
columns in it. This leaves a large white blank on the
running GUI, which is not pretty. Can anyone tell me
how to have the subframe and sizer automatically
shrink to fit whatever number of rows/columns I have
in the wx.grid? Do you use bestFittingSize or
clientSize of the subframe or box sizer or wx.grid?

If the initial size is passed to the grid constructor then it is setting the widget's minimal size, and minimal size overrides best size when the sizers calculate layout. Take a look at the code Boa is generating and see if it does that, and then either try to make it not set the initial size or add a call to theGrid.SetMinSize((-1,-1)) to reset it.

···

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

Hello:
I have a wx.StaticLine in the cell of a GridBagSizer
and I would like to keep this line narrow in width but
expadable upon window resizing. The flag wx.EXPAND
will allow the line to expand in all direction, which
is not what I want. I tried the flat wx.SHAPE, but
there appears to be no way to tell it to keep the y
shape but expand the x shape. Does anyone know how to
use expand in only one (x) direction?

···

____________________________________________________________________________________
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
http://farechase.yahoo.com/

Ah, I see now. One has to first use
myStaticLine.SetSize((-1,1)) and then use the wx.SHAPE
flag.

John

···

--- JJ <josh8912@yahoo.com> wrote:

Hello:
I have a wx.StaticLine in the cell of a GridBagSizer
and I would like to keep this line narrow in width
but
expadable upon window resizing. The flag wx.EXPAND
will allow the line to expand in all direction,
which
is not what I want. I tried the flat wx.SHAPE, but
there appears to be no way to tell it to keep the y
shape but expand the x shape. Does anyone know how
to
use expand in only one (x) direction?

____________________________________________________________________________________

Looking for a deal? Find great prices on flights and
hotels with Yahoo! FareChase.
http://farechase.yahoo.com/

---------------------------------------------------------------------

To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwidgets.org

      ____________________________________________________________________________________
Tonight's top picks. What will you watch tonight? Preview the hottest shows on Yahoo! TV.

Hello:
I have a frame with a GridBagSizer on it and two
BoxSizers in the GridBagSizer. I simply want to force
the widgets in a spanned cell to fill the cell (in the
x direction). The code below sets a new span of the
cell where the first BoxSizer is located, but the
widgets in the BoxSizer do not change size. I would
like them to expand to fill the spaned cells. I know
I can set the size of the widgets using SetMinSize,
but I want the widgets to expand and grow (with the
GridBagSizer) when the main frame changes size. Can
anyone tell me where I am going wrong?
PS: I use a wx.TextCtrl here, but could have also used
a grid table, a wx.StaticLine, or a different widget.
Thanks, John

#!/usr/bin/env python
import wx
class myApp(wx.App):
  def OnInit(self):
    frame = Frame1("hello",(50,160),(450,340))
    frame.Show()
    self.SetTopWindow(frame)
    return True
class Frame1(wx.Frame):
  def __init__(self,title,pos,size):
    wx.Frame.__init__(self,None,-1,title,pos,size)
    panelA = wx.Panel(self, -1, name='panelA',
pos=wx.Point(0, 0), style=wx.TAB_TRAVERSAL )
    sizer = wx.GridBagSizer(vgap=9, hgap=9)
    boxsizer_one = wx.BoxSizer(wx.VERTICAL)
    boxsizer_two = wx.BoxSizer(wx.VERTICAL)
    txt_one = wx.StaticText(panelA, -1, label= "txt
1")
    txtctrl_one = wx.TextCtrl(panelA,-1, size =
(100,-1))
    
    txt_two = wx.StaticText(panelA, -1, label= "txt
2")
    line_one = wx.StaticLine(panelA,-1, size =
(100,-1))
    
    boxsizer_one.Add(txt_one,wx.TOP)
    boxsizer_one.Add(txtctrl_one,wx.BOTTOM)
    boxsizer_two.Add(txt_two,wx.TOP)
    boxsizer_two.Add(line_one,wx.BOTTOM)
    sizer.Add(boxsizer_one, pos=(0,0),
span=wx.DefaultSpan, flag=wx.EXPAND, border=6)
    sizer.Add(boxsizer_two, pos=(1,1),
span=wx.DefaultSpan, flag=wx.EXPAND, border=6)
    # now change the span
    itm = sizer.FindItem(boxsizer_one)
    print "item span= ",itm.GetSpan()
    itm.SetSpan((1,2))
    print "item changed span= ", itm.GetSpan()
    sizer.AddGrowableCol(0)
    sizer.AddGrowableCol(1)
    panelA.SetSizerAndFit(sizer)
     
if __name__ == '__main__':
  app = myApp(False)
  app.MainLoop()

···

____________________________________________________________________________________
Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7

JJ wrote:

Hello:
I have a frame with a GridBagSizer on it and two
BoxSizers in the GridBagSizer. I simply want to force
the widgets in a spanned cell to fill the cell (in the
x direction). The code below sets a new span of the
cell where the first BoxSizer is located, but the
widgets in the BoxSizer do not change size. I would
like them to expand to fill the spaned cells. I know
I can set the size of the widgets using SetMinSize,
but I want the widgets to expand and grow (with the
GridBagSizer) when the main frame changes size. Can
anyone tell me where I am going wrong?

You are telling the GBS to expand the box sizer (correct) but you are not telling the box sizer to expand the textctrl (incorrect) so it is leaving it at the default size. You are also not using the box sizer's Add method correctly. You are passing the flags to the proportion parameter.

     boxsizer_one.Add(txt_one, 0, wx.TOP)
     boxsizer_one.Add(txtctrl_one, 0, wx.EXPAND|wx.BOTTOM)

···

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