Hi,
I'm moving my codebase to Gtk 3.1 now with the newly GObject 3.0.1.
My View class has to inherit from Gtk.Scrollable and implement/override a few
properties.
class MyView(Gtk.DrawingArea, Gtk.Scrollable):
pass
On load I get those errors:
/usr/local/Cellar/pygobject3/3.0.1/lib/python2.7/site-packages/gi/_gobject/__init__.py:119:
Warning: Object class
MyView doesn't implement property 'vscroll-policy' from interface
'GtkScrollable'
type_register(cls, namespace.get('__gtype_name__'))
etc.
That's okay, since I have to implement the properties defined in the interface.
GObject provides method for this: GObject.ObjectClass.override_property().
But how do I use this?
Regards,
Arjan
On 17 Jun 2011, at 16:46, Just Fill Bugs wrote:
> On 06/17/2011 05:05 PM, Arjan Molenaar wrote:
>>
>> On 17 Jun 2011, at 05:25, Just Fill Bugs wrote:
>>
>>> On 06/17/2011 12:44 AM, Arjan Molenaar wrote:
>>>> Hi,
>>>>
>>>> I've started porting Gaphas to GTK+ 3 now, using PyGI on Linux. It all
>>>> goes quite smoothly. Only now I'm running
>>>> into the problem that my widget should implement the Gtk.Scrollable
>>>> interface. For that it should define
>>>> a few properties.
>>>>
>>>> In C those need to be declared using g_object_class_override_property().
>>>> What's the Python counterpart for this?
>>>>
>>>
>>> It seems the PyGobject examples/properties.py works okey once you replaced
>>> gobject with GObject to make it gi compatible. So take a look at the
>>> PyGobject's examples directory.
>>
>> Did that. Only there the creation of new properties is demoed. I need to
>> implement properties defined in an interface. For that the protocol is
>> slightly different. I can't find how that is covered.
>>
>
> Aha, looking into pygobject source tree under the tests/test_properties.py,
> it shows how to do the getter/setter in the
> class TestProperty(unittest.TestCase):
>
> def testCustomGetter(self):
> class C(gobject.GObject):
> def get_prop(self):
> return 'value'
> prop = gobject.property(getter=get_prop)
>
> o = C()
> self.assertEqual(o.prop, 'value')
> self.assertRaises(TypeError, setattr, o, 'prop', 'xxx')
>
> def testCustomSetter(self):
> class C(gobject.GObject):
> def set_prop(self, value):
> self._value = value
> prop = gobject.property(setter=set_prop)
>
> def __init__(self):
> self._value = None
> gobject.GObject.__init__(self)
>
> o = C()
> self.assertEquals(o._value, None)
> o.prop = 'bar'
> self.assertEquals(o._value, 'bar')
> self.assertRaises(TypeError, getattr, o, 'prop')
>
> So you have to specify getter/setter when declare properties at
> gobject.property().
>
> Someone should make a better example for the new style property specification
> in the doc.
>
>
>
>
> _______________________________________________
> pygtk mailing list [email protected]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://faq.pygtk.org/
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/