Urwid ((version)) Reference

Urwid Home Page / Example Screenshots / UTF-8 Screenshots / Tutorial / Reference

User interface wrappers
Top-level widgets
Frame [B]
Filler [B]
Decorations
AttrWrap [F/B]
Padding [F/B]
LineBox [F/B]
Composite widgets
Columns [F/B]
Pile [F/B]
Content widgets
Text [F]
Edit [F]
Button [F]
Graphics
Abstract widgets & interfaces
ListBox list walkers
Canvas painting
Custom formatting rules
Character encoding
Screen capture
Web Application Interface

[F] = Flow Widget displayed with assigned screen columns and variable screen rows
[B] = Box Widget displayed with assigned screen columns and assigned screen rows
[F/B] = May behave as either Flow Widget or Box Widget
[X] = Fixed Widget has a fixed number of screen columns and rows

User interface wrappers

raw_display.Screen [back to top]

Methods defined here:
__init__(self)
draw_screen(self, (maxcol, maxrow), r)
Paint screen with rendered canvas.
get_cols_rows(self)
Return the terminal dimensions (num columns, num rows).
get_input(self, raw_keys=False)
Return pending input as a list.
 
raw_keys -- return raw keycodes as well as translated versions
 
This function will immediately return all the input since the
last time it was called.  If there is no input pending it will
wait before returning an empty list.  The wait time may be
configured with the set_input_timeouts function.
 
If raw_keys is False (default) this function will return a list
of keys pressed.  If raw_keys is True this function will return
a ( keys pressed, raw keycodes ) tuple instead.
 
Examples of keys returned
-------------------------
ASCII printable characters:  " ", "a", "0", "A", "-", "/" 
ASCII control characters:  "tab", "enter"
Escape sequences:  "up", "page up", "home", "insert", "f1"
Key combinations:  "shift f1", "meta a", "ctrl b"
Window events:  "window resize"
 
When a narrow encoding is not enabled
"Extended ASCII" characters:  "\xa1", "\xb2", "\xfe"
 
When a wide encoding is enabled
Double-byte characters:  "\xa1\xea", "\xb2\xd4"
 
When utf8 encoding is enabled
Unicode characters: u"\u00a5", u'\u253c"
 
Examples of mouse events returned
---------------------------------
Mouse button press: ('mouse press', 1, 15, 13), 
                    ('meta mouse press', 2, 17, 23)
Mouse drag: ('mouse drag', 1, 16, 13),
            ('mouse drag', 1, 17, 13),
            ('ctrl mouse drag', 1, 18, 13)
Mouse button release: ('mouse release', 0, 18, 13),
                      ('ctrl mouse release', 0, 17, 23)
register_palette(self, l)
Register a list of palette entries.
 
l -- list of (name, foreground, background, mono),
     (name, foreground, background) or
     (name, same_as_other_name) palette entries.
 
calls self.register_palette_entry for each item in l
register_palette_entry(self, name, foreground, background, mono=None)
Register a single palette entry.
 
