Is read_file() always called after an activity __init__?
tomeu at tomeuvizoso.net
Thu Feb 28 10:18:50 EST 2008
On Thu, Feb 28, 2008 at 12:45 PM, Gary C Martin <gary at garycmartin.com> wrote:
> Hi Tomeu,
> On 28 Feb 2008, at 09:40, Tomeu Vizoso wrote:
> > Well, __init__ is too soon.
> Well before calling activity.Activity.__init__(self, handle) yes that
> would be a real bad idea for sure :-) but after that it 'should' be
> fine shouldn't it, as the activity class is all set up? I can
> certainly read the metadata in my main __int__ just after the call up
> to super, and all works well.
You are right, though at some point we would like to defer the fetch
of data from the datastore to a later point after construction. In
this way some activities will be able to launch faster.
> > AFAIK, the API docs say that you can
> > safely access Activity.metadata in the read_file() and write_file()
> > methods. read_file() is called when the user is resuming an existing
> > activity and write_file() when sugar thinks it is a good time to save
> > changes to the journal (probably several times during the life of an
> > activity).
> It does seem like read_file() is only triggered if you have previously
> saved an actual file to filesystem, if you just have metadata, no call
> is ever made to read_file() so it's a rather bad place to pick-up the
> metadata. At least this is what I'm seeing here – I've just created a
> 0 size file in my write_file() and now a resume from that journal
> entry is triggering read_file() every time.
You are right again. Perhaps we should add a read_metadata() method?
An alternative would be to have a 'datastore-loaded' method, but that
would be less consistent with the current API.
> > Is very probable that the API documentation is lacking, can you point
> > me to the docs you were following? Have you already read the HIG in
> > the wiki?
> Not an officially maintained page I know, but:
Not that we have many officially maintained pages about sugar docs :/
> Same suggestion comes from the current pydocs:
> (an online version)
Would be nice to have a wiki bot that would update the API docs in the
wiki from the sources. Anybody know something like that?
> I also went through a number of activity sources in git looking for
> examples, but I didn't find one that ONLY used metadata. They all seem
> to either not bother storing any UI state (so resuming or from new
> makes no difference), or they save actual files.
I think at some point activities like those realize that they have
some data that would be better saved in a file.
But the determining reason would be that metadata properties other
than the custom ones are not preserved across reboots :/
> BTW: I'm quite happy with read_file() not getting called in file-less
> cases, just a matter of documenting it somewhere (if that is indeed
> the correct behaviour intended).
> Thanks for your input.
More information about the Devel