Drawing on a bitmap outside a paint event

Hello All,

I'd like to load a bitmap and paint on it when my application starts.
The code in http://codepad.org/1CmSzpgF does not work, however if
paint after button click (as in http://codepad.org/Ypbznqeh) I get the
drawing I want.

Is there way to know when it's possible to draw on an images?

Thanks,

···

--
Miki Tebeka <miki.tebeka@gmail.com>
http://mikitebeka.com
The only difference between children and adults is the price of the toys

Miki Tebeka wrote:

Hello All,

I'd like to load a bitmap and paint on it when my application starts.
The code in http://codepad.org/1CmSzpgF does not work, however if
paint after button click (as in http://codepad.org/Ypbznqeh) I get the
drawing I want.

Is there way to know when it's possible to draw on an images?

A wx.StaticBitmap is not a bitmap, it is a widget and it has the same paint behaviors as any other window. In your first example you are drawing on it before it is even shown, and so when it is shown it will (re)paint itself like it normally would (draw its bitmap and any borders if specified in the style). You second example also has a problem, try doing something that will cause it to be refreshed (like drag some other window over it.) You'll notice that it again draws the original bitmap.

If you really want to change the bitmap that the wx.StaticBitmap displays, and not just draw on the widget after the fact, then you can do it something like this:

import wx

class T(wx.Dialog):
     def __init__(self):
         wx.Dialog.__init__(self, None, -1)
         sizer = wx.BoxSizer(wx.VERTICAL)
         bmp = wx.Bitmap("0_0.png", wx.BITMAP_TYPE_PNG)

         dc = wx.MemoryDC(self.bmp)
         dc.SetPen(wx.Pen(wx.RED, 1))
         dc.SetBrush(wx.TRANSPARENT_BRUSH)
         dc.DrawCirclePoint((50, 50), 5)
         del dc

         self.sbmp = wx.StaticBitmap(self, -1, bmp)
         sizer.Add(self.sbmp)
         self.SetSizer(sizer)
         sizer.Fit(self)

if __name__ == "__main__":
     app = wx.PySimpleApp()
     dlg = T()
     dlg.ShowModal()

···

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

I'd like to load a bitmap and paint on it when my application starts.
The code in http://codepad.org/1CmSzpgF does not work,

A wx.StaticBitmap is not a bitmap, it is a widget and it has the same paint
...

Thanks Robin, excellent help (as always).

All the best

···

--
Miki Tebeka <miki.tebeka@gmail.com>

The only difference between children and adults is the price of the toys