twisted.web.woven.widgets.Widget

Package twisted :: Package web :: Package woven :: Module widgets :: Class Widget |
[frames | no frames]

## Class Widget

    View --+
           |
          Widget

Known Subclasses:
  `Anchor`, `Attributes`, `Bold`, `Br`, `Break`, `Cell`, `ColumnList`, `DefaultWidget`, `DeferredWidget`, `Div`, `Error`, `ExpandMacro`, `FormFillerWidget`, `Image`, `Input`, `Link`, `List`, `Option`, `ParagraphText`, `RawText`, `Row`, `Span`, `Table`, `Text`

A Widget wraps an object, its model, for display. The model can be a simple Python object (string, list, etc.) or it can be an instance of `model.Model`. (The former case is for interface purposes, so that the rest of the code does not have to treat simple objects differently from Model instances.)

If the model is-a Model, there are two possibilities:

- we are being called to enable an operation on the model
- we are really being called to enable an operation on an attribute of the model, which we will call the submodel

Method Summary
| ``__init__`(self, model, submodel, setup, controller, viewStack, *args, **kwargs)`
| ``__getitem__`(self, item)` Convenience syntax for getting an attribute from the resultant DOM Node of this widget.
| ``__setitem__`(self, item, value)` Convenience syntax for adding attributes to the resultant DOM Node of this widget.
| `_regenerate(self, request, node, data)`
| `_reset(self)`
| ``add`(self, item)` Add `item' to the children of the resultant DOM Node of this widget.
| ``addEventHandler`(self, eventName, handler, *args)` Add an event handler to this widget.
| ``addUpdateMethod`(self, updateMethod)` Add a method to this widget that will be called when the widget is being rendered.
| ``appendChild`(self, item)` Add `item' to the children of the resultant DOM Node of this widget.
| ``cleanNode`(self, node)` Do your part, prevent infinite recursion!
| ``generate`(self, request, node)` Allow a view to be used like a widget.
| ``generateDOM`(self, request, node)` Return a DOM Node to replace the Node in the template that this Widget handles.
| ``getAllPatterns`(self, name, default, clone, deep)` Get all nodes below this one which have a matching pattern attribute.
| ``getAttribute`(self, item)` Convenience syntax for getting an attribute from the resultant DOM Node of this widget.
| ``getData`(self, request)` I have a model; however since I am a widget I am only responsible for a portion of that model.
| ``getPattern`(self, name, default, clone, deep)` Get a named slot from the incoming template node.
| ``getTopModel`(self)` Get a reference to this page's top model object.
| ``initialize`(self, *args, **kwargs)` Use this method instead of __init__ to initialize your Widget, so you don't have to deal with calling the __init__ of the superclass.
| ``insert`(self, index, item)` Insert `item' at `index' in the children list of the resultant DOM Node of this widget.
| `modelChanged(self, payload)`
| ``onEvent`(self, request, eventName, *args)` Dispatch a client-side event to an event handler that was registered using addEventHandler.
| ``setAttribute`(self, item, value)` Convenience syntax for adding attributes to the resultant DOM Node of this widget.
| ``setData`(self, request, data)` If the return value of `getData` is a Deferred, I am called when the result of the Deferred is available.
| `setDataCallback(self, result, request, node)`
| ``setError`(self, request, message)` Convenience method for allowing a Controller to report an error to the user.
| ``setNode`(self, node)` Set a node for this widget to use instead of creating one programatically.
| ``setSubmodel`(self, submodel)` I use the submodel to know which attribute in self.model I am responsible for
| ``setUp`(self, request, node, data)` Override this method to set up your Widget prior to generateDOM.
Inherited from View
| ``dispatchResult`(self, request, node, result)` Check a given result from handling a node and look up a NodeMutator adapter which will convert the result into a node and insert it into the DOM tree.
| ``dispatchResultCallback`(self, result, request, node)` Deal with a callback from a deferred, checking to see if it is ok to send the page yet or not.
| ``getChild`(self, path, request)`
| ``getChildWithDefault`(self, path, request)`
| ``getNodeController`(self, request, node, submodel, model)` Get a controller object to handle this node.
| ``getNodeModel`(self, request, node, submodel)` Get the model object associated with this node.
| ``getNodeView`(self, request, node, submodel, model)`
| ``getSubview`(self, request, node, model, viewName)` Get a sub-view from me.
| ``getTemplate`(self, request)` Override this if you want to have your subclass look up its template using a different method.
| ``handleControllerResults`(self, controllerResult, request, node, controller, view)` Handle a deferred from a controller.
| ``handleDocument`(self, request, document)` Handle the root node, and send the page if there are no outstanding callbacks when it returns.
| ``handleNewNode`(self, request, returnNode)`
| ``handleNode`(self, request, node)`
| ``handleOutstanding`(self, request)`
| ``importViewLibrary`(self, namespace)`
| ``lookupTemplate`(self, request)` Use acquisition to look up the template named by self.templateFile, located anywhere above this object in the heirarchy, and use it as the template.
| ``recurseChildren`(self, request, node)` If this node has children, handle them.
| ``render`(self, request, doneCallback)`
| ``renderFailure`(self, failure, request)`
| ``sendPage`(self, request)` Check to see if handlers recorded any errors before sending the page
| ``setController`(self, controller)`
| ``setSubviewFactory`(self, name, factory, setup, *args, **kwargs)`
| ``setupAllStacks`(self)`
| ``setupViewStack`(self)`
| ``unlinkViews`(self)`

Instance Variable Summary
| `model`: If the current model is an `model.Model`, then the result of model.getData().

