Re: Q: wrappers push/pull and models

"Samuele Pedroni" <[email protected]>
Newsgroups gmane.comp.python.anygui.devel
Message-ID <00d701c25a7e$0dbc0440$6d94fea9@newmexico>
From: Joseph A. Knapka <[email protected]>
> Samuele Pedroni wrote:
> >
> > > Samuele Pedroni wrote:
> > > >
> > >
> > > [scissors of brevity]
> > >
> > > > indeed but not messing with vs. keeping them alive through storing are
> > > > different things. It seems (but maybe I'm wrong) that the current code
> > needs
> > > > the latter, which would be complexity "pushed" down in the wrappers
again.
> > >
> > > Are you concerned with models being GC'd? I would think that if
> > > a model is used, the application would keep a reference to it,
> > > so Anygui doesn't need to worry about that.
> > >
> >
> > Honestly if I set a property to a model in a component a would aspect the
> > component to keep it alive. But anyway the point was another and I was
> > imprecise. The problem:   if the proxy and the wrapper don't keep a
reference
> > to the model and just keep the value or forget about the model how can they
> > behave properly, i.e. e.g. update the model.
> >
> > Maybe the code is correct and it is just me missing something.
>
> OK, I understand. I think you are right and the code is wrong,
> since AFAIK you are the first person to bother about getting
> model behavior correct.

To be precise <wink>, I was trying to look at how optimize the call chains
starting from Attrib.__g/setattr__, and found that Attrib.__setattr__ generates
a pull because of models and that behavior is probably wrong, and thought that
things first should be made work because optimizing not-working code is
pointless <wink>.

> > But if I set a
> > sofar-not-set property to a model it seems that following happens:
> >
> > model goes in proxy state, model is pushed down to wrapper, wrapper sets
model
> > value (if it can deal with model) into widget and forget about model.
> >
> > Now if I try to set the property again: first property value is pulled from
> > wrapper, wrapper get the value from widget (this is the aformen. plain
value),
> > plain value is put in state,  thus any notion of prop being bound to a
model is
> > lost...
> >
> > The relevant code is:
> > Attrib __setattr__ calls set that calls rawSet which does:
> >
> >             old_val = getattr(self, key, None)
> >
> > that triggers the discussed behavior through Attrib __getattr__ that
invokes:
> >
> >                     self.pull(*(name,))
> >
> > triggering in Proxy.pull:
> >
> >         self.wrapper.pull(state)
> >         self.state.update(state)
> >
> > now  wrapper.pull knows nothing about models and simply does with state:
> >
> >       for attr in [k for k in state.keys() if k not in unhandled]:
> >             state[attr] = lstate[attr]
>

The code in Models.py seems just sketched or at least not up-to-date (?), we
would need something along the line of:
  if state[attr] is a model:
    set state[attr] value to lstate[attr] without triggering a push

(( it was something like state[attr]._set_value() and maybe should become
.setValue() ))

I think for the moment we can just keep in mind that that line as it is cannot
deal with models.

IMO
            old_val = getattr(self, key, None)
            try: old_val.removed(self, key)
            except: pass
in rawSet can be safely rewritten as:

  if self.state.has_key[key]:
     try: self.state[key].removed(self, key)
     except: pass

then modattr (in Attribs.py) needs also to be revised.

Anyway all this seems to me too prone to throw exceptions on common paths for
non-models. Maybe we need to keep a ismodel := { 'name': 0/1 ... } dictionary
parallel to state...

regards.



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.