SWIG and wxWindows events

Hi all,

I've been trying to get the custom wxMozilla events running in wxPython, but
so far have had no luck. When the event gets handled, I get a 'freeze' but
no crash. If I break and then check the stack, this is what I get:

7ffe0304()
KERNEL32! WaitForSingleObject@8 + 15 bytes
WS2_32! SockAsyncThread(struct _SOCK_ASYNC_THREAD_PARAMS *) + 48 bytes
KERNEL32! BaseThreadStart@8 + 55 bytes
00080100() (This address just shows ??? instead of assembly code.)

I'm not quite sure to make of this. Events work in the C++ code, so I'm
pretty sure I'm either doing something wrong in setting up the wxPython
event code, or using a method of specifying events that doesn't mesh well
with Python/wxPython. Is there some code that serves as a simple example of
how to setup custom events using SWIG? I've been using the iehtmlwin.i file
as a guide, but I'm not sure if that's an appropriate example to use. (i.e.
do you always need to define EVT_MYEVENT macros using Python code?) Also,
are there any special caveats when SWIGging events?

Any help on this issue would be greatly appreciated! =)

Thanks,

Kevin

Kevin Ollivier wrote:

Hi all,

I've been trying to get the custom wxMozilla events running in wxPython, but
so far have had no luck. When the event gets handled, I get a 'freeze' but
no crash. If I break and then check the stack, this is what I get:

7ffe0304()
KERNEL32! WaitForSingleObject@8 + 15 bytes
WS2_32! SockAsyncThread(struct _SOCK_ASYNC_THREAD_PARAMS *) + 48 bytes
KERNEL32! BaseThreadStart@8 + 55 bytes
00080100() (This address just shows ??? instead of assembly code.)

I'm not quite sure to make of this. Events work in the C++ code, so I'm
pretty sure I'm either doing something wrong in setting up the wxPython
event code, or using a method of specifying events that doesn't mesh well
with Python/wxPython. Is there some code that serves as a simple example of
how to setup custom events using SWIG? I've been using the iehtmlwin.i file
as a guide, but I'm not sure if that's an appropriate example to use.

wxSTC would be another example.

(i.e.
do you always need to define EVT_MYEVENT macros using Python code?)

Yes, because in wxPython they are not macros but wrappers around the Connect method.

Also,
are there any special caveats when SWIGging events?

No, the only tricky thing is creating custom event types from Python, but the wxPyEvent and wxPyCommandEvent classes take care of that.

Oh, also the custom event Ptr classes need to be visible in the main wx namespace because the EventThunker (see helpers.cpp) will use the wxRTTI class name to lookup the wxPython proxy class in order make an instance to pass to the Python handler function. See one of the _*extras.py files for an example. You also need to ensure that the C++ classes use the wx RTTI macros (DECLARE_*_CLASS and IMPLEMENT_*_CLASS)

Any help on this issue would be greatly appreciated! =)

"Freezing" sounds like it might be a global interpreter lock problem.

First of all, make sure that you or Mozilla isn't sending messages/events from an alternate thread. (Although that should actually work since the ProcessEvent will turn it into a AddPendingEvent if it is not the main thread.)

Secondly, ensure that you are wrapping any calls to or from Python in calls to the appropriate functions:

  // For Python --> C++
  PyThreadState* wxPyBeginAllowThreads();
  void wxPyEndAllowThreads(PyThreadState* state);

  // For C++ --> Python
  void wxPyBeginBlockThreads();
  void wxPyEndBlockThreads();

This includes any manipulation of Python objects using the Python API. If you "%include my_typepmaps.i" then the swig generated stuff will make the correct calls to the first pair above.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi Robin,

Exposing the pointers to the global wx namespace resolved the issue. =) Thanks!

Kevin

···

On Monday, March 31, 2003, at 02:31 PM, Robin Dunn wrote:

Kevin Ollivier wrote:

Hi all,
I've been trying to get the custom wxMozilla events running in wxPython, but
so far have had no luck. When the event gets handled, I get a 'freeze' but
no crash. If I break and then check the stack, this is what I get:
7ffe0304()
KERNEL32! WaitForSingleObject@8 + 15 bytes
WS2_32! SockAsyncThread(struct _SOCK_ASYNC_THREAD_PARAMS *) + 48 bytes
KERNEL32! BaseThreadStart@8 + 55 bytes
00080100() (This address just shows ??? instead of assembly code.)
I'm not quite sure to make of this. Events work in the C++ code, so I'm
pretty sure I'm either doing something wrong in setting up the wxPython
event code, or using a method of specifying events that doesn't mesh well
with Python/wxPython. Is there some code that serves as a simple example of
how to setup custom events using SWIG? I've been using the iehtmlwin.i file
as a guide, but I'm not sure if that's an appropriate example to use.

wxSTC would be another example.

(i.e.
do you always need to define EVT_MYEVENT macros using Python code?)

Yes, because in wxPython they are not macros but wrappers around the Connect method.

Also,
are there any special caveats when SWIGging events?

No, the only tricky thing is creating custom event types from Python, but the wxPyEvent and wxPyCommandEvent classes take care of that.

Oh, also the custom event Ptr classes need to be visible in the main wx namespace because the EventThunker (see helpers.cpp) will use the wxRTTI class name to lookup the wxPython proxy class in order make an instance to pass to the Python handler function. See one of the _*extras.py files for an example. You also need to ensure that the C++ classes use the wx RTTI macros (DECLARE_*_CLASS and IMPLEMENT_*_CLASS)

Any help on this issue would be greatly appreciated! =)

"Freezing" sounds like it might be a global interpreter lock problem.

First of all, make sure that you or Mozilla isn't sending messages/events from an alternate thread. (Although that should actually work since the ProcessEvent will turn it into a AddPendingEvent if it is not the main thread.)

Secondly, ensure that you are wrapping any calls to or from Python in calls to the appropriate functions:

  // For Python --> C++
  PyThreadState* wxPyBeginAllowThreads();
  void wxPyEndAllowThreads(PyThreadState* state);

  // For C++ --> Python
  void wxPyBeginBlockThreads();
  void wxPyEndBlockThreads();

This includes any manipulation of Python objects using the Python API. If you "%include my_typepmaps.i" then the swig generated stuff will make the correct calls to the first pair above.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-dev-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-dev-help@lists.wxwindows.org