[Panel-devel] skz files and a crash
A. Wiedenbruch
mail at wiedenbruch.de
Mon Jul 4 13:14:33 CEST 2005
Hi,
ok, a little bit more detailed:
first i have to say that SK doesn't crash, it keeps running but only shows the
uninitialized theme widget.
Now to the real details:
The python scripts are loaded in the KarambaPython constructor.
The most importand parts of it:
...
snprintf(pypath, 1023, "sys.path.insert(0, '%s')", theme.path().ascii());
PyRun_SimpleString(pypath);
...
pName = PyString_FromString(theme.pythonModule().ascii());
pModule = PyImport_Import(pName);
...
So what does it do?
The second function sets the correct path, where the Python script is located.
With a skz-theme it is: /home/wirr/test/lwp-i18n.skz.
Then the second line creates a Python object with the name of the Python
script. So the next function would import the script liquid_weather.py
That's whats printed in the console as you can see from Ryans mail.
In PyImport_Import() the module gets loaded from the filename in pName but
with the path from pypath. So it doesn't load the python script from the skz.
But is trying to load it from /home/wirr/test/lwp-i18n.skz/liquid_weather.py
And that script doesn't exist at this location. That causes to be pModule =
NULL. And i get the error message, when that happens.
Extracting the skz theme to a location does work, because then the path to the
liquid_weather.py is valid.
One thing would be that the PyImport_Import() function is extracting the skz
file automatically. But there are no hints on this in the Python C API.
http://docs.python.org/api/importing.html
To investigate further I searched for a way to access the contents within the
skz file. I fount the method ThemeFile::readThemeFile() that is used to acces
the contents. I grepped for this method but didn't found it in combination
with the python extension.
So I experimented a bit:
QByteArray python = theme.readThemeFile(
theme.pythonModule() + ".py"); // thats the liquid_weather.py
PyObject *tmp = Py_CompileString((char*)python.data(),
theme.pythonModule().ascii(), Py_file_input);
pModule = PyImport_ExecCodeModule((char*)theme.pythonModule().ascii(), tmp);
These lines load the liquid_weather.py from the skz, compiles and run it.
With that, the Python script starts running.
The liquid_weather.py still misses the weather.py as import, but it starts
running until it is needed.
To get complete functionality all python modules should be compiled by SK.
This should be just a matter of iterating over all *.py files that are in the
skz, copile them and ass them as modules.
So, why it works for two people and not for me is a complete mystery for me.
Normally it shouldn't work at all. Perhaps i have missed something.
As i have written earlier, it coul be that both have the theme extraced
manualy in lwp-i18n.skz/ or in the same directory where the lwp-18n.skz is.
Ciao
Alex
More information about the Panel-devel
mailing list