drawing with dc

http://66.25.177.168/~hperes/foolings/Threads.html

The above is a pretty diff.

Basically, I tried to take one thing (the dc) out of a method and bring
it up to the class level, yet it fails to work.

The original file is Threads.py from the demo which needs to be run with
run.py.

Hunter Peress wrote:

http://66.25.177.168/~hperes/foolings/Threads.html

The above is a pretty diff.

Basically, I tried to take one thing (the dc) out of a method and bring
it up to the class level, yet it fails to work.

The original file is Threads.py from the demo which needs to be run with
run.py.

You should probably use wxBufferedDC instead. See the wxScrolledWindow sample in the demo for an example of its use.

···

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

wxBufferedDC isnt in wx2.2

any ideas on how i could do it without 2.3.

···

On Wed, 2002-11-06 at 18:52, Robin Dunn wrote:

Hunter Peress wrote:
> http://66.25.177.168/~hperes/foolings/Threads.html
>
> The above is a pretty diff.
>
> Basically, I tried to take one thing (the dc) out of a method and bring
> it up to the class level, yet it fails to work.
>
> The original file is Threads.py from the demo which needs to be run with
> run.py.
>
>

You should probably use wxBufferedDC instead. See the wxScrolledWindow
sample in the demo for an example of its use.

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

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

Hunter Peress wrote:

wxBufferedDC isnt in wx2.2

any ideas on how i could do it without 2.3.

It's not all that hard to make a double buffered DC yourself.

> > http://66.25.177.168/~hperes/foolings/Threads.html
> >
> > The above is a pretty diff.

I can't access the above URL, so I don't know what it is you're trying
to do. If you post a succict explaination, I'll see if I have any ideas
for you.

NOTE: is upgrading wxPython out of the question?

-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

something that im making this for is only releasing with wx2.2 so far.

THe link works now, sorry.

Making a pointer on how to fix the code would help me the most.

···

On Fri, 2002-11-08 at 11:08, Chris Barker wrote:

Hunter Peress wrote:
> wxBufferedDC isnt in wx2.2
>
> any ideas on how i could do it without 2.3.

It's not all that hard to make a double buffered DC yourself.

> > > http://66.25.177.168/~hperes/foolings/Threads.html
> > >
> > > The above is a pretty diff.

I can't access the above URL, so I don't know what it is you're trying
to do. If you post a succict explaination, I'll see if I have any ideas
for you.

NOTE: is upgrading wxPython out of the question?

-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.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

For an example, please look at the code in CVS in the
http://qualm.sourceforge.net project. Specifically, look at the Buffer
and Canvas class. I also used these in creating the wxPyColourChooser
module, which I'm hoping to get into wxPython shortly :slight_smile:

             Regards,

                       -- Mike

···

On Fri, Nov 08 @ 02:04, Hunter Peress wrote:

wxBufferedDC isnt in wx2.2

any ideas on how i could do it without 2.3.

On Wed, 2002-11-06 at 18:52, Robin Dunn wrote:
> Hunter Peress wrote:
> > http://66.25.177.168/~hperes/foolings/Threads.html
> >
> > The above is a pretty diff.
> >
> > Basically, I tried to take one thing (the dc) out of a method and bring
> > it up to the class level, yet it fails to work.
> >
> > The original file is Threads.py from the demo which needs to be run with
> > run.py.
> >
> >
>
> You should probably use wxBufferedDC instead. See the wxScrolledWindow
> sample in the demo for an example of its use.
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
>
>

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

--
Michael Gilfix
mgilfix@eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html

Er, these are in graphs/graph_tools.py for reference :slight_smile:

···

On Fri, Nov 08 @ 14:25, Michael Gilfix wrote:

  For an example, please look at the code in CVS in the
http://qualm.sourceforge.net project. Specifically, look at the Buffer
and Canvas class. I also used these in creating the wxPyColourChooser
module, which I'm hoping to get into wxPython shortly :slight_smile:

             Regards,

                       -- Mike

On Fri, Nov 08 @ 02:04, Hunter Peress wrote:
> wxBufferedDC isnt in wx2.2
>
> any ideas on how i could do it without 2.3.
>
>
> On Wed, 2002-11-06 at 18:52, Robin Dunn wrote:
> > Hunter Peress wrote:
> > > http://66.25.177.168/~hperes/foolings/Threads.html
> > >
> > > The above is a pretty diff.
> > >
> > > Basically, I tried to take one thing (the dc) out of a method and bring
> > > it up to the class level, yet it fails to work.
> > >
> > > The original file is Threads.py from the demo which needs to be run with
> > > run.py.
> > >
> > >
> >
> > You should probably use wxBufferedDC instead. See the wxScrolledWindow
> > sample in the demo for an example of its use.
> >
> > --
> > Robin Dunn
> > Software Craftsman
> > http://wxPython.org Java give you jitters? Relax with wxPython!
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
> > For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org
>

