Author: jmorliaguet
Date: Fri May 12 15:26:23 2006
New Revision: 3109

Modified:
   cpsskins/branches/paris-sprint-2006/standard/filters/widget/__init__.py
   cpsskins/branches/paris-sprint-2006/standard/filters/widget/interfaces.py
   cpsskins/branches/paris-sprint-2006/standard/filters/widget/widgets.py

Log:

- simpler widget definition syntax 



Modified: 
cpsskins/branches/paris-sprint-2006/standard/filters/widget/__init__.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/filters/widget/__init__.py     
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/filters/widget/__init__.py     
Fri May 12 15:26:23 2006
@@ -93,22 +93,6 @@
 class WidgetView:
     """Widgets are used for formatting elements using some HTML markup.
 
-    The '_preview' variable (a string) contains a preview of the widget
-    that can be used by the style editor.
-
-    To make a tag inactive, i.e. not editable, set any value to the
-    'inactive' attribute:
-
-        _preview = '<div><ul inactive="1"><li>item</li></ul></div>'
-
-    If the "ignore" attribute is set, the tag will be ignored.
-
-        _preview = '<div><ul ignore="1"><li>item</li></ul></div>'
-
-    The "label" attribute will be shown in the tooltip
-
-        _preview = '<div><ul><li label="list item">item</li></ul></div>'
-
     """
     implements(IWidgetView)
 
@@ -120,8 +104,8 @@
         return self.request.response.redirect(url)
 
     def renderPreview(self):
-        if not hasattr(self, '_preview'):
+        if not hasattr(self, 'preview'):
             raise AttributeError(
-                "the '_preview' attribute is missing in %s." % self.__class__)
-        return self._preview
+                "the 'preview' attribute is missing in %s." % self.__class__)
+        return self.preview
 

