Tomás Touceda wrote on 2010-06-06 20:46: > On 06/06/10 18:09, Ian Ward wrote: >> Tomás Touceda wrote on 2010-06-06 15:11: >> >>> Hi, >>> >>> what's the best approach to handle text decorations of the type: syntax >>> highlighting, selected text? >>> >> I would make a custom widget, either a subclass of Text (if you want the >> interface to be very similar to a Text widget) or a subclass of >> WidgetWrap that uses a Text widget as self._w (if you want more control >> over the interface). >> >> If you're making a subclass of Text you can simply override the >> get_text() method and return the attributes you want along with the text >> (see http://excess.org/urwid/reference.html#Text-get_text ) >> >> With a WidgetWrap subclass you can set the Text's attributes when >> setting the text, eg.: >> >> # use attributes based on syntax >> self._w.set_text([('keyword', "class"), " Foo", ('punct', ":")]) >> >> > I'm inheriting from the Edit widget, since I need the cursor methods > from it. But I can't seem to find a way to use the palette with the > edit_text. > > Why is it set_text not supported anymore with an Edit widget? is my > approach with the Edit widget wrong if I want to use formatted text?
If you are subclassing Edit you can redefine get_text for showing a selection range or doing syntax highlighting. Just modify the run-length encoded attributes returned. Edit doesn't support set_text because an Edit widget has a caption and edit_text that are both displayed, not a single text markup value. Ian _______________________________________________ Urwid mailing list [email protected] http://lists.excess.org/mailman/listinfo/urwid
