buffered dc

In my GUI, I have a BufferedPaintDC with some lines drawn on it which updates whenever a user presses a certain button. One thing I’ve noticed is that even when this window with the DC is just minimized and then maximized again, it always takes 1 to 2 seconds for the drawn lines to re-appear. It is just a grey background in the interim. Is there any way to prevent this from happening? It doesn’t seem to stem from the code because nothing is being processed. It’s just that the window is being brought to the foreground again.

Thanks,
Gabriel

Gabriel Murray wrote:

In my GUI, I have a BufferedPaintDC with some lines drawn on it which updates whenever a user presses a certain button. One thing I've noticed is that even when this window with the DC is just minimized and then maximized again, it always takes 1 to 2 seconds for the drawn lines to re-appear. It is just a grey background in the interim. Is there any way to prevent this from happening? It doesn't seem to stem from the code because nothing is being processed. It's just that the window is being brought to the foreground again.

Are you doing anything in the EVT_SIZE handler? (Like recreating the buffer and redrawing the lines into it?)

Are you redrawing everything into the buffer again in the EVT_PAINT handler, or are you saving the buffer and only drawing the buffer to the window?

I experimented with the doodle sample with several thousand line segments and I never saw a delay longer than about a quarter second when restoring from minimized, switching to maximized, and back to unmaximized.

···

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

I am re-drawing to the buffer in the EVT_PAINT handler. About 1500 lines.
Gabriel

···

On 7/13/06, Robin Dunn <robin@alldunn.com > wrote:

Gabriel Murray wrote:

In my GUI, I have a BufferedPaintDC with some lines drawn on it which

updates whenever a user presses a certain button. One thing I’ve noticed
is that even when this window with the DC is just minimized and then
maximized again, it always takes 1 to 2 seconds for the drawn lines to

re-appear. It is just a grey background in the interim. Is there any way
to prevent this from happening? It doesn’t seem to stem from the code
because nothing is being processed. It’s just that the window is being

brought to the foreground again.

Are you doing anything in the EVT_SIZE handler? (Like recreating the
buffer and redrawing the lines into it?)

Are you redrawing everything into the buffer again in the EVT_PAINT

handler, or are you saving the buffer and only drawing the buffer to the
window?

I experimented with the doodle sample with several thousand line
segments and I never saw a delay longer than about a quarter second when

restoring from minimized, switching to maximized, and back to unmaximized.


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


To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org

For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Gabriel Murray wrote:

I am re-drawing to the buffer in the EVT_PAINT handler. About 1500 lines.

If you are saving the buffer then all you need to do in the EVT_PAINT handler is create the wx.BufferedPaintDC and then return and it will draw the current contents of the buffer for you. Please look at the doodle sample or items in the demo that use a a buffered DC.

···

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

Robin Dunn wrote:

Please look at the doodle sample or items in the demo that use a a buffered DC.

Also take a look at:

http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Ah okay - I realized after looking at doodle.py that I was writing all
my lines in the OnPaint() method rather than in a separate DrawLines()
method. I’ve tried to alter my code to look like doodle.py’s structure,
but now am not getting any output at all. This is supposed to be a
small box with a red background and half of it painted light blue. It
seems that the error is coming from the DrawLines() method but I don’t
see what it is.
Gabriel

···

###########
import wx

class MyPanel(wx.Panel):
def init(self,parent,id):
wx.Panel.init(self,parent,id,size=(250,500))

class MyFrame(wx.Frame):
def init(self):
wx.Frame.init(self, None, -1, ‘Global Context’, size=(250,500))
self.panel = MyPanel(self,-1)
self.SetBackgroundColour(“Red”)
self.InitBuffer()
self.panel.Bind(wx.EVT_PAINT, self.onPaint)

def InitBuffer(self):
    size = self.GetClientSize()
    self.buffer = wx.EmptyBitmap(size.width, size.height)
    dc = wx.BufferedDC(None, self.buffer)
    dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
    dc.Clear()
    self.DrawLines(dc)
    self.reInitBuffer = False

def DrawLines(self, dc):
   
    dc.BeginDrawing()
   
    y = 1
    while y < 250:
        self.pen = wx.Pen('Light Blue', 3, wx.SOLID)
        dc.SetPen(self.pen)
        x = 0
        coords = []
        while x < 251:
            coords.append((x,y,x+1,y+1))
            x += 1
       
        for eachcoord in coords:
            dc.DrawLine(*eachcoord)
       
        y += 1
    dc.EndDrawing()
   
def OnPaint(self,event):
    dc = wx.BufferedPaintDC(self, self.buffer)

app = wx.PySimpleApp(redirect=‘True’)

frm = MyFrame()
frm.SetSize((250,500))
frm.Show()

app.SetTopWindow(frm)
app.MainLoop()

########################
###########################

On 7/13/06, Christopher Barker Chris.Barker@noaa.gov wrote:

Robin Dunn wrote:

Please look at the
doodle sample or items in the demo that use a a buffered DC.

Also take a look at:

http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing

-Chris


Christopher Barker, Ph.D.
Oceanographer

NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov


To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Gabriel Murray wrote:

Ah okay - I realized after looking at doodle.py that I was writing all my lines in the OnPaint() method rather than in a separate DrawLines() method. I've tried to alter my code to look like doodle.py's structure, but now am not getting any output at all. This is supposed to be a small box with a red background and half of it painted light blue. It seems that the error is coming from the DrawLines() method but I don't see what it is.

The first problem is that you have an exception in the frame's __init__ that you are not seeing because of the output being redirected, so the app is not starting. (onPaint --> OnPaint)

The main problem is that you are catching the panel's EVT_PAINT event, but in the event you are drawing to the frame, whose client area is totally obscured by the panel, so even if it draws anything it woudl not be seen anyway. (self --> self.panel in OnPaint)

Finally, there are *much* more efficient ways to draw a rectangle than drawing 62499 1 lines of length 1.

buffdraw.py (1.36 KB)

···

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

Thanks, Robin! That solved it.
And the example wasn’t meant to be efficient. I was just showing a dc that involved a lot of redrawing to illustrate the issue.
Thanks again,
Gabriel

···

On 7/14/06, Robin Dunn robin@alldunn.com wrote:

Gabriel Murray wrote:

Ah okay - I realized after looking at doodle.py that I was writing all
my lines in the OnPaint() method rather than in a separate DrawLines()
method. I’ve tried to alter my code to look like doodle.py’s structure,
but now am not getting any output at all. This is supposed to be a small
box with a red background and half of it painted light blue. It seems
that the error is coming from the DrawLines() method but I don’t see

what it is.

The first problem is that you have an exception in the frame’s init
that you are not seeing because of the output being redirected, so the
app is not starting. (onPaint → OnPaint)

The main problem is that you are catching the panel’s EVT_PAINT event,
but in the event you are drawing to the frame, whose client area is
totally obscured by the panel, so even if it draws anything it woudl not

be seen anyway. (self → self.panel in OnPaint)

Finally, there are much more efficient ways to draw a rectangle than
drawing 62499 1 lines of length 1.


Robin Dunn
Software Craftsman

http://wxPython.org Java give you jitters? Relax with wxPython!


To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org