Re: [gtkmvc-users] Communicating between sub-models/sub-controllers
Brought to you by:
cavada
From: Steve M. <smc...@gm...> - 2010-07-16 13:58:01
|
On Fri, Jul 16, 2010 at 2:26 AM, Tobias Weber <to...@ce...> wrote: > On 16.07.2010, at 06:53, Steve McGrath wrote: >> Under appController I have a collectionController, and a playlistController, which each have their own respective view and model. > > I suppose only songs from the collection can be on the playlist, and that the playlist is persistant. Some day there may be multiple playlists. Almost as if playlists were part of the collection! The playlist should also be able to take handle songs added directly from the filesystem. But yes, there will be multiple playlists, though they don't (yet?) live in the collection. Perhaps it would save me some trouble if I did start treating them as part of the collection now though. >> I will also encounter a problem with my actual playback code, which I intend to create as another sub-model of appModel. > > But appModel doesn't know what to play. Maybe it should belong to collectionModel. Or even playlistModel, if you cannot play directly from the collection. > > That wouldn't leave much for appModel to do. So maybe collectionModel *is* your appModel. The program is about music, after all. indeed. appModel, right now, exists only as the root node of a tree of sub-models. Outside of instantiating those sub-models, it has no code of it's own. appController and appView are the main UI, though. They handle everything except for the playlistView/Ctrl which are embodied by a TreeView in the main window, and the collectionView/Ctrl, which have their own separate window. >> Will signals emitted from a sub-model make it to the parent model's controller without help? > > No. Diagonal dependencies are bad. Horizontal is built in. Vertical is up to you: I think I understand the difference, but to be sure; vertical dependencies involve communication between a sub-model or sub-controller and its parent? And horizontal dependencies would be communication between models or controllers under the same parent? Having thought about this, I think I can make this fairly simple as long as I give the collectionCtrl and playerCtrl a reference to the playlistCtrl, so the former can add data, and the latter can access it. > > class appModel: > def init: > self.collection = collectionModel(self) > > class collectionModel: > def init(parent): > self.register_observer(parent) > > class appController: > def init: > self.collection = collectionController(self.model.collection, ..., self) > > class collectionController: > def init(m, v, parent): > # Keep for direct calls. > self.parent = parent Thanks for the help, I'm still kinda new at this, and I don't want to end up in cross-dependency hell like one of my last applications. Regards, -Steve -- If it ain't broke, you're not using a new enough version |