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.
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!
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.
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!
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))
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.
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
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.