embedding python widgets in C++ app
10 answers - 886 bytes -

My mail config was a little messed up, so I'm trying to manually
continue this thread.
David: I've copied your code almost exactly, and I'm getting seg
faults in Py_C after copying your call_function() from the
web. The pyDict and callable pointers are both valid any ideas?
Phil: Why does PyQt4.QtCore still not exist after the following code:
extern "C"
{
void initsip();
void initQtCore();
void initQtGui();
}
int main()
{
struct _inittab builtin_modules[] = {
{ "sip", initsip },
{ "PyQt4.QtCore", initQtCore },
{ "PyQt4.QtGui", initQtGui },
{ NULL, NULL }
};
PyImport_ExtendInittab(builtin_modules);
printf("Initializing Python");
Py_Initialize();
printf(" done.\n");
PyRun_SimpleString("import PyQt4.QtCore");
}
"no module PyQt4.QtCore"
No.1 | | 1295 bytes |
| 
Friday 26 January 2007 7:40 am, Patrick Stinson wrote:
My mail config was a little messed up, so I'm trying to manually
continue this thread.
David: I've copied your code almost exactly, and I'm getting seg
faults in Py_C after copying your call_function() from the
web. The pyDict and callable pointers are both valid any ideas?
Phil: Why does PyQt4.QtCore still not exist after the following code:
extern "C"
{
void initsip();
void initQtCore();
void initQtGui();
}
int main()
{
struct _inittab builtin_modules[] = {
{ "sip", initsip },
{ "PyQt4.QtCore", initQtCore },
{ "PyQt4.QtGui", initQtGui },
{ NULL, NULL }
};
PyImport_ExtendInittab(builtin_modules);
printf("Initializing Python");
Py_Initialize();
printf(" done.\n");
PyRun_SimpleString("import PyQt4.QtCore");
}
"no module PyQt4.QtCore"
I assume that "import sip" works.
I would try something like "import sys; print sys.builtin_module_names" after
the QtCore import to see what's actually there and what it is called. The
fact that QtCore is part of a package may affect things.
Phil
PyKDE mailing list PyKDE (AT) mats (DOT) imk.fraunhofer.de
No.2 | | 3533 bytes |
| 
ok, removing all instances of "PyQt4." from the cpp, and without
modifying the sip files, I get this error for
PyRun_SimpleString("import QtCore; print QtCore"):
SystemError: _PyImport_FixupExtension: module QtCore not loaded
and this error for PyRun_SimpleString("import QtGui; print QtGui"):
ImportError: No module named PyQt4.QtCore
After changing the module names in the sip files and recompiling the
PyQt4 static libs it seems to work. I That means that the PyQt4
package definately gets in the way.
So this looks fine except everyone on our team has to do this
everytime they download a new version. Ideas?
1/26/07, Patrick Stinson <patrickkidd.lists (AT) gmail (DOT) comwrote:
then wouldn't the modulename in the sip file have to not be PyQt4.QtCore?
I'll give it a shot in my cpp, then I'll try changing the module name
in the sip file and rebuilding pyqt
1/26/07, Phil Thompson <phil (AT) riverbankcomputing (DOT) co.ukwrote:
Friday 26 January 2007 11:03 pm, you wrote:
ok, so I added them back in but have the following problem:
struct _inittab builtin_modules[] = {
{ "sip", initsip },
{ "PyQt4.QtCore", initQtCore },
{ "PyQt4.QtGui", initQtGui },
{ NULL, NULL }
};
PyImport_ExtendInittab(builtin_modules);
printf("Initializing Python");
Py_Initialize();
printf(" done.\n");
printf("\n");
PyRun_SimpleString("import sys; print sys.builtin_module_names");
PyRun_SimpleString("import PyQt4.QtGui; print PyQt4.QtGui");
printf("\n");
PyRun_SimpleString("import sys; print sys.builtin_module_names");
PyRun_SimpleString("import sys; print
sys.modules['__builtin__']dict__['PyQt4.QtCore']");
printf("\n");
PyRun_SimpleString("from PyQt4.QtGui import QWidget\n"
"class Widget(QWidget): \n"
" pass");
>
>
>
yields
>
>
>
Initializing Python done.
('PyQt4.QtCore', 'PyQt4.QtGui', '__builtin__', '__main__', '_codecs',
'_sre', '_symtable', 'errno', 'exceptions', 'gc', 'imp', 'marshal',
'posix', 'signal', 'sip', 'sys', 'thread', 'xxsubtype', 'zipimport')
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named PyQt4.QtGui
('PyQt4.QtCore', 'PyQt4.QtGui', '__builtin__', '__main__', '_codecs',
'_sre', '_symtable', 'errno', 'exceptions', 'gc', 'imp', 'marshal',
'posix', 'signal', 'sip', 'sys', 'thread', 'xxsubtype', 'zipimport')
Traceback (most recent call last):
File "<string>", line 1, in ?
KeyError: 'PyQt4.QtCore'
Traceback (most recent call last):
File "<string>", line 1, in ?
ImportError: No module named PyQt4.QtGui
turin:~/test patrick$
The other obvious thing to try is to ignore the PyQt4 package completely. In
the inittab put
{"QtCore", initQtCore}
and then
PyRun_SimpleString("import QtCore; print QtCore");
Phil
>
>
>
No.3 | | 1011 bytes |
| 
Saturday 27 January 2007 4:21 am, Patrick Stinson wrote:
ok, removing all instances of "PyQt4." from the cpp, and without
modifying the sip files, I get this error for
PyRun_SimpleString("import QtCore; print QtCore"):
SystemError: _PyImport_FixupExtension: module QtCore not loaded
and this error for PyRun_SimpleString("import QtGui; print QtGui"):
ImportError: No module named PyQt4.QtCore
After changing the module names in the sip files and recompiling the
PyQt4 static libs it seems to work. I That means that the PyQt4
package definately gets in the way.
So this looks fine except everyone on our team has to do this
everytime they download a new version. Ideas?
So if I added a command line flag to SIP to ignore all but the last part of
a %Module directive, and tied that flag to the -k flag of PyQt's
configure.py, then it should work ?
Phil
PyKDE mailing list PyKDE (AT) mats (DOT) imk.fraunhofer.de
No.4 | | 1461 bytes |
| 
ok, removing all instances of "PyQt4." from the cpp, and without
modifying the sip files, I get this error for
PyRun_SimpleString("import QtCore; print QtCore"):
SystemError: _PyImport_FixupExtension: module QtCore not loaded
and this error for PyRun_SimpleString("import QtGui; print QtGui"):
ImportError: No module named PyQt4.QtCore
After changing the module names in the sip files and recompiling the
PyQt4 static libs it seems to work. I That means that the PyQt4
package definately gets in the way.
So this looks fine except everyone on our team has to do this
everytime they download a new version. Ideas?
So if I added a command line flag to SIP to ignore all but the last part of
a %Module directive, and tied that flag to the -k flag of PyQt's
configure.py, then it should work ?
I run into the exact same problem as Patrick a couple of days ago. I have
submitted a patch to the Python team that allows "import PyQt4.QtCore" to
work. You can find the patch here:
I would vote against renaming PyQt4.QtCore to QtCore for the statically linked
PyQt because then it would mean that you need "from PyQt4 import QtCore" if
you have linked PyQt4 dynamically and "import QtCore" if you have linked it
statically. I use static PyQt4 in Windows (for ease of deployment), but in
Linux I use the dynamic version, so this solution would be inconvenient for
me.
No.5 | | 1976 bytes |
| 
Saturday 27 January 2007 10:33 am, Miguel Lobo wrote:
ok, removing all instances of "PyQt4." from the cpp, and without
modifying the sip files, I get this error for
PyRun_SimpleString("import QtCore; print QtCore"):
SystemError: _PyImport_FixupExtension: module QtCore not loaded
and this error for PyRun_SimpleString("import QtGui; print QtGui"):
ImportError: No module named PyQt4.QtCore
After changing the module names in the sip files and recompiling the
PyQt4 static libs it seems to work. I That means that the PyQt4
package definately gets in the way.
So this looks fine except everyone on our team has to do this
everytime they download a new version. Ideas?
So if I added a command line flag to SIP to ignore all but the last part
of a %Module directive, and tied that flag to the -k flag of PyQt's
configure.py, then it should work ?
I run into the exact same problem as Patrick a couple of days ago. I have
submitted a patch to the Python team that allows "import PyQt4.QtCore" to
work. You can find the patch here:
>305470
>
I would vote against renaming PyQt4.QtCore to QtCore for the statically
linked PyQt because then it would mean that you need "from PyQt4 import
QtCore" if you have linked PyQt4 dynamically and "import QtCore" if you
have linked it statically. I use static PyQt4 in Windows (for ease of
deployment), but in Linux I use the dynamic version, so this solution would
be inconvenient for me.
That's a good point - I was only thinking of the embedded case where you often
do the imports separately.
If your patch doesn't get accepted then I'm happy to host it. As you are
building a bespoke interpreter anyway it's no great problem to have to apply
a patch as well.
Phil
PyKDE mailing list PyKDE (AT) mats (DOT) imk.fraunhofer.de
No.6 | | 2960 bytes |
| 
Well, at the moment everything works (with the exception of the #undef
slots problem) with the python framework that ships with S X Tiger,
and applying a patch means *moving to* building a custom interpreter
for us. Personally I was very excited about how nailed down and easy
deployment of sip and pyqt became with the qt-4 releases - which was
anything but a selling point before that.
As Miguel says, it would also be a shame that the import name would
change between versions. I know the code is not in the beta stage that
it was when I brought this up before, but I personally think that the
PyQt4 package serves no purpose and should be removed entirely.
Elementtree is becoming (already?) part of the stdlib, and uic and
pyqtconfig should also live at the top level.
BTW, what ever became of the #undef slots problem, Phil? Did you ever
add something for that?
1/27/07, Phil Thompson <phil (AT) riverbankcomputing (DOT) co.ukwrote:
Saturday 27 January 2007 10:33 am, Miguel Lobo wrote:
ok, removing all instances of "PyQt4." from the cpp, and without
modifying the sip files, I get this error for
PyRun_SimpleString("import QtCore; print QtCore"):
SystemError: _PyImport_FixupExtension: module QtCore not loaded
and this error for PyRun_SimpleString("import QtGui; print QtGui"):
ImportError: No module named PyQt4.QtCore
After changing the module names in the sip files and recompiling the
PyQt4 static libs it seems to work. I That means that the PyQt4
package definately gets in the way.
So this looks fine except everyone on our team has to do this
everytime they download a new version. Ideas?
So if I added a command line flag to SIP to ignore all but the last part
of a %Module directive, and tied that flag to the -k flag of PyQt's
configure.py, then it should work ?
I run into the exact same problem as Patrick a couple of days ago. I have
submitted a patch to the Python team that allows "import PyQt4.QtCore" to
work. You can find the patch here:
>305470
>
I would vote against renaming PyQt4.QtCore to QtCore for the statically
linked PyQt because then it would mean that you need "from PyQt4 import
QtCore" if you have linked PyQt4 dynamically and "import QtCore" if you
have linked it statically. I use static PyQt4 in Windows (for ease of
deployment), but in Linux I use the dynamic version, so this solution would
be inconvenient for me.
That's a good point - I was only thinking of the embedded case where you often
do the imports separately.
If your patch doesn't get accepted then I'm happy to host it. As you are
building a bespoke interpreter anyway it's no great problem to have to apply
a patch as well.
Phil
PyKDE mailing list PyKDE (AT) mats (DOT) imk.fraunhofer.de
No.7 | | 1182 bytes |
| 
Saturday 27 January 2007 6:38 pm, Patrick Stinson wrote:
Well, at the moment everything works (with the exception of the #undef
slots problem) with the python framework that ships with S X Tiger,
and applying a patch means *moving to* building a custom interpreter
for us. Personally I was very excited about how nailed down and easy
deployment of sip and pyqt became with the qt-4 releases - which was
anything but a selling point before that.
As Miguel says, it would also be a shame that the import name would
change between versions. I know the code is not in the beta stage that
it was when I brought this up before, but I personally think that the
PyQt4 package serves no purpose and should be removed entirely.
Elementtree is becoming (already?) part of the stdlib, and uic and
pyqtconfig should also live at the top level.
It's there to ensure that PyQt4 can be installed side-by-side with PyQt5.
BTW, what ever became of the #undef slots problem, Phil? Did you ever
add something for that?
Check the Changelog.
Phil
PyKDE mailing list PyKDE (AT) mats (DOT) imk.fraunhofer.de
No.8 | | 1229 bytes |
| 
1/27/07, Phil Thompson <phil (AT) riverbankcomputing (DOT) co.ukwrote:
Saturday 27 January 2007 6:38 pm, Patrick Stinson wrote:
Well, at the moment everything works (with the exception of the #undef
slots problem) with the python framework that ships with S X Tiger,
and applying a patch means *moving to* building a custom interpreter
for us. Personally I was very excited about how nailed down and easy
deployment of sip and pyqt became with the qt-4 releases - which was
anything but a selling point before that.
As Miguel says, it would also be a shame that the import name would
change between versions. I know the code is not in the beta stage that
it was when I brought this up before, but I personally think that the
PyQt4 package serves no purpose and should be removed entirely.
Elementtree is becoming (already?) part of the stdlib, and uic and
pyqtconfig should also live at the top level.
It's there to ensure that PyQt4 can be installed side-by-side with PyQt5.
hmm
BTW, what ever became of the #undef slots problem, Phil? Did you ever
add something for that?
Check the Changelog.
Sorry, I don't see anything
Phil
No.9 | | 1282 bytes |
| 
I mashed up a simple and dry reference for this procedure. I'm still
editing it a little
1/27/07, Phil Thompson <phil (AT) riverbankcomputing (DOT) co.ukwrote:
Saturday 27 January 2007 6:38 pm, Patrick Stinson wrote:
Well, at the moment everything works (with the exception of the #undef
slots problem) with the python framework that ships with S X Tiger,
and applying a patch means *moving to* building a custom interpreter
for us. Personally I was very excited about how nailed down and easy
deployment of sip and pyqt became with the qt-4 releases - which was
anything but a selling point before that.
As Miguel says, it would also be a shame that the import name would
change between versions. I know the code is not in the beta stage that
it was when I brought this up before, but I personally think that the
PyQt4 package serves no purpose and should be removed entirely.
Elementtree is becoming (already?) part of the stdlib, and uic and
pyqtconfig should also live at the top level.
It's there to ensure that PyQt4 can be installed side-by-side with PyQt5.
BTW, what ever became of the #undef slots problem, Phil? Did you ever
add something for that?
Check the Changelog.
Phil
No.10 | | 651 bytes |
| 
It's there to ensure that PyQt4 can be installed side-by-side with PyQt5.
I like the fact that QtCore and so on are submodules of PyQt4, instead of
top-level modules. It reduces the chance of namespace clashes, which are
always annoying.
It seems to me that Python is a bit too lax on the namespace clash avoidance
issue. There are too many standard modules with simple names that might
clash with the user's own modules. Perhaps they should do like Java and have
python.lang.*, python.util.* and so on.
Anyway I hope my patch gets accepted, which should solve the problem as far as
PyQt4 is concerned.