diff options
| author | Ian Ward <ian@excess.org> | 2012-10-16 18:55:09 -0400 |
|---|---|---|
| committer | Ian Ward <ian@excess.org> | 2012-10-16 18:55:09 -0400 |
| commit | 31d5502ca57d2cd258e16303f7ffa8bda737e397 (patch) | |
| tree | b69d6267898532a24c568453c827fa1c2f5194b6 /docs | |
| parent | 8574c868e5b434f12877d8861a99eb7cf5d4586c (diff) | |
| download | urwid-31d5502ca57d2cd258e16303f7ffa8bda737e397.tar.gz | |
remove old docs build scripts
Diffstat (limited to 'docs')
| -rwxr-xr-x | docs/build/build.sh | 11 | ||||
| -rwxr-xr-x | docs/build/docgen_reference.py | 391 | ||||
| -rwxr-xr-x | docs/build/docgen_tutorial.py | 706 | ||||
| -rw-r--r-- | docs/build/tmpl_tutorial.html | 743 | ||||
| l--------- | docs/build/urwid | 1 |
5 files changed, 0 insertions, 1852 deletions
diff --git a/docs/build/build.sh b/docs/build/build.sh deleted file mode 100755 index c15e52e..0000000 --- a/docs/build/build.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -set -e - -python docgen_tutorial.py -H > ../tutorial.html -python docgen_tutorial.py -s -mkdir -p ../tutorial_examples -ln -s ../../urwid ../tutorial_examples/urwid -mv example*py ../tutorial_examples/ - -python docgen_reference.py > ../reference.html diff --git a/docs/build/docgen_reference.py b/docs/build/docgen_reference.py deleted file mode 100755 index 4d59dc7..0000000 --- a/docs/build/docgen_reference.py +++ /dev/null @@ -1,391 +0,0 @@ -#!/usr/bin/python -# -# Urwid reference documentation generation program -# Copyright (C) 2004-2007 Ian Ward -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# Urwid web site: http://excess.org/urwid/ - -import pydoc -import urwid.curses_display -import urwid.raw_display -import urwid.web_display -import urwid.html_fragment -import urwid - -import types - -html_template = """<html> -<head> -<title>Urwid %version% Reference</title> -<style type="text/css"> - h1 { text-align: center; } - h2 { margin: 40px 0 0 0; padding: 10px; background: #6d96e8;} - h3 { margin: 0 0 3px 0; padding: 12px 6px 6px 6px; background: #efef96;} - .l1 { margin: 12px 0 0 0; } - .l2 { margin-left: 20px; } -</style> -<body> -<a name="top"></a> -<h1>Urwid %version% Reference</h1> - -<div style="text-align: center;"> -<a href="http://excess.org/urwid/">Urwid Home Page</a> / -<a href="http://excess.org/urwid/examples.html">Example Screenshots</a> / -<a href="http://excess.org/urwid/utf8examples.html">UTF-8 Screenshots</a> / -<a href="tutorial.html">Tutorial</a> / -Reference -</div> -<br> -%toc% -<br> -[<b>F</b>] = Flow Widget displayed with assigned screen columns and variable screen rows<br> -[<b>B</b>] = Box Widget displayed with assigned screen columns and assigned screen rows<br> -[<b>F</b>/<b>B</b>] = May behave as either Flow Widget or Box Widget<br> -[<b>X</b>] = Fixed Widget has a fixed number of screen columns and rows -<br> -%contents% -</body> -</html>""" - -flagd = { - None: "", - "B": "[<b>B</b>]", - "F": "[<b>F</b>]", - "FB": "[<b>F</b>/<b>B</b>]", - "X": "[<b>X</b>]", -} - - -class UrwidHTMLDoc( pydoc.HTMLDoc ): - def heading(self, title, fgcol, bgcol, extras=''): - return extras - - def section(self, title, fgcol, bgcol, contents, width=6, - prelude='', marginalia=None, gap=' '): - if " = " in title: - visible, tail = title.split(" = ",1) - aname = tail.split('">',1)[0] - aname = aname.split('"',1)[1] - aname = aname.replace(" ","_") - title = '<a name="'+aname+'"></a>'+visible - return '<h3>%s <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>%s' % (title,contents) - - def namelink(self, name, *ignore): - return name - - def classlink(self, obj, modname): - return obj.__name__ - - def modulelink(self, obj): - return obj.__name__ - - def modpkglink(self, (name, path, ispackage, shadowed) ): - return name - - def markup(self, text, escape=None, funcs={}, classes={}, methods={}): - return pydoc.HTMLDoc.markup( self, text, escape ) - -class WidgetInterface: - def render(self, size, focus=False): - """ - size -- flow widgets: (maxcol,) box widgets: (maxcol,maxrow) - where maxcol and maxrow are the maximum screen columns - and rows for the canvas returned - focus -- True if this widget is in focus - - Returns a canvas object. - - MUST be implemented. - MUST NOT return a canvas with a cursor when focus=False. - """ - - def rows(self, (maxcol,), focus=False): - """ - maxcol -- maximum screen columns for rendered widget - focus -- True if this widget is in focus - - Returns an integer number or screen rows required. - - MUST be implemented by all flow widgets. - MUST match the number of rows in the canvas returned by - render function called with the same parameters. - """ - - def selectable(self): - """ - Returns True if this widget will accept keyboard input and - should take the focus when changing focus between widgets. - - MUST be implemented. - """ - - def keypress(self, size, key): - """ - size -- flow widgets: (maxcol,) box widgets: (maxcol,maxrow) - where maxcol and maxrow are the maximum screen columns - and rows for the widget when rendered - key -- key pressed - - Returns None if key was handled, returns key if not handled. - - MUST be implemented if selectable function returns True. - MUST NOT be called if selectable function returns False. - """ - - def get_cursor_coords(self, size): - """ - size -- flow widgets: (maxcol,) box widgets: (maxcol,maxrow) - where maxcol and maxrow are the maximum screen columns - and rows for the widget when rendered - - Returns (col,row) coordinates for cursor or None if no cursor. - - MUST be implemented if render function returns a canvas with - a cursor. - MUST match the cursor in the canvas returned by render function - when focus=True. - Caller MUST treat no implementation as equivalent to an - implementation that always returns None. - """ - - def get_pref_col(self, size): - """ - size -- flow widgets: (maxcol,) box widgets: (maxcol,maxrow) - where maxcol and maxrow are the maximum screen columns - and rows for the widget when rendered - - Returns the preferred screen column as an integer or None. - - Caller MUST treat no implementation as equivalent to an - implementation that always returns None. - """ - - def move_cursor_to_coords(self, size, col, row): - """ - size -- flow widgets: (maxcol,) box widgets: (maxcol,maxrow) - where maxcol and maxrow are the maximum screen columns - and rows for the widget when rendered - col -- desired screen column for cursor to appear, relative - to left edge of widget - row -- desired screen row for cursor to appear, relative to - top edge of widget - - Returns True on success, False on failure. - - MUST succeed if there is any column on passed row that the - cursor may be moved to. - Caller MUST treat no implementation as equivalent to an - implementation that always returns True. - """ - - def mouse_event(self, size, event, button, col, row, focus): - """ - size -- flow widgets: (maxcol,) box widgets: (maxcol,maxrow) - where maxcol and maxrow are the maximum screen columns - and rows for the widget when rendered - event -- event part of mouse event structure, eg. 'press', - 'release', 'drag', 'meta press' etc.. - button -- button number for event between 1 and 5, may be 0 - on button release events if button is unknown - col -- screen column of event, relative to left edge of widget - row -- screen row of event, relative to top edge of widget - focus -- True if this widget is in focus - - Returns True if event was handled, False otherwise. - - Caller MUST treat no implementation as equivalent to an - implementation that always returns False. - """ - -class ListWalkerInterface: - - def get_focus(self): - """ - Returns (widget, position). - - MUST be implemented. - Caller MUST NOT assume that position object may be stored and - reused after contents of list change. - """ - - def set_focus(self, position): - """ - position -- a position returned by get_focus, get_next or - get_prev - - Returns None. - - MUST be implemented. Should send "modified" signal (or call - self._modified if inheriting from ListWalker) - """ - - def get_next(self, position): - """ - position -- a position returned by get_focus or get_next - - Returns (widget below, position below). - - MUST be implemented. - Caller MUST NOT assume that position object may be stored and - reused after contents of list change. - """ - - def get_prev(self, position): - """ - position -- a position returned by get_focus or get_prev - - Returns (widget above, position above). - - MUST be implemented. - Caller MUST NOT assume that position object may be stored and - reused after contents of list change. - """ - - - -def main(): - html = UrwidHTMLDoc() - contents = [] - doc = [] - contents.append('<table width="100%"><tr><td width="33%" valign="top">') - - for obj, name, flag in [ - (None,"MainLoop & event loops", None), - (urwid.MainLoop, "MainLoop", None), - (urwid.SelectEventLoop, "SelectEventLoop", None), - (urwid.GLibEventLoop, "GLibEventLoop", None), - (urwid.TwistedEventLoop, "TwistedEventLoop", None), - (None, "Widget base class", None), - (urwid.Widget, "Widget",None), - (None,"Decorations", None), - (urwid.AttrMap, "AttrMap", "FB"), - (urwid.Padding, "Padding", "FB"), - (urwid.Filler, "Filler", "B"), - (urwid.Divider, "Divider", "F"), - (urwid.LineBox, "LineBox", "FB"), - (urwid.SolidFill, "SolidFill", "B"), - (None,"Container widgets", None), - (urwid.Frame, "Frame", "B"), - (urwid.ListBox, "ListBox", "B"), - (urwid.Columns, "Columns", "FB"), - (urwid.Pile, "Pile", "FB"), - (urwid.GridFlow, "GridFlow", "F"), - (urwid.BoxAdapter,"BoxAdapter", "F"), - (urwid.Overlay,"Overlay", "B"), - (None,"Content widgets", None), - (urwid.Text, "Text", "F"), - (urwid.Edit, "Edit", "F"), - (urwid.IntEdit, "IntEdit", "F"), - (urwid.Button, "Button", "F"), - (urwid.CheckBox, "CheckBox", "F"), - (urwid.RadioButton, "RadioButton", "F"), - - (None, None, None), - - (None, "Graphics",None), - (urwid.BarGraph, "BarGraph","B"), - (urwid.GraphVScale, "GraphVScale","B"), - (urwid.ProgressBar, "ProgressBar","F"), - (urwid.PopUpLauncher, "PopUpLauncher", None), - (urwid.PopUpTarget, "PopUpTarget", "B"), - (urwid.BigText, "BigText","X"), - (urwid.get_all_fonts, "get_all_fonts",None), - (None,"Build custom widgets",None), - (urwid.WidgetWrap, "WidgetWrap",None), - (urwid.WidgetDecoration, "WidgetDecoration", None), - (urwid.WidgetPlaceholder, "WidgetPlaceholder",None), - (None,"Abstract widgets & interfaces",None), - (WidgetInterface, "Widget interface definition",None), - (urwid.BoxWidget, "BoxWidget",None), - (urwid.FlowWidget, "FlowWidget",None), - (urwid.FixedWidget, "FixedWidget",None), - (None,"ListBox list walkers",None), - (ListWalkerInterface, "List Walker interface definition",None), - (urwid.ListWalker, "ListWalker", None), - (urwid.SimpleListWalker, "SimpleListWalker",None), - (urwid.PollingListWalker, "PollingListWalker",None), - (None,"Dynamic tree views", None), - (urwid.TreeWidget, "TreeWidget", None), - (urwid.TreeNode, "TreeNode", None), - (urwid.TreeNode, "ParentNode", None), - (urwid.TreeNode, "TreeWalker", None), - (urwid.TreeNode, "TreeListBox", None), - (None,"Experimental", None), - (urwid.Terminal, "Terminal", "B"), - (None, None, None), - - (None,"Canvas painting", None), - (urwid.Canvas, "Canvas", None), - (urwid.TextCanvas, "TextCanvas", None), - (urwid.CompositeCanvas, "CompositeCanvas", None), - (urwid.SolidCanvas, "BlankCanvas", None), - (urwid.SolidCanvas, "SolidCanvas", None), - (urwid.CanvasCombine, "CanvasCombine", None), - (urwid.CanvasJoin, "CanvasJoin", None), - (urwid.CanvasOverlay, "CanvasOverlay", None), - (None,"Raw screen attributes", None), - (urwid.AttrSpec, "AttrSpec", None), - (None,"Custom formatting rules", None), - (urwid.TextLayout,"TextLayout", None), - (urwid.StandardTextLayout,"StandardTextLayout", None), - (None,"Character encoding", None), - (urwid.set_encoding,"set_encoding", None), - (urwid.get_encoding_mode,"get_encoding_mode", None), - (urwid.supports_unicode,"supports_unicode", None), - (None,"Signals", None), - (urwid.connect_signal,"connect_signal", None), - (urwid.disconnect_signal,"disconnect_signal", None), - (urwid.register_signal,"register_signal", None), - (urwid.emit_signal,"emit_signal", None), - (None,"Display modules",None), - (urwid.raw_display.Screen, "raw_display.Screen",None), - (urwid.curses_display.Screen, "curses_display.Screen",None), - (urwid.web_display.Screen,"web_display.Screen",None), - (None,"Screen capture", None), - (urwid.html_fragment.screenshot_init, - "html_fragment.screenshot_init", None), - (urwid.html_fragment.screenshot_collect, - "html_fragment.screenshot_collect", None), - (urwid.html_fragment.HtmlGenerator, - "html_fragment.HtmlGenerator", None), - ]: - if name is None: - contents.append('</td><td width="33%" valign="top">') - elif obj is None: - contents.append('<div class="l1">%s</div>' % name) - doc.append('<h2>%s</h2>' % name ) - else: - lname = name - if type(obj) != types.ClassType: #dirty hack - doc.append('<a name="%s"></a><h3>function %s <span style="font-size:small; padding-left: 20px">[<a href="#top">back to top</a>]</span></h3>' % (name,name) ) - thtm = flagd[flag] - lname = lname.replace(" ","_") - contents.append('<div class="l2">' + - '<a href="#%s">%s</a> %s</div>' % - (lname,name,thtm) ) - doc.append( html.document( obj, name ) ) - - contents.append("</td></tr></table>") - - h = html_template - h = h.replace("%toc%", "".join(contents)) - h = h.replace("%contents%", "".join(doc)) - h = h.replace("%version%", urwid.__version__) - print h - -if __name__ == "__main__": - main() diff --git a/docs/build/docgen_tutorial.py b/docs/build/docgen_tutorial.py deleted file mode 100755 index bb8ac28..0000000 --- a/docs/build/docgen_tutorial.py +++ /dev/null @@ -1,706 +0,0 @@ -#!/usr/bin/python -# -# Urwid tutorial documentation generation program -# Copyright (C) 2004-2007 Ian Ward -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# Urwid web site: http://excess.org/urwid/ - -import sys -import re - -import urwid.html_fragment -import urwid -try: - import templayer -except ImportError: - templayer = None - -examples = {} - -interp_line = "#!/usr/bin/python\n\n" -cut_comment = "# CUT HERE" - -examples["min"] = ["example_min"] -def example_min(): - import urwid - - txt = urwid.Text(u"Hello World") - fill = urwid.Filler(txt, 'top') - loop = urwid.MainLoop(fill) - loop.run() - - -examples["input"] = ["example_input"] -def example_input(): - import urwid - - txt = urwid.Text(u"Hello World") - fill = urwid.Filler(txt, 'top') - - def show_or_exit(input): - if input in ('q', 'Q'): - raise urwid.ExitMainLoop() - txt.set_text(repr(input)) - - loop = urwid.MainLoop(fill, unhandled_input=show_or_exit) - loop.run() - - -examples["attr"] = ["example_attr"] -def example_attr(): - import urwid - - palette = [ - ('banner', 'black', 'light gray', 'standout,underline'), - ('streak', 'black', 'dark red', 'standout'), - ('bg', 'black', 'dark blue'),] - - txt = urwid.Text(('banner', u" Hello World "), align='center') - map1 = urwid.AttrMap(txt, 'streak') - fill = urwid.Filler(map1) - map2 = urwid.AttrMap(fill, 'bg') - - def exit_on_q(input): - if input in ('q', 'Q'): - raise urwid.ExitMainLoop() - - loop = urwid.MainLoop(map2, palette, unhandled_input=exit_on_q) - loop.run() - - -examples["highcolors"] = ["example_highcolors"] -def example_highcolors(): - import urwid - - palette = [ - ('banner', '', '', '', '#ffa', '#60d'), - ('streak', '', '', '', 'g50', '#60a'), - ('inside', '', '', '', 'g38', '#808'), - ('outside', '', '', '', 'g27', '#a06'), - ('bg', '', '', '', 'g7', '#d06'),] - - txt = urwid.Text(('banner', u" Hello World "), align='center') - map1 = urwid.AttrMap(txt, 'streak') - pile = urwid.Pile([ - urwid.AttrMap(urwid.Divider(), 'outside'), - urwid.AttrMap(urwid.Divider(), 'inside'), - map1, - urwid.AttrMap(urwid.Divider(), 'inside'), - urwid.AttrMap(urwid.Divider(), 'outside')]) - fill = urwid.Filler(pile) - map2 = urwid.AttrMap(fill, 'bg') - - def exit_on_q(input): - if input in ('q', 'Q'): - raise urwid.ExitMainLoop() - - loop = urwid.MainLoop(map2, palette, unhandled_input=exit_on_q) - loop.screen.set_terminal_properties(colors=256) - loop.run() - - -examples["edit"] = ["example_edit"] -def example_edit(): - import urwid - - ask = urwid.Edit(u"What is your name?\n") - fill = urwid.Filler( ask ) - - def do_reply(input): - if input != 'enter': - return - if fill.body == ask: - fill.body = urwid.Text(u"Nice to meet you,\n"+ - ask.edit_text+".") - return True - else: - raise urwid.ExitMainLoop() - - loop = urwid.MainLoop(fill, unhandled_input=do_reply) - loop.run() - - -examples["frlb"] = ["example_frlb"] -def example_frlb(): - import urwid - - palette = [('I say', 'default,bold', 'default', 'bold'),] - - ask = urwid.Edit(('I say', u"What is your name?\n")) - reply = urwid.Text(u"") - content = urwid.SimpleListWalker([ask, reply]) - listbox = urwid.ListBox(content) - - def on_ask_change(edit, new_edit_text): - assert edit is ask # we are passed our edit widget - reply.set_text(('I say', - u"Nice to meet you, " + new_edit_text)) - - urwid.connect_signal(ask, 'change', on_ask_change) - - def exit_on_cr(input): - if input == 'enter': - raise urwid.ExitMainLoop() - - loop = urwid.MainLoop(listbox, palette, unhandled_input=exit_on_cr) - loop.run() - - -examples["lbcont"]=["example_lbcont"] -def example_lbcont(): - import urwid - - palette = [('I say', 'default,bold', 'default', 'bold'),] - - def new_question(): - return urwid.Edit(('I say', u"What is your name?\n")) - - def new_answer(name): - return urwid.Text(('I say', u"Nice to meet you, "+name+"\n")) - - content = urwid.SimpleListWalker([new_question()]) - listbox = urwid.ListBox(content) - - def update_on_cr(input): - if input != 'enter': - return - focus_widget, position = listbox.get_focus() - if not hasattr(focus_widget, 'edit_text'): - return - if not focus_widget.edit_text: - raise urwid.ExitMainLoop() - content[position+1:position+2] = [ - new_answer(focus_widget.edit_text)] - if not content[position+2:position + 3]: - content.append(new_question()) - listbox.set_focus(position + 2) - return True - - loop = urwid.MainLoop(listbox, palette, unhandled_input=update_on_cr) - loop.run() - - -examples["lbscr"] = ["example_lbscr"] -def example_lbscr(): - import urwid - - palette = [('header', 'white', 'black'), - ('reveal focus', 'black', 'dark cyan', 'standout'),] - content = urwid.SimpleListWalker([ - urwid.AttrMap(w, None, 'reveal focus') for w in [ - urwid.Text(u"This is a text string that is fairly long"), - urwid.Divider(u"-"), - urwid.Text(u"Short one"), - urwid.Text(u"Another"), - urwid.Divider(u"-"), - urwid.Text(u"What could be after this?"), - urwid.Text(u"The end."),]]) - listbox = urwid.ListBox(content) - show_key = urwid.Text(u"", wrap='clip') - head = urwid.AttrMap(show_key, 'header') - top = urwid.Frame(listbox, head) - - def show_all_input(input, raw): - show_key.set_text(u"Pressed: " + u" ".join([ - unicode(i) for i in input])) - return input - - def exit_on_cr(input): - if input == 'enter': - raise urwid.ExitMainLoop() - - loop = urwid.MainLoop(top, palette, - input_filter=show_all_input, unhandled_input=exit_on_cr) - loop.run() - - -examples["wmod"] = ["example_wmod"] -def example_wmod(): - class QuestionnaireItem(urwid.WidgetWrap): - def __init__(self): - self.options = [] - unsure = urwid.RadioButton(self.options, u"Unsure") - yes = urwid.RadioButton(self.options, u"Yes") - no = urwid.RadioButton(self.options, u"No") - display_widget = urwid.GridFlow([unsure, yes, no], - 15, 3, 1, 'left') - urwid.WidgetWrap.__init__(self, display_widget) - - def get_state(self): - for o in self.options: - if o.get_state() is True: - return o.get_label() - - -examples["wanat"] = ["example_wanat","example_wanat_new","example_wanat_multi"] -def example_wanat(): - class Pudding(urwid.FlowWidget): - def selectable(self): - return False - def rows(self, size, focus=False): - return 1 - def render(self, size, focus=False): - (maxcol,) = size - num_pudding = maxcol / len("Pudding") - return urwid.TextCanvas(["Pudding"*num_pudding], - maxcol=maxcol) - - class BoxPudding(urwid.BoxWidget): - def selectable(self): - return False - def render(self, size, focus=False): - (maxcol, maxrow) = size - num_pudding = maxcol / len("Pudding") - return urwid.TextCanvas( - ["Pudding"*num_pudding] * maxrow, - maxcol=maxcol) - -def example_wanat_new(): - class NewPudding(urwid.FlowWidget): - def selectable(self): - return False - def rows(self, size, focus=False): - w = self.display_widget(size, focus) - return w.rows(size, focus) - def render(self, size, focus=False): - w = self.display_widget(size, focus) - return w.render(size, focus) - def display_widget(self, size, focus): - (maxcol,) = size - num_pudding = maxcol / len("Pudding") - return urwid.Text("Pudding"*num_pudding) - -def example_wanat_multi(): - class MultiPudding(urwid.Widget): - def selectable(self): - return False - def rows(self, size, focus=False): - return 1 - def render(self, size, focus=False): - if len(size) == 1: - (maxcol,) = size - maxrow = 1 - else: - (maxcol, maxrow) = size - num_pudding = maxcol / len("Pudding") - return urwid.TextCanvas( - ["Pudding"*num_pudding] * maxrow, - maxcol=maxcol) - -examples["wsel"] = ["example_wsel"] -def example_wsel(): - class SelectablePudding(urwid.FlowWidget): - def __init__(self): - self.pudding = "pudding" - def selectable(self): - return True - def rows(self, size, focus=False): - return 1 - def render(self, size, focus=False): - (maxcol,) = size - num_pudding = maxcol / len(self.pudding) - pudding = self.pudding - if focus: - pudding = pudding.upper() - return urwid.TextCanvas([pudding*num_pudding], - maxcol=maxcol) - def keypress(self, size, key): - (maxcol,) = size - if len(key)>1: - return key - if key.lower() in self.pudding: - # remove letter from pudding - n = self.pudding.index(key.lower()) - self.pudding = self.pudding[:n]+self.pudding[n+1:] - if not self.pudding: - self.pudding = "pudding" - else: - return key - -examples["wcur"] = ["example_wcur"] -def example_wcur(): - class CursorPudding(urwid.FlowWidget): - def __init__(self): - self.cursor_col = 0 - def selectable(self): - return True - def rows(self, size, focus=False): - return 1 - def render(self, size, focus=False): - (maxcol,) = size - num_pudding = maxcol / len("Pudding") - cursor = None - if focus: - cursor = self.get_cursor_coords(size) - return urwid.TextCanvas( - ["Pudding"*num_pudding], [], cursor, maxcol) - def get_cursor_coords(self, size): - (maxcol,) = size - col = min(self.cursor_col, maxcol-1) - return col, 0 - def keypress(self, size, key): - (maxcol,) = size - if key == 'left': - col = self.cursor_col -1 - elif key == 'right': - col = self.cursor_col +1 - else: - return key - self.cursor_x = max(0, min(maxcol-1, col)) - # CUT HERE - def get_pref_col(self, (maxcol,)): - return self.cursor_x - def move_cursor_to_coords(self, (maxcol,), col, row): - assert row == 0 - self.cursor_x = col - return True - -def read_sections(tmpl): - """Read section tags, section descriptions, and column breaks from - the Templayer template argument. Convert the section data into a - Python data structure called sections. Each sublist of sections - contains one column. Each column contains a list of (tag, desc.) - pairs. Return sections.""" - - sd = tmpl.layer("section_data") - col_break = "---" - sections = [[]] - for ln in sd.split("\n"): - if not ln: continue - if ln == col_break: - sections.append([]) - continue - tag, desc = ln.split(",",1) - sections[-1].append( (tag.rstrip(), desc.lstrip()) ) - return sections - -def read_example_code(): - """By the time this function runs, the examples dictionary contains - a list of function names, all starting with "example_". Create a - second dictionary called code_blocks. Open the file containing this - function. For each function name in examples, read the text of that - function into an entry in the code_blocks dictionary. Return the - code_blocks dictionary.""" - - # invert the "examples" dictionary - example_fns = {} - for tag, l in examples.items(): - for i, fn in zip(range(len(l)), l): - example_fns[fn] = tag, i - - # read our own source code - # strip trailing spaces and tabs from each line - code_blocks = {} - current_block = None - for ln in open( sys.argv[0], 'r').readlines(): - ln = ln.rstrip() - if ( ln[:4] == "def " and ln[-3:] == "():" and - example_fns.has_key( ln[4:-3] ) ): - current_block = ln[4:-3] - code_blocks[current_block] = [] - continue - if ln and not ln.startswith(" "): - current_block = None - continue - if current_block is None: - continue - if ln.startswith(" "): - ln = ln[4:] - code_blocks[current_block].append(ln+"\n") - - # recombine code lines into a single string each - for name, block in code_blocks.items(): - code_blocks[name] = "".join( block ) - - return code_blocks - -def filename(snum, inum, enum): - """Generate a filename to write an example to. Take the section - number from the table of contents, item number (subsection number), - and example number. Numbers start at 1. Return the filename.""" - - assert snum > 0, \ - '%d.%d #%d: Section number should be greater than 0' % \ - (snum, inum, enum) - assert inum > 0, \ - '%d.%d #%d: Item number should be greater than 0' % \ - (snum, inum, enum) - assert enum > 0, \ - '%d.%d #%d: Example number should be greater than 0' % \ - (snum, inum, enum) - assert enum < 28, \ - '%d.%d #%d: Example number should be less than 28' % \ - (snum, inum, enum) - - if enum == 1: estr = '' - else: estr = chr(ord('a') - 2 + enum) - - return "example" + str(snum) + "." + str(inum) + estr + ".py" - -def write_example_files(sections, blocks): - """The sections dictionary gives section tags in the order used by - the HTML output, and going through the tags in order allows us to - generate the same section numbers that the HTML uses. The global - examples dictionary maps each section tag to a list of examples used - in that section. And the blocks dictionary maps each example tag - to the text of that example. - - Generate section numbers and find the examples used in each section. - Assume each example is ready to run -- replace the "cut here" comments - with blank lines, but don't remove any code. Create a file named - according to the section number (and an optional letter to allow for - multiple examples per section). Write the cleaned-up example to the - file.""" - - cut_re = '^\s*' + re.escape(cut_comment) + '\s*$' - cut_re_comp = re.compile(cut_re, re.MULTILINE) - valid_re = 'import urwid' # some examples are not runnable - valid_re_comp = re.compile(valid_re) - snum = inum = enum = 0 - - for col in sections: - for tag, ignore in col: - if not tag: - # new section -- do its first item next time - snum += 1 - inum = 0 - continue - - # new item inside a section - inum += 1 - enum = 0 - for ename in examples.get(tag, []): - etext = blocks[ename] - if not valid_re_comp.search(etext): - continue - enum += 1 - fname = filename(snum, inum, enum) - f = open(fname, 'w') - etext = cut_re_comp.sub("", etext) - etext = interp_line + etext.rstrip() + "\n" - f.write(etext) - f.close() - -def cut_example_code(blocks): - """For brevity, the HTML gives excerpts from some of the examples. - Convert the examples from the full forms stored in this file to the - excerpted forms. Use "cut here" comments in the examples, and the - rules below, to do the conversion. Also check that the full forms - of certain examples contain identical code. Also strip trailing - spaces and tabs from the code. Return a dictionary with the - converted examples.""" - - ## do the conversions and the checks - blocks["example_wcur"], blocks["example_wcur2"] = ( - blocks["example_wcur"].split(cut_comment+"\n") ) - examples["wcur"].append("example_wcur2") - - # strip trailing spaces, tabs, blank lines from each block - # removes spaces/tabs left by splitting at cut_comment - for name, block in blocks.items(): - blocks[name] = block.rstrip() - - return blocks - -def generate_example_results(): - """Create HTML "screen shots" from the example programs defined in - this file. Store the results in a dictionary (mapping example tag - to results) and return the dictionary.""" - - results = {} - - init = urwid.html_fragment.screenshot_init - collect = urwid.html_fragment.screenshot_collect - - init([(21,7)],[[" "]]) - example_min() - results["min"] = collect()[:1] - - init([(12,3)],[["enter"], ["N"], ["O"], ["P"], ["Q"]]) - example_input() - results["input"] = collect()[:5] - - init([(21,7),(10,9),(30,3),(15,2)],[["window resize"]]*3+[["q"]]) - example_attr() - results["attr"] = collect()[:4] - - init([(26,9)],[["q"]]) - example_highcolors() - results["highcolors"] = collect()[:1] - - init([(21,7)],[list("Arthur, King of the Britons"),["enter"],[" "]]) - example_edit() - results["edit"] = collect()[:3] - - init([(21,7)],[list("Tim t"),list("he Ench"),list("anter"),["enter"]]) - example_frlb() - results["frlb"] = collect()[:4] - - init([(23,13)],[list("Abe")+["enter"]+list("Bob"),["enter"]+ - list("Carl")+["enter"], list("Dave")+["enter"], ["enter"]]) - example_lbcont() - results["lbcont"] = collect()[1:4] - - init([(15,7), (20,9), (25,7), (11,13)], - [["down"],["down"],["down"],["up"],["up"]] + - [["window resize"]]*3 + [["enter"]]) - example_lbscr() - results["lbscr"] = collect()[:9] - - return results - -def generate_body(tmpl, sections, blocks, results): - """Assemble most of the HTML output (the body) from the pieces - of text contained in all the arguments. The body contains a table - of contents followed by section headers and section text. Pieces of - section text may contain example code, and pieces of code may be - followed by a "screen shot" of themselves. - - The sections dictionary gives the column formatting for the - table of contents in the HTML and the description shared by the TOC - entry and the section header. With the addition of section numbers - (generated now) sections contains the information needed to write - the finished table of contents. We expect the template to use - two slots, toc_left and toc_right, which we fill with the TOC. - We also expect the template to define two pieces of HTML, - toc_section and toc_item, which give the formatting for all items - in the TOC. - - While handling each entry in the TOC, we use the tag stored in - sections to assemble the corresponding part of the body. We expect - the template to define two pieces of HTML, section_head and - section_body, which give the formatting for all parts of the body - (colored boxes for section headers, and the formatting that applies - to all pieces of section text). The template also defines one slot - for each individual piece of section text, distinguished from the - others by the section tag. - - Each individual body slot may use more slots to hold the examples - and results included in a piece of section text. These slots are - numbered. We use the section tags to look in the examples and - results dictionaries; the dictionary order must match the numerical - order used in the template. We do not use example tags as defined - in the global examples dictionary. The blocks and results arguments - describe which slots are defined; we hope the HTML text will use - all the slots we have defined.""" - - # put TOC columns into the variables used by the template - # assign section numbers - # generate HTML form of TOC entries, corresponding document parts - assert len(sections) == 2, 'sections has %d columns but should have 2!' % len(sections) - - toc_slots = {'toc_left':[], 'toc_right':[]} - body = [] - - snum = inum = 0 - for slot, l in zip(['toc_left','toc_right'], sections): - for tag, name in l: - if not tag: - # new section -- do its first item next time - snum += 1 - inum = 0 - t = tmpl.format('toc_section', snum=repr(snum), - name=name ) - toc_slots[slot].append( t ) - b = tmpl.format('section_head', snum=repr(snum), - name=name ) - body.append( b ) - continue - - # new item inside a section - inum += 1 - t = tmpl.format('toc_item', snum=repr(snum), - inum=repr(inum), name=name, tag=tag) - toc_slots[slot].append( t ) - - slots = {} - i = 0 - for fn in examples.get(tag, []): - slots['example[%d]'%i] = blocks[fn] - i += 1 - i = 0 - for res in results.get(tag, []): - slots['result[%d]'%i] = templayer.RawHTML(res) - i += 1 - b = tmpl.format('body[%s]'%tag, ** slots ) - b = tmpl.format('section_body', snum=repr(snum), - inum=repr(inum), name=name, tag=tag, - content = b) - body.append( b ) - - return (body, toc_slots) - -def parse_options(): - usage = "%s [-h|-?|--help]\n%s [-H|--HTML|--html] [-s|--scripts]" % \ - (sys.argv[0], sys.argv[0]) - help = """%s options: - --h, -?, --help Print this message to standard error and exit. - --H, --HTML, --html Write the HTML documentation to standard output. --s, --scripts Write runnable scripts to files.""" % sys.argv[0] - do_html = False - do_scripts = False - - if len(sys.argv) < 2 or len(sys.argv) > 3: - sys.exit(usage) - - if len(sys.argv) == 2 and (sys.argv[1] in ('-h', '-?', '--help')): - sys.exit(help) - - for arg in sys.argv[1:]: - if arg in ('-H', '--HTML', '--html'): - if do_html: sys.exit(usage) - else: do_html = True - elif arg in ('-s', '--scripts'): - if do_scripts: sys.exit(usage) - else: do_scripts = True - else: - sys.exit(usage) - - return (do_html, do_scripts) - -def main(): - (do_html, do_scripts) = parse_options() - - if templayer is None: - sys.stderr.write( -"""Error importing templayer. Please download and install the Templayer -python module available at: -http://excess.org/templayer/ -""") - sys.exit( 1 ) - - tmpl = templayer.HtmlTemplate( "tmpl_tutorial.html" ) - sections = read_sections( tmpl ) - code_blocks = read_example_code() - - if do_scripts: - write_example_files( sections, code_blocks ) - - if do_html: - code_blocks = cut_example_code( code_blocks ) - results = generate_example_results() - out_file = tmpl.start_file() - (body, toc_slots) = generate_body( tmpl, sections, - code_blocks, results ) - bottom = out_file.open(version=urwid.__version__, ** toc_slots) - bottom.write( body ) - out_file.close() - -if __name__=="__main__": - main() diff --git a/docs/build/tmpl_tutorial.html b/docs/build/tmpl_tutorial.html deleted file mode 100644 index 245f6a3..0000000 --- a/docs/build/tmpl_tutorial.html +++ /dev/null @@ -1,743 +0,0 @@ -<html> -<head> -<title>Urwid %version% Tutorial</title> -<style type="text/css"> - h1 { text-align: center; } - h2 { margin: 40px 0 0 0; padding: 10px; background: #6d96e8;} - h3 { margin: 0 0 3px 0; padding: 12px 6px 6px 6px; background: #efef96;} - .code { background: #dddddd; padding: 5px; margin: 7px 20px; } - .l1 { margin: 12px 0 0 0; } - .l2 { margin-left: 20px; } - .shot { padding: 5px 20px 5px 0px; float: left; } - .back { font-size:small; padding-left: 20px; } -</style> -<body> -<a name="top"></a> -<h1>Urwid %version% Tutorial</h1> - -<div style="text-align: center;"> -<a href="http://excess.org/urwid/">Urwid Home Page</a> / -<a href="http://excess.org/urwid/examples.html">Example Screenshots</a> / -<a href="http://excess.org/urwid/utf8examples.html">UTF-8 Screenshots</a> / -Tutorial / -<a href="reference.html">Reference</a> -</div> -<br> - -<table width="100%"><tr><td width="50%" valign="top"> -%toc_left% -</td><td width="50%" valign="top"> -%toc_right% -</td></tr></table> - -<p> -The programs in this tutorial are available in your Urwid distribution. -Run the command "./docgen_tutorial.py -s" to output the example scripts. -</p> - -{contents} - - -<div style="background:#ffff33; padding: 5px"> -<h1>Urwid Tutorial Template File</h1> -This file is used by <b>docgen_tutorial.py</b> to generate the tutorial -documentation <b>tutorial.html</b>. -<p> -</div> -<div style="background:#ffffaa;"> -<p> -Items in the list that follows are parsed by docgen_tutorial.py. -Each item has a tag and a name, separated by a comma. Whitespace -on either side of the comma is stripped. -</p><p> -Items without tags are new sections. -</p><p> -A --- separates the left and right columns in the table of contents. -</p> - -<pre> -<b>Tag, Section or Item Name</b> -{section_data} -, Hello World Example -min, Minimal Urwid Application -input, Handling Input -attr, AttrMap Widgets and Text Attributes -highcolors, High Color Modes -, Conversation Example -edit, Edit Widgets -frlb, Events and ListBox Widgets -lbcont, Modifying ListBox Content -, Zen of ListBox -lbscr, ListBox Focus and Scrolling -lbdyn, Dynamic ListBox with List Walker -lbfocus, Setting the Focus ---- -, Combining Widgets -pile, Piling Widgets -cols, Dividing into Columns -grid, GridFlow Arrangement -overlay, Overlay Widgets -, Creating Custom Widgets -wmod, Modifying Existing Widgets -wanat, Anatomy of a Widget -wsel, Creating Selectable Widgets -wcur, Widgets Displaying the Cursor -{/section_data} -</pre> -</div> - - - <p> -{toc_section} -<div class="l1">%snum%. %name%</div> -{/toc_section} -<p> -{toc_item} -<div class="l2"><a href="#%tag%">%snum%.%inum%. %name%</a></div> -{/toc_item} -<p> -{section_head} -<h2>%snum%. %name%</h2> -{/section_head} -<p> -{section_body} -<h3><a name="%tag%">%snum%.%inum%. %name%</a> -<span class="back">[<a href="#top">back to top</a>]</span></h3> -%content% -<br clear="left"> -<br> -{/section_body} - -<br clear="left"><hr> - - - -{body[min]} -This program displays the string "Hello World" in the top left corner -of the screen and will run until interrupted with CTRL+C (^C). - -<pre class="code">%example[0]%</pre> - -<ul> -<li>The <a href="reference.html#Text">Text</a> -widget handles formatting blocks of text, wrapping to the next line when -necessary. Widgets like this are called "flow widgets" because their -sizing can have a number of columns given, in this case the full screen -width, then they will flow to fill as many rows as necessary. -<li>The <a href="reference.html#Filler">Filler</a> is widget fills in blank -lines above or below flow widgets so that they can be displayed in a fixed -number of rows. This Filler will align our Text to the top of the screen, -filling all the rows below with blank lines. Widgets which are given both -the number of columns and number of rows they must be displayed in are called -"box widgets". The "topmost" widget displayed on the screen must be -a box widget. -<li>The <a href="reference.html#MainLoop">MainLoop</a> class handles displaying -our widgets as well as input from the user. In this case our widgets can't -handle the input so we need to interrupt the program to exit with ^C.</ul> - -<div align="center">%result[0]%</div> -{/body[min]} - -<br clear="left"><hr> - -{body[input]} -This program initially displays the string "Hello World", then it displays -each key pressed, exiting when the user presses Q. - -<pre class="code">%example[0]%</pre> - -<ul> -<li>The MainLoop class has an optional function parameter unhandled_input -This function will be called once for each keypress that is not handled -by the widgets being displayed. -<li>None of the widgets being displayed here handle input, so every key -the user presses will be passed to the show_or_exit function. -<li>The ExitMainLoop exception is used to -exit cleanly from the MainLoop.run() function when the user presses Q. All -other input is displayed by replacing the current Text widget's content. -</ul> - -<div class="shot">%result[0]%</div> -<div class="shot">%result[1]%</div> -<div class="shot">%result[2]%</div> -<div class="shot">%result[3]%</div> -<div class="shot">%result[4]%</div> -{/body[input]} - -<br clear="left"><hr> - -{body[attr]} -This program displays the string "Hello World" in the center of the screen. -It uses different attributes for the text, the space on either side -of the text and the space above and below the text. It waits for -a keypress before exiting. - -<pre class="code">%example[0]%</pre> - -<ul> -<li>Attributes are defined as part of a palette. Valid foreground, -background and setting values are documented in the -<a href="reference.html#AttrSpec">AttrSpec class</a>. -A palette is a list of tuples containing: - <ol> - <li>Name of the attribute, typically a string - <li>Foreground color and settings for 16-color (normal) mode - <li>Background color for normal mode - <li>Settings for monochrome mode (optional) - <li>Foreground color and settings for 88 and 256-color modes (optional, see next example) - <li>Background color for 88 and 256-color modes (optional) - </ol> -<li>The palette is passed to MainLoop to make it available to our program -<li>A <a href="reference.html#Text">Text</a> widget is created containing -the string " Hello World " with attribute "banner". The attributes of text -in a Text widget is set by using a (attribute, text) tuple instead of a -simple text string. Text attributes will flow with the text, and -multiple attributes may be specified by combining tuples into a -list. -<li>An <a href="reference.html#AttrMap">AttrMap</a> widget is created to -wrap the text widget with attribute "streak". AttrMap widgets allow you -to map any attribute to any other attribute, but by default they will -set the attribute of everything that does not already have an -attribute. In this case the text has an attribute, so only -the areas around the text used for alignment will be have the new attribute. -<li>A second AttrMap widget is created to -wrap the filler widget with attribute "bg". -</ul> - -When this program is run you can now clearly -see the separation of the text, the alignment around the text, and -the filler above and below the text. This is how these widgets -react to being resized: - -<div class="shot">%result[0]%</div> -<div class="shot">%result[1]%</div> -<div class="shot">%result[2]%</div> -<div class="shot">%result[3]%</div> -{/body[attr]} - -<br clear="left"><hr> - -{body[highcolors]} -This program displays the string "Hello World" in the center of the screen. -It uses a number of 256-color-mode background attributes to decorate the -text, and will work in any terminal that supports 256-color mode. -It will exit when Q is pressed. - -<pre class="code">%example[0]%</pre> - -<ul> -<li>This palette only defines values for the high color foreground -and backgrounds, because only the high colors will be used. -A real application should define values for all the modes in their -palette. Valid foreground, -background and setting values are documented in the -<a href="reference.html#AttrSpec">AttrSpec class</a>. -<li><a href="reference.html#Divider">Divider</a> widgets are used to -create blank lines, colored with AttrMap. -<li>A <a href="reference.html#Pile">Pile</a> widget arranges the -Divider widgets above and below our text. -<li>Behind the scenes our MainLoop class has created a -raw_display.Screen object for drawing the screen. -The program is put into 256-color mode by using the screen -object's -<a href="reference.html#Screen-set_terminal_properties" ->set_terminal_properties</a> method. This method works only when -using the default raw_display Screen class in our MainLoop. -</ul> - -<div align="center">%result[0]%</div> -{/body[highcolors]} - -<br clear="left"><hr> - -{body[edit]} -This program asks for your name then responds "Nice to meet you, (your name)." - -<pre class="code">%example[0]%</pre> - -<ul> -<li>An <a href="reference.html#Edit">Edit</a> widget is created with the -caption "What is your name?". A newline at the end of the caption makes -the user input start on the next row. -<li>Most keystrokes will be handled by the Edit widget, allowing -the user to enter their name. -<li>The unhandled_input function will replace the Edit widget inside -the Filler widget with a reply when the user presses ENTER. -<li>When the user presses ENTER again the unhandled_input function -will cause the program to exit. -</ul> - -The Edit widget has many capabilities. It lets you make corrections and move -the cursor around with the HOME, END and arrow keys. It is based on the Text -widget so it supports the same wrapping and alignment modes. - -<div class="shot">%result[0]%</div> -<div class="shot">%result[1]%</div> -<div class="shot">%result[2]%</div> -{/body[edit]} - -<br clear="left"><hr> - -{body[frlb]} -This program asks for your name and responds "Nice to meet you, (your name)" -<i>while</i> you type your name. ENTER exits. - -<pre class="code">%example[0]%</pre> - -<ul> -<li>An Edit widget and Text reply widget are created, like in the -previous example. -<li>A <a href="reference.html#SimpleListWalker">SimpleListWalker</a> -is then created to manage the contents and focus of our ListBox. -The SimpleListWalker behaves just like a list of widgets, and can -be modified like a regular list. -<li>A <a href="reference.html#ListBox">ListBox</a> is created -and passed the SimpleListWalker. The ListBox is a box widget and -allows scrolling through its contents. This example is simple enough -that we could have used a Pile widget and Filler widget instead, but -we will see how the ListBox can be useful in later examples. -<li>The <a href="reference.html#connect_signal">connect_signal</a> -function is used to attach our on_ask_change function to our Edit -widget's "change" event. Now any time the content of the Edit -widget changes on_ask_change will be called and passed the new -content. -<li>Now on_ask_change updates the reply text as the user enters their -name. -</ul> - -<div class="shot">%result[0]%</div> -<div class="shot">%result[1]%</div> -<div class="shot">%result[2]%</div> -<div class="shot">%result[3]%</div> -{/body[frlb]} - -<br clear="left"><hr> - -{body[lbcont]} -This program asks for your name and responds "Nice to meet you, (your name)." -It then asks again, and again. Old values may be changed and the responses -will be updated when you press ENTER. ENTER on a blank line exits. -<br><br> -<pre class="code">%example[0]%</pre> - -<ul> -<li>When the user presses ENTER: - <ul> - <li>The widget in focus and its current position is retrieved by calling the - <a href="reference.html#ListBox-get_focus">get_focus</a> function. - <li>If the widget in focus does not have an edit_text attribute, then it - is not one of the Edit widgets we are interested in. - One of the Text widgets might receive focus - if it covers the entire visible area of the ListBox widget and there is - no Edit widget to take focus. While this is unlikely, it should be handled - or the program will fail when trying to access it. - <li>If there is no edit text we exit the program. - <li>The widget after the widget in focus (if any exists) is replaced - with a response. - <li>If there is no widget after that widget, a new Edit widget is - created. - <li>The focus is then moved to the next Edit widget by calling - <a href="reference.html#ListBox-set_focus">set_focus</a>. - </ul> -<li>All other keys are passed to the top widget to handle. The ListBox widget -does most of the hard work: - <ul> - <li>UP and DOWN will change the focus and/or scroll the widgets in the list - box. - <li>PAGE UP and PAGE DOWN will try to move the focus one screen up or down. - <li>The cursor's column is maintained as best as possible when moving - from one Edit widget to another. - </ul> -</ul> - -<div class="shot">%result[0]%</div> -<div class="shot">%result[1]%</div> -<div class="shot">%result[2]%</div> -{/body[lbcont]} - -<br clear="left"><hr> - -{body[lbscr]} -The -<a href="reference.html#ListBox">ListBox</a> -is a box widget that contains flow widgets. Its contents -are displayed stacked vertically, and the ListBox allows the user to scroll -through its content. One of the flow widgets displayed -in the ListBox is the focus widget. The ListBox passes key presses to the -focus widget to allow the user to interact with it. If the -focus widget does not handle a keypress then the ListBox may handle the -keypress by scrolling and/or selecting another widget to become the focus -widget. -<br><br> -The ListBox tries to do the most sensible thing when scrolling and -changing focus. When the widgets displayed are all Text widgets or -other unselectable widgets then the ListBox will behave like a web browser -does when the user presses UP, DOWN, PAGE UP and PAGE DOWN: new text is -immediately scrolled in from the top or bottom. The ListBox chooses one of the -visible widgets as its focus widget when scrolling. When scrolling up the -ListBox chooses the topmost widget as the focus, and when scrolling down -the ListBox chooses the bottommost widget as the focus. -<br><br> -When all the widgets displayed are not selectable the user would typically -have no way to tell which widget is in focus, but if we wrap the widgets with -AttrWrap we can see what is happening while the focus changes: - -<pre class="code">%example[0]%</pre> -<div class="shot">%result[0]%</div> -<div class="shot">%result[1]%</div> -<div class="shot">%result[2]%</div> -<div class="shot">%result[3]%</div> -<div class="shot">%result[4]%</div> -<div class="shot">%result[5]%</div> -<br clear="left"> - -The ListBox remembers the location of the widget in focus as either an -"offset" or an "inset". An offset is the number of rows between the top -of the ListBox and the beginning of the focus widget. An offset of zero -corresponds to a widget with its top aligned with the top of the ListBox. -An inset is the fraction of rows of the focus widget -that are "above" the top of the ListBox and not visible. -The ListBox uses this method of remembering the focus widget location -so that when the ListBox is resized the text displayed will stay -roughly aligned with the top of the ListBox. -<br><br> -<div class="shot">%result[6]%</div> -<div class="shot">%result[7]%</div> -<div class="shot">%result[8]%</div> -<br clear="left"> -<br><br> -When there are selectable widgets in the ListBox the focus will move -between the selectable widgets, skipping the unselectable widgets. -The ListBox will try to scroll all the rows of a selectable widget into -view so that the user can see the new focus widget in its entirety. -This behavior can be used to bring more than a single widget into view -by using composite widgets to combine a selectable widget with other -widgets that should be displayed at the same time. -{/body[lbscr]} - -<br clear="left"><hr> - -{body[lbdyn]} -While the ListBox stores the location of its focus widget, it -does not directly store the actual focus widget or other contents of the -ListBox. The storage of a ListBox's content is delegated to a "List Walker" -object. If a list of widgets is passed to the ListBox constructor then it -creates a -<a href="reference.html#SimpleListWalker">SimpleListWalker</a> -object to manage the list. -<br><br> -When the ListBox is -<a href="reference.html#ListBox-render">rendering a canvas</a> or -<a href="reference.html#ListBox-keypress">handling input</a> it will: -<ol> -<li>Call the -<a href="reference.html#List_Walker_interface_definition-get_focus">get_focus</a> -method of its list walker object. -This method will return the focus widget and a position object. -<li>Optionally call the -<a href="reference.html#List_Walker_interface_definition-get_prev">get_prev</a> -method of its List Walker object -one or more times, initially passing -the focus position and then passing the new position returned on each -successive call. This method will return the widget and position object -"above" the position passed. -<li>Optionally call the -<a href="reference.html#List_Walker_interface_definition-get_next">get_next</a> -method of its List Walker object -one or more times, similarly, to collect widgets and position objects -"below" the focus position. -<li>Optionally call the -<a href="reference.html#List_Walker_interface_definition-set_focus">set_focus</a> -method passing one of the position -objects returned in the previous steps. -</ol> -This is the only way the ListBox accesses its contents, and it will not -store copies of any of the widgets or position objects beyond the current -rendering or input handling operation. -<br><br> -The SimpleListWalker stores a list of widgets, and uses integer indexes into -this list as its position objects. It stores the focus -position as an integer, so if you insert a widget into the list above the -focus position then you need to remember to increment the focus position in -the SimpleListWalker object or the contents of the ListBox will shift. -<br><br> -A custom List Walker object may be passed to the ListBox constructor instead -of a plain list of widgets. List Walker objects must implement the -<a href="reference.html#List_Walker_interface_definition">List Walker interface</a>. -<br><br> -The -<a href="http://excess.org/urwid/browser/examples/fib.py">fib.py</a> -example program demonstrates a custom list walker that doesn't -store any widgets. It uses a tuple of two successive Fibonacci numbers -as its position objects and it generates Text widgets to display the numbers -on the fly. -The result is a ListBox that can scroll through an unending list of widgets. -<br><br> -The -<a href="http://excess.org/urwid/browser/examples/edit.py">edit.py</a> -example program demonstrates a custom list walker that -loads lines from a text file only as the user scrolls them into view. -This allows even huge files to be opened almost instantly. -<br><br> -The -<a href="http://excess.org/urwid/browser/examples/browse.py">browse.py</a> -example program demonstrates a custom list walker that -uses a tuple of strings as position objects, one for the parent directory -and one for the file selected. The widgets are cached in a separate class -that is accessed using a dictionary indexed by parent directory names. -This allows the directories to be read only as required. The custom list -walker also allows directories to be hidden from view when they are -"collapsed". -{/body[lbdyn]} - -<br clear="left"><hr> - -{body[lbfocus]} -The easiest way to change the current ListBox focus is to call the -<a href="reference.html#ListBox-set_focus">set_focus</a> method. -This method doesn't require that you know the ListBox's -current dimensions (maxcol, maxrow). It will wait until the next call to -either keypress or render to complete setting the offset and inset values -using the dimensions passed to that method. -<br><br> -The position object passed to set_focus must be compatible with the List -Walker object that the ListBox is using. For SimpleListWalker the position -is the integer index of the widget within the list. -<br><br> -The coming_from parameter should be set if you know that the old position -is "above" or "below" the previous position. When the ListBox completes -setting the offset and inset values it tries to find the old widget among -the visible widgets. If the old widget is still visible, if will try to -avoid causing the ListBox contents to scroll up or down from its previous -position. If the widget is not visible, then the ListBox will: -<ul> -<li>Display the new focus at the bottom of the ListBox if coming_from is -"above". -<li>Display the new focus at the top of the ListBox if coming_from is "below". -<li>Display the new focus in the middle of the ListBox if coming_from is None. -</ul> -If you know exactly where you want to display the new focus widget within -the ListBox you may call -<a href="reference.html#ListBox-set_focus_valign">set_focus_valign</a>. -This method lets you specify the -"top", "bottom", "middle", a relative position or the exact number of rows -from the top or bottom of the ListBox. -{/body[lbfocus]} - -<br clear="left"><hr> - -{body[pile]} -<a href="reference.html#Pile">Pile</a> - widgets are used to combine multiple widgets by stacking them -vertically. A Pile can manage selectable widgets by keeping track of which -widget is in focus and it can handle moving the focus between widgets when -the user presses the UP and DOWN keys. A Pile will also work well when used -within a ListBox. -<br><br> -A Pile is selectable only if its focus widget is selectable. If you create -a Pile containing one Text widget and one Edit widget the Pile will -choose the Edit widget as its default focus widget. -To change the pile's focus widget you can call -<a href="reference.html#Pile-set_focus">set_focus</a>. -{/body[pile]} - -<br clear="left"><hr> - -{body[cols]} -<a href="reference.html#Columns">Columns</a> -widgets may be used to arrange either flow widgets or box widgets -horizontally into columns. Columns widgets will manage selectable widgets -by keeping track of which column is in focus and it can handle moving the -focus between columns when the user presses the LEFT and RIGHT keys. -Columns widgets also work well when used within a ListBox. -<br><br> -Columns widgets are selectable only if the column in focus is selectable. -If a focus column is not specified the first selectable widget will be -chosen as the focus column. The -<a href="reference.html#Columns-set_focus">set_focus</a> -method may be used to select the focus column. -{/body[cols]} - -<br clear="left"><hr> - -{body[grid]} -The -<a href="reference.html#GridFlow">GridFlow</a> -widget is a flow widget designed for use with -<a href="reference.html#Button">Button</a>, -<a href="reference.html#CheckBox">CheckBox</a> and -<a href="reference.html#RadioButton">RadioButton</a> widgets. -It renders all the widgets it contains the same width and it arranges them -from left to right and top to bottom. -<br><br> -The GridFlow widget uses Pile, Columns, Padding and Divider widgets to build -a display widget that will handle the keyboard input and rendering. When the -GridFlow widget is resized it regenerates the display widget to accommodate -the new space. -{/body[grid]} - -<br clear="left"><hr> - -{body[overlay]} -The <a href="reference.html#Overlay">Overlay</a> widget is a box widget that -contains two other box widgets. The bottom widget is rendered the full size -of the Overlay widget and the top widget is placed on top, obscuring an area -of the bottom widget. This widget can be used to create effects such as -overlapping "windows" or pop-up menus. -<br><br> -The Overlay widget always treats the top widget as the one in focus. All -keyboard input will be passed to the top widget. -<br><br> -If you want to use a flow -flow widget for the top widget, first wrap the flow widget with a -<a href="reference.html#Filler">Filler</a> widget. -{/body[overlay]} - -<br clear="left"><hr> - -{body[wmod]} -The easiest way to create a custom widget is to modify an existing widget. -This can be done by either subclassing the original widget or by wrapping it. -Subclassing is appropriate when you need to interact at a very low level -with the original widget, such as if you are creating a custom edit widget -with different behavior than the usual Edit widgets. If you are creating -a custom widget that doesn't need tight coupling with the original widget, -such as a widget that displays customer address information, then wrapping -is more appropriate. -<br><br> -The <a href="reference.html#WidgetWrap">WidgetWrap</a> class simplifies -wrapping existing widgets. You can create a custom widget simply by -creating a subclass of WidgetWrap and passing a widget into WidgetWrap's -constructor. -<br><br> -This is an example of a custom widget that uses WidgetWrap: - -<pre class="code">%example[0]%</pre> - -The above code creates a group of RadioButtons and provides a method to -query the state of the buttons. -<br><br> -Wrapped widgets may also override the standard widget methods. These methods -are described in following sections. -{/body[wmod]} - -<br clear="left"><hr> - -{body[wanat]} -Any object that follows the -<a href="reference.html#Widget_interface_definition">Widget interface definition</a> -may be used as a widget. Box widgets must implement -<a href="reference.html#Widget_interface_definition-selectable">selectable</a> -and -<a href="reference.html#Widget_interface_definition-render">render</a> -methods, and flow widgets must implement selectable, render and -<a href="reference.html#Widget_interface_definition-rows">rows</a> -methods. - -<pre class="code">%example[0]%</pre> - -The above code implements two widget classes. Pudding is a flow widget and -BoxPudding is a box widget. Pudding will render as much "Pudding" as will -fit in a single row, and BoxPudding will render as much "Pudding" as will -fit into the entire area given. -<br><br> -It is not strictly necessary to inherit from -<a href="reference.html#FlowWidget">BoxWidget</a> or -<a href="reference.html#FlowWidget">FlowWidget</a>, but doing so does add -some documentation to your code. -<br><br> -Note that the rows and render methods' focus parameter must have a default -value of False. Also note that for flow widgets the number of rows returned -by the rows method must match the number of rows rendered by the render -method. -<br><br> -In most cases it is easier to let other widgets handle the rendering and -row calculations for you: - -<pre class="code">%example[1]%</pre> - -The NewPudding class behaves the same way as the Pudding class above, but in -NewPudding you can change the way the widget appears by modifying only the -display_widget method, whereas in the Pudding class you may have to modify both -the render and rows methods. -<br><br> -To improve the efficiency of your Urwid application you should be careful -of how long your rows methods take to execute. The rows methods may be called -many times as part of input handling and rendering operations. If you are -using a display widget that is time consuming to create you should consider -caching it to reduce its impact on performance. -<br><br> -It is possible to create a widget that will behave as either a flow widget -or box widget depending on what is required: - -<pre class="code">%example[2]%</pre> - -MultiPudding will work in place of either Pudding or BoxPudding above. The -number of elements in the size tuple determines whether the containing widget -is expecting a flow widget or a box widget. -{/body[wanat]} - -<br clear="left"><hr> - -{body[wsel]} -Selectable widgets such as Edit and Button widgets allow the user to -interact with the application. A widget is selectable if its selectable -method returns True. Selectable widgets must implement the -<a href="reference.html#Widget_interface_definition-keypress">keypress</a> -method to handle keyboard input. - -<pre class="code">%example[0]%</pre> - -The SelectablePudding widget will display its contents in uppercase when it -is in focus, and it allows the user to "eat" the pudding by pressing each of -the letters P, U, D, D, I, N and G on the keyboard. When the user has "eaten" -all the pudding the widget will reset to its initial state. -<br><br> -Note that keys that are unhandled in the keypress method are returned so that -another widget may be able to handle them. This is a good convention to follow -unless you have a very good reason not to. In this case the UP and DOWN keys -are returned so that if this widget is in a ListBox the ListBox will behave as -the user expects and change the focus or scroll the ListBox. -{/body[wsel]} - -<br clear="left"><hr> - -{body[wcur]} -Widgets that display the cursor must implement the -<a href="reference.html#Widget_interface_definition-get_cursor_coords">get_cursor_coords</a> -method. Similar to the rows method for flow widgets, this method lets other -widgets make layout decisions without rendering the entire widget. The -ListBox widget in particular uses get_cursor_coords to make sure that the -cursor is visible within its focus widget. - -<pre class="code">%example[0]%</pre> - -CursorPudding will let the user move the cursor through the widget by -pressing LEFT and RIGHT. The cursor must only be added to the canvas when -the widget is in focus. The get_cursor_coords method must always return -the same cursor coordinates that render does. - -<br><br>A widget displaying a cursor may choose to implement -<a href="reference.html#Widget_interface_definition-get_pref_col">get_pref_col</a>. -This method returns the preferred column for the cursor, and is called when -the focus is moving up or down off this widget. -<br><br> -Another optional method is -<a href="reference.html#Widget_interface_definition-move_cursor_to_coords">move_cursor_to_coords</a>. -This method allows other widgets to try to position the cursor within this -widget. The ListBox widget uses move_cursor_to_coords when changing focus and -when the user pressed PAGE UP or PAGE DOWN. This method must return True on -success and False on failure. If the cursor may be placed at any position -within the row specified (not only at the exact column specified) then this -method must move the cursor to that position and return True. - - -<pre class="code">%example[1]%</pre> -{/body[wcur]} - -<br clear="left"><hr> - -{/contents} - -</body> -</html> diff --git a/docs/build/urwid b/docs/build/urwid deleted file mode 120000 index 2657fa1..0000000 --- a/docs/build/urwid +++ /dev/null @@ -1 +0,0 @@ -../../urwid
\ No newline at end of file |
