r3 - 19 Feb 2007 - 16:17:56 - ReidEllisYou are here: OSAF >  Journal Web  >  ContributorNotes > ReidEllisNotes > ReidBlockNotes
This is a transcript of an IRC chat I had with BryanStearns that I found exceptionally useful.

stearns: sorry, was away - back now. Wassup?
reid: Hi there, I was wondering about Blocks and =__init=
It seems like there is a "template" method used everywhere.
stearns: yeah: welcome to the world of our repository.
reid: I'm trying to figure out how/where the __init is getting called
stearns: Blocks are Items - they're persisted.
reid: Ok.. where is the persistent information initialized from?
stearns: Generally, you don't want init...
reid: e.g. when I do a RunChandler --create
stearns: I see. Yes: from this template thing.
one sec, lemme go find an example I can explain.
reid: ok
I will look at code some more meanwhile
stearns: OK, so you've seen the installParcel methods scattered about... they get called to create repository items when creating a new repository.
reid: ok
stearns: Persistent data lives on Items in "schema attributes" - you've seen those, they're declared in Item subclasses like:
class foo(Item):
   attr = schema.One(...)
reid: right
stearns: Each Item class provides an update() method that takes a repository view and a name.
It's used to create or update (hence the name) a named item.
er, Item.
You pass the update method named parameters for the attributes you want to initialize (or update): eg:
foo.update("MyItem", aView, attr="something")

(I may have the unnamed params in the wrong order, and I think there's a parcel there somewhere... anyway)
Blocks (and BlockEvents) can use the update mechanism, but generally they use a "template()" method instead.
It works almost the same, except that what's returned from it isn't actually the item: it's a template that you need to install(aParcel) to actually do the creation/updating.
I forget why we use this template thing - I recall that the plan was for it to be more pervasive, but ended up only used for blocks and blockevents.
Alec could explain more.
(he did the template thing; pje did the schema mechanisms that provide eg "update()")
Anyway: normally, you declare default attribute values in the schema.Whatever(...) declaration.
Values that need to be set for particular instances of things are set in the template() [or =update()=] calls.
so if all that makes sense... what are you wanting to initialize?
reid: The buttons need bitmaps
The class can have them passed in to __init() or added later via a method call
reid is writing this all down; writing helps him to remember
stearns: I think it's natural to work this way:
- the wx MultiButtonWhatever widget takes bitmap args in its init.
- The block that's hosting it (MultiButtonWhateverBlock?) has schema attributes that specify the bitmaps; they'd be initialized in the update() or template() calls that create each MultiButtonWhateverBlock instance.
- (I think the natural thing is to provide names for the bitmap files in the schema attributes, then load them (and pass them to the widget's __init__()) at runtime.
that is: don't load the images into the repository)
- Oops: left this out:
- Your MultiButtonWhateverBlock will have an instantiateWidget() method that actually creates the MultiButtonWhatever wx widget - that's where the widget creation is, and where you'll pass the values from the block's schema attributes (or use those attributes to load the images, or whatever)
(Also, I'd expect your IRC client will let you copy & paste this to save it )

-- ReidEllis - 13 Apr 2006

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r3 < r2 < r1 | More topic actions
 
Open Source Applications Foundation
Except where otherwise noted, this site and its content are licensed by OSAF under an Creative Commons License, Attribution Only 3.0.
See list of page contributors for attributions.