name -- new entry/attribute name
foreground -- foreground colour, one of: 'black', 'dark red',
        'dark green', 'brown', 'dark blue', 'dark magenta',
        'dark cyan', 'light gray', 'dark gray', 'light red',
        'light green', 'yellow', 'light blue', 'light magenta',
        'light cyan', 'white', 'default' (black if unable to
        use terminal's default)
background -- background colour, one of: 'black', 'dark red',
        'dark green', 'brown', 'dark blue', 'dark magenta',
        'dark cyan', 'light gray', 'default' (light gray if
        unable to use terminal's default)
mono -- monochrome terminal attribute, one of: None (default),
        'bold', 'underline', 'standout', or a tuple containing
        a combination eg. ('bold','underline')
run_wrapper(self, fn)
Call fn and reset terminal on exit.
set_input_timeouts(self, max_wait=0.5, complete_wait=0.10000000000000001, resize_wait=0.10000000000000001)
Set the get_input timeout values.  All values have are floating
point number of seconds.
 
max_wait -- amount of time in seconds to wait for input when
        there is no input pending
complete_wait -- amount of time in seconds to wait when
        get_input detects an incomplete escape sequence at the
        end of the available input
resize_wait -- amount of time in seconds to wait for more input
        after receiving two screen resize requests in a row to
        stop Urwid from consuming 100% cpu during a gradual
        window resize operation
set_mouse_tracking(self)
Enable mouse tracking.  
 
After calling this function get_input will include mouse
click events along with keystrokes.
signal_init(self)
Called in the startup of run wrapper to set the SIGWINCH 
signal handler to self._sigwinch_handler.
 
Override this function to call from main thread in threaded
applications.
signal_restore(self)
Called in the finally block of run wrapper to restore the
SIGWINCH handler to the default handler.
 
Override this function to call from main thread in threaded
applications.

curses_display.Screen [back to top]

Methods defined here:
__init__(self)
draw_screen(self, (cols, rows), r)
Paint screen with rendered canvas.
get_cols_rows(self)
Return the terminal dimensions (num columns, num rows).
get_input(self, raw_keys=False)
Return pending input as a list.
 
raw_keys -- return raw keycodes as well as translated versions
 
This function will immediately return all the input since the
last time it was called.  If there is no input pending it will
wait before returning an empty list.  The wait time may be
configured with the set_input_timeouts function.
 
If raw_keys is False (default) this function will return a list
of keys pressed.  If raw_keys is True this function will return
a ( keys pressed, raw keycodes ) tuple instead.
 
Examples of keys returned
-------------------------
ASCII printable characters:  " ", "a", "0", "A", "-", "/" 
ASCII control characters:  "tab", "enter"
Escape sequences:  "up", "page up", "home", "insert", "f1"
Key combinations:  "shift f1", "meta a", "ctrl b"
Window events:  "window resize"
 
When a narrow encoding is not enabled
"Extended ASCII" characters:  "\xa1", "\xb2", "\xfe"
 
When a wide encoding is enabled
Double-byte characters:  "\xa1\xea", "\xb2\xd4"
 
When utf8 encoding is enabled
Unicode characters: u"\u00a5", u'\u253c"
 
Examples of mouse events returned
---------------------------------
Mouse button press: ('mouse press', 1, 15, 13), 
                    ('meta mouse press', 2, 17, 23)
Mouse button release: ('mouse release', 0, 18, 13),
                      ('ctrl mouse release', 0, 17, 23)
register_palette(self, l)
Register a list of palette entries.
 
l -- list of (name, foreground, background, mono),
     (name, foreground, background) or
     (name, same_as_other_name) palette entries.
 
calls self.register_palette_entry for each item in l
register_palette_entry(self, name, foreground, background, mono=None)
Register a single palette entry.
 
name -- new entry/attribute name
foreground -- foreground colour, one of: 'black', 'dark red',
        'dark green', 'brown', 'dark blue', 'dark magenta',
        'dark cyan', 'light gray', 'dark gray', 'light red',
        'light green', 'yellow', 'light blue', 'light magenta',
        'light cyan', 'white', 'default' (black if unable to
        use terminal's default)
background -- background colour, one of: 'black', 'dark red',
        'dark green', 'brown', 'dark blue', 'dark magenta',
        'dark cyan', 'light gray', 'default' (light gray if
        unable to use terminal's default)
mono -- monochrome terminal attribute, one of: None (default),
        'bold', 'underline', 'standout', or a tuple containing
        a combination eg. ('bold','underline')
run_wrapper(self, fn)
Call fn in fullscreen mode.  Return to normal on exit.
 
This function should be called to wrap your main program loop.
Exception tracebacks will be displayed in normal mode.
set_input_timeouts(self, max_wait=0.5, complete_wait=0.10000000000000001, resize_wait=0.10000000000000001)
Set the get_input timeout values.  All values have a granularity
of 0.1s, ie. any value between 0.15 and 0.05 will be treated as
0.1 and any value less than 0.05 will be treated as 0. 
 
max_wait -- amount of time in seconds to wait for input when
        there is no input pending
complete_wait -- amount of time in seconds to wait when
        get_input detects an incomplete escape sequence at the
        end of the available input
resize_wait -- amount of time in seconds to wait for more input
        after receiving two screen resize requests in a row to
        stop urwid from consuming 100% cpu during a gradual
        window resize operation
set_mouse_tracking(self)
Enable mouse tracking.  
 
After calling this function get_input will include mouse
click events along with keystrokes.

web_display.Screen [back to top]

Methods defined here:
__init__(self)
draw_screen(self, (cols, rows), r)
Send a screen update to the client.
get_cols_rows(self)
Return the screen size.
get_input(self, raw_keys=False)
Return pending input as a list.
register_palette(self, l)
Register a list of palette entries.
 
l -- list of (name, foreground, background) or
     (name, same_as_other_name) palette entries.
 
calls self.register_palette_entry for each item in l
register_palette_entry(self, name, foreground, background, mono=None)
Register a single palette entry.
 
name -- new entry/attribute name
foreground -- foreground colour
background -- background colour
mono -- monochrome terminal attribute
 
See curses_display.register_palette_entry for more info.
run_wrapper(self, fn)
Start the application main loop.
 
This function reads the initial screen size, generates a
unique id and handles cleanup when fn exits.
 
web_display.set_preferences(..) must be called before calling
this function for the preferences to take effect
set_mouse_tracking(self)
Not yet implemented

Top-level widgets

class Frame(BoxWidget) [back to top]

Methods defined here:
__init__(self, body, header=None, footer=None, focus_part='body')
body -- a box widget for the body of the frame
header -- a flow widget for above the body (or None)
footer -- a flow widget for below the body (or None)
focus_part -- 'header', 'footer' or 'body'
frame_top_bottom(self, (maxcol, maxrow), focus)
Calculate the number of rows for the header and footer.
 
Returns (head rows, foot rows),(orig head, orig foot).
orig head/foot are from rows() calls.
keypress(self, (maxcol, maxrow), key)
Pass keypress to widget in focus.
mouse_event(self, (maxcol, maxrow), event, button, col, row, focus)
Pass mouse event to appropriate part of frame.
Focus may be changed on button 1 press.
render(self, (maxcol, maxrow), focus=False)
Render frame and return it.
set_focus(self, part)
Set the part of the frame that is in focus.
 
part -- 'header', 'footer' or 'body'

Methods inherited from BoxWidget:
selectable(self)
Return True.  Selectable by default.

class Filler(BoxWidget) [back to top]

Methods defined here:
__init__(self, body, valign='middle', height=None, min_height=None)
body -- a flow widget or box widget to be filled around
valign -- one of:
    'top', 'middle', 'bottom'
    ('fixed top', rows)
    ('fixed bottom', rows)
    ('relative', percentage 0=top 100=bottom)
height -- one of:
    None if body is a flow widget
    number of rows high 
    ('fixed bottom', rows)  Only if valign is 'fixed top'
    ('fixed top', rows)  Only if valign is 'fixed bottom'
    ('relative', percentage of total height)
min_height -- one of:
    None if no minimum or if body is a flow widget
    minimum number of rows for the widget when height not fixed
 
If body is a flow widget then height and min_height must be set
to None.
 
Filler widgets will try to satisfy height argument first by
reducing the valign amount when necessary.  If height still 
cannot be satisfied it will also be reduced.
filler_values(self, (maxcol, maxrow), focus)
Return the number of rows to pad on the top and bottom.
 
Override this method to define custom padding behaviour.
get_cursor_coords(self, (maxcol, maxrow))
Return cursor coords from self.body if any.
get_pref_col(self, (maxcol, maxrow))
Return pref_col from self.body if any.
keypress(self, (maxcol, maxrow), key)
Pass keypress to self.body.
mouse_event(self, (maxcol, maxrow), event, button, col, row, focus)
Pass to self.body.
move_cursor_to_coords(self, (maxcol, maxrow), col, row)
Pass to self.body.
render(self, (maxcol, maxrow), focus=False)
Render self.body with space above and/or below.
selectable(self)
Return selectable from body.

class ListBox(BoxWidget) [back to top]

Methods defined here:
__init__(self, body)
body -- list or a SimpleListWalker-like object that contains
        widgets to be displayed inside the list box
calculate_visible(self, (maxcol, maxrow), focus=False)
Return (middle,top,bottom) or None,None,None.
 
middle -- ( row offset(when +ve) or inset(when -ve),
        focus widget, focus position, focus rows, 
        cursor coords or None )
top -- ( # lines to trim off top, 
        list of (widget, position, rows) tuples above focus
        in order from bottom to top )
bottom -- ( # lines to trim off bottom, 
        list of (widget, position, rows) tuples below focus
        in order from top to bottom )
change_focus(self, (maxcol, maxrow), position, offset_inset=0, coming_from=None, cursor_coords=None, snap_rows=None)
Change the current focus widget.
 
position -- a position compatible with self.body.set_focus
offset_inset_rows -- either the number of rows between the 
  top of the listbox and the start of the focus widget (+ve
  value) or the number of lines of the focus widget hidden off 
  the top edge of the listbox (-ve value) or 0 if the top edge
  of the focus widget is aligned with the top edge of the
  listbox (default if unspecified)
coming_from -- eiter 'above', 'below' or unspecified (None)
cursor_coords -- (x, y) tuple indicating the desired
  column and row for the cursor, a (x,) tuple indicating only
  the column for the cursor, or unspecified (None)
snap_rows -- the maximum number of extra rows to scroll
  when trying to "snap" a selectable focus into the view
ends_visible(self, (maxcol, maxrow), focus=False)
Return a list that may contain 'top' and/or 'bottom'.
 
convenience function for checking whether the top and bottom
of the list are visible
get_focus(self)
Return a (focus widget, focus position) tuple.
get_focus_offset_inset(self, (maxcol, maxrow))
Return (offset rows, inset rows) for focus widget.
keypress(self, (maxcol, maxrow), key)
Move selection through the list elements scrolling when 
necessary. 'up' and 'down' are first passed to widget in focus
in case that widget can handle them. 'page up' and 'page down'
are always handled by the ListBox.
 
Keystrokes handled by this widget are:
 'up'        up one line (or widget)
 'down'      down one line (or widget)
 'page up'   move cursor up one listbox length
 'page down' move cursor down one listbox length
make_cursor_visible(self, (maxcol, maxrow))
Shift the focus widget so that its cursor is visible.
mouse_event(self, (maxcol, maxrow), event, button, col, row, focus)
Pass the event to the contained widgets.
May change focus on button 1 press.
render(self, (maxcol, maxrow), focus=False)
Render listbox and return canvas.
set_focus(self, position, coming_from=None)
Set the focus position and try to keep the old focus in view.
 
position -- a position compatible with self.body.set_focus
coming_from -- set to 'above' or 'below' if you know that
               old position is above or below the new position.
set_focus_valign(self, valign)
Set the focus widget's display offset and inset.
 
valign -- one of:
        'top', 'middle', 'bottom'
        ('fixed top', rows)
        ('fixed bottom', rows)
        ('relative', percentage 0=top 100=bottom)
shift_focus(self, (maxcol, maxrow), offset_inset)
Move the location of the current focus relative to the top.
 
offset_inset -- either the number of rows between the 
  top of the listbox and the start of the focus widget (+ve
  value) or the number of lines of the focus widget hidden off 
  the top edge of the listbox (-ve value) or 0 if the top edge
  of the focus widget is aligned with the top edge of the
  listbox
update_pref_col_from_focus(self, (maxcol, maxrow))
Update self.pref_col from the focus widget.

Methods inherited from BoxWidget:
selectable(self)
Return True.  Selectable by default.

Decorations

class WidgetWrap [back to top]

Methods defined here:
__getattr__(self, name)
Call self.w if name is in Widget interface definition.
__init__(self, w)
w -- widget to wrap, stored as self.w
 
This object will pass the functions defined in Widget interface
definition to self.w.

class AttrWrap [back to top]

Methods defined here:
__getattr__(self, name)
Call getattr on wrapped widget.
__init__(self, w, attr, focus_attr=None)
w -- widget to wrap
attr -- attribute to apply to w
focus_attr -- attribute to apply when in focus, if None use attr
 
This object will pass all function calls and variable references
to the wrapped widget.
render(self, size, focus=False)
Render self.w and apply attribute. Return canvas.
 
size -- (maxcol,) if self.w contains a flow widget or
        (maxcol, maxrow) if it contains a box widget.

class Padding [back to top]

Methods defined here:
__init__(self, w, align, width, min_width=None)
w -- a box, flow or fixed widget to pad on the left and/or right
align -- one of:
    'left', 'center', 'right'
    ('fixed left', columns)
    ('fixed right', columns)
    ('relative', percentage 0=left 100=right)
width -- one of:
    number of columns wide 
    ('fixed right', columns)  Only if align is 'fixed left'
    ('fixed left', columns)  Only if align is 'fixed right'
    ('relative', percentage of total width)
    None   to enable clipping mode
min_width -- the minimum number of columns for w or None
        
Padding widgets will try to satisfy width argument first by
reducing the align amount when necessary.  If width still 
cannot be satisfied it will also be reduced.
 
Clipping Mode:
In clipping mode w is treated as a fixed widget and this 
widget expects to be treated as a flow widget.  w will
be clipped to fit within the space given.  For example,
if align is 'left' then w may be clipped on the right.
get_cursor_coords(self, size)
Return the (x,y) coordinates of cursor within self.w.
get_pref_col(self, size)
Return the preferred column from self.w, or None.
keypress(self, size, key)
Pass keypress to self.w.
mouse_event(self, size, event, button, x, y, focus)
Send mouse event if position is within self.w.
move_cursor_to_coords(self, size, x, y)
Set the cursor position with (x,y) coordinates of self.w.
 
Returns True if move succeeded, False otherwise.
padding_values(self, size, focus)
Return the number of columns to pad on the left and right.
 
Override this method to define custom padding behaviour.
render(self, size, focus=False)
rows(self, (maxcol,), focus=False)
Return the rows needed for self.w.
selectable(self)
Return the selectable value of self.w.

class Divider(FlowWidget) [back to top]

Methods defined here:
__init__(self, div_char=' ', top=0, bottom=0)
div_char -- character to repeat across line
top -- number of blank lines above
bottom -- number of blank lines below
render(self, (maxcol,), focus=False)
Render the divider as a canvas and return it.
rows(self, (maxcol,), focus=False)
Return the number of lines that will be rendered.

Methods inherited from FlowWidget:
selectable(self)
Return False.  Not selectable by default.

class LineBox(WidgetWrap) [back to top]

Methods defined here:
__init__(self, w)
Draw a line around w.

Methods inherited from WidgetWrap:
__getattr__(self, name)
Call self.w if name is in Widget interface definition.

class SolidFill(BoxWidget) [back to top]

Methods defined here:
__init__(self, fill_char=' ')
fill_char -- character to fill area with
render(self, (maxcol, maxrow), focus=False)
Render the Fill as a canvas and return it.
selectable(self)
Not selectable.

Composite widgets

class Columns [back to top]

Methods defined here:
__init__(self, widget_list, dividechars=0, focus_column=0, min_width=1, box_columns=None)
widget_list -- list of flow widgets or list of box widgets
dividechars -- blank characters between columns
focus_column -- index into widget_list of column in focus
min_width -- minimum width for each column before it is hidden
box_columns -- a list of column indexes containing box widgets
        whose maxrow is set to the maximum of the rows 
        required by columns not listed in box_columns.
 
widget_list may also contain tuples such as:
('fixed', width, widget) give this column a fixed width
('weight', weight, widget) give this column a relative weight
 
widgets not in a tuple are the same as ('weight', 1, widget)    
 
box_columns is ignored when this widget is being used as a
box widget because in that case all columns are treated as box
widgets.
column_widths(self, size)
Return a list of column widths.
 
size -- (maxcol,) if self.widget_list contains flow widgets or
        (maxcol, maxrow) if it contains box widgets.
get_cursor_coords(self, size)
Return the cursor coordinates from the focus widget.
get_focus(self)
Return the widget in focus.
get_focus_column(self)
Return the focus column index.
get_pref_col(self, size)
Return the pref col from the column in focus.
keypress(self, size, key)
Pass keypress to the focus column.
 
size -- (maxcol,) if self.widget_list contains flow widgets or
        (maxcol, maxrow) if it contains box widgets.
mouse_event(self, size, event, button, col, row, focus)
Send event to appropriate column.
May change focus on button 1 press.
move_cursor_to_coords(self, size, col, row)
Choose a selectable column to focus based on the coords.
render(self, size, focus=False)
Render columns and return canvas.
 
size -- (maxcol,) if self.widget_list contains flow widgets or
        (maxcol, maxrow) if it contains box widgets.
rows(self, (maxcol,), focus=0)
Return the number of rows required by the columns.
Only makes sense if self.widget_list contains flow widgets.
selectable(self)
Return the selectable value of the focus column.
set_focus(self, item)
Set the item in focus.  
 
item -- widget or integer index
set_focus_column(self, num)
Set the column in focus by its index in self.widget_list.

class Pile [back to top]

Methods defined here:
__init__(self, widget_list, focus_item=0)
widget_list -- list of widgets
focus_item -- widget or integer index
 
widget_list may also contain tuples such as:
('flow', widget) always treat widget as a flow widget
('fixed', height, widget) give this box widget a fixed height
('weight', weight, widget) if the pile is treated as a box
        widget then treat widget as a box widget with a
        height based on its relative weight value, otherwise
        treat widget as a flow widget
 
widgets not in a tuple are the same as ('weight', 1, widget)
 
If the pile is treated as a box widget there must be at least
one 'weight' tuple in widget_list.
get_cursor_coords(self, size)
Return the cursor coordinates of the focus widget.
get_focus(self)
Return the widget in focus.
get_item_rows(self, size, focus)
Return a list of the number of rows used by each widget
in self.item_list.
get_item_size(self, size, i, focus, item_rows=None)
Return a size appropriate for passing to self.widget_list[i]
get_pref_col(self, size)
Return the preferred column for the cursor, or None.
keypress(self, size, key)
Pass the keypress to the widget in focus.
Unhandled 'up' and 'down' keys may cause a focus change.
mouse_event(self, size, event, button, col, row, focus)
Pass the event to the contained widget.
May change focus on button 1 press.
move_cursor_to_coords(self, size, col, row)
Capture pref col and set new focus.
render(self, size, focus=False)
Render all widgets in self.widget_list and return the results
stacked one on top of the next.
rows(self, (maxcol,), focus=False)
Return the number of rows required for this widget.
selectable(self)
Return True if the focus item is selectable.
set_focus(self, item)
Set the item in focus.  
 
item -- widget or integer index

class GridFlow(FlowWidget) [back to top]

Methods defined here:
__init__(self, cells, cell_width, h_sep, v_sep, align)
cells -- list of flow widgets to display
cell_width -- column width for each cell
h_sep -- blank columns between each cell horizontally
v_sep -- blank rows between cells vertically (if more than
         one row is required to display all the cells)
align -- horizontal alignment of cells, see "align" parameter
         of Padding widget for available options
generate_display_widget(self, (maxcol,))
Actually generate display widget (ignoring cache)
get_cursor_coords(self, (maxcol,))
Get cursor from display widget.
get_display_widget(self, (maxcol,))
Arrange the cells into columns (and possibly a pile) for 
display, input or to calculate rows.
get_pref_col(self, (maxcol,))
Return pref col from display widget.
keypress(self, (maxcol,), key)
Pass keypress to display widget for handling.  
Capture focus changes.
mouse_event(self, (maxcol,), event, button, col, row, focus)
Send mouse event to contained widget.
move_cursor_to_coords(self, (maxcol,), col, row)
Set the widget in focus based on the col + row.
render(self, (maxcol,), focus=False)
Use display widget to render.
rows(self, (maxcol,), focus=False)
Return rows used by this widget.
selectable(self)
Return True if the cell in focus is selectable.
set_focus(self, cell)
Set the cell in focus.  
 
cell -- widget or integer index into self.cells

class BoxAdapter [back to top]

Methods defined here:
__getattr__(self, name)
Pass calls to box widget.
__init__(self, box_widget, height)
Create a flow widget that contains a box widget
 
box_widget -- box widget
height -- number of rows for box widget
get_cursor_coords(self, (maxcol,))
get_pref_col(self, (maxcol,))
keypress(self, (maxcol,), key)
mouse_event(self, (maxcol,), event, button, col, row, focus)
move_cursor_to_coords(self, (maxcol,), col, row)
render(self, (maxcol,), focus=False)
rows(self, (maxcol,), focus=False)
Return self.height
selectable(self)
Return box widget's selectable value

class Overlay(BoxWidget) [back to top]

Methods defined here:
__init__(self, top_w, bottom_w, align, width, valign, height, min_width=None, min_height=None)
top_w -- a flow, box or fixed widget to overlay "on top"
bottom_w -- a box widget to appear "below" previous widget
align -- one of:
    'left', 'center', 'right'
    ('fixed left', columns)
    ('fixed right', columns)
    ('relative', percentage 0=left 100=right)
width -- one of:
    None if top_w is a fixed widget
    number of columns wide
    ('fixed right', columns)  Only if align is 'fixed left'
    ('fixed left', columns)  Only if align is 'fixed right'
    ('relative', percentage of total width)
valign -- one of:
    'top', 'middle', 'bottom'
    ('fixed top', rows)
    ('fixed bottom', rows)
    ('relative', percentage 0=top 100=bottom)
height -- one of:
    None if top_w is a flow or fixed widget
    number of rows high 
    ('fixed bottom', rows)  Only if valign is 'fixed top'
    ('fixed top', rows)  Only if valign is 'fixed bottom'
    ('relative', percentage of total height)
min_width -- the minimum number of columns for top_w
    when width is not fixed
min_height -- one of:
    minimum number of rows for the widget when height not fixed
 
Overlay widgets behave similarly to Padding and Filler widgets
when determining the size and position of top_w.  bottom_w is
always rendered the full size available "below" top_w.
calculate_padding_filler(self, (maxcol, maxrow), focus)
Return (padding left, right, filler top, bottom).
get_cursor_coords(self, size)
Return cursor coords from top_w, if any.
keypress(self, size, key)
Pass keypress to top_w.
mouse_event(self, size, event, button, col, row, focus)
Pass event to top_w, ignore if outside of top_w.
render(self, size, focus=False)
Render top_w overlayed on bottom_w.
selectable(self)
Return selectable from top_w.
top_w_size(self, size, left, right, top, bottom)
Return the size to pass to top_w.

Content widgets

class Text(FlowWidget) [back to top]

Methods defined here:
__init__(self, markup, align='left', wrap='space', layout=None)
markup -- content of text widget, one of:
        plain string -- string is displayed
        ( attr, markup2 ) -- markup2 is given attribute attr
        [ markupA, markupB, ... ] -- list items joined together
align -- align mode for text layout
wrap -- wrap mode for text layout
layout -- layout object to use, defaults to StandardTextLayout
get_line_translation(self, maxcol, ta=None)
Return layout structure for mapping self.text to a canvas.
get_text(self)
Returns (text, attributes).
 
text -- complete string content of text widget
attributes -- run length encoded attributes for text
pack(self, size=None, focus=False)
Return the number of screen columns required for this Text
widget to be displayed without wrapping or clipping, as a 
single element tuple.
 
size -- None for unlimited screen columns or (maxcol,) to
        specify a maximum column size
render(self, (maxcol,), focus=False)
Render contents with wrapping and alignment.  Return canvas.
rows(self, (maxcol,), focus=False)
Return the number of rows the rendered text spans.
set_align_mode(self, mode)
Set text alignment / justification.  
 
Valid modes for StandardTextLayout are: 
        'left', 'center' and 'right'
set_layout(self, align, wrap, layout=None)
Set layout object, align and wrap modes.
 
align -- align mode for text layout
wrap -- wrap mode for text layout
layout -- layout object to use, defaults to StandardTextLayout
set_text(self, markup)
Set content of text widget.
set_wrap_mode(self, mode)
Set wrap mode.  
 
Valid modes for StandardTextLayout are :
        'any'   : wrap at any character
        'space' : wrap on space character
        'clip'  : truncate lines instead of wrapping

Methods inherited from FlowWidget:
selectable(self)
Return False.  Not selectable by default.

class Edit(Text) [back to top]

Method resolution order:
Edit
Text
FlowWidget

Methods defined here:
__init__(self, caption='', edit_text='', multiline=False, align='left', wrap='space', allow_tab=False, edit_pos=None, layout=None)
caption -- markup for caption preceeding edit_text
edit_text -- text string for editing
multiline -- True: 'enter' inserts newline  False: return it
align -- align mode
wrap -- wrap mode
allow_tab -- True: 'tab' inserts 1-8 spaces  False: return it
edit_pos -- initial position for cursor, None:at end
layout -- layout object
get_cursor_coords(self, (maxcol,))
Return the (x,y) coordinates of cursor within widget.
get_edit_text(self)
Return the edit text for this widget.
get_line_translation(self, maxcol, ta=None)
get_pref_col(self, (maxcol,))
Return the preferred column for the cursor, or the
current cursor x value.
get_text(self)
get_text() -> text, attributes
 
text -- complete text of caption and edit_text
attributes -- run length encoded attributes for text
insert_text(self, text)
Insert text at the cursor position and update cursor.
keypress(self, (maxcol,), key)
Handle editing keystrokes, return others.
mouse_event(self, (maxcol,), event, button, x, y, focus)
Move the cursor to the location clicked for button 1.
move_cursor_to_coords(self, (maxcol,), x, y)
Set the cursor position with (x,y) coordinates.
 
Returns True if move succeeded, False otherwise.
position_coords(self, maxcol, pos)
Return (x,y) coordinates for an offset into self.edit_text.
render(self, (maxcol,), focus=False)
Render edit widget and return canvas.  Include cursor when in
focus.
selectable(self)
set_caption(self, caption)
Set the caption markup for this widget.
set_edit_pos(self, pos)
Set the cursor position with a self.edit_text offset.
set_edit_text(self, text)
Set the edit text for this widget.
update_text(self)
Deprecated.  Use set_caption and/or set_edit_text instead.
 
Make sure any cached line translation is not reused.
valid_char(self, ch)
Return true for printable characters.

Methods inherited from Text:
pack(self, size=None, focus=False)
Return the number of screen columns required for this Text
widget to be displayed without wrapping or clipping, as a 
single element tuple.
 
size -- None for unlimited screen columns or (maxcol,) to
        specify a maximum column size
rows(self, (maxcol,), focus=False)
Return the number of rows the rendered text spans.
set_align_mode(self, mode)
Set text alignment / justification.  
 
Valid modes for StandardTextLayout are: 
        'left', 'center' and 'right'
set_layout(self, align, wrap, layout=None)
Set layout object, align and wrap modes.
 
align -- align mode for text layout
wrap -- wrap mode for text layout
layout -- layout object to use, defaults to StandardTextLayout
set_text(self, markup)
Set content of text widget.
set_wrap_mode(self, mode)
Set wrap mode.  
 
Valid modes for StandardTextLayout are :
        'any'   : wrap at any character
        'space' : wrap on space character
        'clip'  : truncate lines instead of wrapping

class IntEdit(Edit) [back to top]

Method resolution order:
IntEdit
Edit
Text
FlowWidget

Methods defined here:
__init__(self, caption='', default=None)
caption -- caption markup
default -- default edit value
keypress(self, (maxcol,), key)
Handle editing keystrokes.  Return others.
valid_char(self, ch)
Return true for decimal digits.
value(self)
Return the numeric value of self.edit_text.

Methods inherited from Edit:
get_cursor_coords(self, (maxcol,))
Return the (x,y) coordinates of cursor within widget.
get_edit_text(self)
Return the edit text for this widget.
get_line_translation(self, maxcol, ta=None)
get_pref_col(self, (maxcol,))
Return the preferred column for the cursor, or the
current cursor x value.
get_text(self)
get_text() -> text, attributes
 
text -- complete text of caption and edit_text
attributes -- run length encoded attributes for text
insert_text(self, text)
Insert text at the cursor position and update cursor.
mouse_event(self, (maxcol,), event, button, x, y, focus)
Move the cursor to the location clicked for button 1.
move_cursor_to_coords(self, (maxcol,), x, y)
Set the cursor position with (x,y) coordinates.
 
Returns True if move succeeded, False otherwise.
position_coords(self, maxcol, pos)
Return (x,y) coordinates for an offset into self.edit_text.
render(self, (maxcol,), focus=False)
Render edit widget and return canvas.  Include cursor when in
focus.
selectable(self)
set_caption(self, caption)
Set the caption markup for this widget.
set_edit_pos(self, pos)
Set the cursor position with a self.edit_text offset.
set_edit_text(self, text)
Set the edit text for this widget.
update_text(self)
Deprecated.  Use set_caption and/or set_edit_text instead.
 
Make sure any cached line translation is not reused.

Methods inherited from Text:
pack(self, size=None, focus=False)
Return the number of screen columns required for this Text
widget to be displayed without wrapping or clipping, as a 
single element tuple.
 
size -- None for unlimited screen columns or (maxcol,) to
        specify a maximum column size
rows(self, (maxcol,), focus=False)
Return the number of rows the rendered text spans.
set_align_mode(self, mode)
Set text alignment / justification.  
 
Valid modes for StandardTextLayout are: 
        'left', 'center' and 'right'
set_layout(self, align, wrap, layout=None)
Set layout object, align and wrap modes.
 
align -- align mode for text layout
wrap -- wrap mode for text layout
layout -- layout object to use, defaults to StandardTextLayout
set_text(self, markup)
Set content of text widget.
set_wrap_mode(self, mode)
Set wrap mode.  
 
Valid modes for StandardTextLayout are :
        'any'   : wrap at any character
        'space' : wrap on space character
        'clip'  : truncate lines instead of wrapping

class Button(FlowWidget) [back to top]

Methods defined here:
__init__(self, label, on_press)
label -- markup for button label
on_press -- callback function for button "press"
           on_press( button object )
get_cursor_coords(self, (maxcol,))
Return the location of the cursor.
get_label(self)
keypress(self, (maxcol,), key)
Call on_press on spage or enter.
mouse_event(self, (maxcol,), event, button, x, y, focus)
Call on_press on button 1 press.
render(self, (maxcol,), focus=False)
Display button. Show a cursor when in focus.
rows(self, (maxcol,), focus=False)
Return rows required for button.
selectable(self)
set_label(self, label)

Data and other attributes defined here:
button_left = <urwid.widget.Text instance>
button_right = <urwid.widget.Text instance>

class CheckBox(FlowWidget) [back to top]

Methods defined here:
__init__(self, label, state=False, has_mixed=False, on_state_change=None)
label -- markup for check box label
state -- False, True or "mixed"
has_mixed -- True if "mixed" is a state to cycle through
on_state_change -- callback function for state changes
                   on_state_change( check box, new state )
get_cursor_coords(self, (maxcol,))
Return cursor coords from display widget.
get_label(self)
Return label text.
get_state(self)
Return the state of the checkbox.
keypress(self, (maxcol,), key)
Toggle state on space or enter.
mouse_event(self, (maxcol,), event, button, x, y, focus)
Toggle state on button 1 press.
render(self, (maxcol,), focus=False)
Render check box.
rows(self, (maxcol,), focus=False)
Return rows required for check box.
selectable(self)
set_label(self, label)
Change the check box label.
set_state(self, state, do_callback=True)
Call on_state_change if do_callback is True,
then change the check box state.
toggle_state(self)
Cycle to the next valid state.

Data and other attributes defined here:
reserve_columns = 4
states = {False: <urwid.widget.SelectableIcon instance>, True: <urwid.widget.SelectableIcon instance>, 'mixed': <urwid.widget.SelectableIcon instance>}

class RadioButton(FlowWidget) [back to top]

Methods defined here:
__init__(self, group, label, state='first True', on_state_change=None)
group -- list for radio buttons in same group
label -- markup for radio button label
state -- False, True, "mixed" or "first True"
on_state_change -- callback function for state changes
                   on_state_change( radio_button, new_state )
 
This function will append the new radio button to group.
"first True" will set to True if group is empty.
get_cursor_coords(self, (maxcol,))
Return cursor coords from display widget.
get_label(self)
Return label text.
get_state(self)
Return the state of the radio button.
keypress(self, (maxcol,), key)
Set state to True on space or enter.
mouse_event(self, (maxcol,), event, button, x, y, focus)
Set state to True on button 1 press.
render(self, (maxcol,), focus=False)
Render radio button.
rows(self, (maxcol,), focus=False)
Return rows required for radio button.
selectable(self)
set_label(self, label)
Change the check box label.
set_state(self, state, do_callback=True)
Call on_state_change if do_callback is True,
then change the radio button state.
if state is True set all other radio buttons in group to False.

Data and other attributes defined here:
reserve_columns = 4
states = {False: <urwid.widget.SelectableIcon instance>, True: <urwid.widget.SelectableIcon instance>, 'mixed': <urwid.widget.SelectableIcon instance>}

Graphics

class BarGraph(BoxWidget) [back to top]

Methods defined here:
__init__(self, attlist, hatt=None, satt=None)
Create a bar graph with the passed display characteristics.
see set_segment_attributes for a description of the parameters.
calculate_bar_widths(self, (maxcol, maxrow), bardata)
Return a list of bar widths, one for each bar in data.
 
If self.bar_width is None this implementation will stretch 
the bars across the available space specified by maxcol.
calculate_display(self, (maxcol, maxrow))
Calculate display data.
get_data(self, (maxcol, maxrow))
Return (bardata, top, hlines)
 
This function is called by render to retrieve the data for
the graph. It may be overloaded to create a dynamic bar graph.
 
This implementation will truncate the bardata list returned 
if not all bars will fit within maxcol.
hlines_display(self, disp, top, hlines, maxrow)
Add hlines to display structure represented as bar_type tuple
values:
(bg, 0-5)
bg is the segment that has the hline on it
0-5 is the hline graphic to use where 0 is a regular underscore
and 1-5 are the UTF-8 horizontal scan line characters.
render(self, (maxcol, maxrow), focus=False)
Render BarGraph.
selectable(self)
Return False.
set_bar_width(self, width)
Set a preferred bar width for calculate_bar_widths to use.
 
width -- width of bar or None for automatic width adjustment
set_data(self, bardata, top, hlines=None)
Store bar data, bargraph top and horizontal line positions.
 
bardata -- a list of bar values.
top -- maximum value for segments within bardata
hlines -- None or a bar value marking horizontal line positions
 
bar values are [ segment1, segment2, ... ] lists where top is 
the maximal value corresponding to the top of the bar graph and
segment1, segment2, ... are the values for the top of each 
segment of this bar.  Simple bar graphs will only have one
segment in each bar value.
 
Eg: if top is 100 and there is a bar value of [ 80, 30 ] then
the top of this bar will be at 80% of full height of the graph
and it will have a second segment that starts at 30%.
set_segment_attributes(self, attlist, hatt=None, satt=None)
attlist -- list containing attribute or (attribute, character)
        tuple for background, first segment, and optionally
        following segments. ie. len(attlist) == num segments+1
        character defaults to ' ' if not specified.
hatt -- list containing attributes for horizontal lines. First 
        lement is for lines on background, second is for lines
        on first segment, third is for lines on second segment
        etc..
satt -- dictionary containing attributes for smoothed 
        transitions of bars in UTF-8 display mode. The values
        are in the form:
                (fg,bg) : attr
        fg and bg are integers where 0 is the graph background,
        1 is the first segment, 2 is the second, ...  
        fg > bg in all values.  attr is an attribute with a 
        foreground corresponding to fg and a background 
        corresponding to bg.
        
If satt is not None and the bar graph is being displayed in
a terminal using the UTF-8 encoding then the character cell
that is shared between the segments specified will be smoothed
with using the UTF-8 vertical eighth characters.
 
eg: set_segment_attributes( ['no', ('unsure',"?"), 'yes'] )
will use the attribute 'no' for the background (the area from
the top of the graph to the top of the bar), question marks 
with the attribute 'unsure' will be used for the topmost 
segment of the bar, and the attribute 'yes' will be used for
the bottom segment of the bar.
smooth_display(self, disp)
smooth (col, row*8) display into (col, row) display using
UTF vertical eighth characters represented as bar_type
tuple values:
( fg, bg, 1-7 )
where fg is the lower segment, bg is the upper segment and
1-7 is the vertical eighth character to use.
use_smoothed(self)

Data and other attributes defined here:
eighths = u' \u2581\u2582\u2583\u2584\u2585\u2586\u2587'
hlines = u'_\u23ba\u23bb\u2500\u23bc\u23bd'

class GraphVScale(BoxWidget) [back to top]

Methods defined here:
__init__(self, labels, top)
GraphVScale( [(label1 position, label1 markup),...], top )
label position -- 0 < position < top for the y position
label markup -- text markup for this label
top -- top y position
 
This widget is a vertical scale for the BarGraph widget that
can correspond to the BarGraph's horizontal lines
render(self, (maxcol, maxrow), focus=False)
Render GraphVScale.
selectable(self)
Return False.
set_scale(self, labels, top)
set_scale( [(label1 position, label1 markup),...], top )
label position -- 0 < position < top for the y position
label markup -- text markup for this label
top -- top y position

class ProgressBar(FlowWidget) [back to top]

Methods defined here:
__init__(self, normal, complete, current=0, done=100, satt=None)
normal -- attribute for uncomplete part of progress bar
complete -- attribute for complete part of progress bar
current -- current progress
done -- progress amount at 100%
satt -- attribute for smoothed part of bar where the foreground
        of satt corresponds to the normal part and the
        background corresponds to the complete part.  If satt
        is None then no smoothing will be done.
render(self, (maxcol,), focus=False)
Render the progress bar.
rows(self, (maxcol,), focus=False)
Return 1.
set_completion(self, current)
current -- current progress

Data and other attributes defined here:
eighths = u' \u258f\u258e\u258d\u258c\u258b\u258a\u2589'

Methods inherited from FlowWidget:
selectable(self)
Return False.  Not selectable by default.

class BigText(FixedWidget) [back to top]

Methods defined here:
__init__(self, markup, font)
markup -- same as Text widget markup
font -- instance of a Font class
get_text(self)
Returns (text, attributes).
pack(self, size=None, focus=False)
render(self, size, focus=False)
set_font(self, font)
set_text(self, markup)

Methods inherited from FixedWidget:
selectable(self)
Return False.  Not selectable by default.

function get_all_fonts [back to top]

get_all_fonts()
Return a list of (font name, font class) tuples.

Abstract widgets & interfaces

Widget interface definition [back to top]

Methods defined here:
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.
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.
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.
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.
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.
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.
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.
selectable(self)
Returns True if this widget will accept keyboard input and
should take the focus when changing focus between widgets.
 
MUST be implemented.

class BoxWidget [back to top]

Methods defined here:
render(self, size, focus=False)
All widgets must implement this function.
selectable(self)
Return True.  Selectable by default.

class FlowWidget [back to top]

Methods defined here:
render(self, (maxcol,), focus=False)
All widgets must implement this function.
rows(self, (maxcol,), focus=False)
All flow widgets must implement this function.
selectable(self)
Return False.  Not selectable by default.

class FixedWidget [back to top]

Methods defined here:
pack(self, size=None, focus=False)
All fixed widgets must implement this function.
render(self, size, focus=False)
All widgets must implement this function.
selectable(self)
Return False.  Not selectable by default.

List Walker interface definition [back to top]

Methods defined here:
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.
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.
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.
set_focus(self, position)
position -- a position returned by get_focus, get_next or
            get_prev
 
Returns None.
 
MUST be implemented.

ListBox list walkers

class SimpleListWalker [back to top]

Methods defined here:
__init__(self, contents)
contents -- list to walk
get_focus(self)
Return (focus widget, focus position).
get_next(self, start_from)
Return (widget after start_from, position after start_from).
get_prev(self, start_from)
Return (widget before start_from, position before start_from).
set_focus(self, position)
Set focus position.

Canvas painting

class Canvas [back to top]

Methods defined here:
__init__(self, text=None, attr=None, cs=None, cursor=None, maxcol=None)
text -- list of strings, one for each line
attr -- list of run length encoded attributes for text
cs -- list of run length encoded character set for text
cursor -- (x,y) of cursor or None
maxcol -- screen columns taken by this canvas
cols(self)
Return the screen column width of this canvas.
fill_attr(self, a)
Apply attribute a to all areas of this canvas with
attribute currently set to None, leaving other attributes
intact.
overlay(self, other, left, right, top, bottom)
Overlay other onto this canvas.
pad_trim(self, left, right, top, bottom)
Pad or trim this canvas on all sides.
 
values > 0 indicate screen columns or rows to pad
values < 0 indicate screen columns or rows to trim
pad_trim_left_right(self, left, right)
Pad or trim this canvas on the left and right
 
values > 0 indicate screen columns to pad
values < 0 indicate screen columns to trim
rows(self)
Return the number of rows in this canvas.
translate_coords(self, dx, dy)
Shift cursor coords by (dx, dy).
trim(self, top, count=None)
Trim lines from the top and/or bottom of canvas.
 
top -- number of lines to remove from top
count -- number of lines to keep, or None for all the rest
trim_end(self, end)
Trim lines from the bottom of the canvas.
 
end -- number of lines to remove from the end

function CanvasCombine [back to top]

CanvasCombine(l)
Stack canvases in l vertically and return resulting canvas.

function CanvasJoin [back to top]

CanvasJoin(l)
Join canvases in l horizontally. Return result.
 
l -- [canvas1, colnum2, canvas2, ... ,colnumN, canvasN]
        colnumX is the screen column count between the start of
        canvas(X-1) and canvasX, colnumX >= canvas(X-1).cols()

Custom formatting rules

class TextLayout [back to top]

Methods defined here:
layout(self, text, width, align, wrap)
Return a layout structure for text.
 
text -- string in current encoding or unicode string
width -- number of screen columns available
align -- align mode for text
wrap -- wrap mode for text
 
Layout structure is a list of line layouts, one per output line.
Line layouts are lists than may contain the following tuples:
  ( column width of text segment, start offset, end offset )
  ( number of space characters to insert, offset or None)
  ( column width of insert text, offset, "insert text" )
 
The offset in the last two tuples is used to determine the
attribute used for the inserted spaces or text respectively.  
The attribute used will be the same as the attribute at that 
text offset.  If the offset is None when inserting spaces
then no attribute will be used.
supports_align_mode(self, align)
Return True if align is a supported align mode.
supports_wrap_mode(self, wrap)
Return True if wrap is a supported wrap mode.

class StandardTextLayout(TextLayout) [back to top]

Methods defined here:
__init__(self)
align_layout(self, text, width, segs, wrap, align)
Convert the layout segs to an aligned layout.
calculate_text_segments(self, text, width, wrap)
Calculate the segments of text to display given width screen 
columns to display them.  
 
text - text to display
width - number of available screen columns
wrap - wrapping mode used
 
Returns a layout structure without aligmnent applied.
layout(self, text, width, align, wrap)
Return a layout structure for text.
pack(self, maxcol, layout)
Return a minimal maxcol value that would result in the same
number of lines for layout.  layout must be a layout structure
returned by layout().
supports_align_mode(self, align)
Return True if align is 'left', 'center' or 'right'.
supports_wrap_mode(self, wrap)
Return True if wrap is 'any', 'space' or 'clip'.

Character encoding

function set_encoding [back to top]

set_encoding(encoding)
Set the byte encoding to assume when processing strings and the
encoding to use when converting unicode strings.

function get_encoding_mode [back to top]

get_encoding_mode()
Get the mode Urwid is using when processing text strings.
Returns 'narrow' for 8-bit encodings, 'wide' for CJK encodings
or 'utf8' for UTF-8 encodings.

function supports_unicode [back to top]

supports_unicode()
Return True if python is able to convert non-ascii unicode strings
to the current encoding.

Screen capture

function html_fragment.screenshot_init [back to top]

html_fragment.screenshot_init = screenshot_init(sizes, keys)
Replace curses_display.Screen and raw_display.Screen class with 
HtmlGenerator.
 
Call this function before executing an application that uses 
curses_display.Screen to have that code use HtmlGenerator instead.
 
sizes -- list of ( columns, rows ) tuples to be returned by each call
         to HtmlGenerator.get_cols_rows()
keys -- list of lists of keys to be returned by each call to
        HtmlGenerator.get_input()
 
Lists of keys may include "window resize" to force the application to
call get_cols_rows and read a new screen size.
 
For example, the following call will prepare an application to:
 1. start in 80x25 with its first call to get_cols_rows()
 2. take a screenshot when it calls draw_screen(..)
 3. simulate 5 "down" keys from get_input()
 4. take a screenshot when it calls draw_screen(..)
 5. simulate keys "a", "b", "c" and a "window resize"
 6. resize to 20x10 on its second call to get_cols_rows()
 7. take a screenshot when it calls draw_screen(..)
 8. simulate a "Q" keypress to quit the application
 
screenshot_init( [ (80,25), (20,10) ],
        [ ["down"]*5, ["a","b","c","window resize"], ["Q"] ] )

function html_fragment.screenshot_collect [back to top]

html_fragment.screenshot_collect = screenshot_collect()
Return screenshots as a list of HTML fragments.

html_fragment.HtmlGenerator [back to top]

Methods defined here:
__init__(self)
draw_screen(self, (cols, rows), r)
Create an html fragment from the render object. 
Append it to HtmlGenerator.fragments list.
get_cols_rows(self)
Return the next screen size in HtmlGenerator.sizes.
get_input(self)
Return the next list of keypresses in HtmlGenerator.keys.
register_palette(self, l)
Register a list of palette entries.
 
l -- list of (name, foreground, background) or
     (name, same_as_other_name) palette entries.
 
calls self.register_palette_entry for each item in l
register_palette_entry(self, name, foreground, background, mono=None)
Register a single palette entry.
 
name -- new entry/attribute name
foreground -- foreground colour
background -- background colour
mono -- monochrome terminal attribute
 
See curses_display.register_palette_entry for more info.
run_wrapper(self, fn)
Call fn.
set_mouse_tracking(self)
Not yet implemented

Data and other attributes defined here:
fragments = []
keys = []
sizes = []

Web Application Interface

function web_display.is_web_request [back to top]

web_display.is_web_request = is_web_request()
Return True if this is a CGI web request.

function web_display.set_preferences [back to top]

web_display.set_preferences = set_preferences(app_name, pipe_dir='/tmp', allow_polling=True, max_clients=20)
Set web_display preferences.
 
app_name -- application name to appear in html interface
pipe_dir -- directory for input pipes, daemon update sockets 
            and daemon error logs
allow_polling -- allow creation of daemon processes for 
                 browsers without multipart support 
max_clients -- maximum concurrent client connections. This
               pool is shared by all urwid applications
               using the same pipe_dir

function web_display.handle_short_request [back to top]

web_display.handle_short_request = handle_short_request()
Handle short requests such as passing keystrokes to the application
or sending the initial html page.  If returns True, then this
function recognised and handled a short request, and the calling
script should immediately exit.
 
web_display.set_preferences(..) should be called before calling this
function for the preferences to take effect