wx.lib.plot, PlotCanvas, and wx.DC drawing problem

Denis Spasyuk wrote:

Hi Guys,

I am trying to draw on PlotCanvas using wx.DC module. I have several
problems with drawing on WXBufferedPaintDC, for some reason my DC text
disappears after windows resizing and it looks that I draw my text in
the wrong place. Any help appreciated. Here is my code:

There are several issues here, although I'm not sure any of them by
themselves would cause this issue.

There is no point in creating a wx.BufferedDC during __init__. At that
point, your window does not exist yet, so there's nothing to draw on.

Don't call UpdateDrawing during wx.Paint. UpdateDrawing is just a
placeholder that you copied from an example. It's supposed to represent
a function that recreates whatever needs to be in the bitmap, such as
when the window changes size. The whole point here is that you don't
need to recreate the drawing at OnPaint time. You just update your
bitmap when updates are available, then the buffered DC will copy
whatever's in the bitmap to the live window.

You need to decide whether the bitmap reflects the entire wx.Frame or
just the plot_window.canvas. You have it both ways here.

In mouseleftdown, you probably don't want to use the BufferedDC either.
You would use a MemoryDC, do whatever drawing you need to do, then call
self.Refresh() to cause OnPaint to execute, which will send the bitmap
to the live window.

···

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

Thanks you Tim! This is my first experience with wx.lib.plot and literature on this subject is somewhat conflicting. Thank you for your help!
I will incorporate these changes in my code.

···

On Monday, May 4, 2015 at 11:26:52 AM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:

Hi Guys,

I am trying to draw on PlotCanvas using wx.DC module. I have several

problems with drawing on WXBufferedPaintDC, for some reason my DC text

disappears after windows resizing and it looks that I draw my text in

the wrong place. Any help appreciated. Here is my code:

There are several issues here, although I’m not sure any of them by

themselves would cause this issue.

There is no point in creating a wx.BufferedDC during init. At that

point, your window does not exist yet, so there’s nothing to draw on.

Don’t call UpdateDrawing during wx.Paint. UpdateDrawing is just a

placeholder that you copied from an example. It’s supposed to represent

a function that recreates whatever needs to be in the bitmap, such as

when the window changes size. The whole point here is that you don’t

need to recreate the drawing at OnPaint time. You just update your

bitmap when updates are available, then the buffered DC will copy

whatever’s in the bitmap to the live window.

You need to decide whether the bitmap reflects the entire wx.Frame or

just the plot_window.canvas. You have it both ways here.

In mouseleftdown, you probably don’t want to use the BufferedDC either.
You would use a MemoryDC, do whatever drawing you need to do, then call

self.Refresh() to cause OnPaint to execute, which will send the bitmap

to the live window.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Hi Tim,

I have modified the code according to your suggestions and everything looks fine, however, when I call dc.DrawText from within mouseleftdown function together with a Textlabel I get black square in the left-top conner. I tried to play with MemoryDC instead of BufferedPaintDC but I am not able to draw anything using this method. I have attached my new code, I would appreciate if you could take a look at it. Thank you in advance!

cheers

denis

code.py (1.76 KB)

···

On Monday, May 4, 2015 at 6:05:25 PM UTC-6, Denis Spasyuk wrote:

Thanks you Tim! This is my first experience with wx.lib.plot and literature on this subject is somewhat conflicting. Thank you for your help!
I will incorporate these changes in my code.

On Monday, May 4, 2015 at 11:26:52 AM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:

Hi Guys,

I am trying to draw on PlotCanvas using wx.DC module. I have several

problems with drawing on WXBufferedPaintDC, for some reason my DC text

disappears after windows resizing and it looks that I draw my text in

the wrong place. Any help appreciated. Here is my code:

There are several issues here, although I’m not sure any of them by

themselves would cause this issue.

There is no point in creating a wx.BufferedDC during init. At that

point, your window does not exist yet, so there’s nothing to draw on.

Don’t call UpdateDrawing during wx.Paint. UpdateDrawing is just a

placeholder that you copied from an example. It’s supposed to represent

a function that recreates whatever needs to be in the bitmap, such as

when the window changes size. The whole point here is that you don’t

need to recreate the drawing at OnPaint time. You just update your

bitmap when updates are available, then the buffered DC will copy

whatever’s in the bitmap to the live window.

You need to decide whether the bitmap reflects the entire wx.Frame or

just the plot_window.canvas. You have it both ways here.

In mouseleftdown, you probably don’t want to use the BufferedDC either.
You would use a MemoryDC, do whatever drawing you need to do, then call

self.Refresh() to cause OnPaint to execute, which will send the bitmap

to the live window.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Denis Spasyuk wrote:

I have modified the code according to your suggestions and everything
looks fine, however, when I call dc.DrawText from within mouseleftdown
function together with a Textlabel I get black square in the left-top
conner. I tried to play with MemoryDC instead of BufferedPaintDC but I
am not able to draw anything using this method. I have attached my new
code, I would appreciate if you could take a look at it.

It seems like you're flailing at random here.

The code you attached does not work. It does not have a TextLabel.
PaintDC objects can only be created within a Paint handler.

You need to step back for a few minutes and describe what you are trying
to do, step by step, in words, and in detail. When you do that kind of
exercise, it's usually possible to map the words directly to Python code.

···

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

Thank Tim for your reply. I am not sure why code does not work in your hands. I am using Ubuntu 14.04. Anyway, here is another code which I took from here http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/ and slightly modified it. I would like to be able to draw text in the graph window, for example to label graphs or to make notes on the graph. If I use normal wx.DC not buffered drawn labels disappear after screen resize, so that reason I would like to use buffered DC module. So the code I’ve attached draws a bar graph and on left mouse click sets labels, but together with labels I get black square at the top left conner of the graph. See attached…

Thank you for your help,

denis

code.py (2.92 KB)

···

On Tuesday, May 5, 2015 at 10:45:16 AM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:

I have modified the code according to your suggestions and everything

looks fine, however, when I call dc.DrawText from within mouseleftdown

function together with a Textlabel I get black square in the left-top

conner. I tried to play with MemoryDC instead of BufferedPaintDC but I

am not able to draw anything using this method. I have attached my new

