help creating a bitmap

I'm trying to create a red square bitmap and attach it to a sizer I have. I found an example of manually creating the bitmap in the wxPython book, but it's for attaching to a toolbar. I've gotten the bitmap to attach as a button with the code below. I don't need it to be a button, but not sure how to attach it to the sizer correctly. I've tried changing the style to 0 on the button, but it doesn't seem to want to remove the border as it should.

Any help getting this on is appreciated.

Rick

Current code:
         self.status_light = wx.EmptyBitmap(15,15)
         dc = wx.MemoryDC()
         dc.SelectObject(self.status_light)
         dc.SetBackground(wx.Brush("Red"))
         dc.Clear()
         dc.SelectObject(wx.NullBitmap)

         self.status_light_button = wx.BitmapButton(panel, -1, self.status_light, style = 0)
         self.Bind(wx.EVT_BUTTON, self.OnStatusChange, self.status_light_button)

         sizer.Add(self.status_light_button)

Maybe you can try wx.NO_BORDER style like this:

self.status_light_button = wx.BitmapButton(panel, -1,
self.status_light, style = wx.NO_BORDER)

···

2007/1/24, Richard Harding <rharding@mitechie.com>:

I'm trying to create a red square bitmap and attach it to a sizer I
have. I found an example of manually creating the bitmap in the wxPython
book, but it's for attaching to a toolbar. I've gotten the bitmap to
attach as a button with the code below. I don't need it to be a button,
but not sure how to attach it to the sizer correctly. I've tried
changing the style to 0 on the button, but it doesn't seem to want to
remove the border as it should.

Any help getting this on is appreciated.

Rick

Current code:
         self.status_light = wx.EmptyBitmap(15,15)
         dc = wx.MemoryDC()
         dc.SelectObject(self.status_light)
         dc.SetBackground(wx.Brush("Red"))
         dc.Clear()
         dc.SelectObject(wx.NullBitmap)

         self.status_light_button = wx.BitmapButton(panel, -1,
self.status_light, style = 0)
         self.Bind(wx.EVT_BUTTON, self.OnStatusChange,
self.status_light_button)

         sizer.Add(self.status_light_button)

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

Murat Erten wrote:

Maybe you can try wx.NO_BORDER style like this:

self.status_light_button = wx.BitmapButton(panel, -1,
self.status_light, style = wx.NO_BORDER)

Thanks, that got rid of the border in until it's hovered over. In the end I'd rather attach the bitmap without it being a button, but this will work for now.

Rick

Richard Harding wrote:

Thanks, that got rid of the border in until it's hovered over. In the end I'd rather attach the bitmap without it being a button,

Then don't make it a Button!

self.status_light_button = wx.StaticBitmap(panel,
                                            bitmap=self.status_light)

# but I wouldn't call it a button anymore!
# and you can't bind EVT_BUTTON any more:
self.status_light_button.Bind(wx.EVT_LEFT_DOWN, self.OnStatusChange)

sizer.Add(self.status_light_button)

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Christopher Barker wrote:

Richard Harding wrote:

Thanks, that got rid of the border in until it's hovered over. In the end I'd rather attach the bitmap without it being a button,

Then don't make it a Button!

self.status_light_button = wx.StaticBitmap(panel,
                                           bitmap=self.status_light)

# but I wouldn't call it a button anymore!
# and you can't bind EVT_BUTTON any more:
self.status_light_button.Bind(wx.EVT_LEFT_DOWN, self.OnStatusChange)

sizer.Add(self.status_light_button)

Thanks, that worked great.

Rick

The 0 style doesn't remove the border. You need to use the wx.NO_BORDER to do that as in:

self.status_light_button = wx.BitmapButton(panel, -1, self.status_light, style = wx.NO_BORDER)

I think you might be mixing up the borders used in sizers and the borders controls have - this can sometimes be be confusing. A border of a window is something visible. It is usually a black line around the control or some kind of a 3D effect like the one used for buttons. Those are controlled with the style parameter you pass when you *create* the control such as in the code above. If you don't specify anything, the control will use its default border, which is the case of a BitmapButton is a raised bevel. There are also wx.SIMPLE_BORDER (a black line), wx.STATIC_BORDER (a sunken line around the control) and others.

The borders you use with sizer are completely different. Those are used exclusively for creating spaces between controls. You define those borders when you add a control to a sizer, as in :

sizer.Add(self.status_light_button, flag=wx.TOP | wx.BOTTOM, border=10)

The line above adds the status_light_button control to sizer and specified that a space of 10 pixels should be reserved both above and below it. Again, this is only a layout issue and doesn't influence the appearance of the control itself in any way - only its location (and perhaps size). There are 5 sizer flags that can be used with borders : wx.TOP, wx.BOTTOM, wx.LEFT, wx.RIGHT (you can use any combination of them) or wx.ALL which is a combination of all the others.

One final note: if you don't need a bitmap button, don't use one. You can use wx.StaticBitmap to display your red square instead.

Eli

Richard Harding wrote:

···

I'm trying to create a red square bitmap and attach it to a sizer I have. I found an example of manually creating the bitmap in the wxPython book, but it's for attaching to a toolbar. I've gotten the bitmap to attach as a button with the code below. I don't need it to be a button, but not sure how to attach it to the sizer correctly. I've tried changing the style to 0 on the button, but it doesn't seem to want to remove the border as it should.

Any help getting this on is appreciated.

Rick

Current code:
        self.status_light = wx.EmptyBitmap(15,15)
        dc = wx.MemoryDC()
        dc.SelectObject(self.status_light)
        dc.SetBackground(wx.Brush("Red"))
        dc.Clear()
        dc.SelectObject(wx.NullBitmap)

        self.status_light_button = wx.BitmapButton(panel, -1, self.status_light, style = 0)
        self.Bind(wx.EVT_BUTTON, self.OnStatusChange, self.status_light_button)

        sizer.Add(self.status_light_button)

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