OT : Python embedding in wxWindows C++ (w/ hint for your Ctrl-C problem)

See the docs for sys.settrace

Looks like it'll do it... It's fairly well laid out in python's
Lib/pdb.py debugger.

Which got me to thinking that maybe I should just embed wxPython itself and just use PyShell as is. I tried the embedded.cpp sample, but it exits with this (current CVS, GTK 1.2)

[New Thread 16384 (LWP 19760)]
Fatal Python error: PyEval_RestoreThread: NULL tstate

Program received signal SIGABRT, Aborted.
[Switching to Thread 16384 (LWP 19760)]
0x4073f481 in kill () from /lib/i686/libc.so.6
(gdb) bt
#0 0x4073f481 in kill () from /lib/i686/libc.so.6
#1 0x406cfacd in pthread_kill () from /lib/i686/libpthread.so.0
#2 0x406cfdeb in raise () from /lib/i686/libpthread.so.0
#3 0x4073f224 in raise () from /lib/i686/libc.so.6
#4 0x4074076b in abort () from /lib/i686/libc.so.6
#5 0x405a0049 in Py_FatalError () from /usr/lib/libpython2.2.so.0.0
#6 0x402aaafe in ~wxAppBase (this=0x80a97f0) at src/common/appcmn.cpp:115
#7 0x4023e168 in ~wxApp (this=0x80a97f0) at src/gtk/app.cpp:428
#8 0x0804d49c in MyApp::~MyApp() ()
#9 0x4023edeb in wxApp::CleanUp() () at src/gtk/app.cpp:729
#10 0x4023f086 in wxEntryCleanup() () at src/gtk/app.cpp:839
#11 0x4023f3bb in wxEntry(int, char**) (argc=1, argv=0xbffff664) at src/gtk/app.cpp:930
#12 0x0804d580 in main ()
#13 0x4072c7f7 in __libc_start_main () from /lib/i686/libc.so.6

The line numbers are probably wrong, since I first tried to move the python shutdown stuff to a virtual int MyApp::OnExit() so that it would get shutdown before wxApp::Cleanup, but finally I had to move it to the Frame's OnExit and then it exited without error. This is not the most sensible place for it, but it seems as though python has to get shutdown before wxApp's OnExit and I don't know another way.

John Labenski

ps. You need to add these to the current CVS for your setup.py to get and scintilla python code to work, otherwise you get undefined symbols.

diff -bu2 setup.py mysetup.py

@@ -807,13 +807,17 @@
                       '%s/scintilla/src/ViewStyle.cxx' % STCLOC,
                       '%s/scintilla/src/WindowAccessor.cxx' % STCLOC,
+ '%s/scintilla/src/XPM.cxx' % STCLOC,

                       '%s/scintilla/src/LexAda.cxx' % STCLOC,
+ '%s/scintilla/src/LexAsm.cxx' % STCLOC,
                       '%s/scintilla/src/LexAVE.cxx' % STCLOC,
                       '%s/scintilla/src/LexBaan.cxx' % STCLOC,
                       '%s/scintilla/src/LexBullant.cxx' % STCLOC,
- '%s/scintilla/src/LexCPP.cxx' % STCLOC,
                       '%s/scintilla/src/LexConf.cxx' % STCLOC,
+ '%s/scintilla/src/LexCPP.cxx' % STCLOC,
                       '%s/scintilla/src/LexCrontab.cxx' % STCLOC,
+ '%s/scintilla/src/LexCSS.cxx' % STCLOC,
                       '%s/scintilla/src/LexEiffel.cxx' % STCLOC,
+ '%s/scintilla/src/LexFortran.cxx' % STCLOC,
                       '%s/scintilla/src/LexHTML.cxx' % STCLOC,
                       '%s/scintilla/src/LexLisp.cxx' % STCLOC,
@@ -823,4 +827,5 @@
                       '%s/scintilla/src/LexPascal.cxx' % STCLOC,
                       '%s/scintilla/src/LexPerl.cxx' % STCLOC,
+ '%s/scintilla/src/LexPOV.cxx' % STCLOC,
                       '%s/scintilla/src/LexPython.cxx' % STCLOC,
                       '%s/scintilla/src/LexRuby.cxx' % STCLOC,

John Labenski:

ps. You need to add these to the current CVS for your setup.py to get
and scintilla python code to work, otherwise you get undefined symbols.

diff -bu2 setup.py mysetup.py

@@ -807,13 +807,17 @@
                       '%s/scintilla/src/ViewStyle.cxx' % STCLOC,
                       '%s/scintilla/src/WindowAccessor.cxx' % STCLOC,
+ '%s/scintilla/src/XPM.cxx' % STCLOC,

                       '%s/scintilla/src/LexAda.cxx' % STCLOC,
+ '%s/scintilla/src/LexAsm.cxx' % STCLOC,
                       '%s/scintilla/src/LexAVE.cxx' % STCLOC,
                       '%s/scintilla/src/LexBaan.cxx' % STCLOC,
                       '%s/scintilla/src/LexBullant.cxx' % STCLOC,
- '%s/scintilla/src/LexCPP.cxx' % STCLOC,
                       '%s/scintilla/src/LexConf.cxx' % STCLOC,
+ '%s/scintilla/src/LexCPP.cxx' % STCLOC,
                       '%s/scintilla/src/LexCrontab.cxx' % STCLOC,
+ '%s/scintilla/src/LexCSS.cxx' % STCLOC,
                       '%s/scintilla/src/LexEiffel.cxx' % STCLOC,
+ '%s/scintilla/src/LexFortran.cxx' % STCLOC,
                       '%s/scintilla/src/LexHTML.cxx' % STCLOC,
                       '%s/scintilla/src/LexLisp.cxx' % STCLOC,
@@ -823,4 +827,5 @@
                       '%s/scintilla/src/LexPascal.cxx' % STCLOC,
                       '%s/scintilla/src/LexPerl.cxx' % STCLOC,
+ '%s/scintilla/src/LexPOV.cxx' % STCLOC,
                       '%s/scintilla/src/LexPython.cxx' % STCLOC,
                       '%s/scintilla/src/LexRuby.cxx' % STCLOC,

   If you can stick arbitrary executable python code here, it is safe to add
the equivalent of
   '%s/scintilla/src/Lex*.cxx' % STCLOC,
   The naming convention is very stable and is used by the included
LexGen.py that regenerates most of the project and make files distributed
with Scintilla.

   Neil

John Labenski wrote:

> See the docs for sys.settrace

Looks like it'll do it... It's fairly well laid out in python's
Lib/pdb.py debugger.

Which got me to thinking that maybe I should just embed wxPython itself and just use PyShell as is. I tried the embedded.cpp sample, but it exits with this (current CVS, GTK 1.2)

[New Thread 16384 (LWP 19760)]
Fatal Python error: PyEval_RestoreThread: NULL tstate

Thanks, I'll check into this.

ps. You need to add these to the current CVS for your setup.py to get and scintilla python code to work, otherwise you get undefined symbols.

I've been working mostly on the 2.4 branch for the past few weeks and I still need to merge recent changes back to the main trunk...

···

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

Neil Hodgson wrote:

   If you can stick arbitrary executable python code here, it is safe to add
the equivalent of
   '%s/scintilla/src/Lex*.cxx' % STCLOC,
   The naming convention is very stable and is used by the included
LexGen.py that regenerates most of the project and make files distributed
with Scintilla.

Good idea. Thanks.

···

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