code, I would appreciate if you could take a look at it.

It seems like you’re flailing at random here.

The code you attached does not work. It does not have a TextLabel.
PaintDC objects can only be created within a Paint handler.

You need to step back for a few minutes and describe what you are trying

to do, step by step, in words, and in detail. When you do that kind of

exercise, it’s usually possible to map the words directly to Python code.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Thank Tim for your reply. I am not sure why code does not work in your
hands. I am using Ubuntu 14.04.

the platfroms are a bit different. If you do things teh "right" way, they
usually work accross platfroms, but you can get awy with different erors on
different platfroms.

You are using a PaintDC outside of a Paint Event -- that may kinda-sorta
work on GTK, but Windows is more sensitive to that.

Sorry, I'm not really set up for testing this now (crashed computer :frowning: ),
but a couple comments:

read up on the various DCs here:

http://wiki.wxpython.org/CustomisedDrawing

and other pages in the Wiki you find with a search for "graphics" -- that
should help you sort it out.

But your real trick here is that the PlotCanvas is handling the drawing
here -- if you draw something on top of it, it will probably get erased on
the next paint event.

I'd probably look at the PlotCanvas code, and see if you can add some
labeling there -- writing directly to its buffer.

Note that that is a very limited widget -- you may be better off using a
full featured plotting lib, like Matplotlib -- it can be embedded in wx,
and has some really nice labeling features.

If you really want to draw on top of the PlotCanvas, you'll need to capture
the Paint Event, and make sure that you draw your stuff, with a PaintDC,
inside that paint event -- that way it should always get re-drawn whenever
the Window gets refreshed.

In this case, I'd probably store the text and coords you want them drawn in
the class, and actually draw it in the Paint event. Then whenever the data
changes (on the mouse event), you change those attributes, and then call
Refresh() and Update() t force a new Paint event.

Another option is to use wx.lib.floatcanvas -- it doesn't have the plotting
stuff out of the box, but does have text pbjects, etc, etc, to make par tof
this easy. Take a look at the demos here:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/

BarPlot.py might be a helpful start.

Good luck,

-Chris

···

On Tue, May 5, 2015 at 11:10 AM, Denis Spasyuk <denis.spasyuk@gmail.com> wrote:

Anyway, here is another code which I took from here
http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/
and slightly modified it. I would like to be able to draw text in the graph
window, for example to label graphs or to make notes on the graph. If I use
normal wx.DC not buffered drawn labels disappear after screen resize, so
that reason I would like to use buffered DC module. So the code I've
attached draws a bar graph and on left mouse click sets labels, but
together with labels I get black square at the top left conner of the
graph. See attached...

Thank you for your help,

denis

On Tuesday, May 5, 2015 at 10:45:16 AM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:
>
> I have modified the code according to your suggestions and everything
> looks fine, however, when I call dc.DrawText from within mouseleftdown
> function together with a Textlabel I get black square in the left-top
> conner. I tried to play with MemoryDC instead of BufferedPaintDC but I
> am not able to draw anything using this method. I have attached my new
> code, I would appreciate if you could take a look at it.

It seems like you're flailing at random here.

The code you attached does not work. It does not have a TextLabel.
PaintDC objects can only be created within a Paint handler.

You need to step back for a few minutes and describe what you are trying
to do, step by step, in words, and in detail. When you do that kind of
exercise, it's usually possible to map the words directly to Python code.

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

--

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

Thank you Chris! I was looking into matplotlib earlier but it’s size over 100 mb plus the fact that it’s an external lib to wx kind of kept me away from it. It would be nice to have a small plotting lib with wx. I am aware of floatcanvas, but I cannot say I know much about it. Thank you for the example and suggestions, appreciated. The example I’ve attached in my last post, seem to work and labels redraw themselves after leftmouseclick function. So, it looks like it will work, my problem is with black square in the top-left conner.

thanks for everything,

Denis

···

On Wednesday, May 6, 2015 at 9:52:01 AM UTC-6, Chris Barker wrote:

On Tue, May 5, 2015 at 11:10 AM, Denis Spasyuk denis....@gmail.com wrote:

Thank Tim for your reply. I am not sure why code does not work in your hands. I am using Ubuntu 14.04.

the platfroms are a bit different. If you do things teh “right” way, they usually work accross platfroms, but you can get awy with different erors on different platfroms.

You are using a PaintDC outside of a Paint Event – that may kinda-sorta work on GTK, but Windows is more sensitive to that.

Sorry, I’m not really set up for testing this now (crashed computer :frowning: ), but a couple comments:

read up on the various DCs here:

http://wiki.wxpython.org/CustomisedDrawing

and other pages in the Wiki you find with a search for “graphics” – that should help you sort it out.

But your real trick here is that the PlotCanvas is handling the drawing here – if you draw something on top of it, it will probably get erased on the next paint event.

I’d probably look at the PlotCanvas code, and see if you can add some labeling there – writing directly to its buffer.

Note that that is a very limited widget – you may be better off using a full featured plotting lib, like Matplotlib – it can be embedded in wx, and has some really nice labeling features.

If you really want to draw on top of the PlotCanvas, you’ll need to capture the Paint Event, and make sure that you draw your stuff, with a PaintDC, inside that paint event – that way it should always get re-drawn whenever the Window gets refreshed.

In this case, I’d probably store the text and coords you want them drawn in the class, and actually draw it in the Paint event. Then whenever the data changes (on the mouse event), you change those attributes, and then call Refresh() and Update() t force a new Paint event.

Another option is to use wx.lib.floatcanvas – it doesn’t have the plotting stuff out of the box, but does have text pbjects, etc, etc, to make par tof this easy. Take a look at the demos here:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/

BarPlot.py might be a helpful start.

Good luck,

-Chris

Anyway, here is another code which I took from here http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/ and slightly modified it. I would like to be able to draw text in the graph window, for example to label graphs or to make notes on the graph. If I use normal wx.DC not buffered drawn labels disappear after screen resize, so that reason I would like to use buffered DC module. So the code I’ve attached draws a bar graph and on left mouse click sets labels, but together with labels I get black square at the top left conner of the graph. See attached…

Thank you for your help,

denis

