Note that there are some explanatory texts on larger screens.

plurals
  1. POEliminate unnecessary drawing of an image when using dc?
    primarykey
    data
    text
    <p>I have three questions that I could really use some help on. Hope I'm not asking too much. </p> <p><strong>1)</strong> I am designing a simple GUI that contains one frame and one panel. Let's say I have two images that I draw on the panel using dc. One image will be continually fade in and out (on a timer), and the second is stationary (doesn't change). The fading is accomplished by changing the opacity of the image and use dc.Clear() before redrawing the new version of the image. </p> <p>My question is this: how would I draw the fading in/out image without affecting the second image which does not change? It seems like this causes unnecessary drawing as the stationary image will be redrawn alongside the fading image. Could I selectively clear just the first image without affecting the second? This is my drawing function:</p> <pre><code>def on_paint(self, event): dc = wx.PaintDC(self) dc = wx.BufferedDC(dc) brush = wx.Brush('#3B3B3B') dc.SetBackground(brush) dc.Clear() # Draw the first image (stationary) dc.DrawBitmap(stationaryBitmap, 120, 0, True) # Draw the second image (fading) image = self.image.AdjustChannels(1, 1, 1, self.factoralpha) fadingBitmap = wx.BitmapFromImage(image) dc.DrawBitmap(fadingBitmap, 120, 0, True) </code></pre> <p><strong>2)</strong> How can I bind an event to a wx.Image object? I would like to be able to click on the fading in/out image, though I can't seem to assign it an id. The goal is to bind an event similar to what I could do with a wx.StaticBitmap. </p> <pre><code>self.image = wx.Image("C:\image.png", wx.BITMAP_TYPE_PNG) # Trying to bind an event, but no ID is assigned self.Bind(wx.EVT_BUTTON, self.go_button, id=self.image.GetId()) </code></pre> <p><strong>3)</strong> Is it possible to place wx.DrawBitmap in a sizer? It appears that it only takes an x,y coordinate pair.</p> <pre><code>dc.DrawBitmap(bitmap, 120, 0, True) </code></pre> <p>Thanks everyone. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload