On Wed, 18 Apr 2001, Skip Montanaro wrote:
> In examples/neil/TAppli.py it creates an item factory thus:
>
> itemf = gtk.GtkItemFactory(gtk.GtkMenuBar, "<main>", ag)
>
> This call fails under pygtk2, complaining that the first arg is supposed to
> be an integer. After a little muddling around I found the __gtype__
> attribute of GObjects. On more-or-less of a whim I tried modifying the
> above to
>
> itemf = gtk.GtkItemFactory(gtk.GtkMenuBar.__gtype__, "<main>", ag)
I have been fiddling round with the handling of typecodes (and haven't
finished fiddling). I will probably modify the code generator so that
functions expecting a GType argument will either accept an integer or an
object with a __gtype__ attribute.
>
> After making a couple other unrelated changes, this script seems to work
> (changes appended). I worry about referencing the __gtype__ attribute
> directly, but didn't see any sort of "get_type" method. Am I missing
> something?
I used to have get_type() functions to get the typecode, but switched over
to __gtype__ attributes. For the classes in the gtk module, the __gtype__
attributes are of a special type that doesn't call the C level get_type()
function til it is needed. This delays registration of the types until
they are needed.
Soon I will have support for creating new GTypes for user defined classes,
which will just set an integer as the __gtype__ attribute. The code would
look something like this:
class MyClass(gobject.GObject):
def __init__(self):
# can't chain up to parent class, or we would end up
# wrapping a GObject of the parent type.
self.__generic_init__()
gobject.register_type(MyClass)
You could then add signals to MyClass, without them being added to the
parent class.
>
> On an unrelated note, I think standard practice should be to use "import
> gtk", not "from gtk import *", if for no other reason than that the gtk
> module defines the names TRUE and FALSE, which are fairly easy to clash
> with.
In all my new examples (see examples/pygtk-demo for one), I use "import
gtk". By the time I have a stable 2.0 binding, I plan to have converted
all examples over to using "import gtk". I recommend using "import gtk"
when people ask.
James.
_______________________________________________
pygtk mailing list [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk