Extending python to our own gtk inherited Widgets

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • varuns
    New Member
    • Jun 2007
    • 39

    Extending python to our own gtk inherited Widgets

    hi
    i extended python to my own widgets inherited from gtk.
    But when i try to run command
    Code:
    python2.5 -c "import mygtk"
    it displays following error
    Code:
    "TypeError: mro() returned base with unsuitable layout ('gtkmy.MyChoice')"
    ...
    ..
    
    "** (-c:13962): WARNING **: couldn't make the type `gtkmy.MyList' ready"
    "TypeError: multiple bases have instance lay-out conflict
    (!) [13962:   33.658] --> Caught signal 11 (at (nil), invalid address) <--
    (!) Direct/Thread: Canceling 'Fusion Dispatch' (13964)!
    Aborted (core dumped)
    "
    my widget heirarchy is as shown
    GtkVBox -- > GtkMyDisplayabl e --> GtkMyScreen --> GtkMyList --> GtkMyFileBrowse r

    what i think is python is trying to initialize GtkMyList first before its parent thats why the error "instance lay-out conflict". If i m correct than can any one help me out with a question:: how to serialize the initialization process? (ie parent class gets initialized before child class.) And if i m wrong than whats this error for?

    kindly help

    Varun
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    That sure looks like it's coming from the C API and not from the Python that we all know and love.

    By "extending" , I'm guessing that you mean you are writing and compiling the extension in C.

    Comment

    • varuns
      New Member
      • Jun 2007
      • 39

      #3
      i figured out the problem. I thought, i followed code writing standard of Gtk, but not i did some mistake and the .defs file generator (h2def.py) was unable to generate the "scheme" for interface (GTypeInterface ) (i have to still figure that out). But i edited directly the generated .defs file.
      Generated scheme for my interface looked like
      Code:
      ;; -*- scheme -*-
             ; object definitions ...
             (define-object MyChoice
               (in-module "Gtk")
              (c-name "GtkMyChoice")
              (gtype-id "GTK_TYPE_MY_CHOICE")
             )
      but it should look like

      Code:
      ;; -*- scheme -*-
             ; [B]interface[/B] definitions ...
             (define-[B]interface[/B] MyChoice
               (in-module "Gtk")
               (c-name "GtkMyChoice")
               (gtype-id "GTK_TYPE_MY_CHOICE")
               [B](prerequisites "GtkMyImage") #----> quotes should contain object name of corresponding #included file;(i think so, not so sure, i just checked how pygtk people have written there .defs file). In my case its #include "gtkmyimage.h"[/B]   
             )
      I made these changes and the error was gone.


      Originally posted by bartonc
      By "extending" , I'm guessing that you mean you are writing and compiling the extension in C.
      yes, i m trying to write something similar to pygtk, as we can access gtk api's from python using wrapper functions and Python APIS like Py_ArgParseTupl e, Py_BuildValue etc etc........, so that i can just use python scripts instead of long C code and also i m learning and using python because manipulation of data is really easy in Python.

      Also i have posted solution for "undefined variable gdk_keyval_conv ert_case" for directFB at http://www.thescripts.com/forum/thread657353.html

      Comment

      • varuns
        New Member
        • Jun 2007
        • 39

        #4
        Originally posted by varuns
        generator (h2def.py) was unable to generate the "scheme" for interface (GTypeInterface ) (i have to still figure that out).
        hi
        replying to myself..

        i consulted authors of pygtk group and the information they provided is
        h2def.py never generate scheme as define-interface, they generate it as define-objects. You need to manually edit it.

        Also You could try defsgen.py:



        which uses ctypes to generate .defs - its more comprehensive in
        generating .defs.

        else you can change manually object to interface and use scanvirtuals.py



        to retrive the virtual methods.

        cheers

        Comment

        Working...