Ticket #3636: trac3636_1.patch

File trac3636_1.patch, 4.3 kB (added by itolkov, 4 months ago)
  • a/sage/server/notebook/all.py

    old new  
    1414 
    1515from sagetex import sagetex 
    1616 
    17 from interact import interact, input_box, slider, selector, checkbox, input_grid 
     17from interact import interact, input_box, slider, selector, checkbox, input_grid, text_control 
  • a/sage/server/notebook/interact.py

    old new  
    10011001        return html_slider('slider-%s-%s'%(self.var(), self.cell_id()), 
    10021002                           s, self.interact(), steps=len(self.__values), 
    10031003                           default=self.default_position()) 
    1004      
     1004 
     1005 
     1006class TextControl(InteractControl): 
     1007    def __init__(self, var, data): 
     1008        """ 
     1009        A text field interact control 
     1010 
     1011        INPUT: 
     1012            data -- the HTML value of the text field 
     1013 
     1014        EXAMPLES: 
     1015            sage: sage.server.notebook.interact.TextControl('x', 'something') 
     1016            Text Interact Control: something 
     1017        """ 
     1018        InteractControl.__init__(self, var, data, label='') 
     1019        self.__data = data 
     1020 
     1021    def __repr__(self): 
     1022        """ 
     1023        Return string representation of this control. 
     1024 
     1025        EXAMPLES: 
     1026            sage: sage.server.notebook.interact.TextControl('x', 'something').__repr__() 
     1027            'Text Interact Control: something' 
     1028        """ 
     1029        return 'Text Interact Control: %s'%self.default_value() 
     1030 
     1031    def render(self): 
     1032        """ 
     1033        Render this control as an HTML string. 
     1034 
     1035        OUTPUT: 
     1036             string -- html format 
     1037 
     1038        EXAMPLES: 
     1039            sage: sage.server.notebook.interact.TextControl('x', 'something').render() 
     1040            '<div ...>something</div>' 
     1041        """ 
     1042        return '<div style="color:black; padding-bottom:5px">%s</div>'%self.default_value() 
     1043 
    10051044 
    10061045class InteractCanvas: 
    10071046    def __init__(self, controls, id): 
     
    10921131            sage: sage.server.notebook.interact.InteractCanvas([B], 3).render_controls() 
    10931132            '<table>...' 
    10941133        """ 
    1095         row = '<tr><td align=right><font color="black">%s&nbsp;</font></td><td>%s</td></tr>\n' 
    1096         tbl_body = ''.join([row%(c.label(), c.render()) for c in self.__controls]) 
     1134        tbl_body = '' 
     1135        for c in self.__controls: 
     1136            if c.label() == '': 
     1137                tbl_body += '<tr><td colspan=2>%s</td></tr>\n'%c.render() 
     1138            else: 
     1139                tbl_body += '<tr><td align=right><font color="black">%s&nbsp;</font></td><td>%s</td></tr>\n'%( 
     1140                c.label(), c.render()) 
    10971141        return '<table>%s</table>'%tbl_body 
    10981142 
    10991143    def wrap_in_outside_frame(self, inside): 
     
    19802024                        nrows=self.__nrows, ncols=self.__ncols, width=self.__width, 
    19812025                        buttons=self.__buttons) 
    19822026     
     2027class text_control(control): 
     2028    def __init__(self, value): 
     2029        """ 
     2030        Text that can be inserted among other interact controls. 
     2031 
     2032        INPUT: 
     2033            value -- HTML for the control 
     2034 
     2035        EXAMPLES: 
     2036            sage: text_control('something') 
     2037            Text field: something 
     2038        """ 
     2039        self.__default = value 
     2040        control.__init__(self, '') 
     2041 
     2042    def __repr__(self): 
     2043        """ 
     2044        Return print representation of this control.  
     2045 
     2046        EXAMPLES: 
     2047            sage: text_control('something') 
     2048            Text field: something 
     2049        """ 
     2050        return "Text field: %s"%self.__default 
     2051 
     2052    def render(self, var): 
     2053        """ 
     2054        Return rendering of the text field  
     2055         
     2056        INPUT: 
     2057            var -- a string (variable; one of the variable names input to f) 
     2058 
     2059        OUTPUT: 
     2060            TextControl -- a TextControl instance 
     2061        """ 
     2062        return TextControl(var, self.__default) 
     2063 
    19832064 
    19842065def automatic_control(default): 
    19852066    """