With the python bindings for gtk, we have wrappers around the gtk objects
(widgets are objects).  We don't want the gtk objects to be freed while we
still have a python reference to them, as this would cause problems and
probably also segfaults.

Now in order to have the same python object refer to a particular gtk
object all the time, the gtk object would need to hold a reference to it
(we don't want the python object to be freed while the gtk object is in
use).  This forms a circular dependency, and would prevent objects from
being freed altogether.

To get around this, multiple python objects are used to refer to a single
gtk object.  That is why you got a different python object back in the
selection.  You can use the get_data and set_data methods to associate
data with a particular gtk object that will be accessible from all python
wrapper objects:
  >>> list_item.set_data('my-key', [1,2,3])
  >>> list_item.get_data('my-key')
  [1, 2, 3]

This is what you should use.

James.

--
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/


On Fri, 8 Oct 1999, Jozsa Kristof wrote:

> Hello,
> 
>    I'm new on the list so a short introduction goes here: I'm a newbie both
> in python and pygtk (means a few week experiences - I guess that counts as
> newbie ;), but programmed on several other languages including C/C++, Java,
> PHP3 and a bit Perl. I'm also studying IT in Hungary. /oh well, and sorry
> for my bad English sometimes/
> 
>    I've got confused around GtkList and GtkListItem-s 2 days before and
> seems I cannot figure out what I'm doing wrong. I've defined a GtkList and
> put it out to my GUI. I've filled it with a couple of GtkListItems, and
> stored the references for myself for future use. Later, when I query which
> item of the list is selected, I get an instance of a GtkListItem, which does
> not match with any of the stored instances. 
> 
> """See the code if that's not clear:
> self.dlbox = dlbox = GtkList()
> self.inbox = list_item = GtkListItem("INBOX")
> dlbox.add(list_item)
> list_item.show()
> 
> # later, after selecting the item INBOX from the list visually
> selected = self.dlbox.get_selection()
> selected[0] == self.inbox  # that's false
> 
> The two instances when I print out refer to different memory addresses,
> and (no surprise after that), there's no such instance in my stored
> instances what's get_selection() returns. 
> 
> I guess I'm doing some trivial stupidity, but cant see what's it :(
> Can anyone help please?
> 
> Christopher
> 
> -- 
> +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-: .~. :-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+ 
> | Christopher Jozsa               /V\    Veszprem Linux Users Group |
> | [EMAIL PROTECTED]             /( )\       student of IT, Hungary |
> +-=-=-=-=-=-=-=-=-=-=-=-=-=-=--: ^^-^^ :--=-=-=-=-=-=-=-=-=-=-=-=-=-+
> To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]
> 

To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to