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.
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
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.
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
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'
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 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.
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 )
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
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
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.
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
w -- a box or flow 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)
min_width -- the minimum number of columns for the widget
when width is not fixed
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.
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.
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.
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
top_w -- a box 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:
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:
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.
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
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 )
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.
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.
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%.
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 (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.
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
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
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.
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.
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.
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.
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.
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.
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.
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
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()
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.
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.
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
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]
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