Source

# Created By: Virgil Dupras# Created On: 2011/09/09# Copyright 2012 Hardcoded Software (http://www.hardcoded.net)# # This software is licensed under the "BSD" License as described in the "LICENSE" file, # which should be included with this package. The terms are also available at # http://www.hardcoded.net/licenses/bsd_licensedefnoop(*args,**kwargs):passclassNoopGUI:def__getattr__(self,func_name):returnnoop# A GUIObject is a cross-toolkit "model" representation of a GUI layer object, for example, a table.# It acts as a cross-toolkit interface to multiple what we call here a "view". That view is a# toolkit-specific controller to the actual view (an NSTableView, a QTableView, etc.).# In our GUIObject, we need a reference to that toolkit-specific controller because some actions,# have effects on it (for example, prompting it to refresh its data). The GUIObject is typically# instantiated before its "view", that is why we set it as None on init. However, the GUI# layer is supposed to set the view as soon as its toolkit-specific controller is instantiated.# When you subclass GUIObject, you will likely want to update its view on instantiation. That# is why we call self.view.refresh() in _view_updated(). If you need another type of action on# view instantiation, just override the method.classGUIObject:def__init__(self):self._view=Nonedef_view_updated(self):pass#virtualdefhas_view(self):return(self._viewisnotNone)and(notisinstance(self._view,NoopGUI))@propertydefview(self):returnself._view@view.setterdefview(self,value):# There's two times at which we set the view property: On initialization, where we set the# view that we'll use for your lifetime, and just before the view is deallocated. We need# to unset our view at that time to avoid calls to a deallocated instance (which means a# crash).ifself._viewisNone:# Initial view assignmentifvalueisNone:returnself._view=valueself._view_updated()else:assertvalueisNone# Instead of None, we put a NoopGUI() there to avoid rogue view callback raising an# exception.self._view=NoopGUI()