tw2.core

tw2.core contains the base Widgets from which all others are derived.

Widget
Base class for all widgets.

    CompoundWidget

    A widget that has an arbitrary number of children, this is common for layout components, such as :class:`tw2.forms.TableLayout`.

    System Message: ERROR/3 (<string>, line 2); backlink

    Unknown interpreted text role "class".
    • separator
      • HTML snippet which will be inserted between each repeated child

    RepeatingWidget

    A widget that has a single child, which is repeated an arbitrary number of times, such as :class:`tw2.forms.GridLayout`.

    System Message: ERROR/3 (<string>, line 2); backlink

    Unknown interpreted text role "class".
    • repetitions
      • Fixed number of repetitions. If this is None, it dynamically determined, based on the length of the value list.
    • min_reps
      • Minimum number of repetitions
    • max_reps
      • Maximum number of repetitions
    • extra_reps
      • Number of extra repeitions, beyond the length of the value list.
    • children
      • Children specified for this widget will be passed to the child. In the template, children gets the list of repeated childen.
    • separator
      • HTML snippet which will be inserted between each repeated child

    DisplayOnlyWidget

    A widget that has a single child. The parent widget is only used for display purposes; it does not affect value propagation or validation. This is used by widgets like :class:`tw2.forms.FieldSet`.

    System Message: ERROR/3 (<string>, line 2); backlink

    Unknown interpreted text role "class".
    • children
      • Children specified for this widget will be passed to the child

    Page

    An HTML page. This widget includes a :meth:`request` method that serves the page.

    System Message: ERROR/3 (<string>, line 2); backlink

    Unknown interpreted text role "meth".
    • children
      • Children specified for this widget will be passed to the child
    • title
      • Title for the page
    • content_type
      • Content type header

    JSSource
    Inline JavaScript source code.
    • location
      • Location on the page where the resource should be placed.This can be one of: head, headbottom, bodytop or bodybottom. None means the resource will not be injected, which is still useful, e.g. static images.
    • src
      • Source code

    CSSSource
    Inline Cascading Style-Sheet code.
    • location
      • Location on the page where the resource should be placed.This can be one of: head, headbottom, bodytop or bodybottom. None means the resource will not be injected, which is still useful, e.g. static images.
    • src
      • CSS code

    TGStyleController
    A widget mixin that provides more advanced controller routing and

    dispatching.

    The need for this mainly sprung from a divergence of source trees (unintentionally forking) between the developers of tw2 while it was still alpha/beta. One team expected users to define controllers as a 'request' classmethod on the widget and another team expected users to define a Controller class as a child of the widget. Team A's pattern is now the default in the main tree. This is a shim to support Team B's approach.

    Use it like this:

    >>> import tw2.core
    >>> class MyWidget(tw2.core.TGStyleController, tw2.core.Widget):
    ...     class Controller(object):
    ...         @jsonify
    ...         def some_method(self, req):
    ...             return dict(foo="bar")