wx.TextAttr.Merge(...) in 2.9.2.1 returning None?

Hi all,
I just encountered another difference in wx 2.9 with regard to my
code, namely in wx.TextAttr.Merge,
it seems, that it now returns None (at least in the cases I tested),
which lets the further code crash, as SetStyle obviously expects
wx.TextAtrr ...
Have I missed some documented change? What would be the expected way
to use Merge?
For the snippet below, I get the following traceback in 2.9.2.1:

2.9.2.1 (msw-unicode) merged_style: None

Traceback (most recent call last):
  File "C:\dokumenty\Vlasta\python-wx\TextCtrl--test-Merge-wx-2-9.py",
line 27, in <module>
    testTxtCtrl.SetStyle(90, 131, merged_style)
  File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\_core.py", line
13330, in SetStyle
    return _core_.TextAreaBase_SetStyle(*args, **kwargs)
ValueError: invalid null reference in method 'TextAreaBase_SetStyle',
expected argument 4 of type 'wxTextAttr const &'

TextCtrl–test-Merge-wx-2-9.py (946 Bytes)

···

======

with 2.8 the styling works as expected and the print output is:

2.8.12.1 (msw-unicode) merged_style: <wx._controls.TextAttr; proxy of
<Swig Object of type 'wxTextAttr *' at 0x18868a0> >

======

Thanks in advance for any hints,
   vbr

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # #

#! Python
# -*- coding: utf-8 -*-

import wxversion
# wxversion.select('2.8')
wxversion.select('2.9.2')
import wx

appl = wx.App(redirect=False)
frm = wx.Frame(None, -1, "wx.TextAttr.Merge - test")

testTxtCtrl = wx.TextCtrl(frm, -1, style=wx.TE_MULTILINE | wx.TE_RICH2)
testTxtCtrl.SetValue(u"abcdef ghijklmn op rstu v Z\n" * 7)

sizerFrm = wx.BoxSizer(wx.HORIZONTAL)
sizerFrm.Add(testTxtCtrl, 1, wx.EXPAND)
frm.SetSizer(sizerFrm)

red_text_style = wx.TextAttr("RED", wx.NullColour)
yellow_bg_style = wx.TextAttr(wx.NullColour, "YELLOW")
merged_style = wx.TextAttr.Merge(red_text_style, yellow_bg_style)

print wx.version(), "merged_style: ", merged_style # >> None in wxPython 2.9.2.1

testTxtCtrl.SetStyle(5, 15, red_text_style)
testTxtCtrl.SetStyle(20, 30, yellow_bg_style)
testTxtCtrl.SetStyle(90, 131, merged_style)

frm.Show()

testTxtCtrl.SetInsertionPoint(0) # avoid highlighting the text

appl.MainLoop()

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # #

I don't remember exactly why I did this but apparently in 2.9 I commented out the static version of Merge and uncommented the non-static method. So in other words what we have now is a wrapper for:

     void Merge(const wxTextAttr& overlay)

instead of:

     static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr& overlay)

The non-static version will still do a merge but will merge it into self instead of making a new instance of the wx.TextAttr.

     base.Merge(overlay) # base is modified

If you prefer the old semantics then you can use the new Combine static method like this:

     newAttr = wx.TextAttr.Combine(overlay, base, None)

···

On 8/4/11 10:46 AM, Vlastimil Brom wrote:

Hi all,
I just encountered another difference in wx 2.9 with regard to my
code, namely in wx.TextAttr.Merge,
it seems, that it now returns None (at least in the cases I tested),
which lets the further code crash, as SetStyle obviously expects
wx.TextAtrr ...
Have I missed some documented change? What would be the expected way
to use Merge?
For the snippet below, I get the following traceback in 2.9.2.1:

2.9.2.1 (msw-unicode) merged_style: None

Traceback (most recent call last):
   File "C:\dokumenty\Vlasta\python-wx\TextCtrl--test-Merge-wx-2-9.py",
line 27, in<module>
     testTxtCtrl.SetStyle(90, 131, merged_style)
   File "C:\Python27\lib\site-packages\wx-2.9.2-msw\wx\_core.py", line
13330, in SetStyle
     return _core_.TextAreaBase_SetStyle(*args, **kwargs)
ValueError: invalid null reference in method 'TextAreaBase_SetStyle',
expected argument 4 of type 'wxTextAttr const&'

======

with 2.8 the styling works as expected and the print output is:

2.8.12.1 (msw-unicode) merged_style:<wx._controls.TextAttr; proxy of
<Swig Object of type 'wxTextAttr *' at 0x18868a0> >

--
Robin Dunn
Software Craftsman

Thanks for the prompt clarification Robin!
using wx.TextAttr.Combine(...) with the reversed signature instead of
the original static wx.TextAttr.Merge(...) seems to work ok in both
2.8 and 2.9 versions of wxPython.

I hope, this doesn't have any drawbacks compared to the non static
Merge() - which would require some refactoring of the SetStyle(...)
calls in my code and is incompatible between 2.8 and 2.9.
Are both approaches supposed to be equivalent, or am I missing some
subtle differences, to be surprised by later...?

Many thanks,
   vbr

···

2011/8/4 Robin Dunn <robin@alldunn.com>:

On 8/4/11 10:46 AM, Vlastimil Brom wrote:

Hi all,
I just encountered another difference in wx 2.9 with regard to my
code, namely in wx.TextAttr.Merge,
it seems, that it now returns None (at least in the cases I tested),
which lets the further code crash, as SetStyle obviously expects
wx.TextAtrr ...
Have I missed some documented change? What would be the expected way
to use Merge?
...

I don't remember exactly why I did this but apparently in 2.9 I commented
out the static version of Merge and uncommented the non-static method. So
in other words what we have now is a wrapper for:

void Merge(const wxTextAttr& overlay)

instead of:

static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr&
overlay)

The non-static version will still do a merge but will merge it into self
instead of making a new instance of the wx.TextAttr.

base.Merge(overlay) # base is modified

If you prefer the old semantics then you can use the new Combine static
method like this:

newAttr = wx.TextAttr.Combine(overlay, base, None)

--
Robin Dunn
Software Craftsman
http://wxPython.org

--

In 2.9 at least the Merge functions are implemented using Combine, so there shouldn't be any hidden issues related to different behaviors between them.

     static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr& overlay)
     {
         return Combine(overlay, base, NULL);
     }

     void Merge(const wxTextAttr& overlay)
     {
         *this = Merge(*this, overlay);
     }

···

On 8/4/11 3:28 PM, Vlastimil Brom wrote:

Thanks for the prompt clarification Robin!
using wx.TextAttr.Combine(...) with the reversed signature instead of
the original static wx.TextAttr.Merge(...) seems to work ok in both
2.8 and 2.9 versions of wxPython.

I hope, this doesn't have any drawbacks compared to the non static
Merge() - which would require some refactoring of the SetStyle(...)
calls in my code and is incompatible between 2.8 and 2.9.
Are both approaches supposed to be equivalent, or am I missing some
subtle differences, to be surprised by later...?

--
Robin Dunn
Software Craftsman

Thanks Robin,
If I only knew (some part of) C++, I could find out things like this myself ...
The good news is, I haven't found any other problems with my apps on
wx 2.9.2 sofar ...

Regards,
vbr

···

2011/8/5 Robin Dunn <robin@alldunn.com>:

On 8/4/11 3:28 PM, Vlastimil Brom wrote:

...
Are both approaches supposed to be equivalent, or am I missing some
subtle differences, to be surprised by later...?

In 2.9 at least the Merge functions are implemented using Combine, so there
shouldn't be any hidden issues related to different behaviors between them.

static wxTextAttr Merge(const wxTextAttr& base, const wxTextAttr&
overlay)
{
return Combine(overlay, base, NULL);
}

void Merge(const wxTextAttr& overlay)
{
*this = Merge(*this, overlay);
}

--
Robin Dunn
Software Craftsman
http://wxPython.org