(I asked Kris off-list if he had a better explanation, to which he
answered:)

On Tue, Dec 16, 2003 at 04:44:23PM +0100, Kristian Rietveld wrote:
> Hmm, if you avoid an (explicit) notification to the view, then how could
> the view know about updates? The view does not update itself
> independently, updates only happen after receiving a signal. And,
> anything which changes the model usually emits a signal, which will
> notify the view.

I know, but in this case, Emanuele is doing:

    people=[Person("Emanuele","Olivetti"),
            Person("Laura","Gatti"),
            Person("Richard","Stallman")]

    model = gtk.ListStore(object)
    
    # fill the model with the people
    for i in people:
        row=model.append()
        model.set_value(row, 0, i)

And expecting the View will update itself when he calls

    def change(button, people):
        """Swap name and surname of all people"""
        for i in people:
            tmp=i.name
            i.name=i.surname
            i.surname=tmp

AIUI this just can't work because, in this case:

    class Person(object):
        """A simple class"""
        def __init__(self, name="unknown", surname="unknown"):
            self.name=name
            self.surname=surname
    
-- the Person class has no way of notifying the Store or View that a
setattr() occurred. I guess what's confusing here is that the view
actually redraws correctly if you refresh it (resizing or refrawing),
but if you want it to update right after changing the items you need to
emit a signal explicitly.

The only way I can see this being done automatically is to use an
adapter around Person that triggers a notification whenever it's
modified, or adding a __setattr__() hook to Person. Makes sense?

Take care,
--
Christian Robottom Reis | http://async.com.br/~kiko/ | [+55 16] 261 2331
_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to