GUIObject([multibind]) Cross-toolkit “model” representation of a GUI layer object.
class hscommon.gui.base.GUIObject(multibind=False)

Cross-toolkit “model” representation of a GUI layer object.

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 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 to 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.

Most of the time, you will only one to bind a view once in the lifetime of your GUI object. That is why there are safeguards, when setting view to ensure that we don’t double-assign. However, sometimes you want to be able to re-bind another view. In this case, set the multibind flag to True and the safeguard will be disabled.


(Virtual) Called after view has been set.

Doing nothing by default, this method is called after view has been set (it isn’t called when it’s unset, however). Use this for initialization code that requires a view (which is often the whole of the initialization code).


A reference to our toolkit-specific view controller.

view answering to GUIObject sublass’s view protocol. get/set

This view starts as None and has to be set “manually”. There’s two times at which we set the view property: On initialization, where we set the view that we’ll use for our 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).

To unset our view, we simple assign it to None.