Commits

Anonymous committed 7fbaf5f

Tidy up

Comments (0)

Files changed (15)

 glob:*.pyc
+glob:tw2.yui.egg-info

examples/autocomplete.py

 import tw2.core as twc, tw2.forms as twf, tw2.yui as twy
 
+class MyDataSource(twy.DataSource):
+    @classmethod
+    def ajax_request(self, req):
+        return """
+        {"ResultSet":{
+            "Result":[
+                {'title': 'billy'},
+                {'title': 'betty'},
+                {'title': 'joe'},
+            ]}
+        }
+"""
+#        return "Bob,1\nBilly,2\nBrian,3"
+
 class Index(twf.FormPage):
-    title = 'YUI AutoComplete'
-    attrs = {'class': 'yui-skin-sam'}
+    title = "YUI AutoComplete"
+    attrs = {"class": "yui-skin-sam"}
     class child(twf.TableForm):
-        paj = twy.AutoComplete()
+        paj = twy.AutoComplete(datasrc=MyDataSource(id="bobby"))
 
-if __name__ == '__main__':
+if __name__ == "__main__":
     import wsgiref.simple_server as wrs
-    wrs.make_server('', 8000, twc.make_middleware(controller_prefix='/')).serve_forever()
+    wrs.make_server("", 8000, twc.make_middleware(controller_prefix="/")).serve_forever()
+

examples/example.py

     title = 'YUI Example'
     attrs = {'class': 'yui-skin-sam'}
     class child(twf.TableLayout):
-        auto_complete = twy.AutoComplete()
+#        auto_complete = twy.AutoComplete()
         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')
 
 if __name__ == '__main__':
     import wsgiref.simple_server as wrs

examples/slider.py

-import tw2.core as twc, tw2.forms as twf, tw2.yui as twy
-
-class Index(twf.FormPage):
-    title = 'YUI Slider'
-    class child(twf.Form):
-        class child(twf.TableLayout):
-            check = twf.CheckBox(validator=twc.Required)
-            value = twy.Slider()
-
-if __name__ == '__main__':
-    import wsgiref.simple_server as wrs
-    wrs.make_server('', 8000, twc.make_middleware(controller_prefix='/')).serve_forever()

examples/tabview.py

-import tw2.core as twc, tw2.forms as twf, tw2.yui as twy
-
-class Index(twf.FormPage):
-    title = 'YUI TabView'
-    attrs = {'class': 'yui-skin-sam'}
-    class child(twy.TabView):
-        class paj(twf.TableLayout):
-            a = twf.TextField()
-        class joe(twf.TableLayout):
-            b = twf.TextArea()
-
-if __name__ == '__main__':
-    import wsgiref.simple_server as wrs
-    wrs.make_server('', 8000, twc.make_middleware(controller_prefix='/')).serve_forever()
 from setuptools import setup, find_packages
 
 setup(
-    name='',
+    name='tw2.yui',
     version='',
     description='',
     author='',

tw2/yui/__init__.py

 from widgets import (Slider, TabView, AutoComplete, ColorPicker, Calendar,
-        Editor, TreeView)
+        Editor, TreeView, DataSource)

tw2/yui/samples.py

 
 import widgets
 
-class DemoYui(widgets.Yui):
-    # Provide default parameters, value, etc... here
-    # default = <some-default-value>
-    pass

tw2/yui/templates/autocomplete.html

 <div>
 
 <style>
-    #myAutoComplete {
+    .yui-autocomplete {
        width:15em; /* set width here or else widget will expand to fit its container */
        padding-bottom:2em;
    }
 </style>
 
-<div id="myAutoComplete">
+<div class="yui-autocomplete">
     <input id="$w.compound_id" type="text"/>
     <div id="${w.compound_id}:popup"></div>
 </div>
 
+${w.datasrc.display()}
+
 <script type="text/javascript">
