[pygtk] gobject again: property values being overwritten: possible bug?

Fallenblood fallenblood at gmail.com
Sun Aug 3 23:56:30 WST 2008


Alright, I sorted it all out with do_set_property and
do_get_property... Somebody from the glib guys could've mentioned that
you must attend to storing the values yourself... I see the reason for
things to be that way.

My next problem with gobject is, in short: I have a list of GObject
subclass instances, which are seemingly initialized with correct
(different) gproperties, but, as soon as I try to get them, they're
all the same.

In more detail, I have the following class:

class Playlist(gobject.GObject):
...
  __gproperties__ = {
...
                     'name':
                       (gobject.TYPE_STRING, "", "", "Playlist",
gobject.PARAM_CONSTRUCT|gobject.PARAM_READWRITE),
...
                       }

  __gvalues__ = {}

  def __init__(self, green, format, name):
    gobject.GObject.__init__(self)
...
    self.props.name = name
    print self.props.name

  def get_name(self):
    return self.props.name
  def get_length(self):
    return self.props.length

  def do_set_property(self, property, value):
    self.__gvalues__[property.name] = value
  def do_get_property(self, property):
    try:
      return self.__gvalues__[property.name]
    except KeyError:
      return None

In the __init__ method of another class (let's just call it Engine), I
have this:

for x in plists.value():
  self.props.playlists.append(Playlist(self.green,
self.green.config.get('playlist_format'), x))

where plists.value() is [u'_active', u'Default']. The above code
creates and initializes those Playlist objects with, as some print
statements in Playlist.__init__() state, correct "name" properties.
However, as soon as I call:

for x in self.props.playlists:
  print x.get_name()

both names are 'Default'. Judging from some quick tests I made, all
gproperties are overridden. The ordinary class attributes, however,
remain unaffected.


More information about the pygtk mailing list