[pygtk] Redefining the problem: Related to inheritance

varun_shrivastava varun.celunite at gmail.com
Tue Aug 28 22:29:46 WST 2007


hi

i have inherited my widgets as shown

GtkVBox --> GtkMyDisplayable ---> GtkMyForm

GtkMyDisplayable has an api gtk_my_displayable_add_command(GtkMyDisplayable
*displayable, gchar *string)

so i do following at python prompt

>>> form = mygtk.MyForm()
>>>form.displayable_add_command("_____")
it displays following error
"form has no attribute displayable_add_command"


i have developed the module using steps provided in "extending_python.pdf"
documentation from www.python.org.
So have i done a mistake in writing the mygtkmodule.c file or not using the
codegen scripts properly.
Or i there something i m missing to tell codegen scripts to auto recognize
the inheritance. 


For generating defs file i use this command

python2.5 /usr/local/share/pygtk/2.0/codegen/h2def.py $i > gtkmy.defs
where $i is a variable which contains all the header files name.

For generating enum_types i use glib-mkenums command (providing all the
options it requires)

For generating gtkmywrap.c file i use this command

gtkmywrap.c: gtkmy.defs gtkmy.override
          pygtk-codegen-2.0 --prefix pygtkmy \
              --override gtkmy.override \
             --register $(DEFS)/gtk-types.defs \
              --register $(DEFS)/gdk-types.defs \
              --register $(DEFS)/pango-types.defs \
              gtkmy.defs > $@

i get this as output
***INFO*** The coverage of global functions is 94.12% (16/17)
***INFO*** The coverage of methods is 98.60% (212/215)
***INFO*** There are no declared virtual proxies.
***INFO*** There are no declared virtual accessors.
***INFO*** There are no declared interface proxies. 


i went through the gtk.c file in pygtk source code there i find some
 function as *_class_init being generated.
 but i didn't find any like those in my generated code.
 Is that the problem for not being able to inherit the base class method. 

mygtkmodule.c looks like
1#include <pygobject.h>
      2 
      3 void pygtkmy_register_classes (PyObject *d);
      4 extern PyMethodDef pygtkmy_functions[];
      5 
      6 DL_EXPORT(void)
      7 initpygtkmy(void)
      8 {
      9    PyObject *m, *d;
     10 
     11   init_pygobject ();
     12 
     13    if((m = Py_InitModule ("pygtkmy", pygtkmy_functions)) == NULL)
     14               Py_FatalError ("CAN NOT initialise module pygtkmy");
     15    d = PyModule_GetDict (m);
     16     pygtkmy_add_constants (m,"GTK_MY_");
     17     pygtkmy_register_classes (d);
     18 
     19     if (PyErr_Occurred ()) {
     20             PyErr_Print();
     21               Py_FatalError ("can't initialise module pygtkmy");
     22      }
     23 }




thanks and regards
varun




varun_shrivastava wrote:
> 
> hi
> as we know that in gtk programming i can call API of a GtkWidget using 
> an object of GtkWindow by use of type casting MACROS
> ie
> i can do as
> 
> GtkWindow *window=gtk_window_new();
> ....
> ....
> gtk_widget_show(GTK_WIDGET(window));
> 
> but in python i can't do this because GtkWindow has its own method
> gtk_window_show(), so whenever i do window.show()
> gtk_window_show() will be called instead of gtk_widget_show.
> 
> Is there any solution to this so that i can call gtk_widget_show by using 
> GtkWindow object.
> 

-- 
View this message in context: http://www.nabble.com/how-to-call-a-method-of-GtkWidget-by-using-object-of-GtkWindow-tf4298164.html#a12368922
Sent from the Gtk+ - Python mailing list archive at Nabble.com.



More information about the pygtk mailing list