--
Michael Gilfix
mgilfix@eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html

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

--
Michael Gilfix
mgilfix@eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html

Hunter Peress wrote:

THe link works now, sorry.

OK, I got it. I lost your original message, and I recall that I really
didn't understand what it is you were trying to do when I read it the
first time. However, I looked at your link, and found why the code there
didn't work:

(side note: please post a link to a code file in the future, tather than
html. I had to spend a little time fixing the code I cut & pasted form
my browser)

It looks like you were trying to double buffer the Graph Window. The
reason it didn't work was that you had the size wrong. You had set the
size in the GraphWindow __init__ function, but the window had not yet
been sized to fit the surrounding frame, so you were creating an off
screen buffer that was only 20X20, so of course it didn't draw right.
You were also re-setting the MemDC to a Null bitmap on every OnPaint,
which would kill it.

Fixing these two errors got it working, but I changed a couple of other
things as well. A MamDC is apparently a "scarce resource" on Windows, so
it's not a good idea to keep it around. Instead, you can keep the bitmap
around and re-selct it into a new MemDC when you want to draw to it. I
re-factored your code to do that. Also, you can use DC.DrawBitmap to
blit the offscreen bitmap to the PaintDC. (that there in 2.3.2 anyway,
iot may not be there in older versions, check out DrawIcon if not, or do
what you did with creating a MamDC, selecting the bitmap into it, and
then blitting to the PaintDC. If you do that, you probably want to pass
the MemDC into your draw function, so you can then use it to blit.

NOTES:

I hard-coded the size of the window and off screen bitmap, so if the
window is re-sized, the graphs themselves won't change. You may or may
not want that. If you want the graph to re-size, you need to capture the
OnSize events, and re-size your buffer then.

Why are you doing this anyway? Usually one double buffers so that a
drawing that takes a while to create can be stored, so that the window
will update itself very fast when it is uncovered, or whatever. In this
case, you are calling the Draw function if and only if an Paint event
has happened, so I don't see any apparent advantage.

The way double buffering is usually set up, is that there is an Update
function that updates the buffer, and then updates the screen with a
clientDC. In the OnPaint handler, all you do is Draw the buffer to the
screen, so it doesn't get re-drawn unless it needs to be. In this
example, the figure is getting constantly re-drawn, so there isn't much
point, and the way the demo is originaly written does a fine job. The
way I now have it working might be a slight improvement, because the
bitmap doesn't get re-created each time, but I'm not sure how
significant that is.

So, I got your code working, but either you are doing something
unneccessary, or I didn't get it doing what you want. How do you want it
to function differently than the original demo anyway?

By the way, what was wrong with your code wasn't really a problem of
understanding DCs and all that. If anything, it was a proble with
understanding when windows got sized, but the debugging required wasn
not the least wxWindows specific. Here's how I found it:

I noticed that something was getting drawn, but not the right thing (I
got a little blue splotch)

I put some print statements int he Draw() method, and noticed that only
the first bar was getting drawn.

I then figured out that that the only way out of the bar drawing lop was
the break ionside the checking for ypos being too big, so I put in a
print staement and discoved that self.size was way to small.

Also, the way I've factored the size code is not very clean, I would
redo that. Having a self.size member is a good idea, just make sure it
gets set to the right size! (maybe set it in a OnSize handler or
something)

-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

Hunter Peress wrote:

wxBufferedDC isnt in wx2.2

any ideas on how i could do it without 2.3.

wxBufferedDC and wxBufferedPaintDC are very simple and should be easily duplocated in wxPython code. The classes are defined here:

http://cvs.wxwindows.org/viewcvs.cgi/wxWindows/include/wx/dcbuffer.h?rev=1.3&content-type=text/vnd.viewcvs-markup

and the methods are defined here:

http://cvs.wxwindows.org/viewcvs.cgi/wxWindows/src/generic/dcbuffer.cpp?rev=1.2&content-type=text/vnd.viewcvs-markup

and an example of using it in Python is here:

http://cvs.wxwindows.org/viewcvs.cgi/wxWindows/wxPython/demo/wxScrolledWindow.py?rev=1.19.2.1&content-type=text/vnd.viewcvs-markup

···

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