dc.GetForegroundColour

Theres a bug in UltimateListCtrl related to dc.GetForegrounColour. The
code is:

old = dc.GetForegroundColour()

dc.SetForegroundColour(new)

# paint

dc.SetForegroundColour(old)

For some reason old gets updated by the SetForegroundColour call so
its not actually restoring the color. I've seen this elsewhere in the
wxPython code...

Mark

I don't see that code anywhere in UltimateListCtrl.
GetForegroundColour and SetForegroundColour are methods of a window,
not of a DC. I see it fetching the foreground color from the window
and doing dc.SetTextForeground to set the text color, but it never
tries to save and restore.

Can you be more explicit, or perhaps post a runnable example that
shows the problem?

···

On Jul 22, 10:22 pm, Mark <markree...@gmail.com> wrote:

Theres a bug in UltimateListCtrl related to dc.GetForegrounColour. The
code is:

old = dc.GetForegroundColour()
dc.SetForegroundColour(new)
# paint
dc.SetForegroundColour(old)

For some reason old gets updated by the SetForegroundColour call so
its not actually restoring the color.

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

Sorry the call is dc.GetTextForeground() - it returns a reference
which is something I'm not used to in python. And the bug is only in
one place in UltimateListCtrl, the rest of AGW is fine. I've already
patched and wrote a ticket.

The docs shows this with an &:
const wxColour& GetTextForeground() const

So if I want to save the DC's current text color I can do:

old = *dc.GetTextForeground()
dc.SetTextForeground(new)
dc.SetTextForeground(old)

right?

Mark

···

On Jul 24, 2:42 am, Tim Roberts <t...@probo.com> wrote:

On Jul 22, 10:22 pm, Mark <markree...@gmail.com> wrote:

> Theres a bug in UltimateListCtrl related to dc.GetForegrounColour. The
> code is:

> old = dc.GetForegroundColour()
> dc.SetForegroundColour(new)
> # paint
> dc.SetForegroundColour(old)

> For some reason old gets updated by the SetForegroundColour call so
> its not actually restoring the color.

I don't see that code anywhere in UltimateListCtrl.
GetForegroundColour and SetForegroundColour are methods of a window,
not of a DC. I see it fetching the foreground color from the window
and doing dc.SetTextForeground to set the text color, but it never
tries to save and restore.

Can you be more explicit, or perhaps post a runnable example that
shows the problem?
--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

Look at the wxPython docs.
Gets the current text background colour
It gives you a Color object.
To save the reference to the object, just call “colour =
dc.GetTextBackground()”

wx.DC-class.html (204 KB)

···

t...@probo.commarkree...@gmail.comt...@probo.comhttp://www.wxpython.org/docs/api/wx.DC-class.html#GetTextBackground

Colour``GetTextBackground(self)

http://www.wxpython.org/docs/api/wx.Colour-class.html

-- Steven Sproat, BSc

http://www.whyteboard.org/

Not in Python. The C++ reference concept is not fully equivalent to the Python reference concept. I usually tell SWIG to treat reference returns as if they were value returns instead in order to avoid confusion like this, so this is indeed a bug in the wxPython wrappers.

···

On 7/23/10 2:46 PM, Mark wrote:

Sorry the call is dc.GetTextForeground() - it returns a reference
which is something I'm not used to in python. And the bug is only in
one place in UltimateListCtrl, the rest of AGW is fine. I've already
patched and wrote a ticket.

The docs shows this with an&:
const wxColour& GetTextForeground() const

So if I want to save the DC's current text color I can do:

old = *dc.GetTextForeground()
dc.SetTextForeground(new)
dc.SetTextForeground(old)

right?

--
Robin Dunn
Software Craftsman

Hi,

···

On Mon, Jul 26, 2010 at 2:10 PM, Robin Dunn <robin@alldunn.com> wrote:

On 7/23/10 2:46 PM, Mark wrote:

Sorry the call is dc.GetTextForeground() - it returns a reference
which is something I'm not used to in python. And the bug is only in
one place in UltimateListCtrl, the rest of AGW is fine. I've already
patched and wrote a ticket.

The docs shows this with an&:
const wxColour& GetTextForeground() const

So if I want to save the DC's current text color I can do:

old = *dc.GetTextForeground()
dc.SetTextForeground(new)
dc.SetTextForeground(old)

right?

Not in Python. The C++ reference concept is not fully equivalent to the
Python reference concept. I usually tell SWIG to treat reference returns as
if they were value returns instead in order to avoid confusion like this, so
this is indeed a bug in the wxPython wrappers.

As a workaround you could just make a copy of the Colour object returned.

old = dc.GetTextForeground()
old = wx.Colour(*old.Get())

Cody