Good point. You could override display(...) like this: import tw2.forms as twf import tw2.core.util
class MyWidget(twf.LabelField): @tw2.core.util.class_or_instance def display(cls, *args, **kwargs): return "#occupywallst" -Ralph Excerpts from Daniel Lepage's message of Tue Oct 18 12:26:36 -0400 2011: > Even that still requires that you use a templating language - why not > allow the widget author to produce the output in pure python if they > want to? > > class tw2.forms.Label(Widget): > def render_me(self): > return "<span " + self.attrs + ">" + self.text + "</span>" > > -- > Dan > > On Wed, Oct 12, 2011 at 9:10 AM, Ralph Bean <ralph.b...@gmail.com> wrote: > > I think you've correctly described the current state of tw2. > > > > In tw1, there was the option to specify the content of the template in the > > python module that defines your widget, like: > > > > class tw2.forms.Label(Widget): > > template = """ > > <%namespace name="tw" module="tw2.core.mako_util"/>\ > > <span ${tw.attrs(attrs=w.attrs)}>${w.text}</span> > > """ > > > > I think this would be called "inline templates", and it looks like there's > > already a ticket for it: > > https://bitbucket.org/paj/tw2core/issue/69/inline-templates > > > > I'm for it, we just have to implement it. :) > > > > -Ralph > > > > > > Excerpts from Daniel Lepage's message of Tue Oct 11 20:00:18 -0400 2011: > >> Is there a way to make widgets that don't have template files, but > >> just call python functions to render themselves? I ask because > >> templating sometimes seems like overkill. > >> > >> For example, suppose for some reason I needed to reimplement > >> tw2.forms.Label, which has the following mako template: > >> > >> <%namespace name="tw" module="tw2.core.mako_util"/>\ > >> <span ${tw.attrs(attrs=w.attrs)}>${w.text}</span> > >> > >> and the following genshi template: > >> > >> <span xmlns:py="http://genshi.edgewall.org/" py:attrs="w.attrs" > >> py:content="w.text" /> > >> > >> I'd like instead to write a function: > >> > >> def render(self): > >> return "<span > >> {attrs}>{text}</span>".format(attrs=tw.attrs(self.attrs), > >> text=self.text) > >> > >> or, with something like Nagare's HTML renderer, > >> > >> def render(self): > >> return h.span(self.text, attrs=tw.attrs(self.attrs)) > >> > >> and suddenly I don't need two extra files for the mako and genshi > >> templates, plus the widget would now work without either engine > >> installed. > >> > >> AFAICT, though, the only way to do this is to overload the display > >> function entirely (and so copying the logic for resources, etc.); am I > >> missing something? > >> > >> Thanks, > >> Dan Lepage > >> > > > > -- > > You received this message because you are subscribed to the Google Groups > > "ToscaWidgets-discuss" group. > > To post to this group, send email to toscawidgets-discuss@googlegroups.com. > > To unsubscribe from this group, send email to > > toscawidgets-discuss+unsubscr...@googlegroups.com. > > For more options, visit this group at > > http://groups.google.com/group/toscawidgets-discuss?hl=en. > > > > > -- You received this message because you are subscribed to the Google Groups "ToscaWidgets-discuss" group. To post to this group, send email to toscawidgets-discuss@googlegroups.com. To unsubscribe from this group, send email to toscawidgets-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/toscawidgets-discuss?hl=en.