On Tuesday, May 5, 2015 at 10:45:16 AM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:

I have modified the code according to your suggestions and everything

looks fine, however, when I call dc.DrawText from within mouseleftdown

function together with a Textlabel I get black square in the left-top

conner. I tried to play with MemoryDC instead of BufferedPaintDC but I

am not able to draw anything using this method. I have attached my new

code, I would appreciate if you could take a look at it.

It seems like you’re flailing at random here.

The code you attached does not work. It does not have a TextLabel.
PaintDC objects can only be created within a Paint handler.

You need to step back for a few minutes and describe what you are trying

to do, step by step, in words, and in detail. When you do that kind of

exercise, it’s usually possible to map the words directly to Python code.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

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

Denis Spasyuk wrote:

Thank Tim for your reply. I am not sure why code does not work in your
hands. I am using Ubuntu 14.04.

It's because I'm using Windows. Your code IS incorrect; a
BufferedPaintDC can only be used inside an EVT_PAINT handler. The fact
that it happens to work on Linux is an accident.

Anyway, here is another code which I took from here
http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/
and slightly modified it. I would like to be able to draw text in the
graph window, for example to label graphs or to make notes on the
graph. If I use normal wx.DC not buffered drawn labels disappear after
screen resize, so that reason I would like to use buffered DC module.

OK, but again you're not thinking this through. If you want to use a
buffered DC, then ALL drawing has to be done through your buffered
bitmap, including the plot. As it is, you create a new, empty (all
black) bitmap and draw something in it. When the buffered DC is
destroyed, it then flushes that output to the screen, which wipes out
whatever was there before hand.

If you want your annotations to persist, then you need to make sure they
get redrawn during the paint handling, where the plot will redraw
itself. It seems to me that the easy way to do that is just to keep a
record of your annotations, then redraw them all in your paint handler
after the plot has drawn itself. The attached code does that.

NOTE, however, that there is an issue. You're remembering the X and Y
coordinates of the original click. When you resize the window, those
coordinates don't match any more. That problem is clearly solvable, by
handling the EVT_SIZE message and adjusting the coordinates. I'll leave
that as an exercise.

code.py (3.23 KB)

···

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

Thank you Chris! I was looking into matplotlib earlier but it's size over
100 mb plus the fact that it's an external lib to wx kind of kept me away
from it.

yes, it is a heavy dependency.

It would be nice to have a small plotting lib with wx. I am aware of
floatcanvas, but I cannot say I know much about it. Thank you for the
example and suggestions, appreciated. The example I've attached in my last
post, seem to work and labels redraw themselves after leftmouseclick
function. So, it looks like it will work, my problem is with black square
in the top-left corner.

As Tim said -- the fact that it works at all is an accident on GTK -- you
really don't want to rely on that.

If you stick with PlotCanvas, I'd poke into the code and see if you can
find its DC -- I updated that code ages ago, so I may not be corect, but I
think it's double buffered, so you may be able to grab its bitmap and draw
directly to that.

-CHB

thanks for everything,

···

On Wed, May 6, 2015 at 10:28 AM, Denis Spasyuk <denis.spasyuk@gmail.com> wrote:

Denis

On Wednesday, May 6, 2015 at 9:52:01 AM UTC-6, Chris Barker wrote:

On Tue, May 5, 2015 at 11:10 AM, Denis Spasyuk <denis....@gmail.com> >> wrote:

Thank Tim for your reply. I am not sure why code does not work in your
hands. I am using Ubuntu 14.04.

the platfroms are a bit different. If you do things teh "right" way, they
usually work accross platfroms, but you can get awy with different erors on
different platfroms.

You are using a PaintDC outside of a Paint Event -- that may kinda-sorta
work on GTK, but Windows is more sensitive to that.

Sorry, I'm not really set up for testing this now (crashed computer :frowning:
), but a couple comments:

read up on the various DCs here:

CustomisedDrawing - wxPyWiki

and other pages in the Wiki you find with a search for "graphics" -- that
should help you sort it out.

But your real trick here is that the PlotCanvas is handling the drawing
here -- if you draw something on top of it, it will probably get erased on
the next paint event.

I'd probably look at the PlotCanvas code, and see if you can add some
labeling there -- writing directly to its buffer.

Note that that is a very limited widget -- you may be better off using a
full featured plotting lib, like Matplotlib -- it can be embedded in wx,
and has some really nice labeling features.

If you really want to draw on top of the PlotCanvas, you'll need to
capture the Paint Event, and make sure that you draw your stuff, with a
PaintDC, inside that paint event -- that way it should always get re-drawn
whenever the Window gets refreshed.

In this case, I'd probably store the text and coords you want them drawn
in the class, and actually draw it in the Paint event. Then whenever the
data changes (on the mouse event), you change those attributes, and then
call Refresh() and Update() t force a new Paint event.

Another option is to use wx.lib.floatcanvas -- it doesn't have the
plotting stuff out of the box, but does have text pbjects, etc, etc, to
make par tof this easy. Take a look at the demos here:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/

BarPlot.py might be a helpful start.

Good luck,

-Chris

Anyway, here is another code which I took from here
http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/
and slightly modified it. I would like to be able to draw text in the graph
window, for example to label graphs or to make notes on the graph. If I use
normal wx.DC not buffered drawn labels disappear after screen resize, so
that reason I would like to use buffered DC module. So the code I've
attached draws a bar graph and on left mouse click sets labels, but
together with labels I get black square at the top left conner of the
graph. See attached...

Thank you for your help,

denis

On Tuesday, May 5, 2015 at 10:45:16 AM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:
>
> I have modified the code according to your suggestions and everything
> looks fine, however, when I call dc.DrawText from within
mouseleftdown
> function together with a Textlabel I get black square in the
left-top
> conner. I tried to play with MemoryDC instead of BufferedPaintDC but
I
> am not able to draw anything using this method. I have attached my
new
> code, I would appreciate if you could take a look at it.

It seems like you're flailing at random here.

The code you attached does not work. It does not have a TextLabel.
PaintDC objects can only be created within a Paint handler.

You need to step back for a few minutes and describe what you are
trying
to do, step by step, in words, and in detail. When you do that kind of
exercise, it's usually possible to map the words directly to Python
code.

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

