Drawing a rubberband on a panel without redrawing everthing

Hi,

I use a wx.PaintDC() to draw shapes on a panel. After drawing the shapes, when I left click and drag mouse, a rubberband (transparent rectangle) is drawn over shapes. While dragging the mouse, for each motion of mouse, an EVT_PAINT is sent and everything (all shapes and rectangle) is redrawn.

How do I just draw the rubberband over the existing shapes (I don’t want to redraw the shapes), I mean, it would be nice if I can save the existing shapes on some DC object and just draw the rubberband on it. So that the application will draw it faster.

Thanks

Best regards

I use a wx.PaintDC() to draw shapes on a panel. After drawing the shapes,
when I left click and drag mouse, a rubberband (transparent rectangle) is
drawn over shapes. While dragging the mouse, for each motion of mouse, an
EVT_PAINT is sent and everything (all shapes and rectangle) is redrawn.

How do I just draw the rubberband over the existing shapes (I don't want
to redraw the shapes), I mean, it would be nice if I can save the existing
shapes on some DC object and just draw the rubberband on it. So that the
application will draw it faster.

look into:

wx.lib.floatcanvas
   FloatCanvas - wxPyWiki

(this may do everything for you already :slight_smile: )

Double Buffering:
  DoubleBufferedDrawing - wxPyWiki

I have bunch of demos of various stuff here:

I haven't tested most of them in years, but there's good stuff in there --
and PRs accepted if you find and fix issues!

Drawing with a "XOR" twice:
  wxPythonDemos/XOR_test.py at master · PythonCHB/wxPythonDemos · GitHub

wxOverlay:
  I've got 4(!) examples of Overlay here:

not sure why -- it's been a while!

This demo:

may be helpful.

-CHB

···

On Thu, Sep 22, 2016 at 5:45 AM, steve <oslocourse@gmail.com> wrote:

Thanks
Best regards

--
You received this message because you are subscribed to the Google Groups
"wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (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

Sir,

Thank you for the info.

I’d like to use wx.Overlay() but it doesn’t work when Double Buffering is turned on. Thus, I turn it off right before drawing the rubberband, and then turn it on again. Rubberband can be drawn using this workaround. But when I right click on the window to show a pop-up menu and then left click somewhere on the window to remove it, the screen flashes (although I had turned double buffering on). I don’t understand. Do you have any ideas why it happens?

Best regards

···

On Thursday, September 22, 2016 at 7:16:11 PM UTC+3, Chris Barker wrote:

On Thu, Sep 22, 2016 at 5:45 AM, steve osloc...@gmail.com wrote:

I use a wx.PaintDC() to draw shapes on a panel. After drawing the shapes, when I left click and drag mouse, a rubberband (transparent rectangle) is drawn over shapes. While dragging the mouse, for each motion of mouse, an EVT_PAINT is sent and everything (all shapes and rectangle) is redrawn.

How do I just draw the rubberband over the existing shapes (I don’t want to redraw the shapes), I mean, it would be nice if I can save the existing shapes on some DC object and just draw the rubberband on it. So that the application will draw it faster.

look into:

wx.lib.floatcanvas

https://wiki.wxpython.org/FloatCanvas

(this may do everything for you already :slight_smile: )

Double Buffering:

https://wiki.wxpython.org/DoubleBufferedDrawing

I have bunch of demos of various stuff here:

https://github.com/PythonCHB/wxPythonDemos

I haven’t tested most of them in years, but there’s good stuff in there – and PRs accepted if you find and fix issues!

Drawing with a “XOR” twice:

https://github.com/PythonCHB/wxPythonDemos/blob/master/XOR_test.py

wxOverlay:

I’ve got 4(!) examples of Overlay here:

https://github.com/PythonCHB/wxPythonDemos

not sure why – it’s been a while!

This demo:

https://github.com/PythonCHB/wxPythonDemos/blob/master/DrawingWhileMouseMoves.py

may be helpful.

-CHB

Thanks

Best regards

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Christopher Barker, Ph.D.
Oceanographer

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

Chris....@noaa.gov

Sorry,

I found wxOverlay to be a bit tricky – no idea about the flashing :frowning:

-CHB

···

On Thu, Sep 22, 2016 at 12:41 PM, steve oslocourse@gmail.com wrote:

Sir,

Thank you for the info.

I’d like to use wx.Overlay() but it doesn’t work when Double Buffering is turned on. Thus, I turn it off right before drawing the rubberband, and then turn it on again. Rubberband can be drawn using this workaround. But when I right click on the window to show a pop-up menu and then left click somewhere on the window to remove it, the screen flashes (although I had turned double buffering on). I don’t understand. Do you have any ideas why it happens?

Best regards

On Thursday, September 22, 2016 at 7:16:11 PM UTC+3, Chris Barker wrote:

On Thu, Sep 22, 2016 at 5:45 AM, steve osloc...@gmail.com wrote:

I use a wx.PaintDC() to draw shapes on a panel. After drawing the shapes, when I left click and drag mouse, a rubberband (transparent rectangle) is drawn over shapes. While dragging the mouse, for each motion of mouse, an EVT_PAINT is sent and everything (all shapes and rectangle) is redrawn.

How do I just draw the rubberband over the existing shapes (I don’t want to redraw the shapes), I mean, it would be nice if I can save the existing shapes on some DC object and just draw the rubberband on it. So that the application will draw it faster.

look into:

wx.lib.floatcanvas

https://wiki.wxpython.org/FloatCanvas

(this may do everything for you already :slight_smile: )

Double Buffering:

https://wiki.wxpython.org/DoubleBufferedDrawing

I have bunch of demos of various stuff here:

https://github.com/PythonCHB/wxPythonDemos

I haven’t tested most of them in years, but there’s good stuff in there – and PRs accepted if you find and fix issues!

Drawing with a “XOR” twice:

https://github.com/PythonCHB/wxPythonDemos/blob/master/XOR_test.py

wxOverlay:

I’ve got 4(!) examples of Overlay here:

https://github.com/PythonCHB/wxPythonDemos

not sure why – it’s been a while!

This demo:

https://github.com/PythonCHB/wxPythonDemos/blob/master/DrawingWhileMouseMoves.py

may be helpful.

-CHB

Thanks

Best regards

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Christopher Barker, Ph.D.
Oceanographer

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

Chris....@noaa.gov

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (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