Author: chrisz
Date: Mon Jan 28 12:02:13 2008
New Revision: 4064
URL: http://trac.turbogears.org/changeset/4064

Log:
Added parameter docs to the CalendarDatePicker, also explaining and making it 
even easier to use different skins.

Modified:
   branches/1.0/turbogears/widgets/big_widgets.py
   branches/1.1/turbogears/widgets/big_widgets.py

Modified: branches/1.0/turbogears/widgets/big_widgets.py
==============================================================================
--- branches/1.0/turbogears/widgets/big_widgets.py      (original)
+++ branches/1.0/turbogears/widgets/big_widgets.py      Mon Jan 28 12:02:13 2008
@@ -15,37 +15,44 @@
 __all__ = ["CalendarDatePicker", "CalendarDateTimePicker", "AutoCompleteField",
            "LinkRemoteFunction", "RemoteForm", "AjaxGrid", "URLLink"]
 
+
 class CalendarDatePicker(FormField):
-    css = [CSSLink(static, "calendar/calendar-system.css")]
+    """Use a Javascript calendar system to allow picking of calendar dates."""
     template = """
     <div xmlns:py="http://purl.org/kid/ns#";>
-    <input type="text" id="${field_id}" class="${field_class}" name="${name}" 
value="${strdate}" py:attrs="attrs" />
-    <input type="button" id="${field_id}_trigger" class="date_field_button" 
value="${button_text}" />
+    <input type="text" id="${field_id}" class="${field_class}" name="${name}" 
value="${strdate}" py:attrs="attrs"/>
+    <input type="button" id="${field_id}_trigger" class="date_field_button" 
value="${button_text}"/>
     <script type="text/javascript">
     Calendar.setup(
     {
         inputField : "${field_id}",
         ifFormat : "${format}",
         button : "${field_id}_trigger"
-        <span py:if="picker_shows_time" py:replace="', showsTime : true'" />
+        <span py:if="picker_shows_time" py:replace="', showsTime : true'"/>
     }
     );
     </script>
     </div>
     """
-    params = ["button_text", "format", "picker_shows_time", "attrs"]
+    params = ["attrs", "skin", "picker_shows_time", "button_text",
+        "format", "calendar_lang"]
+    params_doc = {'attrs': 'Extra attributes',
+        'skin': 'For alternate skins, such as "calendar-blue" or 
"skins/aqua/theme"',
+        'picker_shows_time': 'Whether the calendar should let you pick a time, 
too',
+
+        'button_text': 'Text for the button that will show the calendar 
picker',
+        'format': 'The date format (default is mm/dd/yyyy)',
+        'calendar_lang': 'The language to be used in the calendar picker.'}
     attrs = {}
+    skin = "calendar-system"
     picker_shows_time = False
     button_text = "Choose"
     format = "%m/%d/%Y"
+    calendar_lang = None
     _default = None
 
     def __init__(self, name=None, default=None, not_empty=True,
                  calendar_lang=None, validator=None, format=None, **kw):
-        """
-        Use a javascript calendar system to allow picking of calendar dates.
-        The format is in mm/dd/yyyy unless otherwise specified
-        """
         super(CalendarDatePicker, self).__init__(name, **kw)
         self.not_empty = not_empty
         if default is not None or not self.not_empty:
@@ -57,10 +64,16 @@
                 format=self.format, not_empty=self.not_empty)
         else:
             self.validator = validator
-        lang_file_link = CalendarLangFileLink(static, language=calendar_lang)
-        self.javascript=[JSLink(static, "calendar/calendar.js"),
-                         JSLink(static, "calendar/calendar-setup.js"),
-                         lang_file_link]
+        if calendar_lang:
+            self.calendar_lang = calendar_lang
+        javascript = [JSLink(static, "calendar/calendar.js"),
+            JSLink(static, "calendar/calendar-setup.js")]
+        javascript.append(CalendarLangFileLink(static,
+            language=self.calendar_lang))
+        self.javascript = self.javascript + javascript
+        if self.skin:
+            css = [CSSLink(static, "calendar/%s.css" % self.skin)]
+            self.css = self.css + css
 
     def _get_default(self):
         if self._default is None and self.not_empty:
@@ -75,6 +88,7 @@
         else:
             d['strdate'] = d['value']
 
+
 class CalendarDatePickerDesc(CoreWD):
     name = "Calendar"
     for_widget = CalendarDatePicker("date_picker")
@@ -84,10 +98,12 @@
     format = "%Y/%m/%d %H:%M"
     picker_shows_time = True
 
+
 class CalendarDateTimePickerDesc(CoreWD):
     name = "Calendar with time"
     for_widget = CalendarDateTimePicker("datetime_picker")
 
+
 class AutoCompleteField(CompoundFormField):
     """Performs Ajax-style autocompletion by requesting search
     results from the server as the user types."""
@@ -105,8 +121,8 @@
 
     ${text_field.display(value_for(text_field), **params_for(text_field))}
     <img py:if="show_spinner" id="autoCompleteSpinner${field_id}"
-        src="${tg.url([tg.widgets, 'turbogears.widgets/spinnerstopped.png'])}" 
alt="" />
-    <div class="autoTextResults" id="autoCompleteResults${field_id}" />
+        src="${tg.url([tg.widgets, 'turbogears.widgets/spinnerstopped.png'])}" 
alt=""/>
+    <div class="autoTextResults" id="autoCompleteResults${field_id}"/>
     ${hidden_field.display(value_for(hidden_field), 
**params_for(hidden_field))}
     </div>
     """
@@ -115,10 +131,10 @@
     member_widgets = ["text_field", "hidden_field"]
     params = ["search_controller", "search_param", "result_name", "attrs",
         "only_suggest", "complete_delay", "take_focus", "show_spinner"]
-    params_doc = {'search_controller': 'Name of the controller returning the 
auto completions',
+    params_doc = {'attrs': 'Extra attributes',
+        'search_controller': 'Name of the controller returning the auto 
completions',
         'search_param': 'Name of the search parameter ("*" passes all form 
fields)',
         'result_name': 'Name of the result list returned by the controller',
-        'attrs': 'Extra attributes',
         'only_suggest': 'If true, pressing enter does not automatically submit 
the first list item.',
         'complete_delay': 'Delay (in seconds) before loading new auto 
completions',
         'take_focus': 'If true, take focus on load.',
@@ -134,6 +150,7 @@
     take_focus = False
     show_spinner = True
 
+
 class AutoCompleteFieldDesc(CoreWD):
     name = "Auto Complete"
 
@@ -172,6 +189,7 @@
                 filter(lambda item: statename in item.lower(), self.states))
     search = expose(format="json")(search)
 
+
 class LinkRemoteFunction(RPC):
     """ Returns a link that executes a POST asynchronously
     and updates a DOM Object with the result of it """
@@ -182,6 +200,7 @@
     params = ["attrs"]
     attrs = {}
 
+
 class LinkRemoteFunctionDesc(CoreWD):
     name = "Ajax remote function"
 
@@ -213,12 +232,13 @@
             data = dict(state_starts_with="N"))
 
     def search_linkrf(self, state_starts_with):
-        return '<br />'.join(
+        return '<br/>'.join(
                 filter(lambda item: item.startswith(state_starts_with),
                        self.states)
        )
     search_linkrf = expose()(search_linkrf)
 
+
 class RemoteForm(RPC, TableForm):
     """A TableForm that submits the data asynchronously and loads the resulting
     HTML into a DOM object"""
@@ -264,9 +284,10 @@
         )
 
     def post_data_rf(self, **kw):
-        return """Received data:<br />%r""" % kw
+        return """Received data:<br/>%r""" % kw
     post_data_rf = expose()(post_data_rf)
 
+
 ajaxgridcounter = itertools.count()
 
 class AjaxGrid(Widget):
@@ -308,6 +329,7 @@
         super(AjaxGrid, self).update_params(d)
         d["defaults"] = jsonify.encode(d["defaults"])
 
+
 class AjaxGridDesc(CoreWD):
     name = "Ajax Grid"
 

Modified: branches/1.1/turbogears/widgets/big_widgets.py
==============================================================================
--- branches/1.1/turbogears/widgets/big_widgets.py      (original)
+++ branches/1.1/turbogears/widgets/big_widgets.py      Mon Jan 28 12:02:13 2008
@@ -15,37 +15,44 @@
 __all__ = ["CalendarDatePicker", "CalendarDateTimePicker", "AutoCompleteField",
            "LinkRemoteFunction", "RemoteForm", "AjaxGrid", "URLLink"]
 
+
 class CalendarDatePicker(FormField):
-    css = [CSSLink(static, "calendar/calendar-system.css")]
+    """Use a Javascript calendar system to allow picking of calendar dates."""
     template = """
     <div xmlns:py="http://purl.org/kid/ns#";>
