ui factory - what should it do?
John Arbash Meinel
john at arbash-meinel.com
Wed Feb 22 04:18:14 GMT 2006
Martin Pool wrote:
> On Tue, 2006-02-21 at 17:05 -0800, Robey Pointer wrote:
>
>> The code I posted last week used a single pbar object, on which
>> callers could push and pop state. Debouncing is trivial that way.
>> We could also use weakref to do an automatic pop when a child pbar is
>> collected (though I may be jumping ahead here).
>
> Probably better to just have code use a try/finally block in the scope
> where the progressbar is created.
>
The way I did it was to have 1 object which was responsible for updating
the screen (CallbackHandler). It had a function called 'new_progress'
which would return a Progress object. these objects had a member called
"new_sub_progress" which would return another Progress object.
The current state was a tree (list of lists) of ProgressInfo objects. So
when new_sub_progress() created a new Progress, it would create a
ProgressInfo, append it to its list. Instantiate the child Progress with
this info object, a pointer to self, and a pointer to CallbackHandler.
So children know about their parents, but parents only know about their
child's current state.
All Progress objects have a 'done()' member, but this is also called in
their __del__.
When a Progress is updated, it does:
self.info.position += 1
self.cb_handler.update()
Where CallbackHandler.update() traverses the tree, and figures out what
should be displayed.
This avoids cyclical references, and I've seen that it works fairly
well. If you have 'try/finally' you can force a '.done()' command.
My code mixes C++ with python, so I don't always have a finally. And my
code is such that I have an abstract Progress object, which has a very
fast inline 'update()' function, which occasionally calls a virtual
'do_update' function.
John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060221/e6a1cc35/attachment.pgp
More information about the bazaar
mailing list