Class Variable Summary
`int` | `clearNode` = 0
`int` | `livePage` = 1
`int` | `setupStacks` = 0
`NoneType` | `tagName`: The tag name of the element that this widget creates.
| `wantsAllNotifications`: Indicate that this widget wants to recieve every change notification from the main model, not just notifications that affect its model.
Inherited from View
`tuple` | `__implements__` = `(<class twisted.web.resource.IResource ...`
`NoneType` | `doneCallback` = None
`int` | `isLeaf` = 1
`str` | `template` = `''`
`str` | `templateDirectory` = `''`
`str` | `templateFile` = `''`
`NoneType` | `templateNode` = None
`list` | `viewLibraries` = `[]`

Method Details

### __init__(self, model=None, submodel=None, setup=None, controller=None, viewStack=None, *args, **kwargs) (Constructor) Parameters: `model` (type=`interfaces.IModel`) `submodel` - see `Widget.setSubmodel` (type=String) `setup` (type=Callable) Overrides: `twisted.web.woven.view.View.__init__`

### __getitem__(self, item) (Indexing operator) Convenience syntax for getting an attribute from the resultant DOM Node of this widget.

### __setitem__(self, item, value) (Index assignment operator) Convenience syntax for adding attributes to the resultant DOM Node of this widget. Overrides: `twisted.web.woven.view.View.__setitem__`

### add(self, item) Add `item' to the children of the resultant DOM Node of this widget. Parameters: `item` (type=A DOM node or `Widget`.)

### addEventHandler(self, eventName, handler, *args) Add an event handler to this widget. eventName is a string indicating which javascript event handler should cause this handler to fire. Handler is a callable that has the signature handler(request, widget, *args).

### addUpdateMethod(self, updateMethod) Add a method to this widget that will be called when the widget is being rendered. The signature for this method should be updateMethod(request, widget, data) where widget will be the instance you are calling addUpdateMethod on.

### appendChild(self, item) Add `item' to the children of the resultant DOM Node of this widget. Parameters: `item` (type=A DOM node or `Widget`.)

### cleanNode(self, node) Do your part, prevent infinite recursion!

### generate(self, request, node) Allow a view to be used like a widget. Will look up the template file and return it in place of the incoming node. Overrides: `twisted.web.woven.view.View.generate` (inherited documentation)

### generateDOM(self, request, node) Returns: A DOM Node to replace the Node in the template that this Widget handles. This Node is created based on `tagName`, `children`, and `attributes` (You should populate these in `setUp`, probably).

### getAllPatterns(self, name, default=Element('div', attributes={'style': 'border: dashed red 1..., clone=1, deep=1) Get all nodes below this one which have a matching pattern attribute.

### getAttribute(self, item) Convenience syntax for getting an attribute from the resultant DOM Node of this widget.

### getData(self, request=None) I have a model; however since I am a widget I am only responsible for a portion of that model. This method returns the portion I am responsible for. The return value of this may be a Deferred; if it is, then `setData` will be called once the result is available.

### getPattern(self, name, default=Element('div', attributes={'style': 'border: dashed red 1..., clone=1, deep=1) Get a named slot from the incoming template node. Returns a copy of the node and all its children. If there was more than one node with the same slot identifier, they will be returned in a round-robin fashion.

### getTopModel(self) Get a reference to this page's top model object.

### initialize(self, *args, **kwargs) Use this method instead of __init__ to initialize your Widget, so you don't have to deal with calling the __init__ of the superclass.

### insert(self, index, item) Insert `item' at `index' in the children list of the resultant DOM Node of this widget. Parameters: `item` (type=A DOM node or `Widget`.)

### onEvent(self, request, eventName, *args) Dispatch a client-side event to an event handler that was registered using addEventHandler.

### setAttribute(self, item, value) Convenience syntax for adding attributes to the resultant DOM Node of this widget. Overrides: `twisted.web.woven.view.View.__setitem__`

### setData(self, request=None, data=None) If the return value of `getData` is a Deferred, I am called when the result of the Deferred is available.

### setError(self, request, message) Convenience method for allowing a Controller to report an error to the user. When this is called, a Widget of class self.errorFactory is instanciated and set to self.become. When generate is subsequently called, self.become will be responsible for mutating the DOM instead of this widget.

### setNode(self, node) Set a node for this widget to use instead of creating one programatically. Useful for looking up a node in a template and using that. Overrides: `twisted.web.woven.view.View.setNode`

### setSubmodel(self, submodel) I use the submodel to know which attribute in self.model I am responsible for Overrides: `twisted.web.woven.view.View.setSubmodel`

### setUp(self, request, node, data) Override this method to set up your Widget prior to generateDOM. This is a good place to call methods like `add`, `insert`, `__setitem__` and `__getitem__`. Overriding this method obsoletes overriding generateDOM directly, in most cases. Parameters: `request` (type=`twisted.web.server.Request`.) `node` - The DOM node which this Widget is operating on. `data` - The Model data this Widget is meant to operate upon. Overrides: `twisted.web.woven.view.View.setUp`

Instance Variable Details

### model If the current model is an `model.Model`, then the result of model.getData(). Otherwise the original object itself.

Class Variable Details

    ### clearNode Type: `int` Value:
        0

    ### livePage Type: `int` Value:
        1

    ### setupStacks Type: `int` Value:
        0

    ### tagName The tag name of the element that this widget creates. If this is None, then the original Node will be cloned. Type: `NoneType` Value:
        None

### wantsAllNotifications Indicate that this widget wants to recieve every change notification from the main model, not just notifications that affect its model.

Generated by Epydoc 2.0 on Sat May 15 20:08:38 2004 | http://epydoc.sf.net