StaticBitmap and EVT_PAINT

Hello,

I am writting picture browser.

I have ScrolledWindow with GridSizer with images.

First I filled GridSizer with Panels with StaticBitmaps, it worked correctly, but was slow (sometime I have lots of images).

So I filled GridSizers with StaticBitmaps, without panels, and now I can’t detect when bitmaps are visible.
I use following code:

    bitmap.Bind(wx.EVT_LEFT_DOWN,self.OnClick)
    bitmap.Bind(wx.EVT_LEFT_DCLICK,self.OnDoubleClick)

    bitmap.Bind(wx.EVT_PAINT,self.OnPaint)

Both OnClick and OnDoubleClick are called correctly. OnPaint is never called.

Before I was using:

    panel.Bind(wx.EVT_PAINT,self.OnPaint)

(there was one panel for each bitmap), and OnPaint was called when bitmap was visible on screen.

  1. Why my bitmaps never receive EVT_PAINT?
  2. Is there a better way to detect when objects in GridSizer are visible?
···


Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies

Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from http://decopter.sf.net

Jacek Poplawski wrote:

Hello,

I am writting picture browser.

I have ScrolledWindow with GridSizer with images.

First I filled GridSizer with Panels with StaticBitmaps, it worked correctly, but was slow (sometime I have lots of images).
So I filled GridSizers with StaticBitmaps, without panels, and now I can't detect when bitmaps are visible.
I use following code:

        bitmap.Bind(wx.EVT_LEFT_DOWN,self.OnClick)
        bitmap.Bind(wx.EVT_LEFT_DCLICK,self.OnDoubleClick)
        bitmap.Bind(wx.EVT_PAINT,self.OnPaint)

Both OnClick and OnDoubleClick are called correctly. OnPaint is never called.

Before I was using:

        panel.Bind(wx.EVT_PAINT,self.OnPaint)

(there was one panel for each bitmap), and OnPaint was called when bitmap was visible on screen.

1) Why my bitmaps never receive EVT_PAINT?

It depends on the platform and the particular widget, but in some cases they are not real windows and are drawn directly on the parent. In other cases the native widget might capture events in a way that they can't be passed on to wx event handlers. There is a generic static bitmap widget in wx.lib.statbmp that you can use instead.

2) Is there a better way to detect when objects in GridSizer are visible?

I'm not sure what you need but using EVT_PAINT for this is probably a bad idea. Why can't you just check the child's position and size relative to the scroll offset and size of the client area of the parent window?

···

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