︠fc1c0058-e545-41bc-af54-2f749af7cc9bs︠ @interact def f(a=True, b=False, auto_update=False): print a, b ︡00d67566-a4ba-43ef-aac2-e588c3811305︡{"interact":{"controls":[{"control_type":"checkbox","default":true,"label":"a","readonly":false,"var":"a"},{"control_type":"checkbox","default":false,"label":"b","readonly":false,"var":"b"},{"control_type":"checkbox","default":false,"label":"auto_update","readonly":false,"var":"auto_update"}],"flicker":false,"id":"79cdc3b9-9ea4-440f-9e64-8d5a3fa5dd36","layout":[[["a",12,null]],[["b",12,null]],[["auto_update",12,null]],[["",12,null]]],"style":"None"}}︡{"done":true}︡ ︠00ba7007-b9e5-42b4-9827-bc06a8364a8bs︠ interact?? ︡807ec86f-ec0b-40e7-8f30-913cc615d370︡{"code":{"filename":null,"lineno":-1,"mode":"python","source":" File: /projects/sage/sage-7.3/local/lib/python2.7/site-packages/smc_sagews/sage_salvus.py\n Source:\n class Interact(object):\n \"\"\"\n Use interact to create interactive worksheet cells with sliders,\n text boxes, radio buttons, check boxes, color selectors, and more.\n\n Put ``@interact`` on the line before a function definition in a\n cell by itself, and choose appropriate defaults for the variable\n names to determine the types of controls (see tables below). You\n may also put ``@interact(layout=...)`` to control the layout of\n controls. Within the function, you may explicitly set the value\n of the control corresponding to a variable foo to bar by typing\n interact.foo = bar.\n\n Type \"interact.controls.[tab]\" to get access to all of the controls.\n\n INPUT:\n\n - ``f`` -- function\n - ``width`` -- number, or string such as '80%', '300px', '20em'.\n - ``style`` -- CSS style string, which allows you to change the border,\n background color, etc., of the interact.\n - ``update_args`` -- (default: None); list of strings, so that\n only changing the corresponding controls causes the function to\n be re-evaluated; changing other controls will not cause an update.\n - ``auto_update`` -- (default: True); if False, a button labeled\n 'Update' will appear which you can click on to re-evalute.\n - ``layout`` -- (default: one control per row) a list [row0,\n row1, ...] of lists of tuples row0 = [(var_name, width,\n label), ...], where the var_name's are strings, the widths\n must add up to at most 12, and the label is optional. This\n will layout all of the controls and output using Twitter\n Bootstraps \"Fluid layout\", with spans corresponding\n to the widths. Use var_name='' to specify where the output\n goes, if you don't want it to last. You may specify entries for\n controls that you will create later using interact.var_name = foo.\n\n\n NOTES: The flicker and layout options above are only in SALVUS.\n For backwards compatibility with the Sage notebook, if layout\n is a dictionary (with keys 'top', 'bottom', 'left', 'right'),\n then the appropriate layout will be rendered as it used to be\n in the Sage notebook.\n\n OUTPUT:\n\n - creates an interactive control.\n\n\n AUTOMATIC CONTROL RULES\n -----------------------\n\n There are also some defaults that allow you to make controls\n automatically without having to explicitly specify them. E.g.,\n you can make ``x`` a continuous slider of values between ``u`` and\n ``v`` by just writing ``x=(u,v)`` in the argument list.\n\n - ``u`` - blank input_box\n - ``u=elt`` - input_box with ``default=element``, unless other rule below\n - ``u=(umin,umax)`` - continuous slider (really `100` steps)\n - ``u=(umin,umax,du)`` - slider with step size ``du``\n - ``u=list`` - buttons if ``len(list)`` at most `5`; otherwise, drop down\n - ``u=generator`` - a slider (up to `10000` steps)\n - ``u=bool`` - a checkbox\n - ``u=Color('blue')`` - a color selector; returns ``Color`` object\n - ``u=matrix`` - an ``input_grid`` with ``to_value`` set to\n ``matrix.parent()`` and default values given by the matrix\n - ``u=(default, v)`` - ``v`` anything as above, with given ``default`` value\n - ``u=(label, v)`` - ``v`` anything as above, with given ``label`` (a string)\n\n EXAMPLES:\n\n\n The layout option::\n\n @interact(layout={'top': [['a', 'b']], 'left': [['c']],\n 'bottom': [['d']], 'right':[['e']]})\n def _(a=x^2, b=(0..20), c=100, d=x+1, e=sin(2)):\n print(a+b+c+d+e)\n\n We illustrate some features that are only in Salvus, not in the\n Sage cell server or Sage notebook.\n\n You can set the value of a control called foo to 100 using\n interact.foo=100. For example::\n\n @interact\n def f(n=20, twice=None):\n interact.twice = int(n)*2\n\n\n In this example, we create and delete multiple controls depending\n on properties of the input::\n\n @interact\n def f(n=20, **kwds):\n print(kwds)\n n = Integer(n)\n if n % 2 == 1:\n del interact.half\n else:\n interact.half = input_box(n/2, readonly=True)\n if n.is_prime():\n interact.is_prime = input_box('True', readonly=True)\n else:\n del interact.is_prime\n\n You can access the value of a control associated to a variable foo\n that you create using interact.foo, and check whether there is a\n control associated to a given variable name using hasattr::\n\n @interact\n def f():\n if not hasattr(interact, 'foo'):\n interact.foo = 'hello'\n else:\n print(interact.foo)\n\n An indecisive interact::\n\n @interact\n def f(n=selector(['yes', 'no'])):\n for i in range(5):\n interact.n = i%2\n sleep(.2)\n\n We use the style option to make a holiday interact::\n\n @interact(width=25,\n style=\"background-color:lightgreen; border:5px dashed red;\")\n def f(x=button('Merry ...',width=20)):\n pass\n\n We make a little box that can be dragged around, resized, and is\n updated via a computation (in this case, counting primes)::\n\n @interact(width=30,\n style=\"background-color:lightorange; position:absolute; z-index:1000; box-shadow : 8px 8px 4px #888;\")\n def f(prime=text_control(label=\"Counting primes: \")):\n salvus.javascript(\"cell.element.closest('.salvus-cell-output-interact').draggable().resizable()\")\n p = 2\n c = 1\n while True:\n interact.prime = '%s, %.2f'%(p, float(c)/p)\n p = next_prime(p)\n c += 1\n sleep(.25)\n \"\"\"\n def __call__(self, f=None, layout=None, width=None, style=None, update_args=None, auto_update=True, flicker=False, output=True):\n if f is None:\n return _interact_layout(layout, width, style, update_args, auto_update, flicker)\n else:\n return salvus.interact(f, layout=layout, width=width, style=style,\n update_args=update_args, auto_update=auto_update, flicker=flicker, output=output)\n\n def __setattr__(self, arg, value):\n I = interact_exec_stack[-1]\n if arg in I._controls and not isinstance(value, control):\n # setting value of existing control\n v = I._controls[arg].convert_to_client(value)\n desc = {'var':arg, 'default':v}\n I._last_vals[arg] = value\n else:\n # create a new control\n new_control = interact_control(arg, value)\n I._controls[arg] = new_control\n desc = new_control.jsonable()\n desc['id'] = I._uuid\n salvus.javascript(\"worksheet.set_interact_var(obj)\", obj=desc)\n\n def __delattr__(self, arg):\n try:\n del interact_exec_stack[-1]._controls[arg]\n except KeyError:\n pass\n desc['id'] = I._uuid\n salvus.javascript(\"worksheet.del_interact_var(obj)\", obj=jsonable(arg))\n\n def __getattr__(self, arg):\n try:\n return interact_exec_stack[-1]._last_vals[arg]\n except Exception as err:\n raise AttributeError(\"no interact control corresponding to input variable '%s'\"%arg)\n\n def changed(self):\n \"\"\"\n Return the variables that changed since last evaluation of the interact function\n body. [SALVUS only]\n\n For example::\n\n @interact\n def f(n=True, m=False, xyz=[1,2,3]):\n print n, m, xyz, interact.changed()\n \"\"\"\n return interact_exec_stack[-1].changed\n"}}︡{"done":true}︡ ︠4158b284-d4e2-4531-b146-502bf42e71d1︠