</filler> <script> def init(self, opts): self.name = opts['name'] self.enable_input = True def keypress(self, size, key): import sys, urwid print >> sys.stderr, size, key if not self.enable_input: return True if key == 'enter': self.enable_input = True self.name = self.ui.body.edit_text self.ui.body = urwid.Text('%s loves you, too. Press q to exit.' % self.name) return True return False </script> </question-box> ''') root = convert_string_to_node('<question-box></question-box>') mount(root, 'question-box', 'question-box', {'name': 'hello world'}) app = parse_tag_from_node(root) run_tag( app, unhandled_input=lambda key: key in ('q', 'Q') and quit_app() )
# -*- coding: utf-8 -*- from riot.tags.tags import parse_tag_from_string from riot.tags.style import parse_style from riot.app import run_tag, quit_app run_tag(parse_tag_from_string(''' <filler class="bg"> <text class="streak" align="center"> <span class="banner">hello world</span> </text> </filler> '''), parse_style(''' .banner { foreground: black; background: light gray; } .streak { foreground: black; background: dark red; } .bg { foreground: black; background: dark blue; } '''), unhandled_input=lambda key: key in ('q', 'Q') and quit_app())
def show_or_exit(key): if key in ('Q', 'q'): quit_app() tag.body.set_text(repr(key))