-    <input type="text" id="${field_id}" class="${field_class}" name="${name}" 
value="${strdate}" py:attrs="attrs" />
-    <input type="button" id="${field_id}_trigger" class="date_field_button" 
value="${button_text}" />
+    <input type="text" id="${field_id}" class="${field_class}" name="${name}" 
value="${strdate}" py:attrs="attrs"/>
+    <input type="button" id="${field_id}_trigger" class="date_field_button" 
value="${button_text}"/>
     <script type="text/javascript">
     Calendar.setup(
     {
         inputField : "${field_id}",
         ifFormat : "${format}",
         button : "${field_id}_trigger"
-        <span py:if="picker_shows_time" py:replace="', showsTime : true'" />
+        <span py:if="picker_shows_time" py:replace="', showsTime : true'"/>
     }
     );
     </script>
     </div>
     """
-    params = ["button_text", "format", "picker_shows_time", "attrs"]
+    params = ["attrs", "skin", "picker_shows_time", "button_text",
+        "format", "calendar_lang"]
+    params_doc = {'attrs': 'Extra attributes',
+        'skin': 'For alternate skins, such as "calendar-blue" or 
"skins/aqua/theme"',
+        'picker_shows_time': 'Whether the calendar should let you pick a time, 
too',
+
+        'button_text': 'Text for the button that will show the calendar 
picker',
+        'format': 'The date format (default is mm/dd/yyyy)',
+        'calendar_lang': 'The language to be used in the calendar picker.'}
     attrs = {}
+    skin = "calendar-system"
     picker_shows_time = False
     button_text = "Choose"
     format = "%m/%d/%Y"
+    calendar_lang = None
     _default = None
 
     def __init__(self, name=None, default=None, not_empty=True,
                  calendar_lang=None, validator=None, format=None, **kw):
-        """
-        Use a javascript calendar system to allow picking of calendar dates.
-        The format is in mm/dd/yyyy unless otherwise specified
-        """
         super(CalendarDatePicker, self).__init__(name, **kw)
         self.not_empty = not_empty
         if default is not None or not self.not_empty:
@@ -57,10 +64,16 @@
                 format=self.format, not_empty=self.not_empty)
         else:
             self.validator = validator
-        lang_file_link = CalendarLangFileLink(static, language=calendar_lang)
-        self.javascript=[JSLink(static, "calendar/calendar.js"),
-                         JSLink(static, "calendar/calendar-setup.js"),
-                         lang_file_link]
+        if calendar_lang:
+            self.calendar_lang = calendar_lang
+        javascript = [JSLink(static, "calendar/calendar.js"),
+            JSLink(static, "calendar/calendar-setup.js")]
+        javascript.append(CalendarLangFileLink(static,
+            language=self.calendar_lang))
+        self.javascript = self.javascript + javascript
+        if self.skin:
+            css = [CSSLink(static, "calendar/%s.css" % self.skin)]
+            self.css = self.css + css
 
     def _get_default(self):
         if self._default is None and self.not_empty:
@@ -75,6 +88,7 @@
         else:
             d['strdate'] = d['value']
 
+
 class CalendarDatePickerDesc(CoreWD):
     name = "Calendar"
     for_widget = CalendarDatePicker("date_picker")
@@ -84,10 +98,12 @@
     format = "%Y/%m/%d %H:%M"
     picker_shows_time = True
 
+
 class CalendarDateTimePickerDesc(CoreWD):
     name = "Calendar with time"
     for_widget = CalendarDateTimePicker("datetime_picker")
 
+
 class AutoCompleteField(CompoundFormField):
     """Performs Ajax-style autocompletion by requesting search
     results from the server as the user types."""
@@ -105,8 +121,8 @@
 
     ${text_field.display(value_for(text_field), **params_for(text_field))}
     <img py:if="show_spinner" id="autoCompleteSpinner${field_id}"
-        src="${tg.url([tg.widgets, 'turbogears.widgets/spinnerstopped.png'])}" 
alt="" />
-    <div class="autoTextResults" id="autoCompleteResults${field_id}" />
+        src="${tg.url([tg.widgets, 'turbogears.widgets/spinnerstopped.png'])}" 
alt=""/>
+    <div class="autoTextResults" id="autoCompleteResults${field_id}"/>
     ${hidden_field.display(value_for(hidden_field), 
**params_for(hidden_field))}
     </div>
     """
