Commits

Anonymous committed e9eda18

LogReader, improvements to AutoComplete

  • Participants
  • Parent commits 7fbaf5f

Comments (0)

Files changed (8)

examples/autocomplete.py

 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"
+        return {'result': ['a','b','c']}
 
 class Index(twf.FormPage):
     title = "YUI AutoComplete"
     attrs = {"class": "yui-skin-sam"}
     class child(twf.TableForm):
-        paj = twy.AutoComplete(datasrc=MyDataSource(id="bobby"))
+        paj = twy.AutoComplete(datasrc=MyDataSource())
+        fred = twy.LogReader()
 
 if __name__ == "__main__":
     import wsgiref.simple_server as wrs
     wrs.make_server("", 8000, twc.make_middleware(controller_prefix="/")).serve_forever()
-

examples/example.py

 import tw2.core as twc, tw2.forms as twf, tw2.yui as 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)]},
+]
+
 class Index(twf.FormPage):
     title = 'YUI Example'
     attrs = {'class': 'yui-skin-sam'}
         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')
+        treeview = twy.TreeView(content=treeview_content)
 
 if __name__ == '__main__':
     import wsgiref.simple_server as wrs

tw2/yui/__init__.py

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

tw2/yui/templates/autocomplete.html

-<div>
+<div xmlns:py="http://genshi.edgewall.org/">
 
-<style>
-    .yui-autocomplete {
-       width:15em; /* set width here or else widget will expand to fit its container */
-       padding-bottom:2em;
-   }
-</style>
-
-<div class="yui-autocomplete">
-    <input id="$w.compound_id" type="text"/>
-    <div id="${w.compound_id}:popup"></div>
-</div>
+<input py:attrs="w.attrs"/>
+<div id="${w.compound_id}:popup"></div>
 
 ${w.datasrc.display()}
 
 <script type="text/javascript">
-    var oAC = new YAHOO.widget.AutoComplete("$w.compound_id", "${w.compound_id}:popup", tw2_yui_datasources["$w.datasrc.compound_id"], $w.config);
+    var oAC = new YAHOO.widget.AutoComplete("$w.compound_id", "${w.compound_id}:popup", tw2_yui_datasources["$w.datasrc.compound_id"], $w.options);
 </script>
 
 </div>

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'],}}
-                                 );
+    var oDS = new YAHOO.util.XHRDataSource("/$w.compound_id", $w.options);
     tw2_yui_datasources["$w.compound_id"] = oDS;
 </script>

tw2/yui/templates/logreader.html

+<div xmlns:py="http://genshi.edgewall.org/">
+
+<div py:attrs="w.attrs"/>
+
+<script type="text/javascript">
+    var oAC = new YAHOO.widget.LogReader("$w.compound_id", $w.options);
+</script>
+
+</div>

tw2/yui/templates/treeview.html

 
 <script type="text/javascript">
     YAHOO.util.Event.onDOMReady(function() {
-        tree = new YAHOO.widget.TreeView("$w.compound_id", $w.options);
+        tree = new YAHOO.widget.TreeView("$w.compound_id", $w.content);
         tree.render();
     });
 </script>

tw2/yui/widgets.py

     options = twc.Param('Configuration options for the widget. See the YUI docs for available options.', default={})
     def prepare(self):
         super(YuiWidget, self).prepare()
+        print 123, self.options
         self.options = encoder.encode(self.options)
+        print 124, self.options
 
 
 class Slider(YuiWidget):
     template = "genshi:tw2.yui.templates.tabview"
 
 
-class AutoComplete(YuiWidget):
+class AutoComplete(twf.TextField, 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/connection/connection-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/autocomplete/autocomplete-min.js"),
     ]
     template = "genshi:tw2.yui.templates.autocomplete"
+    attrs = {'style': 'width:15em;'}
     datasrc = twc.Param('DataSource to use')
 
     @classmethod
 
 
 class DataSource(YuiWidget):
-    # TBD: resources
+    resources = [ # don't use YuiWidget.resources
+        twc.JSLink(modname=__name__, filename="static/2.7.0/datasource/datasource-min.js"),
+    ]
+    responseSchema = twc.Param('TBD', default={'resultsList':'result'})
     template = "genshi:tw2.yui.templates.datasource"
+    #options = {
+    #    'responseType': 3, # YAHOO.util.XHRDataSource.TYPE_JSON
+    #}
+
+    def prepare(self):
+        self.safe_modify('options')
+        self.options['responseSchema'] = 'fred'
+        super(DataSource, self).prepare()
 
     @classmethod
     def request(self, req):
         resp = webob.Response(request=req, content_type="text/plain; charset=UTF8")
-        x = self.ajax_request(req)
-        resp.body = x
+        resp.body = encoder.encode(self.ajax_request(req))
         return resp
 
 
         twc.JSLink(modname=__name__, filename="static/2.7.0/slider/slider-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/element/element-min.js"),
         twc.JSLink(modname=__name__, filename="static/2.7.0/colorpicker/colorpicker-min.js"),
+        twc.Link(id='picker_thumb', modname=__name__, filename="static/2.7.0/colorpicker/assets/picker_thumb.png"),
+        twc.Link(id='hue_thumb', modname=__name__, filename="static/2.7.0/colorpicker/assets/hue_thumb.png"),
     ]
     template = "genshi:tw2.yui.templates.colorpicker"
 
     def prepare(self):
         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"
+            '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',
         }
         super(ColorPicker, self).prepare()
 
         twc.JSLink(modname=__name__, filename="static/2.7.0/treeview/treeview-min.js"),
     ]
     template = "genshi:tw2.yui.templates.treeview"
+    content = twc.Param('Content', default=[])
+    def prepare(self):
+        super(TreeView, self).prepare()
+        self.content = encoder.encode(self.content)
+
+
+class LogReader(YuiWidget):
+    resources = YuiWidget.resources + [
+        twc.CSSLink(modname=__name__, filename="static/2.7.0/logger/assets/skins/sam/logger.css"),
+        twc.JSLink(modname=__name__, filename="static/2.7.0/logger/logger-min.js"),
+    ]
+    template = "genshi:tw2.yui.templates.logreader"