Re: [pygtk] Problem incorporating Python-subclassed widget into Glade

2004-09-02 Thread Johan Dahlin
ons 2004-09-01 klockan 15.27 skrev Skip Montanaro:
 I subclassed gtk.Table, then started trying to integrate it with Glade-2.  I
 realized I needed to set __gproperties__ to add a property to the class, so
 I added that:

In 2.3.9x I added a fourth argument to gtk.glade.XML, it's a dictionary
used to do lookups, so if you send in {'GtkTable': 'MyTable' } and have
registered a GType with the same name it should instanstiate that
object.

However, as you have noticed the python constructor, __init__ is not
called. That's because when libglade creates widgets it uses
g_object_new (which is wrapped as gobject.new in python) which just uses
a GObject constructor. I don't think, at this point, that its possible
to put any python code in there. I'm afraid you have to do something
else, perhaps __new__ works?


Johan
-- 
Johan Dahlin [EMAIL PROTECTED]

___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/


[pygtk] Problem incorporating Python-subclassed widget into Glade

2004-09-01 Thread Skip Montanaro

I subclassed gtk.Table, then started trying to integrate it with Glade-2.  I
realized I needed to set __gproperties__ to add a property to the class, so
I added that:

__gproperties__ = { 
'use_checkboxes' :
(gobject.TYPE_BOOLEAN,  # type
 'use checkboxes for Booleans', # nick name
 'use checkboxes for Booleans', # description
 True,  # default value
 gobject.PARAM_READWRITE|gobject.PARAM_CONSTRUCT # flags
 )   
}

I also changed my superclass init call from

gtk.GtkTable.__init__(self, rows, cols)

to

gobject.__gobject_init__()
self.set_property(n-rows, rows)
self.set_property(n-columns, cols)

I have other instance attributes as well:

self.widgets = {}
self.values = {}
self.formats = {}
self.default_format = %s

I will eventually change default_format to a property.

If I instantiate my Table widget from Python, it seems to work fine.  When
it's instantiated via Glade its __init__ method doesn't appear to be called
though.  A print statement placed in Table.__init__() is not executed, and
Python denies that my class has a widgets attribute.

I incorporated the class into Glade by adding a regular GtkTable where I
wanted my Table, then using the output of

print gobject.type_name(Table)

I substituted that for GtkTable in my Glade file:

widget class=Utilities+table+Table id=ContractArea
  property name=visibleTrue/property
  property name=n_rows1/property
  property name=n_columns6/property
  property name=homogeneousFalse/property
  property name=row_spacing0/property
  property name=column_spacing0/property
/widget

I must be missing something, but I'm not sure what.  Any ideas?

Thx,

-- 
Skip Montanaro
Got spam? http://www.spambayes.org/
[EMAIL PROTECTED]
___
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/