ID range bug with Connect and 2.9

Folks,

I just tried to get wxPython2.9 working with a wxmpl- based app (wxmpl
is a library for embedding Matplotlib in wx apps). It crashed out on
me with:

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wxmpl.py",
line 1127, in __init__
    topwin.Connect(-1, self.GetId(), wx.wxEVT_ACTIVATE, self.OnActivate)
  File "/usr/local/lib/wxPython-2.9.3.1/lib/python2.7/site-packages/wx-2.9.3-osx_carbon/wx/_core.py",
line 4184, in Connect
    return _core_.EvtHandler_Connect(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "idLast == wxID_ANY || winid
<= idLast" failed at
/BUILD/wxPython-src-2.9.3.1/include/wx/event.h(2875) in
wxEventTableEntryBase(): invalid IDs range: lower bound > upper bound

I've isolated the issue, and made the simple enclosed sample app:

If you try to call Connect, with an ID generated by using wx.ID_ANY,
it fails with:

wx._core.PyAssertionError: C++ assertion "idLast == wxID_ANY || winid
<= idLast" failed at
/BUILD/wxPython-src-2.9.3.1/include/wx/event.h(2875) in
wxEventTableEntryBase(): invalid IDs range: lower bound > upper bound

if seems that there is an issue with negative IDs -- when I pass in
wx.ID_ANY, the panel gets the
ID: -2007. If I explicitly give the panel an ID (like 100) it works
fine -- but I really don't like explicite IDs!

see lines 34-35 in the sample enclosed.

-Chris

test_connect.py (1.04 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

You've slightly misinterpreted the assert. Basically it is saying that either the 2nd ID must be wx.ID_ANY or it must be greater than the 1st ID. (Since it is to be used when specifying a range of IDs). Changing your sample code to this should take care of the problem:

         topwin.Connect(self.GetId(), wx.ID_ANY, wx.wxEVT_ACTIVATE, self.OnActivate)

or even:

         topwin.Bind(wx.EVT_ACTIVATE, self.OnActivate, id=self.GetId())

However there is a worse problem lurking there in that it is making a binding for EVT_ACTIVATE at topwin, but telling it to watch for events from self, which won't happen. (wx.ActivateEvent is not a command event, and I don't think they are delivered to non top-level windows anyway.) So it probably should be just this:

         topwin.Bind(wx.EVT_ACTIVATE, self.OnActivate)

···

On 4/23/12 1:24 PM, Chris Barker wrote:

Folks,

I just tried to get wxPython2.9 working with a wxmpl- based app (wxmpl
is a library for embedding Matplotlib in wx apps). It crashed out on
me with:

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wxmpl.py",
line 1127, in __init__
     topwin.Connect(-1, self.GetId(), wx.wxEVT_ACTIVATE, self.OnActivate)
   File "/usr/local/lib/wxPython-2.9.3.1/lib/python2.7/site-packages/wx-2.9.3-osx_carbon/wx/_core.py",
line 4184, in Connect
     return _core_.EvtHandler_Connect(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "idLast == wxID_ANY || winid
<= idLast" failed at
/BUILD/wxPython-src-2.9.3.1/include/wx/event.h(2875) in
wxEventTableEntryBase(): invalid IDs range: lower bound> upper bound

I've isolated the issue, and made the simple enclosed sample app:

If you try to call Connect, with an ID generated by using wx.ID_ANY,
it fails with:

wx._core.PyAssertionError: C++ assertion "idLast == wxID_ANY || winid
<= idLast" failed at
/BUILD/wxPython-src-2.9.3.1/include/wx/event.h(2875) in
wxEventTableEntryBase(): invalid IDs range: lower bound> upper bound

if seems that there is an issue with negative IDs -- when I pass in
wx.ID_ANY, the panel gets the
ID: -2007. If I explicitly give the panel an ID (like 100) it works
fine -- but I really don't like explicite IDs!

--
Robin Dunn
Software Craftsman

   topwin\.Connect\(self\.GetId\(\), wx\.ID\_ANY, wx\.wxEVT\_ACTIVATE,

self.OnActivate)

or even:

   topwin\.Bind\(wx\.EVT\_ACTIVATE, self\.OnActivate, id=self\.GetId\(\)\)

This is actually from wxmpl code, and I haven't dug in to see why it's
even there...but I'll pass this on the Ken McIvor.

Just to be clear -- this code did (does) work with 2.8 -- should it not have?

However there is a worse problem lurking there in that it is making a
binding for EVT_ACTIVATE at topwin, but telling it to watch for events from
self, which won't happen. (wx.ActivateEvent is not a command event, and I
don't think they are delivered to non top-level windows anyway.) So it
probably should be just this:

   topwin\.Bind\(wx\.EVT\_ACTIVATE, self\.OnActivate\)

OK -- I'll pass that along, and maybe take a look myself to see what
he's really trying to do there.

Thanks,
  -Chris

···

On Mon, Apr 23, 2012 at 1:50 PM, Robin Dunn <robin@alldunn.com> wrote:

On 4/23/12 1:24 PM, Chris Barker 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

        topwin.Connect(self.GetId(), wx.ID_ANY, wx.wxEVT_ACTIVATE,
self.OnActivate)

or even:

        topwin.Bind(wx.EVT_ACTIVATE, self.OnActivate, id=self.GetId())

This is actually from wxmpl code, and I haven't dug in to see why it's
even there...but I'll pass this on the Ken McIvor.

Just to be clear -- this code did (does) work with 2.8 -- should it not have?

The assert is new, and with wx.ID_ANY being passed for the first ID to Connect then IIRC the conditional statement that is used for searching a binding probably just ignores the 2nd ID, so it would end up being basically the same as:

···

On 4/24/12 8:48 AM, Chris Barker wrote:

On Mon, Apr 23, 2012 at 1:50 PM, Robin Dunn<robin@alldunn.com> wrote:

On 4/23/12 1:24 PM, Chris Barker wrote:

        topwin.Bind(wx.EVT_ACTIVATE, self.OnActivate)

--
Robin Dunn
Software Craftsman