[wx.DC] Delete a drawing

Hello, first of all the question: is it possible to delete a drawing done by
using tools such as dc.drawline or dc.drawcircle?

not su much delete, as re-draw without it.

DCs don't provide any persistance, etc by themselves, you need to
write all that yourself, or use a library someone else as already
written:

wx.lib.floatcanvas: for object-persistant, scalable drawing
wx.lib.ogl: for "boxes with lines" type drawings

If you want to write it from scratch yourself, take a look at the
wiki, with a search for "drawing":

http://wiki.wxpython.org/FrontPage?action=fullsearch&context=180&value=drawing&titlesearch=Titles

Sample file attached

ouch!

  def on_paint(self, event):
    #painting surface
    global dc

you do not want to do this -- first, global is almost never the right
way to do this, second, you really don't want to use it for things
like dcs.

I couldn't help myse4lf, so I re-fatored it for you, see enclosed.

Note that this really needs some more cleaning up. Be sure to check out:

http://wiki.wxpython.org/wxPython%20Style%20Guide

and maybe:

http://wiki.wxpython.org/ModelViewController
and
http://wiki.wxpython.org/ModelViewPresenter

i.e: even if you dont do full-on MVC or MVP, you probably want simpel
data model that captures the sate of the drawing, and have the buttons
change that data model, and have the drawing code draw baed on the
contents of that data model -- the model could be as simple as a dict.

-HTH,
  -Chris

wx_draw2.py (2.43 KB)

···

On Tue, Feb 12, 2013 at 7:47 AM, <andreafran@gmail.com> wrote:

--

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

ok I will take a look at them… and thankyou for the file, I knew it was not right to make DC global but I was in a hurry… :wink:

@Tim: yes with just three objects redraw the scene is the best choice but I’m thinking about drawing grids on top of webcam videos, and redraw all is not possible

Andrea

···

Il giorno martedì 12 febbraio 2013 18:48:50 UTC+1, Chris Barker - NOAA Federal ha scritto:

wx.lib.floatcanvas: for object-persistant, scalable drawing

wx.lib.ogl: for “boxes with lines” type drawings

then you'll want to double buffer -- so you only re-draw what's changing.

or wx.Overlay may be helpful.

-Chris

···

On Wed, Feb 13, 2013 at 1:50 AM, <andreafran@gmail.com> wrote:

@Tim: yes with just three objects redraw the scene is the best choice but
I'm thinking about drawing grids on top of webcam videos, and redraw all is
not possible

--

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

andreafran@gmail.com wrote:

@Tim: yes with just three objects redraw the scene is the best choice
but I'm thinking about drawing grids on top of webcam videos, and
redraw all is not possible

Sure it is. With a webcam, the image gets redrawn 30 times per second
anyway, so your graphics are going to be erased as soon as you draw them.

The RIGHT way to do something like this is to use a "colorkey", which is
very similar to the green screen technology you see on television. When
you set up a graph to do video capture, the stream usually gets drawn
into an overlay surface or a texture surface on the graphics card. You
can draw your onscreen window using a solid color, then tell the
renderer that this color is your "colorkey". The graphics card will
then replace the colorkey pixels with pixels from the movie.

Now, you can draw on your window in some other color. Anywhere the
pixels do not match the colorkey color, your pixels will show through.
You let the movie show through again by drawing over it in the colorkey
color.

However, I'm not sure how you're going to do all of this from Python.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

well, PyOpenGL would probably let you do that == or something like it.

But I doubt it's necessary -- computers are fast these days! If you
are drawing on order of 100 simple objects, I can't imagine you'd have
a problem.

-Chris

···

On Wed, Feb 13, 2013 at 9:53 AM, Tim Roberts <timr@probo.com> wrote:

However, I'm not sure how you're going to do all of this from Python.

--

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

wx.Overlay looks promising… I have to do some testing