"Ian Wilson" <[EMAIL PROTECTED]> writes:

> I think the documentation is there.  Its just hard to understand in
> different contexts.  I can't tell if you mean you are making your own
> Widget or just using a non-form preexisting widget.  I'm going to
> assume you are making your own widget but if you mean preexisting you
> need to inherit from its class and do something similar to what is
> below.
>
> You must set the params explicity in your Widget subclass before
> instantiation.  So in your widgets.py you have something like this:
>
> class Tabber(Widget):
>     template = "some.defaulttemplate"
>     # You need this to provide params
>     params = ['mydata']
>     # You probably want to(but don't need to) set a default
>     mydata = 'Ian is not creative'
>
> Then you initialize it:
> tabber = Tabber(mydata = mydata)
>
> Then you display it as you have already done in your example.
>
> Of course if you reuse the tabber frequently with different data you
> will want to move the mydata passing to display time and out of
> initialization time.
>
> Ie.
> ${ET(tabber.display(mydata=mydata))}
>
>
> Here is a real, yet very lame, example i did in tg-admin:
>
>
> [EMAIL PROTECTED] ~/uwe $ tg-admin shell
> Python 2.4.3 (#1, Oct  2 2006, 16:53:53)
> [GCC 4.1.1 (Gentoo 4.1.1)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (CustomShell)
>>>> from turbogears.widgets import Widget
>>>> class Tabber(Widget):
> ...     template = """<div
> xmlns:py="http://purl.org/kid/ns#";>${str(mydata)}</div>"""
> ...     mydata = {}
> ...     params = ['mydata']
> ...
>>>> tabber = Tabber()
>>>> print tabber.render()
> <DIV>{}</DIV>
>>>> print tabber.render(mydata={'x':14, 'y':400})
> <DIV>{'y': 400, 'x': 14}</DIV>
>>>> newTabber = Tabber(mydata='Ian lacks creativity when providing examples')
>>>> newTabber.render()
> '<DIV>Ian lacks creativity when providing examples</DIV>'
>>>>


You do realize, though, that it will not work as intended.  And that the
only way to use a widget that needs wrapping things such as tabber does
is by creating a custom template.

There was a proposition I made a while ago where we had "start" and
"stop" (i.e. "<div class='tabbertab'>" and then "</div>") elements to
use such widgets more easily, but the whole idea of valid XML is against
that usage, so one couldn't do that with Kid or Genshi.

Also, by the time of that proposition, it wasn't possible to use another
thing to write widgets as easily as it is today with ToscaWidgets.  With
TW you can use other templating systems that would allow the
"start"/"stop" pattern to use widgets directly from your form, without
having to provide a custom template.

I haven't insisted on that and I haven't even considered how would it
behave if one was going to use a, e.g., Cheetah / Mako templated widget
on a Kid templated page with that particularity... 

Anyway, the thing is: it's not as easy as it is with other widgets.

-- 
Jorge Godoy      <[EMAIL PROTECTED]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to