Problem with selection rectangle in ogl

Please make a runnable, small as possible, sample application that demonstrates the problem, and let us know the platform and wx version you are using. MakingSampleApps - wxPyWiki

···

On 12/21/12 3:54 AM, Adri�n Morales Torres wrote:

I would like to draw a selection rectangle when I drag with left button
in an ogl canvas written with wxpython. I have written the following
code to draw the selection rectangle for the OnDragLeft event:

     def OnDragLeft(self, draw, x, y, keys = 0, attachment = 0):
         dc = wx.ClientDC(self)
         del self ["SELEC"]
         self.GetDiagram().Clear(dc)
         self.update()
         self ["SELEC"] = ogl.RectangleShape(abs(x-self.xini),
abs(y-self.yini))
         self ["SELEC"].SetX((self.xini+x)/2)
         self ["SELEC"].SetY((self.yini+y)/2)
         self ["SELEC"].SetPen(wx.Pen((130,130,130), style=wx.DOT))
         self ["SELEC"].SetBrush(wx.TRANSPARENT_BRUSH)
         self ["SELEC"].Show(True)
         self ["SELEC"].Draw(dc)

self.xini and self.yini are the initial coordinates of the selection
rectangle. It works properly but the canvas is continuously being
refreshed, what makes the process slow. Do you know how could I draw
this rectangle without refreshing the canvas in each step?

--
Robin Dunn
Software Craftsman

You could certainly save some work by only creating the rectangle once and changing its size and/or position instead of deleting it and recreating it for every mouse drag event.

···

On 12/24/12 3:05 AM, Adri�n Morales Torres wrote:

Ok, I have made the following simple App which draws a selection
rectangle in a canvas when the mouse is left dragged:

I would like to avoid the clear and update processes because they make
the selection rectangle drawing slowlier. I am using Windows7 and
wxPython 2.8.12.1. Thank you.

--
Robin Dunn
Software Craftsman

I have tried to create
the rectangle once and changing its size and position with the OnDragLeftEvent.
I have made the attached simple app. But the selection rectangle is
drawn in each step and it is not erased, which produces many different
selection rectangles.

Thank you for your
help.

Test rect select.py (1.47 KB)