r5 - 20 Apr 2003 - 17:58:54 - KaitlinDuckSherwoodYou are here: OSAF >  Projects Web  >  ChandlerHome > DeveloperDocumentation > HowToWriteAParcelTutorial > SynchronizingViewsInChandler

Synchronizing Views in Chandler

@@@ Wickedly under construction!!!

As mentioned before, ViewerParcels use a modified Model-View-Controller architecture, where the Model is a subclass of ViewerParcel (FooView in the example) and the View is a subclass of wxViewerParcel (wxFooView).

Usually when the Model (FooView) changes, you want the View (wxFooView) to change as well. In general, as long as only the Model (e.g. FooView) and the view (e.g. wxFooView) are involved, you can handle the changes pretty simply. The Chandler ViewerParcel handles things for you.

However, when a third class gets involved, things get more complicated. (The most common case where this happens is when a background process checks for updates on a regular basis, e.g. an email client checking for new mail.) At that point, the Model needs to do more work.

Currently, the easiest way to explicitly force the View to update is to do a SynchronizeView?() from the model. Unless the Model overrides SynchronizeView?(), all this does is repaint the entire View as if this were the first time that the View was shown. Note also that this is slow: it repaints the entire parcel portion of the window, even if there were only a few pixels that changed.

@@@ talk about invalidating View

class FooView(ViewerParcel): 
    def __init__(self): 
        self.displayName = _('Foo') 
        self.number = 0
        
    def SynchronizeView(self):
        ViewerParcel.SynchronizeView(self)
        app.association[key(id(self))].ChangeNumber(self.number))


class wxFooView(wxViewerParcel):
    def OnInit(self, event):
        EVT_BUTTON(self, XRCID('FooButton'), self.OnFooButton)
        self.fooText = XRCCTRL(self, 'FooText')

    def OnFooButton(self, event):
        model.number = model.number + 1
        model.SynchronizeView()

    def ChangeNumber(self, aNumber):
        self.fooText.SetLabel(str(aNumber))
 

         

This is a somewhat pathological case, as it is so simple that you normally wouldn't need to do anything nearly so complicated.

-- DuckySherwood - 17 Apr 2003

Edit | WYSIWYG | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r5 < r4 < 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.