Hi,
MxItemFactory is an interface, so you have to subclass a GObject _and_
On Sun, Dec 16, 2012 at 10:27:55PM +0000, Nox Deleo wrote:
> Hi,
>
> I'm using Clutter and Mx in Python using GObject introspection bindings.
> I've got a Clutter.ListModel full of data, which I'm trying to use with an
> Mx.ItemView. My problem is that I can't seem to subclass either
> Mx.ItemFactory or any Clutter.Actor in a way that the ItemView accepts.
>
> If I try to subclass ItemFactory (to use with Mx.ItemView.set_factory), it
> tells me my object needs to be a GObject derivative. If I try to subclass
> from GObject, it tells me it's expecting an ItemFactory. I'm probably
> missing something obvious.
implement the interface.
This should work as well.
> On the other hand, if I try to subclass a Clutter.Actor, use it with
> Mx.ItemView.set_item_type, and add attribute mappings, I can't seem to get
> my custom properties into the class. The properties from the parent class
> make it in, but any I declare in the __gproperties__ attribute of my class
> just get ignored. It's fine if I subclass straight from GObject, but then
> it rightfully complains that it's not a derivative of Actor.
Here's some sample code to clarify both methods:
from gi.repository import GObject, Clutter, Mx
Clutter.init([])
class CustomActor(Clutter.Text):
def get_custom(self):
return self.get_text()
def set_custom(self, value):
print 'setting custom property to "%s"' % value
self.set_text(value)
custom = GObject.Property(get_custom, set_custom, str)
class CustomFactory(GObject.Object, Mx.ItemFactory):
def do_create(self):
# note the 'do_' prefix when implementing a vfunc
print 'creating actor from factory'
return CustomActor()
stage = Clutter.Stage()
stage.connect('destroy', lambda stage: Clutter.main_quit())
model = Clutter.ListModel()
model.set_types([str])
model.set_names(['custom'])
for i in range(10):
model.insert_value(i, 0, 'custom value %d' % i)
view = Mx.ListView()
# either use the GType with the custom ClutterActor
#view.set_item_type(CustomActor)
# or the custom MxItemFactory
view.set_factory(CustomFactory())
view.add_attribute('custom', 0)
view.set_model(model)
stage.add_child(view)
stage.show()
Clutter.main()
I hope that helps a bit
so long
:wq buz
--
GnuPG Fingerprint: 2FFF FC48 C7DF 1EA0 00A0 FD53 8C35 FD2E 6908 7B82
_______________________________________________
clutter-list mailing list
clutter-list gnome org
https://mail.gnome.org/mailman/listinfo/clutter-list