Ticket #6840: trac_6840-notebook-documentation-v2.patch
File trac_6840-notebook-documentation-v2.patch, 112.6 KB (added by , 13 years ago) |
---|
-
doc/en/reference/notebook.rst
# HG changeset patch # User Mitesh Patel <qed777@gmail.com> # Date 1249912330 25200 # Node ID 37265ae04e84b07cd71367819c6e85ccfbeb18f8 # Parent 832b4605800675c661715a511041de9ea77904a7 #6840 Fixes documentation for sage.server.* diff -r 832b46058006 -r 37265ae04e84 doc/en/reference/notebook.rst
a b 11 11 sage/server/notebook/worksheet 12 12 sage/server/notebook/twist 13 13 14 sage/server/notebook/interact 14 15 sage/server/notebook/js 15 16 sage/server/notebook/config 16 17 sage/server/notebook/css 18 sage/server/notebook/docHTMLProcessor 19 sage/server/notebook/template 17 20 21 sage/server/misc 18 22 sage/server/support 19 23 sage/server/introspect 20 24 -
sage/server/introspect.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/introspect.py
a b 1 1 """ 2 Sage Notebook :Introspection2 Sage Notebook Introspection 3 3 4 4 TODO: - add support for grabbing source code from Pyrex functions 5 5 (even if not perfect is better than nothing). - PNG or MathML -
sage/server/misc.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/misc.py
a b 1 1 """ 2 Misc code useful for the notebook2 Miscellaneous Notebook Functions 3 3 """ 4 4 5 5 ############################################################################# … … 24 24 secure -- bool (default: False); whether to put HTTP or HTTPS 25 25 path -- path after the port. 26 26 27 EXAMPLES: 27 EXAMPLES:: 28 28 29 sage: sage.server.misc.print_open_msg('localhost', 8000, True) 29 30 **************************************************** 30 31 * * … … 84 85 OUTPUT: 85 86 an integer, or if no port is found, raises a RuntimError exception 86 87 87 EXAMPLES: 88 EXAMPLES:: 89 88 90 sage: sage.server.misc.find_next_available_port(9000, verbose=False) # random output -- depends on network 89 91 9002 90 92 """ -
sage/server/notebook/avatars.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/avatars.py
a b 28 28 OUTPUT: 29 29 string -- 'invalid_user', 'admin', 'user' 30 30 31 EXAMPLES: 31 EXAMPLES:: 32 32 33 sage: import sage.server.notebook.twist 33 34 sage: import sage.server.notebook.avatars as avatars 34 35 sage: avatars.user_type(avatars.FailedLogin('fake')) -
sage/server/notebook/cell.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/cell.py
a b 1910 1910 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 1911 1911 sage: nb.add_user('sage','sage','sage@sagemath.org',force=True) 1912 1912 sage: W = nb.create_new_worksheet('Test', 'sage') 1913 sage: C = sage.server.notebook.cell.Cell(0, 'plot(sin(x),0,5)', ", W)1913 sage: C = sage.server.notebook.cell.Cell(0, 'plot(sin(x),0,5)', '', W) 1914 1914 sage: C.evaluate() 1915 1915 sage: W.check_comp(wait=9999) 1916 1916 ('d', Cell 0; in=plot(sin(x),0,5), out= … … 1937 1937 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 1938 1938 sage: nb.add_user('sage','sage','sage@sagemath.org',force=True) 1939 1939 sage: W = nb.create_new_worksheet('Test', 'sage') 1940 sage: C = sage.server.notebook.cell.Cell(0, 'plot(sin(x),0,5)', ", W)1940 sage: C = sage.server.notebook.cell.Cell(0, 'plot(sin(x),0,5)', '', W) 1941 1941 sage: C.evaluate() 1942 1942 sage: W.check_comp(wait=9999) 1943 1943 ('d', Cell 0; in=plot(sin(x),0,5), out= -
sage/server/notebook/config.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/config.py
a b 1 1 """ 2 Customization of theNotebook Keybindings2 Notebook Keybindings 3 3 4 4 This module is responsible for setting the keyboard bindings for the notebook. 5 5 """ -
sage/server/notebook/css.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/css.py
a b 1 1 """nodoctest 2 Sage Notebook CSS 2 Notebook Stylesheets (CSS) 3 3 """ 4 4 5 5 -
sage/server/notebook/docHTMLProcessor.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/docHTMLProcessor.py
a b 35 35 This function is called by SGMLParser.__init__ so all necessary things 36 36 are initialized here. 37 37 38 EXAMPLES: 38 EXAMPLES:: 39 39 40 sage: from sage.server.notebook.docHTMLProcessor import SphinxHTMLProcessor 40 41 sage: d = SphinxHTMLProcessor() 41 42 sage: d.bodyQ … … 103 104 Returns the current cell count and increments it 104 105 by one. 105 106 106 EXAMPLES: 107 EXAMPLES:: 108 107 109 sage: from sage.server.notebook.docHTMLProcessor import SphinxHTMLProcessor 108 110 sage: d = SphinxHTMLProcessor() 109 111 sage: d.get_cellcount() … … 217 219 """ 218 220 This just sets self.bodyQ to True once we've hit the body tag. 219 221 220 EXAMPLES: 222 EXAMPLES:: 223 221 224 sage: from sage.server.notebook.docHTMLProcessor import SphinxHTMLProcessor 222 225 sage: d = SphinxHTMLProcessor() 223 226 sage: d.bodyQ -
sage/server/notebook/interact.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/interact.py
a b 6 6 ############################################################################# 7 7 8 8 r""" 9 Interact Sage functions in the notebook9 Interact Functions in the Notebook 10 10 11 This module implements a interact decorator for function inthe Sage11 This module implements an ``interact`` function decorator for the Sage 12 12 notebook. 13 13 14 14 AUTHORS: 15 -- William Stein (2008-03-02): version 1.0 at Sage/Enthought Days 8 in Texas 15 16 -- William Stein (2008-03-02): version 1.0 at Sage/Enthought Days 17 8 in Texas 18 16 19 -- Jason Grout (2008-03): discussion and first few prototypes 17 -- Jason Grout (2008-05): input_grid control 20 21 -- Jason Grout (2008-05): ``input_grid`` control 18 22 """ 19 23 20 24 """ … … 158 162 159 163 def reset_state(): 160 164 """ 161 Reset the interactstate of this sage process.165 Reset the ``interact`` state of this sage process. 162 166 163 EXAMPLES: 167 EXAMPLES:: 168 164 169 sage: sage.server.notebook.interact.state # random output 165 170 {1: {'function': <function g at 0x72aaab0>, 'variables': {'m': 3, 'n': 5}, 'adapt': {1: <bound method Slider._adaptor of Slider Interact Control: n [1--|1|---10].>, 2: <bound method Slider._adaptor of Slider Interact Control: m [1--|1|---10].>}}} 166 171 sage: from sage.server.notebook.interact import reset_state … … 174 179 _k = 0 175 180 def new_adapt_number(): 176 181 """ 177 Return an integer, always counting up, and starting with 0. This182 Return an integer, always counting up, and starting with ``0``. This 178 183 is used for saving the adapt methods for controls. An adapt 179 184 method is just a function that coerces data into some object, 180 185 e.g., makes sure the control always produces int's. 181 186 182 187 OUTPUT: 188 183 189 integer 184 190 185 EXAMPLES: 191 EXAMPLES:: 192 186 193 sage: sage.server.notebook.interact.new_adapt_number() # random output -- depends on when called 187 194 1 188 195 """ … … 193 200 194 201 def html(s): 195 202 """ 196 Render the input string sin a form that tells the notebook203 Render the input string ``s`` in a form that tells the notebook 197 204 to display it in the HTML portion of the output. 198 205 199 206 INPUT: 200 s -- a string 207 208 ``s`` -- a string 201 209 202 210 OUTPUT: 203 string -- html format204 211 205 EXAMPLES: 212 string -- HTML format 213 214 EXAMPLES:: 215 206 216 sage: sage.server.notebook.interact.html('hello') 207 217 <html>hello</html> 208 218 """ … … 213 223 Return the HTML representation of a jQuery slider. 214 224 215 225 INPUT: 216 id -- string -- the DOM id of the slider (better be unique) 217 values -- 'null' or javascript string containing array of values on slider 218 callback-- javascript that is executed whenever the slider is done moving 219 steps -- number of steps from minimum to maximum value. 220 default -- (default: 0) the default position of the slider 221 margin -- (default: 0) size of margin to insert around the slider 226 227 ``id`` -- string -- the DOM id of the slider (better be unique) 228 229 ``values`` -- 'null' or JavaScript string containing array of 230 values on slider 231 232 ``callback`` -- JavaScript that is executed whenever the 233 slider is done moving 234 235 ``steps`` -- number of steps from minimum to maximum value. 236 237 ``default`` -- (default: ``0``) the default position of the 238 slider 239 240 ``margin`` -- (default: ``0``) size of margin to insert around 241 the slider 222 242 223 243 EXAMPLES: 244 224 245 We create a jQuery HTML slider. If you do the following in the notebook 225 246 you should obtain a slider that when moved pops up a window showing its 226 current position. 247 current position:: 248 227 249 sage: from sage.server.notebook.interact import html_slider, html 228 250 sage: html(html_slider('slider-007', 'null', 'alert(position)', steps=5, default=2, margin=5)) 229 251 <html>...</html> … … 257 279 Return the HTML representation of a jQuery range slider. 258 280 259 281 INPUT: 260 id -- string -- the DOM id of the slider (better be unique) 261 values -- 'null' or javascript string containing array of values on slider 262 callback-- javascript that is executed whenever the slider is done moving 263 steps -- number of steps from minimum to maximum value. 264 default_l -- (default: 0) the default position of the left edge of the slider 265 default_r -- (default: 1) the default position of the right edge of the slider 266 margin -- (default: 0) size of margin to insert around the slider 282 283 ``id`` -- string -- the DOM id of the slider (better be 284 unique) 285 286 ``values`` -- 'null' or JavaScript string containing array of 287 values on slider 288 289 ``callback`` -- JavaScript that is executed whenever the 290 slider is done moving 291 292 ``steps`` -- number of steps from minimum to maximum value. 293 294 ``default_l`` -- (default: ``0``) the default position of the left 295 edge of the slider 296 297 ``default_r`` -- (default: ``1``) the default position of the 298 right edge of the slider 299 300 ``margin`` -- (default: ``0``) size of margin to insert around the 301 slider 267 302 268 303 EXAMPLES: 269 We create a jQuery range slider. If you do the following in the notebook 270 you should obtain a slider that when moved pops up a window showing its 271 current position. 304 305 We create a jQuery range slider. If you do the following in the 306 notebook you should obtain a slider that when moved pops up a 307 window showing its current position:: 308 272 309 sage: from sage.server.notebook.interact import html_rangeslider, html 273 310 sage: html(html_rangeslider('slider-007', 'null', 'alert(pos[0]+", "+pos[1])', steps=5, default_l=2, default_r=3, margin=5)) 274 311 <html>...</html> … … 324 361 Return HTML representation of a jQuery color selector. 325 362 326 363 INPUT: 327 id -- integer; the id of the html div element that this selector should have 328 change -- javascript code to execute when the color selector changes. 329 default -- string (default: '000000'); default color as a 6-character 330 HTML hex string. 364 365 ``id`` -- integer; the id of the HTML div element that this 366 selector should have 367 368 ``change`` -- JavaScript code to execute when the color 369 selector changes. 370 371 ``default`` -- string (default: ``'000000'``); default color as a 372 6-character HTML hex string. 331 373 332 374 OUTPUT: 375 333 376 string -- HTML that creates the slider. 334 377 335 EXAMPLES: 378 EXAMPLES:: 379 336 380 sage: sage.server.notebook.interact.html_color_selector(0, 'alert("changed")', '', default='0afcac') 337 381 '<table>...' 338 382 """ … … 366 410 Returns an empty label for this element. This should be 367 411 overridden for subclasses that need a label. 368 412 369 EXAMPLES: 413 EXAMPLES:: 414 370 415 sage: from sage.server.notebook.interact import UpdateButton, InteractElement 371 416 sage: b = UpdateButton(1) 372 417 sage: isinstance(b, InteractElement) … … 378 423 379 424 def set_canvas(self, canvas): 380 425 """ 381 Sets the InteractCanvas on which this element appears. This382 method is primarily called in the constructor for383 InteractCanvas.426 Sets the ``InteractCanvas`` on which this element appears. 427 This method is primarily called in the constructor for 428 ``InteractCanvas``. 384 429 385 EXAMPLES: 430 EXAMPLES:: 431 386 432 sage: from sage.server.notebook.interact import InputBox, InteractCanvas 387 433 sage: B = InputBox('x',2) 388 434 sage: canvas1 = InteractCanvas([B], 3) … … 398 444 399 445 def canvas(self): 400 446 """ 401 Returns the InteractCanvas associated to this element. If no402 canvas has been set (via the set_canvas method), then this403 will return a ValueError.447 Returns the ``InteractCanvas`` associated to this element. If 448 no canvas has been set (via the ``set_canvas`` method), then 449 this will return a ``ValueError``. 404 450 405 EXAMPLES: 451 EXAMPLES:: 452 406 453 sage: from sage.server.notebook.interact import InputBox, InteractCanvas 407 454 sage: B = InputBox('x',2) 408 455 sage: canvas1 = InteractCanvas([B], 3) … … 420 467 class InteractControl(InteractElement): 421 468 def __init__(self, var, default_value, label=None): 422 469 """ 423 Abstract base class for interactcontrols. These are controls424 that are used in a specific interact. They have internal425 state information about the specific function being interact d,470 Abstract base class for ``interact`` controls. These are controls 471 that are used in a specific ``interact``. They have internal 472 state information about the specific function being interacted, 426 473 etc. 427 474 428 475 INPUT: 429 var -- string; name of variable that this control interacts430 default_value -- the default value of the variable431 corresponding to this control.432 label -- string (default: None) label of this control; if None433 then defaults to var.434 476 435 EXAMPLES: 477 ``var`` -- string; name of variable that this control 478 interacts 479 480 ``default_value`` -- the default value of the variable 481 corresponding to this control. 482 483 ``label`` -- string (default: ``None``) label of this 484 control; if ``None`` then defaults to ``var``. 485 486 EXAMPLES:: 487 436 488 sage: from sage.server.notebook.interact import InteractControl 437 489 sage: InteractControl('x', default_value=5) 438 490 A InteractControl (abstract base class) … … 450 502 451 503 def __repr__(self): 452 504 """ 453 String representation of interactcontrol.505 String representation of ``interact`` control. 454 506 455 EXAMPLES: 507 EXAMPLES:: 508 456 509 sage: from sage.server.notebook.interact import InteractControl 457 510 sage: InteractControl('x', default_value=5).__repr__() 458 511 'A InteractControl (abstract base class)' … … 461 514 462 515 def value_js(self): 463 516 """ 464 Java script that when evaluated gives the current value of this517 JavaScript that when evaluated gives the current value of this 465 518 control. This should be redefined in a derived class. 466 519 467 520 OUTPUT: 468 string -- defaults to NULL -- this should be redefined.469 521 470 EXAMPLES: 522 string -- defaults to ``'NULL'`` -- this should be redefined. 523 524 EXAMPLES:: 525 471 526 sage: sage.server.notebook.interact.InteractControl('x', default_value=5).value_js() 472 527 'NULL' 473 528 """ … … 475 530 476 531 def label(self): 477 532 """ 478 Return the text label of this interactcontrol.533 Return the text label of this ``interact`` control. 479 534 480 EXAMPLES: 535 EXAMPLES:: 536 481 537 sage: from sage.server.notebook.interact import InteractControl 482 538 sage: InteractControl('x', default_value=5, label='the x value').label() 483 539 'the x value' … … 487 543 def default_value(self): 488 544 """ 489 545 Return the default value of the variable corresponding to this 490 interactcontrol.546 ``interact`` control. 491 547 492 548 OUTPUT: 549 493 550 object 494 551 495 EXAMPLES: 552 EXAMPLES:: 553 496 554 sage: from sage.server.notebook.interact import InteractControl 497 555 sage: InteractControl('x', 19/3).default_value() 498 556 19/3 … … 502 560 def html_escaped_default_value(self): 503 561 """ 504 562 Returns the HTML escaped default value of the variable 505 corresponding to this interactcontrol. Note that any506 HTML that uses quotes around this should use double 507 quotes andnot single quotes.563 corresponding to this ``interact`` control. Note that any 564 HTML that uses quotes around this should use double quotes and 565 not single quotes. 508 566 509 EXAMPLES: 567 EXAMPLES:: 568 510 569 sage: from sage.server.notebook.interact import InteractControl 511 570 sage: InteractControl('x', '"cool"').html_escaped_default_value() 512 571 '"cool"' … … 528 587 called to adapt the values of this control to Python. 529 588 530 589 OUTPUT: 590 531 591 an integer 532 592 533 EXAMPLES: 593 EXAMPLES:: 594 534 595 sage: from sage.server.notebook.interact import InteractControl 535 596 sage: InteractControl('x', 19/3).adapt_number() # random -- depends on call order 536 597 2 … … 543 604 by this control. 544 605 545 606 INPUT: 546 value -- the string the user typed in 547 globs -- the globals interpreter variables, e.g., 548 globals(), which is useful for evaling value. 607 608 ``value`` -- the string the user typed in 609 610 ``globs`` -- the globals interpreter variables, e.g., 611 ``globals()``, which is useful for evaling value. 549 612 550 613 OUTPUT: 614 551 615 object 552 616 553 EXAMPLES: 617 EXAMPLES:: 618 554 619 sage: sage.server.notebook.interact.InteractControl('x', 1)._adaptor('2/3', globals()) 555 620 2/3 556 621 """ … … 558 623 559 624 def interact(self, *args): 560 625 """ 561 Return a string that when evaluated in Java script calls the562 javascript interactfunction with appropriate inputs for626 Return a string that when evaluated in JavaScript calls the 627 JavaScript ``interact`` function with appropriate inputs for 563 628 this control. 564 629 565 630 This method will check to see if there is a canvas attached to … … 569 634 automatically update. 570 635 571 636 OUTPUT: 572 string -- that is meant to be evaluated in Javascript573 637 574 EXAMPLES: 638 string -- that is meant to be evaluated in JavaScript 639 640 EXAMPLES:: 641 575 642 sage: sage.server.notebook.interact.InteractControl('x', 1).interact() 576 643 'interact(..., "sage.server.notebook.interact.update(..., \\"x\\", ..., sage.server.notebook.interact.standard_b64decode(\\""+encode64(NULL)+"\\"), globals());sage.server.notebook.interact.recompute(0)")' 577 644 """ … … 599 666 Return the name of the variable that this control interacts. 600 667 601 668 OUTPUT: 669 602 670 string -- name of a variable as a string. 603 671 604 EXAMPLES: 672 EXAMPLES:: 673 605 674 sage: sage.server.notebook.interact.InteractControl('theta', 1).var() 606 675 'theta' 607 676 """ … … 609 678 610 679 def cell_id(self): 611 680 """ 612 Return the id of the cell that contains this interactcontrol.681 Return the id of the cell that contains this ``interact`` control. 613 682 614 683 OUTPUT: 684 615 685 integer -- id of cell that this control interacts 616 686 617 687 EXAMPLES: 618 The output below should equal the ID of the current cell. 688 689 The output below should equal the id of the current cell:: 690 619 691 sage: sage.server.notebook.interact.InteractControl('theta', 1).cell_id() 620 692 0 621 693 """ … … 624 696 class InputBox(InteractControl): 625 697 def __init__(self, var, default_value, label=None, type=None, width = 80): 626 698 """ 627 An input box interactcontrol.699 An input box ``interact`` control. 628 700 629 InputBox(var, default_value, label, type)701 ``InputBox(var, default_value, label, type)`` 630 702 631 EXAMPLES: 703 EXAMPLES:: 704 632 705 sage: sage.server.notebook.interact.InputBox('theta', 1, 'theta') 633 706 An InputBox interactive control with theta=1 and label 'theta' 634 707 sage: sage.server.notebook.interact.InputBox('theta', 1, 'theta', int) … … 640 713 641 714 def __repr__(self): 642 715 """ 643 String representation of an InputBoxinteractive control.716 String representation of an ``InputBox`` interactive control. 644 717 645 EXAMPLES: 718 EXAMPLES:: 719 646 720 sage: sage.server.notebook.interact.InputBox('theta', 1).__repr__() 647 721 "An InputBox interactive control with theta=1 and label 'theta'" 648 722 """ … … 655 729 element selected by this control. 656 730 657 731 INPUT: 658 value -- text entered by user 659 globs -- the globals interpreter variables (not used here). 732 733 ``value`` -- text entered by user 734 ``globs`` -- the ``globals`` interpreter variables (not used here). 660 735 661 736 OUTPUT: 737 662 738 object 663 739 664 EXAMPLES: 740 EXAMPLES:: 741 665 742 sage: sage.server.notebook.interact.InputBox('theta', Color('red'), type=Color)._adaptor('#aaaaaa',globals()) 666 743 RGB color (0.6640625, 0.6640625, 0.6640625) 667 744 """ … … 676 753 677 754 def value_js(self): 678 755 """ 679 Return javascript string that will give the value of this756 Return JavaScript string that will give the value of this 680 757 control element. 681 758 682 759 OUTPUT: 683 string -- javascript684 760 685 EXAMPLES: 761 string -- JavaScript 762 763 EXAMPLES:: 764 686 765 sage: sage.server.notebook.interact.InputBox('theta', 1).value_js() 687 766 'this.value' 688 767 """ … … 696 775 Render this control as a string. 697 776 698 777 OUTPUT: 699 string -- html format700 778 701 EXAMPLES: 779 string -- HTML format 780 781 EXAMPLES:: 782 702 783 sage: sage.server.notebook.interact.InputBox('theta', 1).render() 703 784 '<input type=\'text\' value="1" size=80 onchange=\'interact(0, "sage.server.notebook.interact.update(0, \\"theta\\", ..., sage.server.notebook.interact.standard_b64decode(\\""+encode64(this.value)+"\\"), globals());sage.server.notebook.interact.recompute(0)")\'></input>' 704 785 """ … … 715 796 class ColorInput(InputBox): 716 797 def value_js(self, n): 717 798 """ 718 Return javascript that evaluates to value of this control.799 Return JavaScript that evaluates to value of this control. 719 800 720 801 INPUT: 721 n -- integer, either 0 or 1.722 802 723 If n is 0 return code for evaluation by the actual color control. 724 If n is 1, return code for the text area that displays the current color. 803 ``n`` -- integer, either ``0`` or ``1``. 725 804 726 EXAMPLES: 805 If ``n`` is ``0`` return code for evaluation by the actual color 806 control. If ``n`` is ``1``, return code for the text area that 807 displays the current color. 808 809 EXAMPLES:: 810 727 811 sage: C = sage.server.notebook.interact.ColorInput('c', Color('red')) 728 812 sage: C.value_js(0) 729 813 'color' … … 737 821 738 822 def render(self): 739 823 """ 740 Render this color input box to html.824 Render this color input box to HTML. 741 825 742 EXAMPLES: 826 EXAMPLES:: 827 743 828 sage: sage.server.notebook.interact.ColorInput('c', Color('red')).render() 744 829 '<table>...' 745 830 """ … … 754 839 """ 755 840 A grid interact control. 756 841 757 INPUT 758 var -- the variable 759 rows -- the number of rows 760 columns -- the number of columns 761 default_value -- if this is a scalar, it is put in every 762 cell; if it is a list, it is filled into the cells row by 763 row; if it is a nested list, then it is filled into the 764 cells according to the nesting structure. 765 label -- the label for the control 766 to_value -- a function which is applied to the nested list 767 from user input when assigning the variable 768 width -- the width of the input boxes 842 INPUT: 769 843 770 EXAMPLES: 844 ``var`` -- the variable 845 846 ``rows`` -- the number of rows 847 848 ``columns`` -- the number of columns 849 850 ``default_value`` -- if this is a scalar, it is put in 851 every cell; if it is a list, it is filled into the cells 852 row by row; if it is a nested list, then it is filled into 853 the cells according to the nesting structure. 854 855 ``label`` -- the label for the control 856 857 ``to_value`` -- a function which is applied to the nested 858 list from user input when assigning the variable 859 860 ``width`` -- the width of the input boxes 861 862 EXAMPLES:: 863 771 864 sage: sage.server.notebook.interact.InputGrid('M', 2,2, default_value = 0, label='M') 772 865 A 2 x 2 InputGrid interactive control with M=[[0, 0], [0, 0]] and label 'M' 773 866 sage: sage.server.notebook.interact.InputGrid('M', 2,2, default_value = [[1,2],[3,4]], label='M') … … 795 888 796 889 def __repr__(self): 797 890 """ 798 String representation of an InputGridinteractive control.891 String representation of an ``InputGrid`` interactive control. 799 892 800 EXAMPLES: 893 EXAMPLES:: 894 801 895 sage: sage.server.notebook.interact.InputGrid('M', 2,2).__repr__() 802 896 "A 2 x 2 InputGrid interactive control with M=[[None, None], [None, None]] and label 'M'" 803 897 """ … … 812 906 element selected by this control. 813 907 814 908 INPUT: 815 value -- text entered by user 816 globs -- the globals interpreter variables (not used here). 909 910 ``value`` -- text entered by user 911 912 ``globs`` -- the ``globals`` interpreter variables (not 913 used here). 817 914 818 915 OUTPUT: 916 819 917 object 820 918 821 EXAMPLES: 919 EXAMPLES:: 920 822 921 sage: sage.server.notebook.interact.InputGrid('M', 1,3, default_value=[[1,2,3]], to_value=lambda x: vector(flatten(x)))._adaptor("[[4,5,6]]", globals()) 823 922 (4, 5, 6) 824 923 """ … … 827 926 828 927 def value_js(self): 829 928 """ 830 Return javascript string that will give the value of this929 Return JavaScript string that will give the value of this 831 930 control element. 832 931 833 932 OUTPUT: 834 string -- javascript835 933 836 EXAMPLES: 934 string -- JavaScript 935 936 EXAMPLES:: 937 837 938 sage: sage.server.notebook.interact.InputGrid('M', 2,2).value_js() 838 939 ' "[["+jQuery(this).parents("table").eq(0).find("tr").map(function(){return jQuery(this).find("input").map(function() {return jQuery(this).val();}).get().join(",");}).get().join("],[")+"]]" ' 839 940 """ … … 848 949 Render this control as a string. 849 950 850 951 OUTPUT: 851 string -- html format852 952 853 EXAMPLES: 953 string -- HTML format 954 955 EXAMPLES:: 956 854 957 sage: sage.server.notebook.interact.InputGrid('M', 1,2).render() 855 958 '<table><tr><td><input type=\'text\' value=\'None\' ... 856 959 … … 874 977 A drop down menu or a button bar that when pressed sets a 875 978 variable to a given value. 876 979 877 Selector(var, values, label=None, nrows=None, ncols=None)980 ``Selector(var, values, label=None, nrows=None, ncols=None)`` 878 981 879 982 INPUT: 880 var -- string; variable name881 values-- list; button values882 label -- string (default: None) label off to the left for this button group883 default -- integer (default: 0) position of default value in values list.884 nrows -- integer (default: None) number of rows885 ncols -- integer (default: None) number of columns886 width -- integer (default: None) width of all the buttons887 buttons -- bool (default: False) if True use buttons instead of dropdown888 983 889 EXAMPLES: 984 ``var`` -- string; variable name 985 986 ``values`` -- list; button values 987 988 ``label`` -- string (default: ``None``) label off to the 989 left for this button group 990 991 ``default`` -- integer (default: ``0``) position of default 992 value in values list. 993 994 ``nrows`` -- integer (default: ``None``) number of rows 995 996 ``ncols`` -- integer (default: ``None``) number of columns 997 998 ``width`` -- integer (default: ``None``) width of all the buttons 999 1000 ``buttons`` -- bool (default: ``False``) if ``True`` use 1001 buttons instead of dropdown 1002 1003 EXAMPLES:: 1004 890 1005 sage: sage.server.notebook.interact.Selector('x', [1..5], 'alpha', default=2) 891 1006 Selector with 5 options for variable 'x' 892 1007 sage: sage.server.notebook.interact.Selector('x', [1..4], 'alpha', default=2, nrows=2, ncols=2, width=10, buttons=True) … … 937 1052 938 1053 def __repr__(self): 939 1054 """ 940 String representation of a Selectorinteractive control.1055 String representation of a ``Selector`` interactive control. 941 1056 942 EXAMPLES: 1057 EXAMPLES:: 1058 943 1059 sage: sage.server.notebook.interact.Selector('x', [1..5]).__repr__() 944 1060 "Selector with 5 options for variable 'x'" 945 1061 """ … … 953 1069 it to be the value that we associate with that button. 954 1070 955 1071 INPUT: 956 value -- value sent in via javascript 957 globs -- the globals interpreter variables (not used here). 1072 1073 ``value` -- value sent in via JavaScript 1074 1075 ``globs`` -- the ``globals`` interpreter variables (not 1076 used here). 958 1077 959 1078 OUTPUT: 1079 960 1080 object 961 1081 962 EXAMPLES: 1082 EXAMPLES:: 1083 963 1084 sage: S = sage.server.notebook.interact.Selector('x', ['first',x^3+5]) 964 1085 sage: S._adaptor(0,globals()) 965 1086 'first' … … 970 1091 971 1092 def use_buttons(self): 972 1093 """ 973 Whether or not to use buttons instead of a drop 974 down menu forthis select list.1094 Whether or not to use buttons instead of a drop down menu for 1095 this select list. 975 1096 976 1097 OUTPUT: 1098 977 1099 bool 978 1100 979 EXAMPLES: 1101 EXAMPLES:: 1102 980 1103 sage: sage.server.notebook.interact.Selector('x', [1..5]).use_buttons() 981 1104 False 982 1105 sage: sage.server.notebook.interact.Selector('x', [1..5], buttons=True).use_buttons() … … 986 1109 987 1110 def value_js(self): 988 1111 """ 989 Return javascript string that will give the value of this1112 Return JavaScript string that will give the value of this 990 1113 control element. 991 1114 992 1115 OUTPUT: 993 string -- javascript994 1116 995 EXAMPLES: 1117 string -- JavaScript 1118 1119 EXAMPLES:: 1120 996 1121 sage: sage.server.notebook.interact.Selector('x', [1..5]).value_js() 997 1122 'this.options[this.selectedIndex].value' 998 1123 sage: sage.server.notebook.interact.Selector('x', [1..5], buttons=True).value_js() … … 1009 1134 Render this control as a string. 1010 1135 1011 1136 OUTPUT: 1012 string -- html format1013 1137 1014 EXAMPLES: 1138 string -- HTML format 1139 1140 EXAMPLES:: 1141 1015 1142 sage: sage.server.notebook.interact.Selector('x', [1..5]).render() 1016 1143 '<select...</select>' 1017 1144 sage: sage.server.notebook.interact.Selector('x', [1..5], buttons=True).render() … … 1066 1193 class SliderGeneric(InteractControl): 1067 1194 def __init__(self, var, values, default_value, label=None, display_value=True): 1068 1195 """ 1069 An abstract slider interact control that takes on the given list of1070 values.1196 An abstract slider ``interact`` control that takes on the 1197 given list of values. 1071 1198 1072 1199 INPUT: 1073 var -- string; name of variable being interactd1074 values -- list; a list of the values that the slider will take on1075 default_value -- default valueoif slider.1076 label -- alternative label to the left of the slider,1077 instead of the variable.1078 display_value -- boolean, whether to display the current value1079 on the slider1080 1200 1081 EXAMPLES: 1201 ``var`` -- string; name of variable being interacted 1202 1203 ``values`` -- list; a list of the values that the slider 1204 will take on 1205 1206 ``default_value`` -- default value of the slider. 1207 1208 ``label`` -- alternative label to the left of the slider, 1209 instead of the variable. 1210 1211 ``display_value`` -- boolean, whether to display the 1212 current value on the slider 1213 1214 EXAMPLES:: 1215 1082 1216 sage: sage.server.notebook.interact.SliderGeneric('x', [1..5], 2, 'alpha') 1083 1217 Abstract Slider Interact Control: alpha [1--|2|---5] 1084 1218 """ … … 1090 1224 """ 1091 1225 Return string representation of this slider control. 1092 1226 1093 EXAMPLES: 1227 EXAMPLES:: 1228 1094 1229 sage: sage.server.notebook.interact.SliderGeneric('x', [1..5], 2, 'alpha').__repr__() 1095 1230 'Abstract Slider Interact Control: alpha [1--|2|---5]' 1096 1231 """ … … 1103 1238 Return list of values the slider acts on. 1104 1239 1105 1240 OUTPUT: 1241 1106 1242 list 1107 1243 1108 EXAMPLES: 1244 EXAMPLES:: 1245 1109 1246 sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha').values() 1110 1247 [1, 2, 3, 4, 5] 1111 1248 """ … … 1116 1253 Returns whether to display the value on the slider. 1117 1254 1118 1255 OUTPUT: 1119 boolean 1256 1257 bool 1120 1258 1121 EXAMPLES: 1259 EXAMPLES:: 1260 1122 1261 sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha').display_value() 1123 1262 True 1124 1263 """ … … 1126 1265 1127 1266 def values_js(self): 1128 1267 """ 1129 Returns Javascript array representation of values or null if display_value is False 1268 Returns JavaScript array representation of values or ``'null'`` if 1269 ``display_value=False`` 1130 1270 1131 1271 OUTPUT: 1272 1132 1273 string 1133 1274 1134 EXAMPLES: 1275 EXAMPLES:: 1276 1135 1277 sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha').values_js() 1136 1278 '["1","2","3","4","5"]' 1137 1279 sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha', False).values_js() … … 1152 1294 class Slider(SliderGeneric): 1153 1295 def __init__(self, var, values, default_position, label=None, display_value=True): 1154 1296 """ 1155 A slider interactcontrol that takes on the given list of1297 A slider ``interact`` control that takes on the given list of 1156 1298 values. 1157 1299 1158 1300 INPUT: 1159 var -- string; name of variable being interactd1160 values -- list; a list of the values that the slider will take on1161 default_position -- int; default location that the slider is set to.1162 label -- alternative label to the left of the slider,1163 instead of the variable.1164 display_value -- boolean, whether to display the current value right1165 of the slider1166 1301 1167 EXAMPLES: 1302 ``var`` -- string; name of variable being interacted 1303 1304 ``values`` -- list; a list of the values that the slider 1305 will take on 1306 1307 ``default_position`` -- int; default location that the 1308 slider is set to. 1309 1310 ``label`` -- alternative label to the left of the slider, 1311 instead of the variable. 1312 1313 ``display_value`` -- boolean, whether to display the 1314 current value right of the slider 1315 1316 EXAMPLES:: 1317 1168 1318 sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha') 1169 1319 Slider Interact Control: alpha [1--|3|---5] 1170 1320 """ … … 1175 1325 """ 1176 1326 Return string representation of this slider control. 1177 1327 1178 EXAMPLES: 1328 EXAMPLES:: 1329 1179 1330 sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha').__repr__() 1180 1331 'Slider Interact Control: alpha [1--|3|---5]' 1181 1332 """ … … 1187 1338 """ 1188 1339 Return the default position (as an integer) of the slider. 1189 1340 1190 EXAMPLES: 1341 EXAMPLES:: 1342 1191 1343 sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha').default_position() 1192 1344 2 1193 1345 """ … … 1195 1347 1196 1348 def value_js(self): 1197 1349 """ 1198 Return javascript string that will give the1199 value of thiscontrol element.1350 Return JavaScript string that will give the value of this 1351 control element. 1200 1352 1201 1353 OUTPUT: 1202 string -- javascript1203 1354 1204 EXAMPLES: 1355 string -- JavaScript 1356 1357 EXAMPLES:: 1358 1205 1359 sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha').value_js() 1206 1360 'position' 1207 1361 """ … … 1213 1367 element selected by this control. 1214 1368 1215 1369 INPUT: 1216 position -- position of the slider 1217 globs -- the globals interpreter variables (not used here). 1370 1371 ``position`` -- position of the slider 1372 1373 ``globs`` -- the ``globals`` interpreter variables (not used here). 1218 1374 1219 1375 OUTPUT: 1376 1220 1377 object 1221 1378 1222 EXAMPLES: 1379 EXAMPLES:: 1380 1223 1381 sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha')._adaptor(2,globals()) 1224 1382 3 1225 1383 """ … … 1233 1391 Render this control as an HTML string. 1234 1392 1235 1393 OUTPUT: 1236 string -- html format1237 1394 1238 EXAMPLES: 1395 string -- HTML format 1396 1397 EXAMPLES:: 1398 1239 1399 sage: sage.server.notebook.interact.Slider('x', [1..5], 2, 'alpha').render() 1240 1400 '<table>...<div ...var values = ["1","2","3","4","5"];...' 1241 1401 … … 1251 1411 class RangeSlider(SliderGeneric): 1252 1412 def __init__(self, var, values, default_position, label=None, display_value=True): 1253 1413 """ 1254 A range slider interact control that takes on the given list of1255 values.1414 A range slider ``interact`` control that takes on the given 1415 list of values. 1256 1416 1257 1417 INPUT: 1258 var -- string; name of variable being interactd1259 values -- list; a list of the values that the slider will take on1260 default_position -- (int,int); default location that the slider is set to.1261 label -- alternative label to the left of the slider,1262 instead of the variable.1263 display_value -- boolean, whether to display the current value below1264 the slider1265 1418 1266 EXAMPLES: 1419 ``var`` -- string; name of variable being interacted 1420 1421 ``values`` -- list; a list of the values that the slider 1422 will take on 1423 1424 ``default_position`` -- (int,int); default location that 1425 the slider is set to. 1426 1427 ``label`` -- alternative label to the left of the slider, 1428 instead of the variable. 1429 1430 ``display_value`` -- boolean, whether to display the 1431 current value below the slider 1432 1433 EXAMPLES:: 1434 1267 1435 sage: sage.server.notebook.interact.RangeSlider('x', [1..5], (2,3), 'alpha') 1268 1436 Range Slider Interact Control: alpha [1--|3==4|---5] 1269 1437 """ … … 1274 1442 """ 1275 1443 Return string representation of this slider control. 1276 1444 1277 EXAMPLES: 1445 EXAMPLES:: 1446 1278 1447 sage: sage.server.notebook.interact.RangeSlider('x', [1..5], (2,3), 'alpha').__repr__() 1279 1448 'Range Slider Interact Control: alpha [1--|3==4|---5]' 1280 1449 """ … … 1286 1455 """ 1287 1456 Return the default position (as an integer) of the slider. 1288 1457 1289 EXAMPLES: 1458 EXAMPLES:: 1459 1290 1460 sage: sage.server.notebook.interact.RangeSlider('x', [1..5], (2,3), 'alpha').default_position() 1291 1461 (2, 3) 1292 1462 """ … … 1294 1464 1295 1465 def value_js(self): 1296 1466 """ 1297 Return javascript string that will give the1298 value of thiscontrol element.1467 Return JavaScript string that will give the value of this 1468 control element. 1299 1469 1300 1470 OUTPUT: 1301 string -- javascript1302 1471 1303 EXAMPLES: 1472 string -- JavaScript 1473 1474 EXAMPLES:: 1475 1304 1476 sage: sage.server.notebook.interact.RangeSlider('x', [1..5], (2,3), 'alpha').value_js() 1305 1477 "pos[0]+' '+pos[1]" 1306 1478 """ … … 1312 1484 element selected by this control. 1313 1485 1314 1486 INPUT: 1315 position -- position of the slider 1316 globs -- the globals interpreter variables (not used here). 1487 1488 ``position`` -- position of the slider 1489 1490 ``globs` -- the ``globals`` interpreter variables (not 1491 used here). 1317 1492 1318 1493 OUTPUT: 1494 1319 1495 object 1320 1496 1321 EXAMPLES: 1497 EXAMPLES:: 1498 1322 1499 sage: sage.server.notebook.interact.RangeSlider('x', [1..5], (2,3), 'alpha')._adaptor("2 3",globals()) 1323 1500 (3, 4) 1324 1501 """ … … 1332 1509 Render this control as an HTML string. 1333 1510 1334 1511 OUTPUT: 1335 string -- html format1336 1512 1337 EXAMPLES: 1513 string -- HTML format 1514 1515 EXAMPLES:: 1516 1338 1517 sage: sage.server.notebook.interact.RangeSlider('x', [1..5], (2,3), 'alpha').render() 1339 1518 '<table>...<div ...var values = ["1","2","3","4","5"];...' 1340 1519 … … 1351 1530 class TextControl(InteractControl): 1352 1531 def __init__(self, var, data): 1353 1532 """ 1354 A text field interactcontrol1533 A text field ``interact`` control 1355 1534 1356 1535 INPUT: 1357 data -- the HTML value of the text field1358 1536 1359 EXAMPLES: 1537 ``data`` -- the HTML value of the text field 1538 1539 EXAMPLES:: 1540 1360 1541 sage: sage.server.notebook.interact.TextControl('x', 'something') 1361 1542 Text Interact Control: something 1362 1543 """ … … 1367 1548 """ 1368 1549 Return string representation of this control. 1369 1550 1370 EXAMPLES: 1551 EXAMPLES:: 1552 1371 1553 sage: sage.server.notebook.interact.TextControl('x', 'something').__repr__() 1372 1554 'Text Interact Control: something' 1373 1555 """ … … 1378 1560 Render this control as an HTML string. 1379 1561 1380 1562 OUTPUT: 1381 string -- html format1382 1563 1383 EXAMPLES: 1564 string -- HTML format 1565 1566 EXAMPLES:: 1567 1384 1568 sage: sage.server.notebook.interact.TextControl('x', 'something').render() 1385 1569 '<div ...>something</div>' 1386 1570 """ … … 1415 1599 """ 1416 1600 Print representation of an interactive canvas. 1417 1601 1418 EXAMPLES: 1602 EXAMPLES:: 1603 1419 1604 sage: B = sage.server.notebook.interact.InputBox('x',2) 1420 1605 sage: sage.server.notebook.interact.InteractCanvas([B], 3).__repr__() 1421 1606 'Interactive canvas in cell 3 with 1 controls' … … 1424 1609 self.__cell_id, len(self.__controls)) 1425 1610 1426 1611 def is_auto_update(self): 1427 """1428 Returns Trueif any change of the values for the controls on1429 this canvas should cause an update. If auto_update=Falsewas1612 r""" 1613 Returns ``True`` if any change of the values for the controls on 1614 this canvas should cause an update. If ``auto_update=False`` was 1430 1615 not specified in the constructor for this canvas, then this 1431 will default to True.1616 will default to ``True``. 1432 1617 1433 EXAMPLES: 1618 EXAMPLES:: 1619 1434 1620 sage: B = sage.server.notebook.interact.InputBox('x',2) 1435 1621 sage: canvas = sage.server.notebook.interact.InteractCanvas([B], 3) 1436 1622 sage: canvas.is_auto_update() … … 1442 1628 return self.__options.get('auto_update', True) 1443 1629 1444 1630 def cell_id(self): 1445 """1446 Returns the cell id associated to this InteractCanvas.1631 r""" 1632 Returns the cell id associated to this ``InteractCanvas``. 1447 1633 1448 EXAMPLES: 1634 EXAMPLES:: 1635 1449 1636 sage: B = sage.server.notebook.interact.InputBox('x',2) 1450 1637 sage: canvas = sage.server.notebook.interact.InteractCanvas([B], 3) 1451 1638 sage: canvas.cell_id() … … 1459 1646 1460 1647 WARNING: Returns a reference to a mutable list. 1461 1648 1462 EXAMPLES: 1649 EXAMPLES:: 1650 1463 1651 sage: B = sage.server.notebook.interact.InputBox('x',2) 1464 1652 sage: sage.server.notebook.interact.InteractCanvas([B], 3).controls() 1465 1653 [An InputBox interactive control with x=2 and label 'x'] … … 1470 1658 """ 1471 1659 Return the cell id that contains this interactive canvas. 1472 1660 1473 EXAMPLES: 1661 EXAMPLES:: 1662 1474 1663 sage: B = sage.server.notebook.interact.InputBox('x',2) 1475 1664 sage: sage.server.notebook.interact.InteractCanvas([B], 3).cell_id() 1476 1665 3 … … 1479 1668 1480 1669 def render_output(self): 1481 1670 """ 1482 Render in text (html) form the output portion of the interact canvas. 1671 Render in text (HTML) form the output portion of the 1672 ``interact`` canvas. 1483 1673 1484 1674 The output contains two special tags, <?TEXT> and <?HTML>, 1485 which get replaced at runtime by the text and htmlparts1675 which get replaced at runtime by the text and HTML parts 1486 1676 of the output of running the function. 1487 1677 1488 1678 OUTPUT: 1489 string -- html1490 1679 1491 EXAMPLES: 1680 string -- HTML 1681 1682 EXAMPLES:: 1683 1492 1684 sage: B = sage.server.notebook.interact.InputBox('x',2) 1493 1685 sage: sage.server.notebook.interact.InteractCanvas([B], 3).render_output() 1494 1686 "<div ...</div>" … … 1501 1693 1502 1694 def render_controls(self): 1503 1695 """ 1504 Render in text ( html) form all the input controls.1696 Render in text (HTML) form all the input controls. 1505 1697 1506 1698 OUTPUT: 1507 string -- html1508 1699 1509 EXAMPLES: 1700 string -- HTML 1701 1702 EXAMPLES:: 1703 1510 1704 sage: B = sage.server.notebook.interact.InputBox('x',2) 1511 1705 sage: sage.server.notebook.interact.InteractCanvas([B], 3).render_controls() 1512 1706 '<table>...' … … 1523 1717 def wrap_in_outside_frame(self, inside): 1524 1718 """ 1525 1719 Return the entire HTML for the interactive canvas, obtained by 1526 wrapping all the inside htmlof the canvas in a div and a1720 wrapping all the inside HTML of the canvas in a div and a 1527 1721 table. 1528 1722 1529 1723 INPUT: 1530 inside -- string (of HTML) 1724 1725 ``inside`` -- string (of HTML) 1531 1726 1532 1727 OUTPUT: 1728 1533 1729 string of HTML 1534 1730 1535 EXAMPLES: 1731 EXAMPLES:: 1732 1536 1733 sage: B = sage.server.notebook.interact.InputBox('x',2) 1537 1734 sage: sage.server.notebook.interact.InteractCanvas([B], 3).wrap_in_outside_frame('<!--inside-->') 1538 1735 "<!--notruncate--><div padding=6 id='div-interact-3'> ...</div>\n " … … 1553 1750 1554 1751 def render(self): 1555 1752 """ 1556 Render in text ( html) the entire interactcanvas.1753 Render in text (HTML) the entire ``interact`` canvas. 1557 1754 1558 1755 OUTPUT: 1559 string -- html 1756 1757 string -- HTML 1560 1758 1561 EXAMPLES: 1759 EXAMPLES:: 1760 1562 1761 sage: B = sage.server.notebook.interact.InputBox('x',2) 1563 1762 sage: sage.server.notebook.interact.InteractCanvas([B], 3).render() 1564 1763 '<!--notruncate--><div padding=6 id=\'div-interact-3\'> ...</div>\n ' … … 1570 1769 class JavascriptCodeButton(InteractElement): 1571 1770 def __init__(self, label, code): 1572 1771 """ 1573 This interactelement displays a button which when clicked1574 executes Java script code in the notebook.1772 This ``interact`` element displays a button which when clicked 1773 executes JavaScript code in the notebook. 1575 1774 1576 EXAMPLES: 1775 EXAMPLES:: 1776 1577 1777 sage: b = sage.server.notebook.interact.JavascriptCodeButton('Push me', 'alert("2")') 1578 1778 """ 1579 1779 self.__label = label … … 1584 1784 r""" 1585 1785 Returns the HTML to display this button. 1586 1786 1587 EXAMPLES: 1787 EXAMPLES:: 1788 1588 1789 sage: b = sage.server.notebook.interact.JavascriptCodeButton('Push me', 'alert("2")') 1589 1790 sage: b.render() 1590 1791 '<input type="button" value="Push me" onclick=\'alert("2")\'>\n' … … 1595 1796 class UpdateButton(JavascriptCodeButton): 1596 1797 def __init__(self, cell_id): 1597 1798 r""" 1598 This interactelement creates a button which when clicked1599 causes the interact function in the cell cell_idto be1799 This ``interact`` element creates a button which when clicked 1800 causes the ``interact`` function in the cell ``cell_id`` to be 1600 1801 recomputed with the current values of the variables. 1601 1802 1602 EXAMPLES: 1803 EXAMPLES:: 1804 1603 1805 sage: b = sage.server.notebook.interact.UpdateButton(0) 1604 1806 sage: b.render() 1605 1807 '<input type="button" value="Update" onclick=\'interact(0, "sage.server.notebook.interact.recompute(0)")\'>\n' … … 1681 1883 <html>... 1682 1884 1683 1885 DEFAULTS: 1886 1684 1887 Defaults for the variables of the input function determine 1685 interactive controls. The standard controls are \code{input_box},1686 \code{slider}, \code{range_slider}, \code{checkbox}, \code{selector},1687 \code{input_grid}. There is also a color selector and text control1888 interactive controls. The standard controls are ``input_box``, 1889 ``slider``, ``range_slider``, ``checkbox``, ``selector``, and 1890 ``input_grid``. There is also a color selector and text control 1688 1891 (see defaults below). 1892 1689 1893 1690 \begin{itemize} 1691 \item u = input_box(default=None, label=None, type=None) 1692 -- input box with given default; use type=str to 1693 get input as an arbitrary string 1694 \item u = slider(vmin, vmax=None,step_size=1,default=None,label=None) 1695 -- slider with given list of possible values; vmin can be a list 1696 \item u = range_slider(vmin, vmax=None,step_size=1,default=None,label=None) 1697 -- range slider with given list of possible values; 1698 vmin can be a list 1699 \item u = checkbox(default=True, label=None) 1700 -- a checkbox 1701 \item u = selector(values, label=None, nrows=None, ncols=None, buttons=False) 1702 -- a dropdown menu or buttons (get buttons if nrows, 1703 ncols, or buttons is set, otherwise a dropdown menu) 1704 \item u = input_grid(nrows, ncols, default=None, label=None, 1705 to_value=lambda x:x, width=4) 1706 -- an editable grid of objects (a matrix or array) 1707 \item u = text_control(value='') 1708 -- a block of text 1709 \end{itemize} 1894 * ``u = input_box(default=None, label=None, type=None)`` -- 1895 input box with given ``default``; use ``type=str`` to get 1896 input as an arbitrary string 1897 1898 1899 * ``u = slider(vmin, vmax=None, step_size=1, default=None, 1900 label=None)`` -- slider with given list of possible values; 1901 ``vmin`` can be a list 1902 1903 1904 * ``u = range_slider(vmin, vmax=None, step_size=1, 1905 default=None, label=None)`` -- range slider with given list 1906 of possible values; ``vmin`` can be a list 1907 1908 1909 * ``u = checkbox(default=True, label=None)`` -- a checkbox 1910 1911 1912 * ``u = selector(values, label=None, nrows=None, ncols=None, 1913 buttons=False)`` -- a dropdown menu or buttons (get buttons 1914 if ``nrows``, ``ncols``, or ``buttons`` is set, otherwise a 1915 dropdown menu) 1916 1917 1918 * ``u = input_grid(nrows, ncols, default=None, label=None, 1919 to_value=lambda x:x, width=4)`` -- an editable grid of 1920 objects (a matrix or array) 1921 1922 1923 * ``u = text_control(value='')`` -- a block of text 1924 1710 1925 1711 1926 You can create a color selector by setting the default value for a 1712 variable to Color(...).1927 variable to ``Color(...)``. 1713 1928 1714 1929 There are also some convenient defaults that allow you to make 1715 1930 controls automatically without having to explicitly specify them. 1716 E.g., you can make $x$ a continuous slider of values between $u$1717 and $v$ by just writing \code{x=(u,v)}in the argument list of1931 E.g., you can make ``x`` a continuous slider of values between ``u`` 1932 and ``v`` by just writing ``x=(u,v)`` in the argument list of 1718 1933 your function. These are all just convenient shortcuts for 1719 1934 creating the controls listed above. 1720 1935 1721 \begin{itemize} 1722 \item u -- blank input_box field 1723 \item u = element -- input_box with default=element, if element not below. 1724 \item u = (umin,umax) -- continuous slider (really 100 steps) 1725 \item u = (umin,umax,du)-- slider with step size du 1726 \item u = list -- buttons if len(list) at most 5; otherwise, drop down 1727 \item u = generator -- a slider (up to 10000 steps) 1728 \item u = bool -- a checkbox 1729 \item u = Color('blue') -- a 2d RGB color selector; returns Color object 1730 \item u = (default, v) -- v as above, with given default value 1731 \item u = (label, v) -- v as above, with given label (a string) 1732 \item u = matrix -- an input_grid with to_value set to matrix.parent() 1733 and default values given by the matrix 1734 \end{itemize} 1936 * ``u`` -- blank input_box field 1937 1938 * ``u = element`` -- input_box with ``default=element``, if 1939 element not below. 1940 1941 * ``u = (umin,umax)`` -- continuous slider (really `100` steps) 1942 1943 * ``u = (umin,umax,du)`` -- slider with step size ``du`` 1944 1945 * ``u = list`` -- buttons if ``len(list)`` at most `5`; 1946 otherwise, drop down 1947 1948 * ``u = generator`` -- a slider (up to `10000` steps) 1949 1950 * ``u = bool`` -- a checkbox 1951 1952 * ``u = Color('blue')`` -- a 2D RGB color selector; returns 1953 ``Color`` object 1954 1955 * ``u = (default, v)`` -- ``v`` as above, with given 1956 ``default`` value 1957 1958 * ``u = (label, v)`` -- ``v`` as above, with given ``label`` 1959 (a string) 1960 1961 * ``u = matrix`` -- an ``input_grid`` with ``to_value`` set to 1962 ``matrix.parent()`` and default values given by the matrix 1735 1963 1736 1964 WARNING: Suppose you would like to make a interactive with a 1737 default rgb color of (1,0,0), so the function would have signature 1738 \code{f(color=(1,0,0))}. Unfortunately, the above shortcuts reinterpret 1739 the (1,0,0) as a discrete slider with step size 0 between 1 and 0. 1740 Instead you should do the following: 1965 default RGB color of ``(1,0,0)``, so the function would have 1966 signature ``f(color=(1,0,0))``. Unfortunately, the above 1967 shortcuts reinterpret the ``(1,0,0)`` as a discrete slider with 1968 step size ``0`` between ``1`` and ``0``. Instead you should do the 1969 following:: 1970 1741 1971 sage: @interact 1742 1972 ... def _(v = input_box((1,0,0))): 1743 1973 ... show(plot(sin,color=v)) 1744 1974 <html>... 1745 1975 1746 1976 MORE EXAMPLES: 1747 We give an input box that allows one to enter completely arbitrary strings. 1977 1978 We give an input box that allows one to enter completely arbitrary 1979 strings:: 1980 1748 1981 sage: @interact 1749 1982 ... def _(a=input_box('sage', label="Enter your name", type=str)): 1750 1983 ... print "Hello there %s"%a.capitalize() 1751 1984 <html>... 1752 1985 1753 The scope of variables that you control via interact are local to 1754 the scope of the function being interacted with. However, by using 1755 the global Python keyword, you can still modify global variables 1756 as follows: 1986 The scope of variables that you control via ``interact`` are local 1987 to the scope of the function being interacted with. However, by 1988 using the ``global`` Python keyword, you can still modify global 1989 variables as follows:: 1990 1757 1991 sage: xyz = 10 1758 1992 sage: @interact 1759 1993 ... def _(a=('xyz',5)): … … 1761 1995 ... xyz = a 1762 1996 <html>... 1763 1997 1764 If you enter the above you obtain an interactcanvas. Entering1765 values in the box , changes the global variable xyz.1998 If you enter the above you obtain an ``interact`` canvas. Entering 1999 values in the box changes the global variable ``xyz``:: 1766 2000 1767 2001 sage: @interact 1768 2002 ... def _(title=["A Plot Demo", "Something silly", "something tricky"], a=input_box(sin(x*sin(x*sin(x))), 'function'), … … 1772 2006 ... show(plot(a, -zoom*pi,zoom*pi, color=clr, thickness=thickness, plot_points=plot_points)) 1773 2007 <html>... 1774 2008 1775 We give defaults and name the variables: 2009 We give defaults and name the variables:: 2010 1776 2011 sage: @interact 1777 2012 ... def _(a=('first', (1,4)), b=(0,10)): 1778 2013 ... show(plot(sin(a*x+sin(b*x)), (x,0,6)), figsize=3) 1779 2014 <html>... 1780 2015 1781 Another example involving labels and defaults, and the 1782 slider command. 2016 Another example involving labels, defaults, and the slider 2017 command:: 2018 1783 2019 sage: @interact 1784 2020 ... def _(a = slider(1, 4, default=2, label='Multiplier'), 1785 2021 ... b = slider(0, 10, default=0, label='Phase Variable')): 1786 2022 ... show(plot(sin(a*x+b), (x,0,6)), figsize=4) 1787 2023 <html>... 1788 2024 1789 An example where the range slider control is useful. 2025 An example where the range slider control is useful:: 2026 1790 2027 sage: @interact 1791 2028 ... def _(b = range_slider(-20, 20, 1, default=(-19,3), label='Range')): 1792 2029 ... plot(sin(x)/x, b[0], b[1]).show(xmin=b[0],xmax=b[1]) 1793 2030 <html>... 1794 2031 1795 An example using checkboxes, obtained by making the default values bools. 2032 An example using checkboxes, obtained by making the default values 2033 bools:: 2034 1796 2035 sage: @interact 1797 2036 ... def _(axes=('Show axes', True), square=False): 1798 2037 ... show(plot(sin, -5,5), axes=axes, aspect_ratio = (1 if square else None)) 1799 2038 <html>... 1800 2039 1801 An example generating a random walk that uses a checkbox control to determine 1802 whether points are placed at each step: 2040 An example generating a random walk that uses a checkbox control 2041 to determine whether points are placed at each step:: 2042 1803 2043 sage: @interact 1804 2044 ... def foo(pts = checkbox(True, "points"), n = (50,(10..100))): 1805 2045 ... s = 0; v = [(0,0)] … … 1811 2051 ... show(L) 1812 2052 <html>... 1813 2053 1814 You can rotate and zoom into 3D graphics while 1815 interacting with a variable. 2054 You can rotate and zoom into 3D graphics while interacting with a 2055 variable:: 2056 1816 2057 sage: @interact 1817 2058 ... def _(a=(0,1)): 1818 2059 ... x,y = var('x,y') 1819 2060 ... show(plot3d(sin(x*cos(y*a)), (x,0,5), (y,0,5)), figsize=4) 1820 2061 <html>... 1821 2062 1822 A random polygon: 2063 A random polygon:: 2064 1823 2065 sage: pts = [(random(), random()) for _ in xrange(20)] 1824 2066 sage: @interact 1825 2067 ... def _(n = (4..len(pts)), c=Color('purple') ): … … 1827 2069 ... show(G, figsize=5, xmin=0, ymin=0) 1828 2070 <html>... 1829 2071 1830 Two "sinks" displayed simultaneously via a contour plot and a 3d 1831 interactive plot: 2072 Two "sinks" displayed simultaneously via a contour plot and a 3D 2073 interactive plot:: 2074 1832 2075 sage: @interact 1833 2076 ... def _(q1=(-1,(-3,3)), q2=(-2,(-3,3))): 1834 2077 ... x,y = var('x,y') … … 1838 2081 ... show(plot3d(f, (x,-2,2), (y,-2,2)), figsize=4) 1839 2082 <html>... 1840 2083 1841 This is similar to above, but you can select the color map from a dropdown menu: 2084 This is similar to above, but you can select the color map from a 2085 dropdown menu:: 2086 1842 2087 sage: @interact 1843 2088 ... def _(q1=(-1,(-3,3)), q2=(-2,(-3,3)), 1844 2089 ... cmap=['autumn', 'bone', 'cool', 'copper', 'gray', 'hot', 'hsv', … … 1849 2094 ... show(C, figsize=3, aspect_ratio=1) 1850 2095 <html>... 1851 2096 1852 A quadratic roots etch-a-sketch: 2097 A quadratic roots etch-a-sketch:: 2098 1853 2099 sage: v = [] 1854 2100 sage: html('<h2>Quadratic Root Etch-a-sketch</h2>') 1855 2101 <html><font color='black'><h2>Quadratic Root Etch-a-sketch</h2></font></html> … … 1863 2109 ... show(line(v, rgbcolor='purple') + point(P, pointsize=200)) 1864 2110 <html>... 1865 2111 1866 In the following example, we only generate data for a given n 1867 once, so that as one varies p the data doesn't not randomly 1868 change. We do this by simply caching the results for each n 1869 in a dictionary. 2112 In the following example, we only generate data for a given ``n`` 2113 once, so that as one varies ``p`` the data does not randomly change. 2114 We do this by simply caching the results for each ``n`` in a 2115 dictionary.:: 2116 1870 2117 sage: data = {} 1871 2118 sage: @interact 1872 2119 ... def _(n=(500,(100,5000,1)), p=(1,(0.1,10))): … … 1876 2123 ... show(points([(x^p,y^p) for x,y in data[n]], rgbcolor='black'), xmin=0, ymin=0, axes=False) 1877 2124 <html>... 1878 2125 1879 A conchoid: 2126 A conchoid:: 2127 1880 2128 sage: @interact 1881 2129 ... def _(k=(1.2,(1.1,2)), k_2=(1.2,(1.1,2)), a=(1.5,(1.1,2))): 1882 2130 ... u, v = var('u,v') … … 1884 2132 ... show(parametric_plot3d(f, (u,0,6*pi), (v,0,2*pi), plot_points=[40,40], texture=(0,0.5,0))) 1885 2133 <html>... 1886 2134 1887 An input grid: 2135 An input grid:: 2136 1888 2137 sage: @interact 1889 2138 ... def _(A=matrix(QQ,3,3,range(9)), v=matrix(QQ,3,1,range(3))): 1890 2139 ... try: … … 1937 2186 class control: 1938 2187 def __init__(self, label=None): 1939 2188 """ 1940 An interactive control object used with the interactcommand.2189 An interactive control object used with the ``interact`` command. 1941 2190 This is the abstract base class. 1942 2191 1943 2192 INPUTS: 1944 label -- a string 2193 2194 ``label`` -- a string 1945 2195 1946 EXAMPLES: 2196 EXAMPLES:: 2197 1947 2198 sage: sage.server.notebook.interact.control('a control') 1948 2199 Interative control 'a control' (abstract base class) 1949 2200 """ … … 1951 2202 1952 2203 def __repr__(self): 1953 2204 """ 1954 Return string representation of this control. 1955 (It justmentions the label and that this is an abstract base class.)2205 Return string representation of this control. (It just 2206 mentions the label and that this is an abstract base class.) 1956 2207 1957 EXAMPLES: 2208 EXAMPLES:: 2209 1958 2210 sage: sage.server.notebook.interact.control('a control').__repr__() 1959 2211 "Interative control 'a control' (abstract base class)" 1960 2212 """ … … 1965 2217 Return the label of this control. 1966 2218 1967 2219 OUTPUT: 2220 1968 2221 a string 1969 2222 1970 EXAMPLES: 2223 EXAMPLES:: 2224 1971 2225 sage: sage.server.notebook.interact.control('a control').label() 1972 2226 'a control' 1973 2227 sage: selector([1,2,7], 'alpha').label() … … 1980 2234 Set the label of this control. 1981 2235 1982 2236 INPUT: 1983 label -- a string 2237 2238 ``label`` -- a string 1984 2239 1985 EXAMPLES: 2240 EXAMPLES:: 2241 1986 2242 sage: C = sage.server.notebook.interact.control('a control') 1987 2243 sage: C.set_label('sage'); C 1988 2244 Interative control 'sage' (abstract base class) … … 1993 2249 def __init__(self, default=None, label=None, type=None, width = 80): 1994 2250 r""" 1995 2251 An input box interactive control. Use this in conjunction 1996 with the interactcommand.2252 with the ``interact`` command. 1997 2253 1998 \code{input_box(default=None, label=None, type=None)}2254 ``input_box(default=None, label=None, type=None)`` 1999 2255 2000 2256 INPUT: 2001 default -- object; the default put in this input box 2002 label -- the label rendered to the left of the box. 2003 type -- coerce inputs to this; this doesn't have to be 2004 an actual type, since anything callable will do. 2005 width -- width of text box in characters 2257 2258 ``default`` -- object; the default put in this input box 2259 2260 ``label`` -- the label rendered to the left of the box. 2261 2262 ``type`` -- coerce inputs to this; this doesn't have to be 2263 an actual type, since anything callable will do. 2264 2265 ``width`` -- width of text box in characters 2006 2266 2007 EXAMPLES: 2267 EXAMPLES:: 2268 2008 2269 sage: input_box("2+2", 'expression') 2009 2270 Interact input box labeled 'expression' with default value '2+2' 2010 2271 sage: input_box('sage', label="Enter your name", type=str) … … 2019 2280 """ 2020 2281 Return print representation of this input box. 2021 2282 2022 EXAMPLES: 2283 EXAMPLES:: 2284 2023 2285 sage: input_box("2+2", 'expression').__repr__() 2024 2286 "Interact input box labeled 'expression' with default value '2+2'" 2025 2287 """ … … 2029 2291 """ 2030 2292 Return the default value of this input box. 2031 2293 2032 EXAMPLES: 2294 EXAMPLES:: 2295 2033 2296 sage: input_box('2+2', 'Expression').default() 2034 2297 '2+2' 2035 2298 sage: input_box(x^2 + 1, 'Expression').default() … … 2042 2305 def type(self): 2043 2306 """ 2044 2307 Return the type that elements of this input box are coerced to 2045 or None if they are not coerced (they have whatever type they2046 evaluate to).2308 or ``None`` if they are not coerced (they have whatever type 2309 they evaluate to). 2047 2310 2048 EXAMPLES: 2311 EXAMPLES:: 2312 2049 2313 sage: input_box("2+2", 'expression', type=int).type() 2050 2314 <type 'int'> 2051 2315 sage: input_box("2+2", 'expression').type() is None … … 2055 2319 2056 2320 def render(self, var): 2057 2321 r""" 2058 Return rendering of this input box as an InputBox to be used2059 for an interact canvas. Basically this specializes this2060 input to be used for a specific function and variable.2322 Return rendering of this input box as an ``InputBox`` to be 2323 used for an ``interact`` canvas. Basically this specializes 2324 this input to be used for a specific function and variable. 2061 2325 2062 2326 INPUT: 2063 var -- a string (variable; one of the variable names input to f) 2327 2328 ``var`` -- a string (variable; one of the variable names 2329 input to ``f``) 2064 2330 2065 2331 OUTPUT: 2066 InputBox -- an InputBox object.2067 2332 2068 EXAMPLES: 2333 ``InputBox`` object. 2334 2335 EXAMPLES:: 2336 2069 2337 sage: input_box("2+2", 'Exp').render('x') 2070 2338 An InputBox interactive control with x='2+2' and label 'Exp' 2071 2339 """ … … 2079 2347 def __init__(self, nrows, ncols, default=None, label=None, to_value=lambda x: x, width=4): 2080 2348 r""" 2081 2349 An input grid interactive control. Use this in conjunction 2082 with the interactcommand.2350 with the ``interact`` command. 2083 2351 2084 2352 INPUT: 2085 nrows -- integer 2086 ncols -- integer 2087 default -- object; the default put in this input box 2088 label -- the label rendered to the left of the box. 2089 to_value -- the grid output (list of rows) is sent through 2090 this function. This may reformat the data or 2091 coerce the type. 2092 width -- size of each input box in characters 2353 2354 ``nrows`` -- integer 2355 2356 ``ncols`` -- integer 2357 2358 ``default`` -- object; the default put in this input box 2359 2360 ``label`` -- the label rendered to the left of the box. 2361 2362 ``to_value`` -- the grid output (list of rows) is sent 2363 through this function. This may reformat the data or 2364 coerce the type. 2365 2366 ``width`` -- size of each input box in characters 2093 2367 2094 2368 NOTEBOOK EXAMPLE: 2369 2095 2370 @interact 2096 2371 def _(m = input_grid(2,2, default = [[1,7],[3,4]], 2097 2372 label='M=', to_value=matrix), … … 2103 2378 except: 2104 2379 html('There is no solution to $$%s x=%s$$'%(latex(m), latex(v))) 2105 2380 2381 EXAMPLES:: 2106 2382 2107 EXAMPLES:2108 2383 sage: input_grid(2,2, default = 0, label='M') 2109 2384 Interact 2 x 2 input grid control labeled M with default value 0 2110 2385 sage: input_grid(2,2, default = [[1,2],[3,4]], label='M') … … 2126 2401 """ 2127 2402 Return print representation of this input box. 2128 2403 2129 EXAMPLES: 2404 EXAMPLES:: 2405 2130 2406 sage: input_grid(2,2, label='M').__repr__() 2131 2407 'Interact 2 x 2 input grid control labeled M with default value None' 2132 2408 … … 2140 2416 """ 2141 2417 Return the default value of this input grid. 2142 2418 2143 EXAMPLES: 2419 EXAMPLES:: 2420 2144 2421 sage: input_grid(2,2, default=1).default() 2145 2422 1 2146 2423 """ … … 2149 2426 2150 2427 def render(self, var): 2151 2428 r""" 2152 Return rendering of this input grid as an InputGrid to be used2153 for an interact canvas. Basically this specializes this2154 input to be used for a specific function and variable.2429 Return rendering of this input grid as an ``InputGrid`` to be 2430 used for an ``interact`` canvas. Basically this specializes 2431 this input to be used for a specific function and variable. 2155 2432 2156 2433 INPUT: 2157 var -- a string (variable; one of the variable names input to f) 2434 2435 ``var`` -- a string (variable; one of the variable names 2436 input to ``f``) 2158 2437 2159 2438 OUTPUT: 2160 InputGrid -- an InputGrid object.2161 2439 2162 EXAMPLES: 2440 ``InputGrid`` object. 2441 2442 EXAMPLES:: 2443 2163 2444 sage: input_grid(2,2).render('x') 2164 2445 A 2 x 2 InputGrid interactive control with x=[[None, None], [None, None]] and label 'x' 2165 2446 … … 2171 2452 class checkbox(input_box): 2172 2453 def __init__(self, default=True, label=None): 2173 2454 """ 2174 A checkbox interactive control. Use this in conj ecture2175 with the interactcommand.2455 A checkbox interactive control. Use this in conjunction with 2456 the ``interact`` command. 2176 2457 2177 2458 INPUT: 2178 default -- bool (default: True); whether box should be checked or not2179 label -- str or None (default: None) text label rendered to the left of the box2180 2459 2181 EXAMPLES: 2460 ``default`` -- bool (default: ``True``); whether box 2461 should be checked or not 2462 2463 ``label`` -- str or ``None`` (default: ``None``) text 2464 label rendered to the left of the box 2465 2466 EXAMPLES:: 2467 2182 2468 sage: checkbox(False, "Points") 2183 2469 Interact checkbox labeled 'Points' with default value False 2184 2470 sage: checkbox(True, "Points") … … 2194 2480 """ 2195 2481 Print representation of this checkbox. 2196 2482 2197 EXAMPLES: 2483 EXAMPLES:: 2484 2198 2485 sage: checkbox(True, "Points").__repr__() 2199 2486 "Interact checkbox labeled 'Points' with default value True" 2200 2487 """ … … 2248 2535 Returns list of values that this slider takes on, in order. 2249 2536 2250 2537 OUTPUT: 2538 2251 2539 list -- list of values 2252 2540 2253 2541 WARNING: This is a reference to a mutable list. 2254 2542 2255 EXAMPLES: 2543 EXAMPLES:: 2544 2256 2545 sage: sage.server.notebook.interact.slider(1,10,1/2).values() 2257 2546 [1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2, 8, 17/2, 9, 19/2, 10] 2258 2547 """ … … 2263 2552 Returns whether to display the value on the slider. 2264 2553 2265 2554 OUTPUT: 2555 2266 2556 boolean 2267 2557 2268 EXAMPLES: 2558 EXAMPLES:: 2559 2269 2560 sage.server.notebook.interact.slider_generic(1,10,1/2).display_value() 2270 2561 True 2271 2562 """ … … 2276 2567 def __init__(self, vmin, vmax=None, step_size=None, default=None, label=None, display_value=True): 2277 2568 r""" 2278 2569 An interactive slider control, which can be used in conjunction 2279 with the interactcommand.2570 with the ``interact`` command. 2280 2571 2281 \code{slider(vmin, vmax=None, step_size=1, default=None, label=None)}2572 ``slider(vmin, vmax=None, step_size=1, default=None, label=None)`` 2282 2573 2283 2574 INPUT: 2284 vmin -- object or number2285 vmax -- object or None; if None then vmin must be a list, and the slider2286 then varies over elements of the list.2287 step_size -- integer (default: 1)2288 default -- object or None; default value is ``closest'' in vmin or range2289 to this default.2290 label -- string2291 display_value -- boolean, whether to display the current value to the right2292 of the slider2293 2575 2294 EXAMPLES: 2295 We specify both vmin and vmax. We make the default 3, but 2296 since 3 isn't one of 3/17-th spaced values between 2 and 5, 2297 52/17 is instead chosen as the default (it is closest). 2576 ``vmin`` -- object or number 2577 2578 ``vmax`` -- object or ``None``; if ``None`` then ``vmin`` 2579 must be a list, and the slider then varies over elements 2580 of the list. 2581 2582 ``step_size`` -- integer (default: ``1``) 2583 2584 ``default`` -- object or ``None``; default value is 2585 "closest" in ``vmin`` or range to this default. 2586 2587 ``label`` -- string 2588 2589 ``display_value`` -- boolean, whether to display the 2590 current value to the right of the slider 2591 2592 EXAMPLES:: 2593 2594 We specify both ``vmin`` and ``vmax``. We make the default 2595 ``3``, but since ``3`` isn't one of ``3/17``-th spaced values 2596 between ``2`` and ``5``, ``52/17`` is instead chosen as the 2597 default (it is closest):: 2598 2298 2599 sage: slider(2, 5, 3/17, 3, 'alpha') 2299 2600 Slider: alpha [2--|52/17|---5] 2300 2601 2301 Here we give a list: 2602 Here we give a list:: 2603 2302 2604 sage: slider([1..10], None, None, 3, 'alpha') 2303 2605 Slider: alpha [1--|3|---10] 2304 2606 2305 The elements of the list can be anything: 2607 The elements of the list can be anything:: 2608 2306 2609 sage: slider([1, 'x', 'abc', 2/3], None, None, 'x', 'alpha') 2307 2610 Slider: alpha [1--|x|---2/3] 2308 2611 """ … … 2329 2632 """ 2330 2633 Return string representation of this slider. 2331 2634 2332 EXAMPLES: 2635 EXAMPLES:: 2636 2333 2637 sage: slider(2, 5, 1/5, 3, 'alpha').__repr__() 2334 2638 'Slider: alpha [2--|3|---5]' 2335 2639 """ … … 2343 2647 Return default index into the list of values. 2344 2648 2345 2649 OUTPUT: 2650 2346 2651 int 2347 2652 2348 EXAMPLES: 2653 EXAMPLES:: 2654 2349 2655 sage: slider(2, 5, 1/2, 3, 'alpha').default_index() 2350 2656 2 2351 2657 """ … … 2353 2659 2354 2660 def render(self, var): 2355 2661 """ 2356 Render the interactcontrol for the given function and2662 Render the ``interact`` control for the given function and 2357 2663 variable. 2358 2664 2359 2665 INPUT: 2360 var -- string; variable name2361 2666 2362 EXAMPLES: 2667 ``var`` -- string; variable name 2668 2669 EXAMPLES:: 2670 2363 2671 sage: S = slider(0, 10, 1, default=3, label='theta'); S 2364 2672 Slider: theta [0--|3|---10] 2365 2673 sage: S.render('x') … … 2375 2683 def __init__(self, vmin, vmax=None, step_size=None, default=None, label=None, display_value=True): 2376 2684 r""" 2377 2685 An interactive range slider control, which can be used in conjunction 2378 with the interactcommand.2686 with the ``interact`` command. 2379 2687 2380 \code{range_slider(vmin, vmax=None, step_size=1, default=None, label=None)}2688 ``range_slider(vmin, vmax=None, step_size=1, default=None, label=None)`` 2381 2689 2382 2690 INPUT: 2383 vmin -- object or number2384 vmax -- object or None; if None then vmin must be a list, and the slider2385 then varies over elements of the list.2386 step_size -- integer (default: 1)2387 default -- (object, object) or None; default range is ``closest'' in vmin or range2388 to this default.2389 label -- string2390 display_value -- boolean, whether to display the current value below2391 the slider2392 2691 2393 EXAMPLES: 2394 We specify both vmin and vmax. We make the default (3,4) but 2395 since neither is one of 3/17-th spaced values between 2 and 5, 2396 the closest values: 52/17 and 67/17, are instead chosen as the 2397 default. 2692 ``vmin`` -- object or number 2693 2694 ``vmax`` -- object or ``None``; if ``None`` then ``vmin`` 2695 must be a list, and the slider then varies over elements 2696 of the list. 2697 2698 ``step_size`` -- integer (default: ``1``) 2699 2700 ``default`` -- (object, object) or ``None``; default range 2701 is "closest" in ``vmin`` or range to this default. 2702 2703 ``label`` -- string 2704 2705 ``display_value`` -- boolean, whether to display the 2706 current value below the slider 2707 2708 EXAMPLES:: 2709 2710 We specify both ``vmin`` and ``vmax``. We make the default 2711 ``(3,4)`` but since neither is one of ``3/17``-th spaced 2712 values between ``2`` and ``5``, the closest values: ``52/17`` 2713 and ``67/17``, are instead chosen as the default:: 2714 2398 2715 sage: range_slider(2, 5, 3/17, (3,4), 'alpha') 2399 2716 Range Slider: alpha [2--|52/17==67/17|---5] 2400 2717 2401 Here we give a list: 2718 Here we give a list:: 2719 2402 2720 sage: range_slider([1..10], None, None, (3,7), 'alpha') 2403 2721 Range Slider: alpha [1--|3==7|---10] 2404 2722 """ … … 2430 2748 """ 2431 2749 Return string representation of this slider. 2432 2750 2433 EXAMPLES: 2751 EXAMPLES:: 2752 2434 2753 sage: range_slider(2, 5, 1/5, (3,4), 'alpha').__repr__() 2435 2754 'Range Slider: alpha [2--|3==4|---5]' 2436 2755 """ … … 2443 2762 Return default index into the list of values. 2444 2763 2445 2764 OUTPUT: 2765 2446 2766 (int, int) 2447 2767 2448 EXAMPLES: 2768 EXAMPLES:: 2769 2449 2770 sage: range_slider(2, 5, 1/2, (3,4), 'alpha').default_index() 2450 2771 (2, 4) 2451 2772 """ … … 2453 2774 2454 2775 def render(self, var): 2455 2776 """ 2456 Render the interactcontrol for the given function and2777 Render the ``interact`` control for the given function and 2457 2778 variable. 2458 2779 2459 2780 INPUT: 2460 var -- string; variable name2461 2781 2462 EXAMPLES: 2782 ``var`` -- string; variable name 2783 2784 EXAMPLES:: 2785 2463 2786 sage: S = range_slider(0, 10, 1, default=(3,7), label='theta'); S 2464 2787 Range Slider: theta [0--|3==7|---10] 2465 2788 sage: S.render('x') … … 2477 2800 r""" 2478 2801 A drop down menu or a button bar that when pressed sets a 2479 2802 variable to a given value. Use this in conjunction with the 2480 interactcommand.2803 ``interact`` command. 2481 2804 2482 \code{selector(values, label=None, nrows=None, ncols=None, buttons=False)}2805 ``selector(values, label=None, nrows=None, ncols=None, buttons=False)`` 2483 2806 2484 2807 We use the same command to create either a drop down menu or 2485 2808 selector bar of buttons, since conceptually the two controls 2486 2809 do exactly the same thing -- they only look different. If 2487 either nrows or ncols is given, then you get a buttons instead2488 of a drop down menu.2810 either ``nrows`` or ``ncols`` is given, then you get a buttons 2811 instead of a drop down menu. 2489 2812 2490 2813 INPUT: 2491 values -- [val0, val1, val2, ...] or2492 [(val0, lbl0), (val1,lbl1), ...] where all labels must be2493 given or given as None.2494 label -- (default: None); if given, this label is placed to2495 the left of the entire button group2496 default -- object (default: 0) default value in values list2497 nrows -- (default: None); if given determines the number2498 of rows of buttons; if given buttons option below is set to True2499 ncols -- (default: None); if given determines the number2500 of columns of buttons; if given buttons option below is set to True2501 width -- (default: None); if given, all buttons are the same2502 width, equal to this in html ex units's.2503 buttons -- (default: False); if True, use buttons2504 2814 2505 EXAMPLES: 2815 ``values`` -- [val0, val1, val2, ...] or [(val0, lbl0), 2816 (val1,lbl1), ...] where all labels must be given 2817 or given as None. 2818 2819 ``label`` -- (default: ``None``); if given, this label is 2820 placed to the left of the entire button group 2821 2822 ``default`` -- object (default: ``0``) default value in 2823 values list 2824 2825 ``nrows`` -- (default: ``None``); if given determines the 2826 number of rows of buttons; if given buttons option below 2827 is set to ``True`` 2828 2829 ``ncols`` -- (default: ``None``); if given determines the 2830 number of columns of buttons; if given buttons option 2831 below is set to ``True`` 2832 2833 ``width`` -- (default: ``None``); if given, all buttons 2834 are the same width, equal to this in HTML ex units's. 2835 2836 ``buttons`` -- (default: ``False``); if ``True``, use buttons 2837 2838 EXAMPLES:: 2839 2506 2840 sage: selector([1..5]) 2507 2841 Drop down menu with 5 options 2508 2842 sage: selector([1,2,7], default=2) … … 2516 2850 sage: selector([1,2,7], buttons=True) 2517 2851 Button bar with 3 buttons 2518 2852 2519 We create an interactive that involves computing charpolys of matrices over various rings: 2853 We create an ``interact`` that involves computing charpolys of 2854 matrices over various rings:: 2855 2520 2856 sage: @interact 2521 2857 ... def _(R=selector([ZZ,QQ,GF(17),RDF,RR]), n=(1..10)): 2522 2858 ... M = random_matrix(R, n) … … 2526 2862 ... print f 2527 2863 <html>... 2528 2864 2529 Here we create a drop-down 2865 Here we create a drop-down:: 2866 2530 2867 sage: @interact 2531 2868 ... def _(a=selector([(2,'second'), (3,'third')])): 2532 2869 ... print a … … 2553 2890 """ 2554 2891 Return print representation of this button. 2555 2892 2556 EXAMPLES: 2893 EXAMPLES:: 2894 2557 2895 sage: selector([1,2,7], default=2).__repr__() 2558 2896 'Drop down menu with 3 options' 2559 2897 """ … … 2568 2906 selector can take on. 2569 2907 2570 2908 OUTPUT: 2909 2571 2910 list 2572 2911 2573 EXAMPLES: 2912 EXAMPLES:: 2913 2574 2914 sage: selector([1..5]).values() 2575 2915 [1, 2, 3, 4, 5] 2576 2916 sage: selector([(5,'fifth'), (8,'eight')]).values() … … 2583 2923 Return the default choice for this control. 2584 2924 2585 2925 OUTPUT: 2586 int -- an integer, with 0 corresponding to the first choice.2587 2926 2588 EXAMPLES: 2927 int -- an integer, with ``0`` corresponding to the first choice. 2928 2929 EXAMPLES:: 2930 2589 2931 sage: selector([1,2,7], default=2).default() 2590 2932 1 2591 2933 """ … … 2593 2935 2594 2936 def render(self, var): 2595 2937 r""" 2596 Return rendering of this button as a Buttoninstance to be2597 used for an interactcanvas.2938 Return rendering of this button as a ``Button`` instance to be 2939 used for an ``interact`` canvas. 2598 2940 2599 2941 INPUT: 2600 var -- a string (variable; one of the variable names input to f) 2942 2943 ``var`` -- a string (variable; one of the variable names 2944 input to ``f``) 2601 2945 2602 2946 OUTPUT: 2603 Button -- a Button instance2604 2947 2605 EXAMPLES: 2948 ``Button`` instance 2949 2950 EXAMPLES:: 2951 2606 2952 sage: selector([1..5]).render('alpha') 2607 2953 Selector with 5 options for variable 'alpha' 2608 2954 """ … … 2614 2960 class text_control(control): 2615 2961 def __init__(self, value=''): 2616 2962 """ 2617 Text that can be inserted among other interactcontrols.2963 Text that can be inserted among other ``interact`` controls. 2618 2964 2619 2965 INPUT: 2620 value -- HTML for the control2621 2966 2622 EXAMPLES: 2967 ``value`` -- HTML for the control 2968 2969 EXAMPLES:: 2970 2623 2971 sage: text_control('something') 2624 2972 Text field: something 2625 2973 """ … … 2630 2978 """ 2631 2979 Return print representation of this control. 2632 2980 2633 EXAMPLES: 2981 EXAMPLES:: 2982 2634 2983 sage: text_control('something') 2635 2984 Text field: something 2636 2985 """ … … 2641 2990 Return rendering of the text field 2642 2991 2643 2992 INPUT: 2644 var -- a string (variable; one of the variable names input to f) 2993 2994 ``var`` -- a string (variable; one of the variable names 2995 input to ``f``) 2645 2996 2646 2997 OUTPUT: 2647 TextControl -- a TextControl instance 2998 2999 ``TextControl`` instance 2648 3000 """ 2649 3001 return TextControl(var, self.__default) 2650 3002 … … 2655 3007 value of the variable. 2656 3008 2657 3009 INPUT: 2658 default -- the default value for v given by the function; see 2659 the documentation to interact? for details. 3010 3011 ``default`` -- the default value for `v` given by the 3012 function; see the documentation to ``interact`` for details. 2660 3013 2661 3014 OUTPUT: 2662 a interact control2663 3015 2664 EXAMPLES: 3016 ``interact`` control 3017 3018 EXAMPLES:: 3019 2665 3020 sage: sage.server.notebook.interact.automatic_control('') 2666 3021 Interact input box labeled None with default value '' 2667 3022 sage: sage.server.notebook.interact.automatic_control(15) … … 2764 3119 2765 3120 2766 3121 def update(cell_id, var, adapt, value, globs): 2767 """3122 r""" 2768 3123 Called when updating the positions of an interactive control. 2769 3124 Note that this just causes the values of the variables to be 2770 3125 updated; it does not reevaluate the function with the new values. 2771 3126 2772 3127 INPUT: 2773 cell_id -- the id of a interact cell 2774 var -- a variable associated to that cell 2775 adapt -- the number of the adapt function 2776 value -- new value of the control 2777 globs -- global variables. 3128 ``cell_id`` -- the id of an ``interact`` cell 3129 3130 ``var`` -- a variable associated to that cell 3131 3132 ``adapt`` -- the number of the adapt function 3133 3134 ``value`` -- new value of the control 3135 3136 ``globs`` -- global variables. 2778 3137 2779 3138 EXAMPLES: 3139 2780 3140 The following outputs __SAGE_INTERACT_RESTART__ to indicate that 2781 not all the state of the interrupt canvas has been setup yet (this 2782 setup happens when javascript calls certain functions). 3141 not all the state of the ``interact`` canvas has been set up yet 3142 (this setup happens when JavaScript calls certain functions):: 3143 2783 3144 sage: sage.server.notebook.interact.update(0, 'a', 0, '5', globals()) 2784 3145 __SAGE_INTERACT_RESTART__ 2785 3146 """ … … 2795 3156 2796 3157 def recompute(cell_id): 2797 3158 """ 2798 Evaluates the interactfunction associated to the cell2799 cell_id. This typically gets called after a call to2800 sage.server.notebook.interact.update.3159 Evaluates the ``interact`` function associated to the cell 3160 ``cell_id``. This typically gets called after a call to 3161 ``sage.server.notebook.interact.update``. 2801 3162 2802 3163 EXAMPLES: 3164 2803 3165 The following outputs __SAGE_INTERACT_RESTART__ to indicate that 2804 not all the state of the interrupt canvas has been setup yet (this 2805 setup happens when javascript calls certain functions). 3166 not all the state of the ``interact`` canvas has been set up yet 3167 (this setup happens when JavaScript calls certain functions):: 3168 2806 3169 sage: sage.server.notebook.interact.recompute(10) 2807 3170 __SAGE_INTERACT_RESTART__ 2808 3171 -
sage/server/notebook/js.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/js.py
a b 1 1 r"""nodoctest 2 Java script (AJAX) Component of \sage Notebook2 JavaScript (AJAX) Components of the Notebook 3 3 4 4 AUTHORS: 5 5 -
sage/server/notebook/notebook.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/notebook.py
a b 284 284 285 285 def create_user_with_same_password(self, user, other_user): 286 286 r""" 287 Changes password of ``user`` to that of ``other_user``. 288 287 289 INPUT: 288 290 289 291 290 292 - ``user`` - a string 291 293 292 - ``other_user`` - a strin g294 - ``other_user`` - a strin 293 295 294 296 295 OUTPUT: Changes password of ``user`` to that of296 ``other_user``.297 298 297 EXAMPLES:: 299 298 300 299 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) … … 315 314 316 315 def user_is_admin(self, user): 317 316 """ 317 Returns true if ``user`` is an admin. 318 319 INPUT: 320 321 - user - instance of User 322 318 323 EXAMPLES:: 319 324 320 325 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 321 sage: nb.add_user('Administrator', 'password', ", 'admin', True)322 sage: nb.add_user('RegularUser', 'password', ", 'user', True)326 sage: nb.add_user('Administrator', 'password', '', 'admin', True) 327 sage: nb.add_user('RegularUser', 'password', '', 'user', True) 323 328 sage: nb.user_is_admin('Administrator') 324 329 True 325 330 sage: nb.user_is_admin('RegularUser') … … 329 334 330 335 def user_is_guest(self, username): 331 336 """ 337 Returns true if ``username`` is a guest. 338 339 INPUT: 340 341 - username - String of the username 342 332 343 EXAMPLES:: 333 344 334 345 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) … … 384 395 Creating default users. 385 396 sage: nb.valid_login_names() 386 397 ['admin'] 387 sage: nb.add_user('Mark', 'password', ", force=True)388 sage: nb.add_user('Sarah', 'password', ", force=True)389 sage: nb.add_user('David', 'password', ", force=True)398 sage: nb.add_user('Mark', 'password', '', force=True) 399 sage: nb.add_user('Sarah', 'password', '', force=True) 400 sage: nb.add_user('David', 'password', '', force=True) 390 401 sage: sorted(nb.valid_login_names()) 391 402 ['David', 'Mark', 'Sarah', 'admin'] 392 403 """ 393 404 return [x for x in self.usernames() if not x in ['guest', '_sage_', 'pub']] 394 405 395 406 def default_user(self): 396 """407 r""" 397 408 Return a default login name that the user will see when confronted 398 409 with the Sage notebook login page. 399 410 400 OUTPUT: string 401 402 Currently this returns 'admin' if that is the *only* user. 403 Otherwise it returns the string ". 411 OUTPUT: 412 413 string -- the default username. Currently this returns 'admin' 414 if that is the *only* user. Otherwise it returns an empty string 415 (''). 404 416 405 417 EXAMPLES:: 406 418 … … 409 421 Creating default users. 410 422 sage: nb.default_user() 411 423 'admin' 412 sage: nb.add_user('AnotherUser', 'password', ", force=True)424 sage: nb.add_user('AnotherUser', 'password', '', force=True) 413 425 sage: nb.default_user() 414 426 '' 415 427 """ … … 478 490 EXAMPLES:: 479 491 480 492 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 481 sage: nb.add_user('Mark', 'password', ", force=True)493 sage: nb.add_user('Mark', 'password', '', force=True) 482 494 sage: nb.user('Mark') 483 495 Mark 484 496 sage: nb.add_user('Sarah', 'password', ") … … 512 524 EXAMPLES:: 513 525 514 526 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 515 sage: nb.add_user('Mark', 'password', ", force=True)527 sage: nb.add_user('Mark', 'password', '', force=True) 516 528 sage: nb.user('Mark').password() 517 529 'aajfMKNH1hTm2' 518 530 sage: nb.change_password('Mark', 'different_password') … … 528 540 EXAMPLES:: 529 541 530 542 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 531 sage: nb.add_user('Mark', 'password', ", force=True)543 sage: nb.add_user('Mark', 'password', '', force=True) 532 544 sage: nb.user('Mark') 533 545 Mark 534 546 sage: nb.del_user('Mark') … … 549 561 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 550 562 sage: nb.create_default_users('password') 551 563 Creating default users. 552 sage: nb.add_user('Mark', 'password', ", force=True)564 sage: nb.add_user('Mark', 'password', '', force=True) 553 565 sage: list(sorted(nb.passwords().iteritems())) 554 566 [('Mark', 'aajfMKNH1hTm2'), ('_sage_', 'aaQSqAReePlq6'), ('admin', 'aajfMKNH1hTm2'), ('guest', 'aaQSqAReePlq6'), ('pub', 'aaQSqAReePlq6')] 555 567 """ … … 1170 1182 Outputs html containing the plain text version of a worksheet 1171 1183 1172 1184 INPUT: 1185 1186 1173 1187 - ``filename`` - filename of a worksheet 1188 1174 1189 - ``prompts`` - boolean 1175 1190 1176 1191 OUTPUT: 1177 - A string containing the html for the plain text version 1192 1193 - string -- containing the html for the plain text version 1178 1194 """ 1179 1195 worksheet = self.get_worksheet_with_filename(filename) 1180 1196 text = escape(worksheet.plain_text(prompts = prompts)) … … 1309 1325 return s 1310 1326 1311 1327 def worksheet_html(self, filename, do_print=False): 1312 """1328 r""" 1313 1329 Returns the HTML for the worksheet. 1314 1330 1315 1331 INPUT: 1332 1333 1316 1334 - ``username`` - a string 1335 1317 1336 - ``worksheet`` - an instance of Worksheet 1318 1337 1319 1338 OUTPUT: 1320 - a string containing the HTML 1339 1340 - string -- the HTML for the worksheet 1321 1341 1322 1342 EXAMPLES:: 1323 1343 … … 1359 1379 # Revision history for a worksheet 1360 1380 ########################################################## 1361 1381 def html_worksheet_revision_list(self, username, worksheet): 1362 """1382 r""" 1363 1383 Returns the HTML for the revision list of a worksheet. 1364 1384 1365 1385 INPUT: 1386 1387 1366 1388 - ``username`` - a string 1389 1367 1390 - ``worksheet`` - an instance of Worksheet 1368 1391 1369 1392 OUTPUT: 1370 - a string containing the HTML 1393 1394 1395 - string -- the HTML for the revision list 1371 1396 1372 1397 EXAMPLES:: 1373 1398 … … 1389 1414 1390 1415 1391 1416 def html_specific_revision(self, username, ws, rev): 1392 """1417 r""" 1393 1418 Returns the HTML for a revision of the worksheet. 1394 1419 1395 1420 INPUT: 1421 1422 1396 1423 - ``username`` - a string 1424 1397 1425 - ``ws`` - an instance of Worksheet 1426 1398 1427 - ``rev`` - a string containing the key of the revision 1399 1428 1400 1429 OUTPUT: 1401 - a string containing the HTML 1430 1431 - string -- the HTML for the revision 1402 1432 """ 1403 1433 t = time.time() - float(rev[:-4]) 1404 1434 time_ago = worksheet.convert_seconds_to_meaningful_time_span(t) … … 1434 1464 1435 1465 1436 1466 def html_share(self, worksheet, username): 1437 """1467 r""" 1438 1468 Returns the HTML for the share page of a worksheet. 1439 1469 1440 1470 INPUT: 1471 1472 1441 1473 - ``username`` - a string 1474 1442 1475 - ``worksheet`` - an instance of Worksheet 1443 1476 1444 1477 OUTPUT: 1445 - a string containing the HTML 1478 1479 1480 - string -- the HTML for the share page 1446 1481 1447 1482 EXAMPLES:: 1448 1483 … … 1466 1501 1467 1502 1468 1503 def html_download_or_delete_datafile(self, ws, username, filename): 1469 """1504 r""" 1470 1505 Returns the HTML for the download or delete datafile page. 1471 1506 1472 1507 INPUT: 1508 1509 1473 1510 - ``username`` - a string 1511 1474 1512 - ``ws`` - an instance of Worksheet 1513 1475 1514 - ``filename`` - the name of the file 1476 1515 1477 1516 OUTPUT: 1478 - a string containing the HTML 1517 1518 1519 - string -- the HTML for the page 1479 1520 1480 1521 EXAMPLES:: 1481 1522 … … 1613 1654 # HTML -- generate most html related to the whole notebook page 1614 1655 ########################################################### 1615 1656 def html_debug_window(self): 1616 """1657 r""" 1617 1658 Returns the HTML for the debug window 1618 1659 1619 1660 OUTPUT: 1620 - the HTML for the debug window 1661 1662 - string -- the HTML for the debug window 1621 1663 1622 1664 EXAMPLES:: 1623 1665 1624 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 1625 sage: print(nb.html_debug_window()) 1626 <div class='debug_window'> 1627 <div class='debug_output'><pre id='debug_output'></pre></div> 1628 <textarea rows=5 id='debug_input' class='debug_input' 1629 onKeyPress='return debug_keypress(event);' 1630 onFocus='debug_focus();' onBlur='debug_blur();'></textarea> 1631 </div> 1666 sage: nb = sage.server.notebook.notebook.Notebook(tmp_dir()) 1667 sage: nb.html_debug_window() 1668 "\n<div class='debug_window'>...</div>" 1632 1669 """ 1633 1670 return template("notebook/debug_window.html") 1634 1671 1635 1672 1636 1673 def html_plain_text_window(self, worksheet, username): 1637 """1674 r""" 1638 1675 Returns a window that displays a plain text version of the 1639 1676 worksheet 1640 1677 1641 1678 INPUT: 1679 1680 1642 1681 - ``worksheet`` - a worksheet 1682 1643 1683 - ``username`` - name of the user 1644 1684 1645 1685 OUTPUT: 1646 - a window that displays a plain text version of the 1647 worksheet 1686 1687 1688 - string -- html for a window that displays a plain text 1689 version of the worksheet 1648 1690 1649 1691 EXAMPLES:: 1650 1692 … … 1669 1711 Return a window for editing ``worksheet``. 1670 1712 1671 1713 INPUT: 1714 1715 1672 1716 - ``username`` - a string containing the username 1717 1673 1718 - ``worksheet`` - a Worksheet instance 1674 1719 1675 1720 OUTPUT: 1721 1676 1722 - html for a window for editing ``worksheet``. 1677 1723 1678 1724 EXAMPLES:: … … 1695 1741 sage_jsmath_macros = sage_jsmath_macros) 1696 1742 1697 1743 def html_beforepublish_window(self, worksheet, username): 1698 """1744 r""" 1699 1745 Return the html code for a page dedicated to worksheet publishing 1700 1746 prior to the publication of the given worksheet. 1701 1747 1702 1748 INPUT: 1749 1750 1703 1751 - ``worksheet`` - instance of Worksheet 1752 1704 1753 - ``username`` - string 1705 1754 1706 1755 EXAMPLES:: … … 1728 1777 sage_jsmath_macros = sage_jsmath_macros) 1729 1778 1730 1779 def html_afterpublish_window(self, worksheet, username, url, dtime): 1731 """1780 r""" 1732 1781 Return the html code for a page dedicated to worksheet publishing 1733 1782 after the publication of the given worksheet. 1734 1783 1735 1784 INPUT: 1785 1786 1736 1787 - ``worksheet`` - instance of Worksheet 1788 1737 1789 - ``username`` - string 1790 1738 1791 - ``url`` - a string representing the url of the published worksheet 1792 1739 1793 - ``dtime`` - instance of time.struct_time representing the publishing time 1740 1794 """ 1741 1795 from time import strftime … … 1750 1804 sage_jsmath_macros = sage_jsmath_macros) 1751 1805 1752 1806 def html_upload_data_window(self, ws, username): 1753 """1807 r""" 1754 1808 Returns the html for the "Upload Data" window 1755 1809 1756 1810 INPUT: 1811 1812 1757 1813 - ``worksheet`` - instance of Worksheet 1814 1758 1815 - ``username`` - string 1759 1816 1760 1817 EXAMPLES:: … … 1773 1830 1774 1831 1775 1832 def html(self, worksheet_filename=None, username='guest', show_debug=False, admin=False): 1776 """1833 r""" 1777 1834 Returns the html for index page of a worksheet. 1778 1835 1779 1836 INPUT: 1837 1838 1780 1839 - ``worksheet_filename`` - a string 1840 1781 1841 - ``username`` - a string 1842 1782 1843 - ``show_debug`` - a boolean 1844 1783 1845 - ``admin`` - a boolean 1784 1846 1785 1847 EXAMPLES:: … … 1820 1882 1821 1883 1822 1884 def html_worksheet_settings(self, ws, username): 1823 """1885 r""" 1824 1886 Returns the html for the setings page of the worksheet. 1825 1887 1826 1888 INPUT: 1889 1827 1890 - ``ws`` - instance of Worksheet 1891 1828 1892 - ``username`` - string 1829 1893 1830 1894 EXAMPLES:: … … 1856 1920 return s 1857 1921 1858 1922 def html_doc(self, username): 1859 """1923 r""" 1860 1924 Returns the html for the documentation pages. 1861 1925 1862 1926 INPUT: 1927 1863 1928 - ``worksheet_filename`` - a string 1929 1864 1930 - ``username`` - a string 1931 1865 1932 - ``show_debug`` - a boolean 1933 1866 1934 - ``admin`` - a boolean 1867 1935 1868 1936 EXAMPLES:: -
sage/server/notebook/sage_email.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/sage_email.py
a b 6 6 email server or anything else, since Sage already includes by default 7 7 a sophisticated email server (which is part of Twisted). 8 8 9 EXAMPLES: 9 EXAMPLES:: 10 10 11 sage: email('xxxsageuser@gmail.com', 'The calculation finished!') # not tested 11 12 Child process ... is sending email to xxxsageuser@gmail.com 12 13 … … 32 33 OUTPUT: 33 34 string 34 35 35 EXAMPLES: 36 EXAMPLES:: 37 36 38 sage: sage.server.notebook.sage_email.default_email_address() 37 39 '...@...' 38 40 """ … … 64 66 be a problem, but might be useful for certain 65 67 users. 66 68 67 EXAMPLES: 69 EXAMPLES:: 70 68 71 sage: email('xxxsageuser@gmail.com', 'The calculation finished!') # not tested 69 72 Child process ... is sending email to xxxsageuser@gmail.com 70 73 -
sage/server/notebook/sagetex.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/sagetex.py
a b 8 8 9 9 THIS IS ONLY A PROOF-of-CONCEPT. 10 10 11 EXAMPLES: 11 EXAMPLES:: 12 12 13 sage: sagetex('foo.tex') # not tested 13 14 [pops up web browser with live version of foo.tex.] 14 15 """ -
sage/server/notebook/template.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/template.py
a b 1 1 # -*- coding: utf-8 -*- 2 2 """ 3 HTML templating for the notebook3 HTML Templating for the Notebook 4 4 5 5 AUTHORS: 6 6 -- Bobby Moretti (2007-07-18): initial version … … 26 26 and returns True if that value is in the container and False 27 27 otherwise. This is registered and used as a test in the templates. 28 28 29 EXAMPLES: 29 EXAMPLES:: 30 30 31 sage: from sage.server.notebook.template import contained_in 31 32 sage: f = contained_in([1,2,3]) 32 33 sage: f(None, None, 2) … … 54 55 filename -- the filename of the template relative to 55 56 $SAGE_ROOT/devel/sage/sage/server/notebook/templates 56 57 57 EXAMPLES: 58 EXAMPLES:: 59 58 60 sage: from sage.server.notebook.template import template 59 61 sage: s = template('yes_no.html'); type(s) 60 62 <type 'str'> -
sage/server/notebook/twist.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/twist.py
a b 134 134 Returns an HTMLResponse object whose 'Content-Type' header has been set 135 135 to 'text/html; charset=utf-8 136 136 137 EXAMPLES: 137 EXAMPLES:: 138 138 139 sage: from sage.server.notebook.twist import HTMLResponse 139 140 sage: response = HTMLResponse(stream='<html><head><title>Test</title></head><body>Test</body></html>') 140 141 sage: response.headers -
sage/server/notebook/user.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/user.py
a b 63 63 64 64 def username(self): 65 65 """ 66 EXAMPLES: 66 EXAMPLES:: 67 67 68 sage: from sage.server.notebook.user import User 68 69 sage: User('andrew', 'tEir&tiwk!', 'andrew@matrixstuff.com', 'user').username() 69 70 'andrew' … … 79 80 80 81 def conf(self): 81 82 """ 82 EXAMPLES: 83 EXAMPLES:: 84 83 85 sage: from sage.server.notebook.user import User 84 86 sage: config = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin').conf(); config 85 87 Configuration: {} … … 102 104 103 105 def password(self): 104 106 """ 105 EXAMPLES: 107 EXAMPLES:: 108 106 109 sage: from sage.server.notebook.user import User 107 110 sage: user = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin') 108 111 sage: user.password() … … 112 115 113 116 def set_password(self, password): 114 117 """ 115 EXAMPLES: 118 EXAMPLES:: 119 116 120 sage: from sage.server.notebook.user import User 117 121 sage: user = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin') 118 122 sage: old = user.password() … … 127 131 128 132 def set_hashed_password(self, password): 129 133 """ 130 EXAMPLES: 134 EXAMPLES:: 135 131 136 sage: from sage.server.notebook.user import User 132 137 sage: user = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin') 133 138 sage: user.set_hashed_password('Crrc!') … … 138 143 139 144 def get_email(self): 140 145 """ 141 EXAMPLES: 146 EXAMPLES:: 147 142 148 sage: from sage.server.notebook.user import User 143 149 sage: user = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin') 144 150 sage: user.get_email() … … 148 154 149 155 def set_email(self, email): 150 156 """ 151 EXAMPLES: 157 EXAMPLES:: 158 152 159 sage: from sage.server.notebook.user import User 153 160 sage: user = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin') 154 161 sage: user.get_email() … … 161 168 162 169 def set_email_confirmation(self, value): 163 170 """ 164 EXAMPLES: 171 EXAMPLES:: 172 165 173 sage: from sage.server.notebook.user import User 166 174 sage: user = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin') 167 175 sage: user.is_email_confirmed() … … 178 186 179 187 def is_email_confirmed(self): 180 188 """ 181 EXAMPLES: 189 EXAMPLES:: 190 182 191 sage: from sage.server.notebook.user import User 183 192 sage: user = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin') 184 193 sage: user.is_email_confirmed() … … 192 201 193 202 def password_is(self, password): 194 203 """ 195 EXAMPLES: 204 EXAMPLES:: 205 196 206 sage: from sage.server.notebook.user import User 197 207 sage: user = User('bob', 'Aisfa!!', 'bob@sagemath.net', 'admin') 198 208 sage: user.password_is('ecc') … … 206 216 207 217 def account_type(self): 208 218 """ 209 EXAMPLES: 219 EXAMPLES:: 220 210 221 sage: from sage.server.notebook.user import User 211 222 sage: User('A', account_type='admin').account_type() 212 223 'admin' … … 221 232 222 233 def is_admin(self): 223 234 """ 224 EXAMPLES: 235 EXAMPLES:: 236 225 237 sage: from sage.server.notebook.user import User 226 238 sage: User('A', account_type='admin').is_admin() 227 239 True … … 232 244 233 245 def is_guest(self): 234 246 """ 235 EXAMPLES: 247 EXAMPLES:: 248 236 249 sage: from sage.server.notebook.user import User 237 250 sage: User('A', account_type='guest').is_guest() 238 251 True -
sage/server/notebook/worksheet.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/notebook/worksheet.py
a b 1236 1236 OUTPUT: 1237 1237 1238 1238 1239 - ``string`` - a string of HTML as a bunch of table1239 - ``string`` -- a string of HTML as a bunch of table 1240 1240 rows. 1241 1241 1242 1242 … … 2097 2097 - ``text`` - a string 2098 2098 2099 2099 - ``ignore_ids`` - bool (default: False); if True 2100 ignore all the id's in the code block.2100 ignore all the id's in the {{{}}} code block. 2101 2101 2102 2102 2103 2103 EXAMPLES: We create a new test notebook and a worksheet. … … 2212 2212 ########################################################## 2213 2213 def html(self, include_title=True, do_print=False, 2214 2214 confirm_before_leave=False, read_only=False): 2215 """ 2216 INPUT: 2215 r""" 2216 INPUT: 2217 2218 2217 2219 - publish - a boolean stating whether the worksheet is published 2220 2218 2221 - do_print - a boolean 2219 2222 2220 2223 OUTPUT: 2221 - returns the html for the worksheet 2224 2225 2226 - string -- the html for the worksheet 2222 2227 2223 2228 EXAMPLES:: 2224 2229 … … 2275 2280 def html_save_discard_buttons(self): 2276 2281 r""" 2277 2282 OUTPUT: 2278 - returns the html for the save, discard, etc. buttons 2283 2284 - string -- the html for the save, discard, etc. buttons 2279 2285 2280 2286 EXAMPLES:: 2281 2287 … … 2289 2295 def html_share_publish_buttons(self, select=None, backwards=False): 2290 2296 r""" 2291 2297 INPUT: 2298 2299 2292 2300 - select - a boolean 2301 2293 2302 - backwards - a boolean 2294 2303 2295 2304 OUTPUT: 2296 - returns the html for the share, publish, etc. buttons 2305 2306 2307 - string -- the html for the share, publish, etc. buttons 2297 2308 2298 2309 EXAMPLES:: 2299 2310 … … 2310 2321 # <option title="Configure this worksheet" value="worksheet_settings();">Worksheet settings</option> 2311 2322 2312 2323 def html_menu(self): 2313 """ 2314 OUTPUT: 2315 - returns the html for the menus of the worksheet 2324 r""" 2325 OUTPUT: 2326 2327 - string -- the html for the menus of the worksheet 2316 2328 2317 2329 EXAMPLES:: 2318 2330 … … 2330 2342 doc_worksheet = self.is_doc_worksheet()) 2331 2343 2332 2344 def html_worksheet_body(self, do_print, publish=False): 2333 """ 2334 INPUT: 2345 r""" 2346 INPUT: 2347 2348 2335 2349 - publish - a boolean stating whether the worksheet is published 2350 2336 2351 - do_print - a boolean 2337 2352 2338 2353 OUTPUT: 2339 - returns the html for the File menu of the worksheet 2354 2355 2356 - string -- the html for the File menu of the worksheet 2340 2357 2341 2358 EXAMPLES:: 2342 2359 … … 4020 4037 def format_completions_as_html(cell_id, completions): 4021 4038 """ 4022 4039 INPUT: 4040 4041 4023 4042 - cell_id - id for the cell of the completions 4043 4024 4044 - completions - list of completions in row-major order 4025 4045 4026 4046 OUTPUT: 4027 - html for the completions formatted in rows and columns 4047 4048 4049 - string -- html for the completions formatted in rows and columns 4028 4050 """ 4029 4051 if len(completions) == 0: 4030 4052 return '' -
sage/server/simple/twist.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/simple/twist.py
a b 1 1 r""" 2 Simple Sage API2 Simple Sage Server API 3 3 4 4 This module provides a very simple API for interacting with a Sage session 5 5 over HTTP. It runs as part of the notebook server. -
sage/server/support.py
diff -r 832b46058006 -r 37265ae04e84 sage/server/support.py
a b 1 1 """ 2 Support for the Notebook (introspection and setup)2 Support for Notebook Introspection and Setup 3 3 4 4 AUTHORS: 5 5 … … 350 350 OUTPUT: 351 351 The output of system.eval is returned. 352 352 353 EXAMPLES: 353 EXAMPLES:: 354 354 355 sage: from sage.misc.python import python 355 356 sage: sage.server.support.syseval(python, '2+4/3') 356 357 3