@@ -115,10 +131,10 @@
     member_widgets = ["text_field", "hidden_field"]
     params = ["search_controller", "search_param", "result_name", "attrs",
         "only_suggest", "complete_delay", "take_focus", "show_spinner"]
-    params_doc = {'search_controller': 'Name of the controller returning the 
auto completions',
+    params_doc = {'attrs': 'Extra attributes',
+        'search_controller': 'Name of the controller returning the auto 
completions',
         'search_param': 'Name of the search parameter ("*" passes all form 
fields)',
         'result_name': 'Name of the result list returned by the controller',
-        'attrs': 'Extra attributes',
         'only_suggest': 'If true, pressing enter does not automatically submit 
the first list item.',
         'complete_delay': 'Delay (in seconds) before loading new auto 
completions',
         'take_focus': 'If true, take focus on load.',
@@ -134,6 +150,7 @@
     take_focus = False
     show_spinner = True
 
+
 class AutoCompleteFieldDesc(CoreWD):
     name = "Auto Complete"
 
@@ -172,6 +189,7 @@
                 filter(lambda item: statename in item.lower(), self.states))
     search = expose(format="json")(search)
 
+
 class LinkRemoteFunction(RPC):
     """ Returns a link that executes a POST asynchronously
     and updates a DOM Object with the result of it """
@@ -182,6 +200,7 @@
     params = ["attrs"]
     attrs = {}
 
+
 class LinkRemoteFunctionDesc(CoreWD):
     name = "Ajax remote function"
 
@@ -213,12 +232,13 @@
             data = dict(state_starts_with="N"))
 
     def search_linkrf(self, state_starts_with):
-        return '<br />'.join(
+        return '<br/>'.join(
                 filter(lambda item: item.startswith(state_starts_with),
                        self.states)
        )
     search_linkrf = expose()(search_linkrf)
 
+
 class RemoteForm(RPC, TableForm):
     """A TableForm that submits the data asynchronously and loads the resulting
     HTML into a DOM object"""
@@ -264,9 +284,10 @@
         )
 
     def post_data_rf(self, **kw):
-        return """Received data:<br />%r""" % kw
+        return """Received data:<br/>%r""" % kw
     post_data_rf = expose()(post_data_rf)
 
+
 ajaxgridcounter = itertools.count()
 
 class AjaxGrid(Widget):
@@ -308,6 +329,7 @@
         super(AjaxGrid, self).update_params(d)
         d["defaults"] = jsonify.encode(d["defaults"])
 
+
 class AjaxGridDesc(CoreWD):
     name = "Ajax Grid"
 

Reply via email to