There are a number of approaches that could be used, and which is best
depends on the needs of your application. You could draw it all
yourself without using a separate wx.StaticBitmap, for example in a
paint event for the parent window draw the bitmap and then draw the
grid. Or you could create a new bitmap from the original image plus the
grid, using a wx.MemoryDC, and then either draw the new bitmap, or use
it in a wx.StaticBitmap, etc.
You should take a look at the ScrolledWindow sample in the demo (or
several others in the demo or the wiki) for an example of drawing things
on windows.
--
Robin Dunn
Software Craftsman
http://wxPython.org
On Wed, Apr 13, 2011 at 9:11 AM, PRobbins <pjrob...@gmail.com> wrote:
> Thanks for the help. One point I'm a little confused on...when
> exactly is Paint event actually called? In my application the image
> shows up on the screen unchanged at first. The user can choose a
> radio button for a 3x3, 6x6, 9x9 grid or no grid at all. I need the
> grid to show up as soon as the radio button is selected. Will a paint
> event be called? If not, can I manually call a paint event?
>
Yes, simply call Refresh() on the window that is bound to the paint event.
Cody
On Wed, Apr 13, 2011 at 9:50 AM, PRobbins <pjrob...@gmail.com> wrote:
> Ok I have implemented your suggestions and I can see bits of the grid
> sticking out from behind the image now and whenever the image
> refreshes I can briefly see the grid flash on the screen before it is
> covered up by the image. Any idea what's going on? How can I make my
> image transparent and/or put the grid on top? Sorry if some of these
> questions are elementary, this is really the first time I've worked
> with images in wxPython before.
>
Can't say without knowing what your doing.
Please make a runnable, small as possible sample
(http://wiki.wxpython.org/MakingSampleApps) that demonstrates the
problem.
I also attached a simple example that you can try out.
Regards,
Cody
https://www.packtpub.com/wxpython-2-8-application-development-cookbook/book
On Wed, Apr 13, 2011 at 10:39 AM, PRobbins <pjrob...@gmail.com> wrote:
> My application is quite large so I'm not sure I can make a small
> enough sample. Here is the relevant code from my program however:
>
> First I am creating a panel and putting a Static Bitmap on it:
Thats your problem then. The StaticBitmap is a separate window from
the one your drawing on. So your drawing on its parent and then the
StaticBitmap is getting displayed over it.
Draw the bitmap in the OnPaint handler instead of using a StaticBitmap
control. See the sample I attached to the previous message and replace
the DrawCircle code with DrawBitmap to draw your Bitmap instead.
Cody
On Wed, Apr 13, 2011 at 11:19 AM, PRobbins <pjrob...@gmail.com> wrote:
> Ok, I think I understand where you're going. I'm still taking baby
> steps with understanding how this works though. In my above code, I
> create the static bitmap and then every time the user asks the program
> to switch images, the bitmap is set to a new bitmap created from the
> image self.img. If I'm understanding you correctly, you want me to
> draw the new images bitmap in the OnPaint function, then draw the grid
> lines over it, right?
>
Yes, I think you will find that to work much better for this type of task.
Cody
p.s) this group prefers bottom posting when replying to messages.
(http://www.caliburn.nl/topposting.html)
On Wed, Apr 13, 2011 at 1:04 PM, PRobbins <pjrob...@gmail.com> wrote:
>
>
> I've played around with this suggestion a little bit and haven't made
> any worthwhile progress. I'm coming in and working on code that
> someone else has written so my hands are tied a little bit as far as
> restructuring it. I've poked around the forums and wxPython website/
> code samples a bit more and I was wondering if I could solve my
> problem by keeping the static bitmap and converting my image to a
> bitmap, using a memory DC, drawing the gridlines on it and loading the
> resulting bitmap into the static bitmap?
>
It adds some extra steps, but you can certainly do that too.
You would need to get rid of the OnPaint handling and add an method
that you would have to manually call when you change the grid layout
or image that is being displayed to update the StaticBitmap control
with a new Bitmap.
Pretty much been handed the code to do what you need to do already so
not sure what else you are stuck on at this point. Highly suggest
making a minimal sample app as mentioned before, as you there is a
good chance you would figure out what your doing wrong while writing
the sample.
Cody