Roberto Cavada wrote:
>>> I am currently trying to port the python wrapper for a gtk
>>> widget (gtkscintilla2).

I got it!
As soon as I get the time to provide some missing code, as well as configuration/building stuff, I'll release PyScintilla-1.99.0.
rob

----------------------------------
(What follows a report that might be useful in the future for other users. Also, contains suggestion about possible improvement of codegen).

Generated code imports from gtk the widget base class, for Scintilla the gtk.Frame type:

_PyGtkFrame_Type = (PyTypeObject *)PyDict_GetItemString(moddict,
"Frame");

Where 'moddict' is of course the gtk module.
Notice that this function does not raise an exception if the given key is not found in the dictionary. In this case returned value is simply NULL.

* My claim here is that codegen should generate code to check the returned value, and if this is NULL, to raise an exception. *


Returned value is used when registering the widget class, as base type:

pygobject_register_class(d, "GtkScintilla", GTK_TYPE_SCINTILLA,
&PyGtkScintilla_Type, Py_BuildValue("(O)", &PyGtkFrame_Type));


Again, notice that Py_BuildValue assumes that if the given object is NULL, an error occurred before it is called, so the corresponding exception has been already handled.
Python documentation states that in this case it returns NULL, without raising an exception. Moreover, if there are not previously set exceptions, it sets PyExc_SystemError.


IN CONCLUSION:
If - as happened in my case - someone specifies a wrong name for the base class type in the override file, the resulting (wrong) behaviour can be really hard to understand.

To complete the report, this was the wrong line in the scintilla.override file:
import gtk.GtkFrame as PyGtkFrame_Type

The fixed version is obviously:
import gtk.Frame as PyGtkFrame_Type


rob

--
------------------------------------------------------
Roberto Cavada
ITC-irst Institute for Scientific and Technological Research
Automated Reasoning Systems - Formal Methods Group
Via Sommarive, 18 - 38050 Povo (TN) - Italy
Tel: +39 0461 314 321 Fax: +39 0461 302 040
[EMAIL PROTECTED] http://sra.itc.it/people/cavada/
------------------------------------------------------

_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to