Is ClientDC the right solution?

Hey wxers,
[Windows 7, Python 2.7, wx 2.8.12.1]
Background info: I have a wxgrid. The grid data changes based on user actions (clicking “Next Page”, “Archiving” a row to get rid of it from the screen). I need to outline each row with a box, and the outline color changes based on data from the Row (if column 1 is “True”, the box will be green, if “False”, the box will be red).
My solution was to use a ClientDC to make a Rectangle with full transparency, thus giving me a simple colored box.

My question is 2 fold–

  1. Does this sound like the best solution? I’m a little worried that DC will not be preserved, and I may have to redraw the boxes each time. Also, I’m not sure this is what ClientDC was intended to do. However, I couldn’t think of any other solution. StaticBox doesn’t allow you to change just the box outline (correct?).
  2. I cannot get my ClientDC to render the square in the attached file. Am I missing a step? I have seen some code with dc.BeginDrawing and EndDrawing, but that didn’t do the trick, either.
    Any help would be greatly appreciated.

Thanks,
Jake

wxtesting.py (952 Bytes)

In short,

ClientDC is probably not the right approach.

screen). I need to outline each row with a box, and the outline color
changes based on data from the Row (if column 1 is "True", the box will be
green, if "False", the box will be red).

My question is 2 fold--
1. Does this sound like the best solution? I'm a little worried that DC
will not be preserved, and I may have to redraw the boxes each time.

you will -- you'd do that by capturing the paint event, and using a wx.PaintDC.

think of any other solution. StaticBox doesn't allow you to change just the
box outline (correct?).

I think you're right, and this is in no way a StaticBox anyway.

Have you looked into wx.Grid custom renderers? that's probably the way to go.

2. I cannot get my ClientDC to render the square in the attached file. Am I
missing a step? I have seen some code with dc.BeginDrawing and EndDrawing,
but that didn't do the trick, either.

It is a bit tricky to draw on top of existing Windows -- in general,
wx.Windows are nto designed to overlap, and draw themselves. Google
around for "wxpython drwwing on top" and see what you find.

I've enclosed a fixed version of your code -- you need to use a
PaintDC and the paint event.

Search the wiki for "Drawing" and you'll find a number of pages that
explain all this.

I also cleaned up a bit of style Do take a moment to read:

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

HTH,
  -Chris

···

On Mon, Aug 19, 2013 at 8:06 AM, Jake Larrimore <jacoblarrimore@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

oops.

This time with the attachment.

-Chris

wxtesting.py (1.08 KB)

···

--

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

Hey Chris, Thanks for the input.

In short,

ClientDC is probably not the right approach.

As I feared.

screen). I need to outline each row with a box, and the outline color

changes based on data from the Row (if column 1 is “True”, the box will be

green, if “False”, the box will be red).

My question is 2 fold–

  1. Does this sound like the best solution? I’m a little worried that DC

will not be preserved, and I may have to redraw the boxes each time.

you will – you’d do that by capturing the paint event, and using a wx.PaintDC.

Okay, I was a bit unsure of the OnDraw event handling. If I use this solution of drawing the boxes I’ll play around more with the wx.PaintDC.

think of any other solution. StaticBox doesn’t allow you to change just the

box outline (correct?).

I think you’re right, and this is in no way a StaticBox anyway.

Have you looked into wx.Grid custom renderers? that’s probably the way to go.

Yes, I am using the custom renderers to do images and the like inside the grid. This was my first thought, but the only thing I could find with the renders was placing other objects INSIDE a cell, not outlining an entire row of multiple cells. I’ll dig a little more, maybe there is something that can be used.

  1. I cannot get my ClientDC to render the square in the attached file. Am I

missing a step? I have seen some code with dc.BeginDrawing and EndDrawing,

but that didn’t do the trick, either.

It is a bit tricky to draw on top of existing Windows – in general,

wx.Windows are nto designed to overlap, and draw themselves. Google

around for “wxpython drwwing on top” and see what you find.

Hmm, i see. I guess I misunderstood the inteded use of the DC’s.

I’ve enclosed a fixed version of your code – you need to use a

PaintDC and the paint event.

Search the wiki for “Drawing” and you’ll find a number of pages that

explain all this.

Thanks, I’ll take a look

I also cleaned up a bit of style Do take a moment to read:

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

Ha, yes, I am familiar with the style guide. I guess when I am experimenting I don’t take too much time to conform completely, especially when copy and pasting from multiple sources on the interwebs/demo. Sorry about that-- I’ll be sure to pay more attention

···

On Monday, August 19, 2013 2:56:33 PM UTC-4, Chris Barker - NOAA Federal wrote:

On Mon, Aug 19, 2013 at 8:06 AM, Jake Larrimore > > jacobla...@gmail.com wrote:

HTH,

-Chris

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

Yes, I am using the custom renderers to do images and the like inside the grid. This was my first thought, but the only thing I could find with the renders was placing other objects INSIDE a cell, not outlining an entire row of multiple cells.

Indeed–though you could draw the top and bottom outlines of each box on a row, and draw the right and left edges of the ones on the end.

But if you really want the box outside the cells, you will indeed need to draw another way.

The trick is that the cells are children of the grid Window. I played a bit with this, and if you capture the paint event of the Grid, you can draw, but the cells get drawn after.

I’m not sure there is a way that is not kludgy–do here goes.

Try using wx.CallAfter in the Grid’s Paint event to call a method that uses a ScreenDC to draw your box on top of everything else. Note that you’ll need to capture all events that might require an update to the. Box-- moving, etc.

And this is likely to work differently on different platforms.

Maybe someone else has a better idea…

Chris

···

On Aug 19, 2013, at 12:17 PM, Jake Larrimore jacoblarrimore@gmail.com wrote:

I’ll dig a little more, maybe there is something that can be used.

  1. I cannot get my ClientDC to render the square in the attached file. Am I

missing a step? I have seen some code with dc.BeginDrawing and EndDrawing,

but that didn’t do the trick, either.

It is a bit tricky to draw on top of existing Windows – in general,

wx.Windows are nto designed to overlap, and draw themselves. Google

around for “wxpython drwwing on top” and see what you find.

Hmm, i see. I guess I misunderstood the inteded use of the DC’s.

I’ve enclosed a fixed version of your code – you need to use a

PaintDC and the paint event.

Search the wiki for “Drawing” and you’ll find a number of pages that

explain all this.

Thanks, I’ll take a look

I also cleaned up a bit of style Do take a moment to read:

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

Ha, yes, I am familiar with the style guide. I guess when I am experimenting I don’t take too much time to conform completely, especially when copy and pasting from multiple sources on the interwebs/demo. Sorry about that-- I’ll be sure to pay more attention

HTH,

-Chris

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/groups/opt_out.