Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 3 and Version 4 of DiveIntoWidgets


Ignore:
Timestamp:
01/31/07 10:49:55 (12 years ago)
Author:
jorge.vargas
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DiveIntoWidgets

    v3 v4  
    1 The idea was to provide some explanation but I haven't been able to make it in time for the DocSprint. 
    2  
    3 ATM there is only an interactive session showing some of the very import ants widgets features (template, name, value, params and subclassing), I hope you can make some doc from there. 
    4  
    5 I need to add a section regarding CompoundWidgets, I hope to be there within some hours to do that. 
    6  
    71{{{ 
    8 #!python 
    9 >>> from turbogears import widgets 
    10 >>> class HelloWorldWidget(widgets.Widget): 
    11 ...     template = """ 
    12 ...     <div>Hello World!</div> 
    13 ...     """ 
    14 ... 
    15 >>> hello = HelloWorldWidget() 
    16 >>> hello.render() 
    17 '<DIV>Hello World!</DIV>' 
    18 >>> class FooBarWidget(widgets.Widget): 
    19 ...     template = """ 
    20 ...     <ul> 
    21 ...             <li>my name is ${name}</li> 
    22 ...             <li>my value is ${value}</li> 
    23 ...     </ul> 
    24 ...     """ 
    25 ... 
    26 >>> foobar = FooBarWidget(name="foobar") 
    27 >>> print foobar.render() 
    28 '<UL> 
    29                 <LI>my name is foobar</LI> 
    30                 <LI>my value is </LI> 
    31         </UL>' 
    32 >>> print foobar.render(value=5) 
    33 '<UL> 
    34                 <LI>my name is foobar</LI> 
    35                 <LI>my value is 5</LI> 
    36         </UL>' 
    37 >>> foobar = FooBarWidget(name="foobar", default=10) 
    38 >>> print foobar.render() 
    39 '<UL> 
    40                 <LI>my name is foobar</LI> 
    41                 <LI>my value is 10</LI> 
    42         </UL>' 
    43 >>> print foobar.render(value=60) 
    44 '<UL> 
    45                 <LI>my name is foobar</LI> 
    46                 <LI>my value is 60</LI> 
    47         </UL>' 
    48 >>> print foobar.render(value=60, name="wrong") 
    49 '<UL> 
    50                 <LI>my name is foobar</LI> 
    51                 <LI>my value is 60</LI> 
    52         </UL>' 
    53 >>> class ParamsWidget(widgets.Widget): 
    54 ...     template = """ 
    55 ...     <div>my attitude is ${attitude}</div> 
    56 ...     """ 
    57 ...     params = ["attitude"] 
    58 ...     attitude = "high" 
    59 ... 
    60 >>> param = ParamsWidget() 
    61 >>> param.render() 
    62 '<DIV>my attitude is high</DIV>' 
    63 >>> param = ParamsWidget(attitude="medium") 
    64 >>> param.render() 
    65 '<DIV>my attitude is medium</DIV>' 
    66 >>> param.render(attitude="low") 
    67 '<DIV>my attitude is low</DIV>' 
    68 >>> param.params 
    69 ['attitude'] 
    70 >>> param.attitude 
    71 'medium' 
    72 >>> ParamsWidget.attitude 
    73 'high' 
    74 >>> class AnotherParamsWidget(ParamsWidget): 
    75 ...     template = """ 
    76 ...     <div>my attitude is ${attitude} and my favourite language is ${language}</div> 
    77 ...     """ 
    78 ...     params = ["language"] 
    79 ...     language = "python" 
    80 ... 
    81 >>> another = AnotherParamsWidget() 
    82 >>> another.render() 
    83 '<DIV>my attitude is high and my favourite language is python</DIV>' 
    84 >>> AnotherParamsWidget.params 
    85 ['attitude', 'language'] 
    86 >>> another.params 
    87 ['attitude', 'language'] 
    88 >>> AnotherParamsWidget.attitude 
    89 'high' 
    90 >>> another.attitude 
    91 'high' 
    92 >>> AnotherParamsWidget.language 
    93 'python' 
    94 >>> another.language 
    95 'python' 
    96 >>> another = AnotherParamsWidget(attitude="nice", language="java") 
    97 >>> AnotherParamsWidget.attitude 
    98 'high' 
    99 >>> another.attitude 
    100 'nice' 
    101 >>> AnotherParamsWidget.language 
    102 'python' 
    103 >>> another.language 
    104 'java' 
    105 >>> another.render() 
    106 '<DIV>my attitude is nice and my favourite language is java</DIV>' 
    107 >>> another.render(attitude="very low", language="ruby") 
    108 '<DIV>my attitude is very low and my favourite language is ruby</DIV>' 
     2#!NewsFlash 
     3This wiki page has been migrated to the new docs site currently at  
     4http://docs.turbogears.org/1.0/RoughDocs/DiveIntoWidgets 
    1095}}}