views:

405

answers:

3

I would like to have a python gui that loads different images from files. I've seen many exmples of loading an image with some code like:

img = wx.Image("1.jpg", wx.BITMAP_TYPE_ANY, -1)
sb = wx.StaticBitmap(rightPanel, -1, wx.BitmapFromImage(img))
sizer.Add(sb)

It seems to be suited for an image that will be there for the entire life of the program. I could not find an elegant way to delete/reload images with this. Would using a wx.DC be a better idea for my application?

A: 

You don't have to delete the StaticBitmap, you can just set another bitmap to it using it's SetBitmap method.

If the new image has different dimensions you will probably have to do an explicit Layout call on it's parent so that the sizers would adjust.

Toni Ruža
I searched for the SetBitmap method, and it seems to be for a instances of wx.MenuItem. The image I'm displaying takes up about 1/4 of the GUI.
Derrick
Look again http://docs.wxwidgets.org/stable/wx_wxstaticbitmap.html#wxstaticbitmapsetbitmap
Toni Ruža
A: 

I read here: http://docs.wxwidgets.org/trunk/classwx%5Fstatic%5Fbitmap.html

"Native implementations on some platforms are only meant for display of the small icons in the dialog boxes. In particular, under Windows 9x the size of bitmap is limited to 64*64 pixels."

Which may be a problem. If you do use a DC, then you may have to "double buffer" it, or it may flicker on redraw, resize or update.

Otherwise it seems to me that you should use a "normal" Bitmap if you are oging to update it often.

Spacen Jasset
+1  A: 

If you have rapidly changing big images, or you would like some custom effect in future, it better to write your own control and doing painting using paintDC, and it is not that hard.

Doing your own drawing you can correctly scale, avoid flicker and may be do blend of one image into other if you like :)

Anurag Uniyal