--

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

thanks Chris!

···

On Wednesday, May 6, 2015 at 1:29:17 PM UTC-6, Chris Barker wrote:

On Wed, May 6, 2015 at 10:28 AM, Denis Spasyuk denis....@gmail.com wrote:

Thank you Chris! I was looking into matplotlib earlier but it’s size over 100 mb plus the fact that it’s an external lib to wx kind of kept me away from it.

yes, it is a heavy dependency.

It would be nice to have a small plotting lib with wx. I am aware of floatcanvas, but I cannot say I know much about it. Thank you for the example and suggestions, appreciated. The example I’ve attached in my last post, seem to work and labels redraw themselves after leftmouseclick function. So, it looks like it will work, my problem is with black square in the top-left corner.

As Tim said – the fact that it works at all is an accident on GTK – you really don’t want to rely on that.

If you stick with PlotCanvas, I’d poke into the code and see if you can find its DC – I updated that code ages ago, so I may not be corect, but I think it’s double buffered, so you may be able to grab its bitmap and draw directly to that.

-CHB

thanks for everything,

Denis

On Wednesday, May 6, 2015 at 9:52:01 AM UTC-6, Chris Barker wrote:

On Tue, May 5, 2015 at 11:10 AM, Denis Spasyuk denis....@gmail.com wrote:

Thank Tim for your reply. I am not sure why code does not work in your hands. I am using Ubuntu 14.04.

the platfroms are a bit different. If you do things teh “right” way, they usually work accross platfroms, but you can get awy with different erors on different platfroms.

You are using a PaintDC outside of a Paint Event – that may kinda-sorta work on GTK, but Windows is more sensitive to that.

Sorry, I’m not really set up for testing this now (crashed computer :frowning: ), but a couple comments:

read up on the various DCs here:

http://wiki.wxpython.org/CustomisedDrawing

and other pages in the Wiki you find with a search for “graphics” – that should help you sort it out.

But your real trick here is that the PlotCanvas is handling the drawing here – if you draw something on top of it, it will probably get erased on the next paint event.

I’d probably look at the PlotCanvas code, and see if you can add some labeling there – writing directly to its buffer.

Note that that is a very limited widget – you may be better off using a full featured plotting lib, like Matplotlib – it can be embedded in wx, and has some really nice labeling features.

If you really want to draw on top of the PlotCanvas, you’ll need to capture the Paint Event, and make sure that you draw your stuff, with a PaintDC, inside that paint event – that way it should always get re-drawn whenever the Window gets refreshed.

In this case, I’d probably store the text and coords you want them drawn in the class, and actually draw it in the Paint event. Then whenever the data changes (on the mouse event), you change those attributes, and then call Refresh() and Update() t force a new Paint event.

Another option is to use wx.lib.floatcanvas – it doesn’t have the plotting stuff out of the box, but does have text pbjects, etc, etc, to make par tof this easy. Take a look at the demos here:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/FloatCanvas/Demos/

BarPlot.py might be a helpful start.

Good luck,

-Chris

Anyway, here is another code which I took from here http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/ and slightly modified it. I would like to be able to draw text in the graph window, for example to label graphs or to make notes on the graph. If I use normal wx.DC not buffered drawn labels disappear after screen resize, so that reason I would like to use buffered DC module. So the code I’ve attached draws a bar graph and on left mouse click sets labels, but together with labels I get black square at the top left conner of the graph. See attached…

Thank you for your help,

denis

On Tuesday, May 5, 2015 at 10:45:16 AM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:

I have modified the code according to your suggestions and everything

looks fine, however, when I call dc.DrawText from within mouseleftdown

function together with a Textlabel I get black square in the left-top

conner. I tried to play with MemoryDC instead of BufferedPaintDC but I

am not able to draw anything using this method. I have attached my new

code, I would appreciate if you could take a look at it.

It seems like you’re flailing at random here.

The code you attached does not work. It does not have a TextLabel.
PaintDC objects can only be created within a Paint handler.

You need to step back for a few minutes and describe what you are trying

to do, step by step, in words, and in detail. When you do that kind of

exercise, it’s usually possible to map the words directly to Python code.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

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-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

Ah, I see now. Thank you very much, Tim!

···

On Wednesday, May 6, 2015 at 11:45:32 AM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:

Thank Tim for your reply. I am not sure why code does not work in your

hands. I am using Ubuntu 14.04.

It’s because I’m using Windows. Your code IS incorrect; a

BufferedPaintDC can only be used inside an EVT_PAINT handler. The fact

that it happens to work on Linux is an accident.

Anyway, here is another code which I took from here

http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/

and slightly modified it. I would like to be able to draw text in the

graph window, for example to label graphs or to make notes on the

graph. If I use normal wx.DC not buffered drawn labels disappear after

screen resize, so that reason I would like to use buffered DC module.

OK, but again you’re not thinking this through. If you want to use a

buffered DC, then ALL drawing has to be done through your buffered

bitmap, including the plot. As it is, you create a new, empty (all

black) bitmap and draw something in it. When the buffered DC is

destroyed, it then flushes that output to the screen, which wipes out

whatever was there before hand.

If you want your annotations to persist, then you need to make sure they

get redrawn during the paint handling, where the plot will redraw

itself. It seems to me that the easy way to do that is just to keep a

record of your annotations, then redraw them all in your paint handler

after the plot has drawn itself. The attached code does that.

NOTE, however, that there is an issue. You’re remembering the X and Y

coordinates of the original click. When you resize the window, those

coordinates don’t match any more. That problem is clearly solvable, by

handling the EVT_SIZE message and adjusting the coordinates. I’ll leave

that as an exercise.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

Hi Tim,

I’ve looked at your code but it does not do what I want it to do. I can draw myself on wx.ClientDC or wx.PaintDC with no problems, and there are tons of examples of wx.ClientDC usage. My problem, as I’ve mentioned in my first post, is drawing using wx.BufferedDC or by using wxMemoryDC to avoid label disappearance on resize. And I cannot find an example where wx.BufferedDC is used to draw on a Graph created via wx.lib.plot.PlotCanvas. Anyway, I do not want to waist your time with this.

