Bitmap Button in StaticBoxSizer

I have a bitmap button in a StaticBoxSizer. I need to toggle the button between two images periodically (based on the status of of a device). To ‘change’ the bitmap button, do I need to detach the button from the sizer, destroy the button, recreate the button with the other bitmap, then add it to the sizer? Or is there a better way?

Thanks,
Patrick

Hi Patrick,

···

On Feb 26, 9:07 am, Patrick Tisdale <patrick.tisd...@gmail.com> wrote:

I have a bitmap button in a StaticBoxSizer. I need to toggle the button
between two images periodically (based on the status of of a device). To
'change' the bitmap button, do I need to detach the button from the sizer,
destroy the button, recreate the button with the other bitmap, then add it
to the sizer? Or is there a better way?

Thanks,
Patrick

I think it would be easier to just create two buttons and show/hide
them as needed. Put both in the sizer, hide the one you don't want to
see initially and then when you need to show it, hide the original
button. You may need to call Layout() after the show/hide.

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

Blog: http://blog.pythonlibrary.org

That worked perfectly!

Thanks,
Patrick

···

On Fri, Feb 26, 2010 at 10:32 AM, Mike Driscoll kyosohma@gmail.com wrote:

Hi Patrick,

On Feb 26, 9:07 am, Patrick Tisdale patrick.tisd...@gmail.com wrote:

I have a bitmap button in a StaticBoxSizer. I need to toggle the button

between two images periodically (based on the status of of a device). To

‘change’ the bitmap button, do I need to detach the button from the sizer,

destroy the button, recreate the button with the other bitmap, then add it

to the sizer? Or is there a better way?

Thanks,

Patrick

I think it would be easier to just create two buttons and show/hide

them as needed. Put both in the sizer, hide the one you don’t want to

see initially and then when you need to show it, hide the original

button. You may need to call Layout() after the show/hide.


Mike Driscoll

Blog: http://blog.pythonlibrary.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Mike Driscoll wrote:

I think it would be easier to just create two buttons and show/hide
them as needed. Put both in the sizer, hide the one you don't want to
see initially and then when you need to show it, hide the original
button. You may need to call Layout() after the show/hide.

couldn't you just call SetBitmap() on the button when you want to change it?

-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

button.SetBitmapLabel(newBitmap)

···

On 2/26/10 7:07 AM, Patrick Tisdale wrote:

I have a bitmap button in a StaticBoxSizer. I need to toggle the button
between two images periodically (based on the status of of a device).
To 'change' the bitmap button, do I need to detach the button from the
sizer, destroy the button, recreate the button with the other bitmap,
then add it to the sizer? Or is there a better way?

--
Robin Dunn
Software Craftsman

I couldn't tell from the docs if that would work or not and didn't
want to spend the time putting together a script to test it.

- Mike

···

On Feb 26, 12:01 pm, Chris Barker <Chris.Bar...@noaa.gov> wrote:

Mike Driscoll wrote:
> I think it would be easier to just create two buttons and show/hide
> them as needed. Put both in the sizer, hide the one you don't want to
> see initially and then when you need to show it, hide the original
> button. You may need to call Layout() after the show/hide.

couldn't you just call SetBitmap() on the button when you want to change it?

-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.Bar...@noaa.gov

If I’m using a png, does this mean that I’ll have to use img2py to convert it first?

···

On Fri, Feb 26, 2010 at 1:07 PM, Robin Dunn robin@alldunn.com wrote:

button.SetBitmapLabel(newBitmap)

Hi,

···

On Feb 26, 1:57 pm, Patrick Tisdale <patrick.tisd...@gmail.com> wrote:

If I'm using a png, does this mean that I'll have to use img2py to convert
it first?

On Fri, Feb 26, 2010 at 1:07 PM, Robin Dunn <ro...@alldunn.com> wrote:

> button.SetBitmapLabel(newBitmap)

> <http://groups.google.com/group/wxPython-users?hl=en&gt;

No, you should be able to do something like this:

button.SetBitmapLabel(wx.Bitmap(r"\\path\to\my.png"))

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

Blog: http://blog.pythonlibrary.org

This works, however I’m having trouble getting it to update. It only updates the bitmap at the next gui event(when I click on another button). I’ve tried button.GetParent().Layout(), but still no update.

BTW, this is a GenBitmapButton.

Thanks,
Patrick

···

On Fri, Feb 26, 2010 at 3:05 PM, Mike Driscoll kyosohma@gmail.com wrote:

No, you should be able to do something like this:

button.SetBitmapLabel(wx.Bitmap(r"\path\to\my.png"))


Hi,

···

On Wed, Mar 3, 2010 at 10:20 AM, Patrick Tisdale <patrick.tisdale@gmail.com> wrote:

On Fri, Feb 26, 2010 at 3:05 PM, Mike Driscoll <kyosohma@gmail.com> wrote:

No, you should be able to do something like this:

button.SetBitmapLabel(wx.Bitmap(r"\\path\to\my.png"))

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

This works, however I'm having trouble getting it to update. It only
updates the bitmap at the next gui event(when I click on another button).
I've tried button.GetParent().Layout(), but still no update.

BTW, this is a GenBitmapButton.

You might need to explicitly call

button.Refresh() and/or button.Update()

to get it to redraw itself sooner.

Cody

I should have known better than to post without searching the archives… button.Refresh() did the trick.

Thanks to everyone on this list! My first wxPython app, heck, my first real program of any sort, is complete (until the client wants a new feature).

Patrick

···

On Wed, Mar 3, 2010 at 11:20 AM, Patrick Tisdale patrick.tisdale@gmail.com wrote:

This works, however I’m having trouble getting it to update. It only updates the bitmap at the next gui event(when I click on another button). I’ve tried button.GetParent().Layout(), but still no update.

BTW, this is a GenBitmapButton.

Thanks,
Patrick