1. Ralph Bean
  2. tw2.yui


tw2.yui / examples / example.py

import tw2.core as twc, tw2.forms as twf, tw2.yui as twy

class Index(twf.FormPage):
    title = 'YUI Example'
    css_class = 'yui-skin-sam'
    class child(twf.TableLayout):
        class auto_complete(twy.AutoComplete):
            label = 'Enter a state'
            class datasrc(twy.XHRDataSource):
                def ajax_request(self, req):
                    q = req.GET['query'].lower()
                    return {'result': [s for s in arrayStates if s.lower().startswith(q)]}

        color_picker = twy.ColorPicker()
        calendar = twy.Calendar()
        slider = twy.Slider()
        editor = twy.Editor()
        class tabview(twy.TabView):
            tab1 = twf.Label(label='Tab 1', text='This is the first tab')
            tab2 = twf.Label(label='Tab 2', text='And this is the other tab')
        class treeview(twy.TreeView):
            content = [
                {'type':'Text', 'label':'Label 1', 'children':['Sub label %d' % i for i in range(1,11)]},
                {'type':'Text', 'label':'Label 2', 'children':['Sub label %d' % i for i in range(1,11)]},
                {'type':'Text', 'label':'Label 3', 'children':['Sub label %d' % i for i in range(1,11)]},

arrayStates = [
    "New Hampshire",
    "New Jersey",
    "New Mexico",
    "New York",
    "North Dakota",
    "North Carolina",
    "Rhode Island",
    "South Carolina",
    "South Dakota",
    "West Virginia",

if __name__ == '__main__':
    import wsgiref.simple_server as wrs
    wrs.make_server('', 8000, twc.make_middleware(controller_prefix='/')).serve_forever()