thank you for your help,

cheers,

Denis

···

On Wednesday, May 6, 2015 at 11:45:32 AM UTC-6, Tim Roberts wrote

Denis Spasyuk wrote:

Thank Tim for your reply. I am not sure why code does not work in your

hands. I am using Ubuntu 14.04.

It’s because I’m using Windows. Your code IS incorrect; a

BufferedPaintDC can only be used inside an EVT_PAINT handler. The fact

that it happens to work on Linux is an accident.

Anyway, here is another code which I took from here

http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/

and slightly modified it. I would like to be able to draw text in the

graph window, for example to label graphs or to make notes on the

graph. If I use normal wx.DC not buffered drawn labels disappear after

screen resize, so that reason I would like to use buffered DC module.

OK, but again you’re not thinking this through. If you want to use a

buffered DC, then ALL drawing has to be done through your buffered

bitmap, including the plot. As it is, you create a new, empty (all

black) bitmap and draw something in it. When the buffered DC is

destroyed, it then flushes that output to the screen, which wipes out

whatever was there before hand.

If you want your annotations to persist, then you need to make sure they

get redrawn during the paint handling, where the plot will redraw

itself. It seems to me that the easy way to do that is just to keep a

record of your annotations, then redraw them all in your paint handler

after the plot has drawn itself. The attached code does that.

NOTE, however, that there is an issue. You’re remembering the X and Y

coordinates of the original click. When you resize the window, those

coordinates don’t match any more. That problem is clearly solvable, by

handling the EVT_SIZE message and adjusting the coordinates. I’ll leave

that as an exercise.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

I've looked at your code but it does not do what I want it to do. I can
draw myself on wx.ClientDC or wx.PaintDC with no problems, and there are
tons of examples of wx.ClientDC usage. My problem, as I've mentioned in my
first post, is drawing using wx.BufferedDC or by using wxMemoryDC to avoid
label disappearance on resize. And I cannot find an example where
wx.BufferedDC is used to draw on a Graph created via
wx.lib.plot.PlotCanvas. Anyway, I do not want to waist your time with this.

This trick here is that PlotCanvas is handling the drawing for you -- so
you either want to use teh same DC (or probably the same buffer) as
PlotCanvas -- which would take poking into the PlotCanvas code -- which I
think is pretty clean, or, drawing on top of the PlotCanvas after it has
done its thing -- which means doing the drawing in a PaintDC.

The reason to use a BufferedDC is to reduce flicker if you have lot to
draw -- I wouldn't bother -- at least at first -- do the drawing of the
label in a PaintDC INSIDE A PAINT EVENT, and you should be all set.

This is core of how all custom drawing works. You'd think (at least I did,
way back when), that there would be a build in system for refreshing the
drawing, but, in fact, your app needs to do that itself -- when the Window
gets messed up somehow the ssytem sends a paint event to your app. If you
have any custom drawing at all, you need to handle that Paint event, and
make sure that the event handler re-draws the Window. Anything that got
drawn by a clientDC or whatever could be erased -- your paint event handler
needs to put it back.

PlotCanvas is doing this for you -- FloatCanvas does this for you (that's
one of the reason it exists...) If you want to do your own drawing, you
need to do it in your code. tim's code is pretty much it, though I"d use a
PaintDC in that Paint event. I think it worked with the ClientDC because
the Canvas is creating a PaintDC, but in general, you NEED to create a
PaintDC in a paint event (at least n Windows)

Good Luck,

-Chris

···

On Wed, May 6, 2015 at 7:40 PM, Denis Spasyuk <denis.spasyuk@gmail.com> wrote:

thank you for your help,

cheers,

Denis

On Wednesday, May 6, 2015 at 11:45:32 AM UTC-6, Tim Roberts wrote

Denis Spasyuk wrote:
> Thank Tim for your reply. I am not sure why code does not work in your
> hands. I am using Ubuntu 14.04.

It's because I'm using Windows. Your code IS incorrect; a
BufferedPaintDC can only be used inside an EVT_PAINT handler. The fact
that it happens to work on Linux is an accident.

> Anyway, here is another code which I took from here
>
http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/
> and slightly modified it. I would like to be able to draw text in the
> graph window, for example to label graphs or to make notes on the
> graph. If I use normal wx.DC not buffered drawn labels disappear after
> screen resize, so that reason I would like to use buffered DC module.

OK, but again you're not thinking this through. If you want to use a
buffered DC, then ALL drawing has to be done through your buffered
bitmap, including the plot. As it is, you create a new, empty (all
black) bitmap and draw something in it. When the buffered DC is
destroyed, it then flushes that output to the screen, which wipes out
whatever was there before hand.

If you want your annotations to persist, then you need to make sure they
get redrawn during the paint handling, where the plot will redraw
itself. It seems to me that the easy way to do that is just to keep a
record of your annotations, then redraw them all in your paint handler
after the plot has drawn itself. The attached code does that.

NOTE, however, that there is an issue. You're remembering the X and Y
coordinates of the original click. When you resize the window, those
coordinates don't match any more. That problem is clearly solvable, by
handling the EVT_SIZE message and adjusting the coordinates. I'll leave
that as an exercise.

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

--

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

Thanks for your help, Chris. I’ve been told that I need to use MemoryDC or BufferedDC to be able to keep the labels on the graph after windows resize or after save operation. That is why I was thinking to go that way. I will try to look into MemoryDC again, but it looks very confusing, at least for non-programmer mind.

cheers

denis

···

On Thursday, May 7, 2015 at 10:21:23 AM UTC-6, Chris Barker wrote:

On Wed, May 6, 2015 at 7:40 PM, Denis Spasyuk denis....@gmail.com wrote:

I’ve looked at your code but it does not do what I want it to do. I can draw myself on wx.ClientDC or wx.PaintDC with no problems, and there are tons of examples of wx.ClientDC usage. My problem, as I’ve mentioned in my first post, is drawing using wx.BufferedDC or by using wxMemoryDC to avoid label disappearance on resize. And I cannot find an example where wx.BufferedDC is used to draw on a Graph created via wx.lib.plot.PlotCanvas. Anyway, I do not want to waist your time with this.

