[Glade-users] How-to define my own class inheriting from gtk.Window and using glade file



On Wed, 2011-04-06 at 21:01 -0400, Dominique Beauchamp wrote:
Thanks for the fast answer.


Here is what I did:


1) I copied pythonplugin.py and pythonplugin.xml as shown in the
example in a directory XYZ
2) I defined an environment variable named GLADE_ENV_CATALOG_PATH =
XYZ (where my .py and my .xml are)

Sorry, the docs in that version have a typo, it should be
 "GLADE_CATALOG_PATH"  (with no _ENV).

3) I started Glade (3.7.3) Where is my widget?


In the xml, I find this:


<glade-widget-group name="python" title="Python">
   <glade-widget-class-ref name="MyBox"/>
 </glade-widget-group>


I guess I should have a group (or a tab) named "Python" with a widget
named "MyBox" but I don't. What did I do incorrectly?


Dominique

2011/4/5 Tristan Van Berkom <tvb at gnome.org>
        
        On Wed, Apr 6, 2011 at 12:46 PM, Dominique Beauchamp
        <lgd.beauchamp at gmail.com> wrote:
        > Hello all!
        > I'm using Glade with PyGTK (Python 2.6) and I'm quite happy
        about the
        > results. I succeed to define an application class like this:
        > class MyApp:
        >
        > def __init__( self ):
        >
        > Builder = gtk.Builder()
        > Builder.add_from_file( 'filename' )
        > Builder.connect_signals( self )
        > self.__MainWnd = Builder.get_object( 'MainWnd' )
        >
        > etc...
        >
        > But here is what I want to do: creating a class that derives
        from gtk.window
        > and being the main window defined within Glade.
        > class MyWnd( gtk.Window ):
        >
        > def __init__( self, ??? ):
        >
        > ...
        >
        > Here I want that the object returned by
        Builder.get_object( 'MainWnd' ) be
        > the object created by the actual class MyWnd because this
        class is in fact a
        > gtk.Window.
        > Is my explaination clear?
        > Maybe it is not possible this way and I have to create
        manually my own
        > gtk.Window then grab the VBox/HBox/Table with
        Builder.get_object() and add
        > it to my window. But it is not that cute.
        > Any idea will be welcome and thanks in advance!
        
        
        Yes, you can define classes in python and use them in Glade
        and GtkBuilder.
        
        For PyGTK & GTK+2 you must use Glade 3.6 or 3.8, if you
        migrate to
        PyObject & GTK+3
        then you must use Glade 3.10.
        
        There is an example of how to setup Glade so that your custom
        python widgets
        show up in Glade's palette, in Glade's API reference here:
        
         http://library.gnome.org/devel/gladeui/3.6/pythonsupport.html
        
        Basically you just have to define a short xml catalog and have
        it in
        GLADE_CATALOG_PATH
        when firing up Glade, and have a copy of the python source in
        the same
        directory.
        
        Enjoy,
            -Tristan



-- 
Dominique Beauchamp
lgd.beauchamp at gmail.com



_______________________________________________
Glade-users maillist  -  Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]