Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 4d09c8390a
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 34 lines (25 sloc) 1.111 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
"""
Here you can create samples of your widgets by providing default parameters,
inserting them in a container widget, mixing them with other widgets, etc...
These samples will appear in the WidgetBrowser

See http://toscawidgets.org/documentation/WidgetBrowser for more information
"""

import widgets
import json
import random
import webob

class DemoDynamicTextWidget(widgets.DynamicTextWidget):
    initial_value = "I don't really do anything unless you call setDynamicText()."

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

import tw2.core as twc
mw = twc.core.request_local()['middleware']
mw.controllers.register(DemoPollingDynamicTextWidget, 'dynamic_text_demo')
Something went wrong with that request. Please try again.