This trick here is that PlotCanvas is handling the drawing for you – so you either want to use teh same DC (or probably the same buffer) as PlotCanvas – which would take poking into the PlotCanvas code – which I think is pretty clean, or, drawing on top of the PlotCanvas after it has done its thing – which means doing the drawing in a PaintDC.

The reason to use a BufferedDC is to reduce flicker if you have lot to draw – I wouldn’t bother – at least at first – do the drawing of the label in a PaintDC INSIDE A PAINT EVENT, and you should be all set.

This is core of how all custom drawing works. You’d think (at least I did, way back when), that there would be a build in system for refreshing the drawing, but, in fact, your app needs to do that itself – when the Window gets messed up somehow the ssytem sends a paint event to your app. If you have any custom drawing at all, you need to handle that Paint event, and make sure that the event handler re-draws the Window. Anything that got drawn by a clientDC or whatever could be erased – your paint event handler needs to put it back.

PlotCanvas is doing this for you – FloatCanvas does this for you (that’s one of the reason it exists…) If you want to do your own drawing, you need to do it in your code. tim’s code is pretty much it, though I"d use a PaintDC in that Paint event. I think it worked with the ClientDC because the Canvas is creating a PaintDC, but in general, you NEED to create a PaintDC in a paint event (at least n Windows)

Good Luck,

-Chris

thank you for your help,

cheers,

Denis

On Wednesday, May 6, 2015 at 11:45:32 AM UTC-6, Tim Roberts wrote

Denis Spasyuk wrote:

Thank Tim for your reply. I am not sure why code does not work in your

hands. I am using Ubuntu 14.04.

It’s because I’m using Windows. Your code IS incorrect; a

BufferedPaintDC can only be used inside an EVT_PAINT handler. The fact

that it happens to work on Linux is an accident.

Anyway, here is another code which I took from here

http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/

and slightly modified it. I would like to be able to draw text in the

graph window, for example to label graphs or to make notes on the

graph. If I use normal wx.DC not buffered drawn labels disappear after

screen resize, so that reason I would like to use buffered DC module.

OK, but again you’re not thinking this through. If you want to use a

buffered DC, then ALL drawing has to be done through your buffered

bitmap, including the plot. As it is, you create a new, empty (all

black) bitmap and draw something in it. When the buffered DC is

destroyed, it then flushes that output to the screen, which wipes out

whatever was there before hand.

If you want your annotations to persist, then you need to make sure they

get redrawn during the paint handling, where the plot will redraw

itself. It seems to me that the easy way to do that is just to keep a

record of your annotations, then redraw them all in your paint handler

after the plot has drawn itself. The attached code does that.

NOTE, however, that there is an issue. You’re remembering the X and Y

coordinates of the original click. When you resize the window, those

coordinates don’t match any more. That problem is clearly solvable, by

handling the EVT_SIZE message and adjusting the coordinates. I’ll leave

that as an exercise.

Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

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

Thanks for your help, Chris. I've been told that I need to use MemoryDC or
BufferedDC to be able to keep the labels on the graph after windows resize
or after save operation.

actually, I"m not sure who told you that, but it's just plain wrong.

A MemoryDC or BufferedDC can help you get fast flicker-free re-drawing
when teh window needs refreshing, but no matter how you slice it, if the
Window is re-sized, you need to redraw, and you will need to re-build your
buffer.

Also -- you need to draw your stuf in a Paint event handler -- if it's
buffered, you just daw teh buffer, but you really do need to do that.

Look at the examples in teh Wiki -- they should help -- in particular the
Double Buffer Example.

-Chris

···

On Thu, May 7, 2015 at 1:19 PM, Denis Spasyuk <denis.spasyuk@gmail.com> wrote:

That is why I was thinking to go that way. I will try to look into
MemoryDC again, but it looks very confusing, at least for non-programmer
mind.

cheers

denis

On Thursday, May 7, 2015 at 10:21:23 AM UTC-6, Chris Barker wrote:

On Wed, May 6, 2015 at 7:40 PM, Denis Spasyuk <denis....@gmail.com> >> wrote:

I've looked at your code but it does not do what I want it to do. I can
draw myself on wx.ClientDC or wx.PaintDC with no problems, and there are
tons of examples of wx.ClientDC usage. My problem, as I've mentioned in my
first post, is drawing using wx.BufferedDC or by using wxMemoryDC to avoid
label disappearance on resize. And I cannot find an example where
wx.BufferedDC is used to draw on a Graph created via
wx.lib.plot.PlotCanvas. Anyway, I do not want to waist your time with this.

This trick here is that PlotCanvas is handling the drawing for you -- so
you either want to use teh same DC (or probably the same buffer) as
PlotCanvas -- which would take poking into the PlotCanvas code -- which I
think is pretty clean, or, drawing on top of the PlotCanvas after it has
done its thing -- which means doing the drawing in a PaintDC.

The reason to use a BufferedDC is to reduce flicker if you have lot to
draw -- I wouldn't bother -- at least at first -- do the drawing of the
label in a PaintDC INSIDE A PAINT EVENT, and you should be all set.

This is core of how all custom drawing works. You'd think (at least I
did, way back when), that there would be a build in system for refreshing
the drawing, but, in fact, your app needs to do that itself -- when the
Window gets messed up somehow the ssytem sends a paint event to your app.
If you have any custom drawing at all, you need to handle that Paint event,
and make sure that the event handler re-draws the Window. Anything that got
drawn by a clientDC or whatever could be erased -- your paint event handler
needs to put it back.

PlotCanvas is doing this for you -- FloatCanvas does this for you (that's
one of the reason it exists...) If you want to do your own drawing, you
need to do it in your code. tim's code is pretty much it, though I"d use a
PaintDC in that Paint event. I think it worked with the ClientDC because
the Canvas is creating a PaintDC, but in general, you NEED to create a
PaintDC in a paint event (at least n Windows)

Good Luck,

-Chris

thank you for your help,

cheers,

Denis

On Wednesday, May 6, 2015 at 11:45:32 AM UTC-6, Tim Roberts wrote

Denis Spasyuk wrote:
> Thank Tim for your reply. I am not sure why code does not work in
your
> hands. I am using Ubuntu 14.04.