Modified: 
cpsskins/branches/paris-sprint-2006/standard/filters/widget/interfaces.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/filters/widget/interfaces.py   
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/filters/widget/interfaces.py   
Fri May 12 15:26:23 2006
@@ -17,10 +17,32 @@
 """
 __docformat__ = "reStructuredText"
 
-from zope.interface import Interface
+from zope.interface import Interface, Attribute
 
 class IWidgetView(Interface):
-    """A view for widgets"""
+    """A view for widgets
+
+    The 'preview' attribute (a string) contains a preview of the widget
+    that can be used by the style editor.
+
+    To make a tag inactive, i.e. not editable, set any value to the
+    'inactive' attribute:
+
+        preview = '<div><ul inactive="1"><li>item</li></ul></div>'
+
+    If the "ignore" attribute is set, the tag will be ignored.
+
+        preview = '<div><ul ignore="1"><li>item</li></ul></div>'
+
+    The "label" attribute will be shown in the tooltip
+
+        preview = '<div><ul><li label="list item">item</li></ul></div>'
+
+    """
+    preview = Attribute(u"The widget preview.")
+
+    def __call__():
+        """The rendered widget. Returns HTML, text markup (...) in unicode"""
 
     def __str__():
         """ """
@@ -29,7 +51,7 @@
         """ """
 
     def renderPreview():
-        """ """
+        """Render the preview."""
 
 class IBasicWidgetView(Interface):
     """A marker interface for basic widget views."""

Modified: cpsskins/branches/paris-sprint-2006/standard/filters/widget/widgets.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/standard/filters/widget/widgets.py      
(original)
+++ cpsskins/branches/paris-sprint-2006/standard/filters/widget/widgets.py      
Fri May 12 15:26:23 2006
@@ -24,26 +24,26 @@
 class HTMLView(WidgetView):
     """Simple HTML markup wrapped around some content.
     """
-    _markup = '' # the content will be inserted in %(content)s 
+    markup = '' # the content will be inserted in %(content)s 
 
     def __call__(self, markup, info, **kw):
-        markup = self._markup % {'content': markup}
+        markup = self.markup % {'content': markup}
         # TODO: rendering optional link
         return markup
 
 class MenuView(WidgetView):
     """A menu view displays a list of items.
     """
-    _start = ''     # Optional
-    _repeat = ''    # Mandatory
-    _separator = '' # Optional
-    _end = ''       # Optional
+    start = ''     # Optional
+    repeat = ''    # Mandatory
+    separator = '' # Optional
+    end = ''       # Optional
 
     def __call__(self, markup, info, **kw):
-        start = self._start
-        repeat = self._repeat
-        separator = self._separator
-        end = self._end
+        start = self.start
+        repeat = self.repeat
+        separator = self.separator
+        end = self.end
 
         markup = []
         markup_append = markup.append
@@ -67,7 +67,7 @@
 class PlainHTML(WidgetView):
     """Display the markup with minimal formatting
     """
-    _preview = u'<div>' \
+    preview = u'<div>' \
                '<h1 label="H1">Header level 1</h1>' \
                '<h2 label="H2">Header level 2</h2>' \
                '<h3 label="H3">Header level 3</h3>' \
@@ -108,7 +108,7 @@
 class Image(WidgetView):
     """Display an image
     """
-    _preview = u'<img src="#" alt="" style="border: none" />'
+    preview = u'<img src="#" alt="" style="border: none" />'
 
     def __call__(self, markup, info, **kw):
         data = info.data
@@ -124,14 +124,14 @@
 class PageBody(HTMLView):
     """The page's <body> tag
     """
-    _markup = u'<body>%(content)s</body>'
-    _preview = u'<body>Page content</body>'
+    markup = u'<body>%(content)s</body>'
+    preview = u'<body>Page content</body>'
 
 class VerticalMenu(MenuView):
-    _start = u'<ul>'
-    _repeat = u'<li><a href="%(url)s">%(title)s</a></li>'
-    _end = u'</ul>'
-    _preview = u'<ul label="menu box">' \
+    start = u'<ul>'
+    repeat = u'<li><a href="%(url)s">%(title)s</a></li>'
+    end = u'</ul>'
+    preview = u'<ul label="menu box">' \
                '<li label="menu item">' \
                '<a label="link" href="#">First item</a></li>' \
                '<li label="menu item">' \
@@ -141,10 +141,10 @@
                '</ul>'
 
 class HorizontalTabs(MenuView):
-    _start = u'<ul>'
-    _repeat = u'<li><a href="%(url)s">%(title)s</a></li>'
-    _end = u'</ul>'
-    _preview = u'<ul label="menu box">' \
+    start = u'<ul>'
+    repeat = u'<li><a href="%(url)s">%(title)s</a></li>'
+    end = u'</ul>'
+    preview = u'<ul label="menu box">' \
                '<li label="menu tab">' \
                '<a label="link" href="#">First item</a></li>' \
                '<li label="menu tab">' \
@@ -154,10 +154,10 @@
                '</ul>'
 
 class MenuBar(MenuView):
-    _start = u'<div>'
-    _repeat = u'<a href="%(url)s">%(title)s</a>'
-    _end = u'</div>'
-    _preview = u'<ul label="menu bar">' \
+    start = u'<div>'
+    repeat = u'<a href="%(url)s">%(title)s</a>'
+    end = u'</div>'
+    preview = u'<ul label="menu bar">' \
                '<li label="menu item">' \
                '<a label="link" href="#">First item</a></li>' \
                '<li label="menu item">' \
@@ -167,11 +167,11 @@
                '</ul>'
 
 class HorizontalTrail(MenuView):
-    _start = u'<div>'
-    _repeat = u'<a href="%(url)s">%(title)s</a>'
-    _separator = u'<span class="sep">&gt;</span>'
-    _end = u'</div>'
-    _preview = u'<div label="box">' \
+    start = u'<div>'
+    repeat = u'<a href="%(url)s">%(title)s</a>'
+    separator = u'<span class="sep">&gt;</span>'
+    end = u'</div>'
+    preview = u'<div label="box">' \
                '<a label="trail item" href="#">First item</a>' \
                '<span label="separator" class="sep">&gt;</span>' \
                '<a label="trail item" href="#">Second item</a>' \
@@ -181,19 +181,19 @@
                '</div>'
 
 class DropDownList(MenuView):
-    _start = u'<form action="@@cpsskins_redirect" method="post">' \
+    start = u'<form action="@@cpsskins_redirect" method="post">' \
              '<select onchange="submit()" name="url">' \
              '<option value="./"></option>'
-    _repeat = u'<option value="%(url)s">%(title)s</option>'
-    _end = u'</select></form>'
-    _preview = u'<form label="selector"><select label="item selector">' \
+    repeat = u'<option value="%(url)s">%(title)s</option>'
+    end = u'</select></form>'
+    preview = u'<form label="selector"><select label="item selector">' \
                '<option label="list item">First item</option>' \
                '<option label="list item">Second item</option>' \
                '<option label="list item">Third item</option>' \
                '</select></form>'
 
 class FrameBox(HTMLView):
-    _preview = u'<fieldset label="box">' \
+    preview = u'<fieldset label="box">' \
                '<legend label="legend">Box title</legend>' \
                'Sample content.' \
                '<a label="link" href="#">some link</a>' \
@@ -210,14 +210,14 @@
 class HorizontalScrollBar(HTMLView):
     """Display horizontal scroll bars in case of horizontal overflow
     """
-    _markup = u'<div style="overflow-x:scroll;">%(content)s</div>'
-    _preview = u'<div label="box" style="overflow-x:scroll;">Box content</div>'
+    markup = u'<div style="overflow-x:scroll;">%(content)s</div>'
+    preview = u'<div label="box" style="overflow-x:scroll;">Box content</div>'
 
 class PageBlockFrame(HTMLView):
     """Display a <table><tr> tag
     """
-    _markup = u'<table summary=""><tr>%(content)s</tr></table>'
-    _preview = u'<table summary="" label="table frame">' \
+    markup = u'<table summary=""><tr>%(content)s</tr></table>'
+    preview = u'<table summary="" label="table frame">' \
                '<tbody inactive="1"><tr inactive="1">' \
                '<td inactive="1">Sample content</td>' \
                '</tr></tbody></table>'
@@ -225,8 +225,8 @@
 class CellFrame(HTMLView):
     """Display a <td> tag
     """
-    _markup = u'<td style="vertical-align:top;">%(content)s</td>'
-    _preview = u'<table summary="" ignore="1" inactive="1">' \
+    markup = u'<td style="vertical-align:top;">%(content)s</td>'
+    preview = u'<table summary="" ignore="1" inactive="1">' \
                '<tbody ignore="1" inactive="1">' \
                '<tr ignore="1" inactive="1">' \
                '<td label="cell">Cell content</td>' \
@@ -235,21 +235,21 @@
 class TablelessPageBlockFrame(HTMLView):
     """Display a <div> frame
     """
-    _markup = u'<div>%(content)s<br style="clear:left"/></div>' \
+    markup = u'<div>%(content)s<br style="clear:left"/></div>' \
               '<div style="clear:left"></div>'
-    _preview = u'<div label="frame box">Frame content</div>'
+    preview = u'<div label="frame box">Frame content</div>'
 
 class TablelessCellFrame(HTMLView):
     """Display a floating <div> cell
     """
-    _markup = u'<div style="float:left;overflow:hidden">%(content)s</div>'
-    _preview = u'<div label="cell">Cell content</div>'
+    markup = u'<div style="float:left;overflow:hidden">%(content)s</div>'
+    preview = u'<div label="cell">Cell content</div>'
 
 class MonthlyCalendar(WidgetView):
     """Display a monthly calendar
     """
-    _markup = u'Not done yet'
-    _preview = u'<table label="calendar">' \
+    markup = u'Not done yet'
+    preview = u'<table label="calendar">' \
                '<thead><tr label="header">' \
                '<th>Mo</th><th>Tu</th><th>We</th><th>Th</th>' \
                '<th>Fr</th><th>Sa</th><th>Su</th></tr></thead>' \
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to