# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1210474441 25200
# Node ID eec6e44c279adeb4dd276879060b2acafdf52c1a
# Parent 265aef329367e74d504f4f27d8647023efba02fb
trac #3121 -- slight followup doc patch
diff -r 265aef329367 -r eec6e44c279a sage/server/notebook/interact.py
a
|
b
|
VERSION 2: |
115 | 115 | maxlength -- the maximum number of characters allowed in a text field. |
116 | 116 | name -- defines a unique name for the input element |
117 | 117 | size -- the size of the input element |
118 | | type -- button, checkbox, file, password, radio, slider, text, setter_bar, drop_down |
| 118 | type -- button, checkbox, file, password, radio, slider, text, setter_bar |
119 | 119 | |
120 | 120 | VERSION 3: |
121 | 121 | [ ] protocol for objects to have their own interact function; make |
… |
… |
def interact(f): |
1174 | 1174 | DEFAULTS: |
1175 | 1175 | Defaults for the variables of the input function determine |
1176 | 1176 | interactive controls. The standard controls are \code{input_box}, |
1177 | | \code{slider}, \code{button}, \code{checkbox}. |
| 1177 | \code{slider}, \code{checkbox}, \code{selector}, and |
| 1178 | \code{input_grid}. There is also a color selector (see defaults below). |
1178 | 1179 | |
1179 | 1180 | \begin{itemize} |
1180 | | \item u = input_box(default, label, type=None) |
| 1181 | \item u = input_box(default=None, label=None, type=None) |
1181 | 1182 | -- input box with given default; use type=str to |
1182 | 1183 | get input as an arbitrary string |
1183 | | \item u = slider(vmin, vmax,step_size,default,label) |
| 1184 | \item u = slider(vmin, vmax=None,step_size=1,default=None,label=None) |
1184 | 1185 | -- slider with given list of possible values; vmin an be a list |
1185 | | \item u = checkbox(default, label) |
| 1186 | \item u = checkbox(default=True, label=None) |
1186 | 1187 | -- a checkbox |
1187 | 1188 | \item u = selector(values, label=None, nrows=None, ncols=None, buttons=False) |
1188 | 1189 | -- a dropdown menu or buttons (get buttons if nrows, |
1189 | 1190 | ncols, or buttons is set, otherwise a dropdown menu) |
1190 | | \item u = drop_down(list, label) |
1191 | | -- a drop down menu |
| 1191 | \item u = input_grid(nrows, ncols, default=None, label=None, |
| 1192 | to_value=lambda x:x, width=4) |
| 1193 | -- an editable grid of objects (a matrix or array) |
| 1194 | |
1192 | 1195 | \end{itemize} |
1193 | 1196 | |
1194 | 1197 | You can create a color selector by setting the default value for a |
… |
… |
def interact(f): |
1212 | 1215 | \item u = Color('blue') -- a 2d RGB color selector; returns Color object |
1213 | 1216 | \item u = (default, v) -- v as above, with given default value |
1214 | 1217 | \item u = (label, v) -- v as above, with given label (a string) |
1215 | | \item u = matrix -- an input_grid with to_value set to matrix.parent() and the default values given by the matrix |
| 1218 | \item u = matrix -- an input_grid with to_value set to matrix.parent() |
| 1219 | and default values given by the matrix |
1216 | 1220 | \end{itemize} |
1217 | 1221 | |
1218 | 1222 | WARNING: Suppose you would like to make a interactive with a |
… |
… |
class input_box(control): |
1547 | 1551 | |
1548 | 1552 | |
1549 | 1553 | class input_grid(control): |
1550 | | def __init__(self, rows, columns, default=None, label=None, to_value=lambda x: x, width=4): |
| 1554 | def __init__(self, nrows, ncols, default=None, label=None, to_value=lambda x: x, width=4): |
1551 | 1555 | r""" |
1552 | 1556 | An input grid interactive control. Use this in conjunction |
1553 | 1557 | with the interact command. |
1554 | 1558 | |
1555 | 1559 | INPUT: |
| 1560 | nrows -- integer |
| 1561 | ncols -- integer |
1556 | 1562 | default -- object; the default put in this input box |
1557 | 1563 | label -- the label rendered to the left of the box. |
1558 | 1564 | to_value -- the grid output (list of rows) is sent through |
1559 | | this function. This may reformat the data or coerce the |
1560 | | type. |
| 1565 | this function. This may reformat the data or |
| 1566 | coerce the type. |
1561 | 1567 | width -- size of each input box in characters |
1562 | 1568 | |
1563 | 1569 | NOTEBOOK EXAMPLE: |
… |
… |
class input_grid(control): |
1585 | 1591 | |
1586 | 1592 | """ |
1587 | 1593 | self.__default = default |
1588 | | self.__rows = rows |
1589 | | self.__columns = columns |
| 1594 | self.__rows = nrows |
| 1595 | self.__columns = ncols |
1590 | 1596 | self.__to_value = to_value |
1591 | 1597 | self.__width = width |
1592 | 1598 | control.__init__(self, label) |