[Glade-users] How-to define my own class inheriting from gtk.Window and using glade file
- From: tvb at gnome.org (Tristan Van Berkom)
- Subject: [Glade-users] How-to define my own class inheriting from gtk.Window and using glade file
- Date: Wed, 6 Apr 2011 12:57:32 +0900
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]