tw2.dyntext

DynamicTextWidget
  • initial_text
    • Initial text to place in the widget. Default: None
  • wrap
    • Tag to wrap the widget with. Default: span
class DemoDynamicTextWidget(widgets.DynamicTextWidget):
    initial_value = "I don't really do anything unless you call setDynamicText()."
<%namespace name="tw" module="tw2.core.mako_util"/>
<${w.wrap} id="${w.attrs['id']}">${w.initial_text}</${w.wrap}>

PollingDynamicTextWidget
  • initial_text
    • Initial text to place in the widget. Default: None
  • wrap
    • Tag to wrap the widget with. Default: span
  • data_url
    • (str) URL where JSON data should be pulled from
  • interval
    • (int) Polling interval in milliseconds
class DemoPollingDynamicTextWidget(widgets.PollingDynamicTextWidget):
    # Provide default parameters, value, etc... here
    # default = <some-default-value>
    data_url = '/dynamic_text_demo'
    @classmethod
    def request(cls, req):
        lottery_numbers = ", ".join([str(random.randint(1,100)) for x in range(5)])
        resp = webob.Response(request=req, content_type="application/json")
        resp.body = json.dumps({'text': lottery_numbers})
        return resp
<%namespace name="tw" module="tw2.core.mako_util"/>
<${w.wrap} id="${w.attrs['id']}">${w.initial_text}</${w.wrap}>