[sabayon] how to associate a delegate and a source



get_source is called in several places to construct a source instance
and is passed a storage.

get_files_delegate is called with a source instance (in this case a
FilesSource).

Now suppose the delegate wants to do something on behalf of the source
in the source module, e.g. mozillasource.py creates both a MozillaSource
(returned by get_souarce) and a file delegate watching for changes in
the mozilla directory. When the delegate sees a change it wants to react
to it wants to do this in the context of (e.g. "self") of the right
MozillaSource instance.

I don't see anything that relates a delegate to a source instance (not
the delegates source!, the source the module returns in get_source).

When I run the code I happen to see get_source is called at least twice
to create a MozillaSource instance, once in ProfileWindow and once in
sabayon-apply.

So in the delegate handler I want to invoke the MozillaSource created
for the ProfileWindow. At the moment I'm doing something really kludgy,
I'm setting a global variable in get_source pointing to the last
MozillaSource created and I reference that global variable in the
delegate handler. This clearly is not the right way to do this.

The only way to comes to mind for how to locate the right MozillaSource
instance in the delegate handler was to enter each source instance
created into a dict indexed by its storage, and then lookup the storage
from the FilesDelegate. But I'm not even sure that the right way to make
the association.

What is the right way to make the association?
-- 
John Dennis <jdennis redhat com>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]