-YAHOO.example.BasicLocal = function() {
-    // Use a LocalDataSource
-    var oDS = new YAHOO.util.LocalDataSource(YAHOO.example.Data.arrayStates);
-    // Optional to define fields for single-dimensional array
-    oDS.responseSchema = {fields : ["state"]};
-
-    // Instantiate the AutoComplete
-    var oAC = new YAHOO.widget.AutoComplete("$w.compound_id", "${w.compound_id}:popup", oDS);
-    oAC.prehighlightClassName = "yui-ac-prehighlight";
-    oAC.useShadow = true;
-
-    return {
-        oDS: oDS,
-        oAC: oAC
-    };
-}();
+    var oAC = new YAHOO.widget.AutoComplete("$w.compound_id", "${w.compound_id}:popup", tw2_yui_datasources["$w.datasrc.compound_id"], $w.config);
 </script>
 
 </div>

tw2/yui/templates/calendar.html

 <div id="$w.compound_id"></div>
 <script type="text/javascript">
     YAHOO.util.Event.onDOMReady(function() {
-        cal = new YAHOO.widget.Calendar("$w.compound_id", $w.config);
+        cal = new YAHOO.widget.Calendar("$w.compound_id", $w.options);
         cal.render();
     });
 </script>

tw2/yui/templates/colorpicker.html

 <script type="text/javascript">
     var Event = YAHOO.util.Event;
     Event.onDOMReady(function() {
-        picker = new YAHOO.widget.ColorPicker("$w.compound_id", $w.config);
+        picker = new YAHOO.widget.ColorPicker("$w.compound_id", $w.options);
     });
 </script>
 

tw2/yui/templates/datasource.html

+<script type="text/javascript">
+    tw2_yui_datasources = {}; // TBD: only if undefined
+    var oDS = new YAHOO.util.XHRDataSource("/$w.compound_id", {
+                responseType: YAHOO.util.XHRDataSource.TYPE_JSON,
+                responseSchema: {resultsList:'results.items',
+                                 fields: ['title'],}}
+                                 );
+    tw2_yui_datasources["$w.compound_id"] = oDS;
+</script>

tw2/yui/templates/editor.html

-<div>
-<textarea id="$w.compound_id" name="$w.compound_id" rows="20" cols="75">
-</textarea>
+<div xmlns:py="http://genshi.edgewall.org/">
+<textarea py:attrs="w.attrs"></textarea>
 <script type="text/javascript">
     YAHOO.util.Event.onDOMReady(function() {
-        var myEditor = new YAHOO.widget.Editor('$w.compound_id', $w.config);
+        var myEditor = new YAHOO.widget.Editor('$w.compound_id', $w.options);
         myEditor.render();
     });
 </script>

tw2/yui/templates/tabview.html

 <div xmlns:py="http://genshi.edgewall.org/">
     <div id="$w.compound_id" class="yui-navset">
         <ul class="yui-nav">
-            <li py:for="c in w.children" class="${c is w.children[0] and 'selected' or ''}"><a href="#${c.compound_id}:tab">$c.label</a></li>
+            <li py:for="c in w.children" class="${c is w.children[0] and 'selected' or ''}"><em><a href="#${c.compound_id}:tab">$c.label</a></em></li>
         </ul>
         <div class="yui-content">
             <div py:for="c in w.children" id="${c.compound_id}:tab">${c.display()}</div>

tw2/yui/widgets.py

-import tw2.core as twc, tw2.forms as twf, simplejson
+"""
+ToscaWidgets wrappers for Yahoo User Interface (YUI) widgets.
+"""
+import tw2.core as twc, tw2.forms as twf, simplejson, webob
 encoder = simplejson.encoder.JSONEncoder()
 
 