It's because I'm using Windows. Your code IS incorrect; a
BufferedPaintDC can only be used inside an EVT_PAINT handler. The fact
that it happens to work on Linux is an accident.

> Anyway, here is another code which I took from here
>
http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/
> and slightly modified it. I would like to be able to draw text in the
> graph window, for example to label graphs or to make notes on the
> graph. If I use normal wx.DC not buffered drawn labels disappear
after
> screen resize, so that reason I would like to use buffered DC module.

OK, but again you're not thinking this through. If you want to use a
buffered DC, then ALL drawing has to be done through your buffered
bitmap, including the plot. As it is, you create a new, empty (all
black) bitmap and draw something in it. When the buffered DC is
destroyed, it then flushes that output to the screen, which wipes out
whatever was there before hand.

If you want your annotations to persist, then you need to make sure
they
get redrawn during the paint handling, where the plot will redraw
itself. It seems to me that the easy way to do that is just to keep a
record of your annotations, then redraw them all in your paint handler
after the plot has drawn itself. The attached code does that.

NOTE, however, that there is an issue. You're remembering the X and Y
coordinates of the original click. When you resize the window, those
coordinates don't match any more. That problem is clearly solvable, by
handling the EVT_SIZE message and adjusting the coordinates. I'll
leave
that as an exercise.

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

--

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

Ah ok, thanks Chris! I will try this today-tomorrow and let you know how it goes.

cheers,

Denis

···

On Thursday, May 7, 2015 at 6:29:55 PM UTC-6, Chris Barker wrote:

On Thu, May 7, 2015 at 1:19 PM, Denis Spasyuk denis....@gmail.com wrote:

Thanks for your help, Chris. I’ve been told that I need to use MemoryDC or BufferedDC to be able to keep the labels on the graph after windows resize or after save operation.

actually, I"m not sure who told you that, but it’s just plain wrong.

A MemoryDC or BufferedDC can help you get fast flicker-free re-drawing when teh window needs refreshing, but no matter how you slice it, if the Window is re-sized, you need to redraw, and you will need to re-build your buffer.

Also – you need to draw your stuf in a Paint event handler – if it’s buffered, you just daw teh buffer, but you really do need to do that.

Look at the examples in teh Wiki – they should help – in particular the Double Buffer Example.

-Chris

That is why I was thinking to go that way. I will try to look into MemoryDC again, but it looks very confusing, at least for non-programmer mind.

cheers

denis

On Thursday, May 7, 2015 at 10:21:23 AM UTC-6, Chris Barker wrote:

On Wed, May 6, 2015 at 7:40 PM, Denis Spasyuk denis....@gmail.com wrote:

I’ve looked at your code but it does not do what I want it to do. I can draw myself on wx.ClientDC or wx.PaintDC with no problems, and there are tons of examples of wx.ClientDC usage. My problem, as I’ve mentioned in my first post, is drawing using wx.BufferedDC or by using wxMemoryDC to avoid label disappearance on resize. And I cannot find an example where wx.BufferedDC is used to draw on a Graph created via wx.lib.plot.PlotCanvas. Anyway, I do not want to waist your time with this.

This trick here is that PlotCanvas is handling the drawing for you – so you either want to use teh same DC (or probably the same buffer) as PlotCanvas – which would take poking into the PlotCanvas code – which I think is pretty clean, or, drawing on top of the PlotCanvas after it has done its thing – which means doing the drawing in a PaintDC.

The reason to use a BufferedDC is to reduce flicker if you have lot to draw – I wouldn’t bother – at least at first – do the drawing of the label in a PaintDC INSIDE A PAINT EVENT, and you should be all set.

This is core of how all custom drawing works. You’d think (at least I did, way back when), that there would be a build in system for refreshing the drawing, but, in fact, your app needs to do that itself – when the Window gets messed up somehow the ssytem sends a paint event to your app. If you have any custom drawing at all, you need to handle that Paint event, and make sure that the event handler re-draws the Window. Anything that got drawn by a clientDC or whatever could be erased – your paint event handler needs to put it back.

PlotCanvas is doing this for you – FloatCanvas does this for you (that’s one of the reason it exists…) If you want to do your own drawing, you need to do it in your code. tim’s code is pretty much it, though I"d use a PaintDC in that Paint event. I think it worked with the ClientDC because the Canvas is creating a PaintDC, but in general, you NEED to create a PaintDC in a paint event (at least n Windows)

Good Luck,

-Chris

thank you for your help,

cheers,

Denis

On Wednesday, May 6, 2015 at 11:45:32 AM UTC-6, Tim Roberts wrote

Denis Spasyuk wrote:

Thank Tim for your reply. I am not sure why code does not work in your

hands. I am using Ubuntu 14.04.

It’s because I’m using Windows. Your code IS incorrect; a

BufferedPaintDC can only be used inside an EVT_PAINT handler. The fact

that it happens to work on Linux is an accident.

Anyway, here is another code which I took from here

http://www.blog.pythonlibrary.org/2010/09/27/wxpython-pyplot-graphs-with-python/

and slightly modified it. I would like to be able to draw text in the

graph window, for example to label graphs or to make notes on the

graph. If I use normal wx.DC not buffered drawn labels disappear after

screen resize, so that reason I would like to use buffered DC module.

OK, but again you’re not thinking this through. If you want to use a

buffered DC, then ALL drawing has to be done through your buffered

bitmap, including the plot. As it is, you create a new, empty (all

black) bitmap and draw something in it. When the buffered DC is

destroyed, it then flushes that output to the screen, which wipes out

whatever was there before hand.

If you want your annotations to persist, then you need to make sure they

get redrawn during the paint handling, where the plot will redraw

itself. It seems to me that the easy way to do that is just to keep a

record of your annotations, then redraw them all in your paint handler

after the plot has drawn itself. The attached code does that.

NOTE, however, that there is an issue. You’re remembering the X and Y

coordinates of the original click. When you resize the window, those

coordinates don’t match any more. That problem is clearly solvable, by

handling the EVT_SIZE message and adjusting the coordinates. I’ll leave

that as an exercise.

Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

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-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

Denis Spasyuk wrote:

I've looked at your code but it does not do what I want it to do. I
can draw myself on wx.ClientDC or wx.PaintDC with no problems, and
there are tons of examples of wx.ClientDC usage. My problem, as I've
mentioned in my first post, is drawing using wx.BufferedDC or by using
wxMemoryDC to avoid label disappearance on resize.

Did you understand that my code DOES avoid the label disappearance on
resize? It does it in a different way from what you had imagined, but
it solves the same problem.

Anyway, I do not want to waist your time with this.

Well, that's up to me to decide.

···

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

Hi Tim,

Thank you for your reply,

I do not know why the code does not work, but it does not work. It seems that everything should work, but labels do not stay after windows resize event and do not even flicker, they just disappear. I’ve added a video to show you what I see. I have also tried to bind self.onPaint to wx.EVT_SIZE but labels just flicker during resize and then disappear. However, if I bind onPaint function to wx.EVT_RIGHT_DOWN event labels reappear and stay. Also, then I try to save graph using SaveFile function in PlotCanvas, it only saves the graph. I presume I need to draw both graph and labels on wx.EmptyBitmap for that?

See video bellow for more details:

codetim.py (3.62 KB)

···

On Friday, May 8, 2015 at 12:09:29 PM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:

I’ve looked at your code but it does not do what I want it to do. I

can draw myself on wx.ClientDC or wx.PaintDC with no problems, and

there are tons of examples of wx.ClientDC usage. My problem, as I’ve

mentioned in my first post, is drawing using wx.BufferedDC or by using

wxMemoryDC to avoid label disappearance on resize.

Did you understand that my code DOES avoid the label disappearance on

resize? It does it in a different way from what you had imagined, but

it solves the same problem.

Anyway, I do not want to waist your time with this.

Well, that’s up to me to decide.


Tim Roberts, ti...@probo.com

Providenza & Boekelheide, Inc.

I do not know why the code does not work, but it does not work. It seems
that everything should work, but labels do not stay after windows resize
event and do not even flicker, they just disappear

I see that mouseleftdown() is addin gteh ennotaitons ot self.annotaitons,
but onrightdown is not -- which are you using here?

. I've added a video to show you what I see. I have also tried to bind
self.onPaint to wx.EVT_SIZE but labels just flicker during resize and then
disappear. However, if I bind onPaint function to wx.EVT_RIGHT_DOWN event
labels reappear and stay. Also, then I try to save graph using SaveFile
function in PlotCanvas, it only saves the graph. I presume I need to draw
both graph and labels on wx.EmptyBitmap for that?

yes -- but if you want this, I really, really suggest you look at the
PlotCanvas code,and see if you can subclass it and add this functionality
directly to it. I suspect it's keepign a buffer of teh garph, so you want
to draw your labels on that buffer.

I'm taking a quick look now. I see that the save functionailty is doing
this:

res = self._Buffer.SaveFile(fileName, extensions[fType])

So, you need to draw to that bitmap to get it saved.

note that the plot canvas' paint method is simply this:

def OnPaint(self, event): # All that is needed here is to draw the buffer
to screen if self.last_PointLabel != None:
self._drawPointLabel(self.last_PointLabel)
# erase old self.last_PointLabel = None dc = wx.BufferedPaintDC(self.canvas,
self._Buffer) if self._antiAliasingEnabled: try: dc = wx.GCDC(dc) except
Exception: pass

essentially simply dumping the buffer to the screen -- so what you really
want to do is add to that buffer.

The real drawing is done is the _Draw method, which is pretty big and ugly,
but most of that is drawing teh axis, labels, etc. then it calls the
PlotGraphics class to do the work, and the PlotGraphics class is mostly a
container for various graphics objects.

So what you want is a Poly* type class for your labels -- and you can then
add that to the list.

You could probably take a look at the PolyMarker class, and make something
like that.

Or, you could kludge it a bit more, and write to the _Buffer directly,
keeping track of the scaling, etc, yourself. But this might be tricky to
get the order of operations rigth:

You want the Canvas to draw itself to the Buffer, but not to the paintDC
yet, then you want to draw more on top of it, then you want to darwit ot
the PaintDC.

Also -- take a look at the TestFrame demo, in particular the
DrawPointLabe lmethod
-- maybe it does what you want. I haven't nlooked closely.

-CHB

···

On Fri, May 8, 2015 at 8:10 PM, Denis Spasyuk <denis.spasyuk@gmail.com> wrote:

See video bellow for more details:

Dropbox - Error - Simplify your life

On Friday, May 8, 2015 at 12:09:29 PM UTC-6, Tim Roberts wrote:

Denis Spasyuk wrote:
>
> I've looked at your code but it does not do what I want it to do. I
> can draw myself on wx.ClientDC or wx.PaintDC with no problems, and
> there are tons of examples of wx.ClientDC usage. My problem, as I've
> mentioned in my first post, is drawing using wx.BufferedDC or by using
> wxMemoryDC to avoid label disappearance on resize.

Did you understand that my code DOES avoid the label disappearance on
resize? It does it in a different way from what you had imagined, but
it solves the same problem.

> Anyway, I do not want to waist your time with this.

Well, that's up to me to decide.

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

--

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

Denis Spasyuk wrote:

I do not know why the code does not work, but it does not work. It
seems that everything should work, but labels do not stay after
windows resize event and do not even flicker, they just disappear.

It works fine on Windows. This must be some platform-specific
difference in the behavior of the PlotCanvas. They must not be
completing all of their drawing in the paint handler -- they must
schedule some of it for later. One "hacky" solution would be use
wx.CallAfter within your onPaint handler, and refresh the annotations in
the callback.

Also, then I try to save graph using SaveFile function in PlotCanvas,
it only saves the graph.

Of course it does. You haven't changed the plot in any way. All you've
changed is the screen.

I presume I need to draw both graph and labels on wx.EmptyBitmap for
that?

No, PlotCanvas is managing its own drawing. When you ask it to print,
it's going to print the information it has generated. It doesn't know
anything about your annotations, so they are never going to appear.

If you want to modify the way PlotCanvas works, then you might consider
deriving your own subclass from PlotCanvas. That way, you'll have
access to the internals. You'll need to go through the code for
PlotCanvas to understand how it does what it doesn.

···

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