I've searched but can't find any other mentions of this particular problem. Trying
this test on Mac 10.6.8 with Python 2.7.3/64 and wxPython 2.9.4.0 results in an
OverflowError even though the argument in question is indeed an int.
for id_ in (wx.NewId(), 20393, maxint_32, maxint_32+1, maxint_64):
print id_, isinstance(id_, int)
app.Bind(wx.EVT_MENU_HIGHLIGHT, onHighlight, id=id_)
}}}
Results:
"""
9223372036854775807
100 True
20393 True
2147483647 True
2147483648 True
Traceback (most recent call last):
File "t.py", line 13, in <module>
app.Bind(wx.EVT_MENU_HIGHLIGHT, onHighlight, id=id_)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4228, in Bind
event.Bind(self, id, id2, handler)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4572, in Bind
target.Connect(id1, id2, et, function)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4182, in Connect
return _core_.EvtHandler_Connect(*args, **kwargs)
OverflowError: in method 'EvtHandler_Connect', expected argument 2 of type 'int'
"""
It's using this function to fetch and check the value:
SWIGINTERN int
SWIG_AsVal_int (PyObject * obj, int *val)
{
long v;
int res = SWIG_AsVal_long (obj, &v);
if (SWIG_IsOK(res)) {
if ((v < INT_MIN || v > INT_MAX)) {
return SWIG_OverflowError;
} else {
if (val) *val = static_cast< int >(v);
}
}
return res;
}
So it is dependent on the C compiler's definitions for INT_MIN and INT_MAX, not Python's.
···
On 1/7/13 5:32 PM, Paul McNett wrote:
Hi,
I've searched but can't find any other mentions of this particular problem. Trying
this test on Mac 10.6.8 with Python 2.7.3/64 and wxPython 2.9.4.0 results in an
OverflowError even though the argument in question is indeed an int.
Traceback (most recent call last):
File "t.py", line 13, in <module>
app.Bind(wx.EVT_MENU_HIGHLIGHT, onHighlight, id=id_)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4228, in Bind
event.Bind(self, id, id2, handler)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4572, in Bind
target.Connect(id1, id2, et, function)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4182, in Connect
return _core_.EvtHandler_Connect(*args, **kwargs)
OverflowError: in method 'EvtHandler_Connect', expected argument 2 of type 'int'
"""
Thanks. It turns out I was assigning some id's to menu items not by asking wx for
them but just taking them from Python's id() function, which uses huge ints in 64-bit.
So I fixed that problem in my code.
Paul
···
On 1/9/13 7:47 AM, Robin Dunn wrote:
On 1/7/13 5:32 PM, Paul McNett wrote:
Hi,
I've searched but can't find any other mentions of this particular problem. Trying
this test on Mac 10.6.8 with Python 2.7.3/64 and wxPython 2.9.4.0 results in an
OverflowError even though the argument in question is indeed an int.
Traceback (most recent call last):
File "t.py", line 13, in <module>
app.Bind(wx.EVT_MENU_HIGHLIGHT, onHighlight, id=id_)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4228, in Bind
event.Bind(self, id, id2, handler)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4572, in Bind
target.Connect(id1, id2, et, function)
File
"/usr/local/lib/wxPython-2.9.4.0/lib/python2.7/site-packages/wx-2.9.4-osx_cocoa/wx/_core.py",
line 4182, in Connect
return _core_.EvtHandler_Connect(*args, **kwargs)
OverflowError: in method 'EvtHandler_Connect', expected argument 2 of type 'int'
"""
What am I misunderstanding?
It's using this function to fetch and check the value:
SWIGINTERN int
SWIG_AsVal_int (PyObject * obj, int *val)
{
long v;
int res = SWIG_AsVal_long (obj, &v);
if (SWIG_IsOK(res)) {
if ((v < INT_MIN || v > INT_MAX)) {
return SWIG_OverflowError;
} else {
if (val) *val = static_cast< int >(v);
}
}
return res;
}
So it is dependent on the C compiler's definitions for INT_MIN and INT_MAX, not
Python's.