</filler> <script> import urwid def init(self, opts): import urwid self.name = opts['name'] def answer(self, edit, text): self.name = text </script> </sig> """, ) style = """ .highlight { foreground: default,bold; background: default; mono: bold; } """ root = convert_string_to_node("<sig></sig>") mount(root, "sig", "sig", {"name": "Default"}) app = parse_tag_from_node(root) run_tag(app, parse_style(style))
# -*- 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())
</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.app import run_tag run_tag( parse_tag_from_string(''' <filler valign="top"> <text>hello world!</text> </filler> '''))
# -*- coding: utf-8 -*- from riot.tags.tags import parse_tag_from_string from riot.app import run_tag, quit_app tag = parse_tag_from_string( ''' <filler valign="top"> <text>Hello World</text> </filler> ''' ) def show_or_exit(key): if key in ('Q', 'q'): quit_app() tag.body.set_text(repr(key)) run_tag(tag, unhandled_input=show_or_exit)
</todo>''') root = convert_string_to_node('<filler><todo></todo></filler>') mount( root, 'todo', 'todo', { 'title': 'TODO list', 'items': [{ 'title': 'Avoid excessive coffeine', 'done': True, 'hidden': False }, { 'title': 'Hidden item', 'done': True, 'hidden': True }, { 'title': 'Be less provocative', 'done': False, 'hidden': False }, { 'title': 'Be nice to people', 'done': False, 'hidden': False }] }) app = parse_tag_from_node(root) run_tag(app)
return [item for item in self.items if not item.get('hidden')] def count(self): return len(self.items) def next_count(self): return self.count() + 1 def toggle(self, e): e.item['done'] = not e.item.get('done') return True </script> </todo>''') root = convert_string_to_node('<filler><todo></todo></filler>') mount(root, 'todo', 'todo', { 'title': 'TODO list', 'items': [ {'title': 'Avoid excessive coffeine', 'done': True, 'hidden': False}, {'title': 'Hidden item', 'done': True, 'hidden': True}, {'title': 'Be less provocative', 'done': False, 'hidden': False}, {'title': 'Be nice to people', 'done': False, 'hidden': False} ] }) app = parse_tag_from_node(root) run_tag(app)
<question-box> <filler keypress="{ keypress }"> <edit caption="Who is your love?\n" /> </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())
</pile> </filler> <script> import urwid def init(self, opts): import urwid self.name = opts['name'] def answer(self, edit, text): self.name = text </script> </sig> ''') style = ''' .highlight { foreground: default,bold; background: default; mono: bold; } ''' root = convert_string_to_node('<sig></sig>') mount(root, 'sig', 'sig', {'name': 'Default'}) app = parse_tag_from_node(root) run_tag(app, parse_style(style))
# -*- coding: utf-8 -*- from riot.tags.tags import parse_tag_from_string from riot.app import run_tag run_tag( parse_tag_from_string( ''' <filler valign="top"> <text>hello world!</text> </filler> ''' ) )
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() )
<custom> <filler class="bg"> <pile> <div class="outside"></div> <div class="inside"></div> <text align="center" class="streak"> <span class="banner">hello world</span> </text> <div class="inside"></div> <div class="outside"></div> </pile> </filler> </custom> ''' tag = ''' <solidfill class="bg"></solidfill> ''' run_tag( parse_tag_from_node( riot_mount( convert_string_to_node(tag), 'solidfill.bg', convert_string_to_node(custom) ) ), parse_style(style), unhandled_input=lambda key: key in ('Q', 'q') and quit_app() )
foreground-high: g7; background-high: #d06; } ''' custom = ''' <custom> <filler class="bg"> <pile> <div class="outside"></div> <div class="inside"></div> <text align="center" class="streak"> <span class="banner">hello world</span> </text> <div class="inside"></div> <div class="outside"></div> </pile> </filler> </custom> ''' tag = ''' <solidfill class="bg"></solidfill> ''' run_tag(parse_tag_from_node( riot_mount(convert_string_to_node(tag), 'solidfill.bg', convert_string_to_node(custom))), parse_style(style), unhandled_input=lambda key: key in ('Q', 'q') and quit_app())