-class Slider(twc.Widget):
+class YuiWidget(twc.Widget):
     resources = [
         twc.DirLink(modname=__name__, filename="static/2.7.0/"),
         twc.CSSLink(modname=__name__, filename="static/2.7.0/fonts/fonts-min.css"),
+        twc.JSLink(modname=__name__, filename="static/2.7.0/yahoo-dom-event/yahoo-dom-event.js"),
+    ]
+    options = twc.Param('Configuration options for the widget. See the YUI docs for available options.', default={})
+    def prepare(self):
+        super(YuiWidget, self).prepare()
+        self.options = encoder.encode(self.options)
+
+
+class Slider(YuiWidget):
+    resources = YuiWidget.resources + [
         twc.CSSLink(modname=__name__, filename="static/2.7.0/slider/assets/skins/sam/slider.css"),
-        twc.JSLink(modname=__name__, filename="static/2.7.0/yahoo-dom-event/yahoo-dom-event.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/animation/animation-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/dragdrop/dragdrop-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/slider/slider-min.js"),
 
 
 class TabView(twf.widgets.BaseLayout):
-    resources = [
-        twc.DirLink(modname=__name__, filename="static/2.7.0/"),
-        twc.CSSLink(modname=__name__, filename="static/2.7.0/fonts/fonts-min.css"),
+    resources = YuiWidget.resources + [
         twc.CSSLink(modname=__name__, filename="static/2.7.0/tabview/assets/skins/sam/tabview.css"),
-        twc.JSLink(modname=__name__, filename="static/2.7.0/yahoo-dom-event/yahoo-dom-event.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/element/element-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/tabview/tabview-min.js"),
-        twc.Link(modname=__name__, filename='static/2.7.0/assets/skins/sam/sprite.png'),
     ]
     template = "genshi:tw2.yui.templates.tabview"
 
 
-class AutoComplete(twc.Widget):
-    resources = [
-        twc.DirLink(modname=__name__, filename="static/2.7.0/"),
-        twc.CSSLink(modname=__name__, filename="static/2.7.0/fonts/fonts-min.css"),
+class AutoComplete(YuiWidget):
+    resources = YuiWidget.resources + [
         twc.CSSLink(modname=__name__, filename="static/2.7.0/autocomplete/assets/skins/sam/autocomplete.css"),
-        twc.JSLink(modname=__name__, filename="static/2.7.0/yahoo-dom-event/yahoo-dom-event.js"),
+        twc.JSLink(modname=__name__, filename="static/2.7.0/connection/connection-min.js"),
+        twc.JSLink(modname=__name__, filename="static/2.7.0/json/json-min.js"),
+        twc.JSLink(modname=__name__, filename="static/2.7.0/element/element-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/animation/animation-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/datasource/datasource-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/autocomplete/autocomplete-min.js"),
-
-        twc.JSLink(modname=__name__, filename="static/data.js"), # TBD
     ]
     template = "genshi:tw2.yui.templates.autocomplete"
+    datasrc = twc.Param('DataSource to use')
 
+    @classmethod
+    def post_define(cls):
+        if hasattr(cls, 'datasrc'):
+            cls.datasrc = cls.datasrc(parent=cls, id='datasrc')
 
-class ColorPicker(twc.Widget):
-    resources = [
-        twc.DirLink(modname=__name__, filename="static/2.7.0/"),
-        twc.CSSLink(modname=__name__, filename="static/2.7.0/slider/assets/skins/sam/slider.css"),
-        twc.CSSLink(modname=__name__, filename="static/2.7.0/fonts/fonts-min.css"),
+
+class DataSource(YuiWidget):
+    # TBD: resources
+    template = "genshi:tw2.yui.templates.datasource"
+
+    @classmethod
+    def request(self, req):
+        resp = webob.Response(request=req, content_type="text/plain; charset=UTF8")
+        x = self.ajax_request(req)
+        resp.body = x
+        return resp
+
+
+class ColorPicker(YuiWidget):
+    resources = YuiWidget.resources + [
         twc.CSSLink(modname=__name__, filename="static/2.7.0/colorpicker/assets/skins/sam/colorpicker.css"),
-        twc.JSLink(modname=__name__, filename="static/2.7.0/yahoo-dom-event/yahoo-dom-event.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/dragdrop/dragdrop-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/animation/animation-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/slider/slider-min.js"),
     ]
     template = "genshi:tw2.yui.templates.colorpicker"
 
-    config = twc.Param('config - see yui docs', default={})
-
     def prepare(self):
-        super(ColorPicker, self).prepare()
-        self.safe_modify('config')
-        self.config['images'] = {
+        self.safe_modify('options')
+        self.options['images'] = {
             'PICKER_THUMB': "/resources/tw2.yui.widgets/static/2.7.0/colorpicker/assets/picker_thumb.png",
             'HUE_THUMB': "/resources/tw2.yui.widgets/static/2.7.0/colorpicker/assets/hue_thumb.png"
         }
-        self.config = encoder.encode(self.config)
+        super(ColorPicker, self).prepare()
 
 
-class Calendar(twc.Widget):
-    resources = [
-        twc.DirLink(modname=__name__, filename="static/2.7.0/"),
-        twc.CSSLink(modname=__name__, filename="static/2.7.0/fonts/fonts-min.css"),
+class Calendar(YuiWidget):
+    resources = YuiWidget.resources + [
         twc.CSSLink(modname=__name__, filename="static/2.7.0/calendar/assets/skins/sam/calendar.css"),
-        twc.JSLink(modname=__name__, filename="static/2.7.0/yahoo-dom-event/yahoo-dom-event.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/calendar/calendar-min.js"),
     ]
     template = "genshi:tw2.yui.templates.calendar"
 
-    config = twc.Param('config - see yui docs', default={})
 
-    def prepare(self):
-        super(Calendar, self).prepare()
-        self.config = encoder.encode(self.config)
-
-
-class Editor(twc.Widget):
-    resources = [
-        twc.DirLink(modname=__name__, filename="static/2.7.0/"),
+class Editor(twf.TextArea, YuiWidget):
+    resources = YuiWidget.resources + [
         twc.CSSLink(modname=__name__, filename="static/2.7.0/menu/assets/skins/sam/menu.css"),
         twc.CSSLink(modname=__name__, filename="static/2.7.0/button/assets/skins/sam/button.css"),
-        twc.CSSLink(modname=__name__, filename="static/2.7.0/fonts/fonts-min.css"),
         twc.CSSLink(modname=__name__, filename="static/2.7.0/container/assets/skins/sam/container.css"),
         twc.CSSLink(modname=__name__, filename="static/2.7.0/editor/assets/skins/sam/editor.css"),
-        twc.JSLink(modname=__name__, filename="static/2.7.0/yahoo-dom-event/yahoo-dom-event.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/animation/animation-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/element/element-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/container/container-min.js"),
     ]
     template = "genshi:tw2.yui.templates.editor"
 
-    config = twc.Param('config - see yui docs', default={})
+    # default to a fairly large size
+    rows = 20
+    cols = 75
 
-    def prepare(self):
-        super(Editor, self).prepare()
-        self.config = encoder.encode(self.config)
 
-
-class TreeView(twc.Widget):
-    resources = [
-        twc.DirLink(modname=__name__, filename="static/2.7.0/"),
-        twc.CSSLink(modname=__name__, filename="static/2.7.0/fonts/fonts-min.css"),
+class TreeView(YuiWidget):
+    resources = YuiWidget.resources + [
         twc.CSSLink(modname=__name__, filename="static/2.7.0/treeview/assets/skins/sam/treeview.css"),
-        twc.JSLink(modname=__name__, filename="static/2.7.0/yahoo-dom-event/yahoo-dom-event.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/treeview/treeview-min.js"),
     ]
     template = "genshi:tw2.yui.templates.treeview"
-
-    options = twc.Param('tree options', default=[])
-
-    def prepare(self):
-        super(TreeView, self).prepare()
-        self.options = encoder.encode(self.options)