#7379: layout interact controls
---------------------------+------------------------------------------------
Reporter: jason | Owner: boothby
Type: enhancement | Status: new
Priority: major | Milestone: sage-4.2.1
Component: notebook | Keywords:
Work_issues: | Author:
Reviewer: | Merged:
---------------------------+------------------------------------------------
Comment(by jason):
Here is a patch to the sagenb directory which allows for the following:
{{{
@interact(layout=[['a','b'],['c','d']])
def _(a=(1,2),b=(3,10),c=["test","button"],d=x^2+1):
print a,b,c,d
}}}
{{{
diff -r 69309549b229 notebook/interact.py
--- a/notebook/interact.py Tue Nov 03 03:14:01 2009 -0600
+++ b/notebook/interact.py Tue Nov 03 03:48:40 2009 -0600
@@ -1795,15 +1795,25 @@
sage: sagenb.notebook.interact.InteractCanvas([B],
3).render_controls()
'<table>...'
"""
+ layout = self.__options.get('layout',None)
tbl_body = ''
- for c in self.__controls:
- if c.label() == '':
- tbl_body += '<tr><td colspan=2>%s</td></tr>\n'%c.render()
- else:
- tbl_body += '<tr><td align=right><font
color="black">%s </font></td><td>%s</td></tr>\n'%(
- c.label(), c.render())
+ if layout is None:
+ layout = [[c.var()] for c in self.__controls]
+
+ controls = dict([c.var(), c] for c in self.__controls)
+ for row in layout:
+ tbl_body += '<tr>'
+ for c_name in row:
+ c = controls[c_name]
+ if c.label() == '':
+ tbl_body += '<td colspan=2>%s</td>\n'%c.render()
+ else:
+ tbl_body += '<td align=right><font
color="black">%s </font></td><td>%s</td>\n'%(c.label(), c.render())
+
+ tbl_body += '</tr>'
+
return '<table>%s</table>'%tbl_body
-
+
def wrap_in_outside_frame(self, inside):
"""
Return the entire HTML for the interactive canvas, obtained by
@@ -1907,8 +1917,15 @@
"""
s = 'interact(%s, "_interact_.recompute(%s)")'%(cell_id, cell_id)
JavascriptCodeButton.__init__(self, "Update", s)
-
-def interact(f):
+
+def interact(*args,**kwds):
+ if len(kwds)==0 and len(args)==1:
+ # call without parentheses
+ return _interact(*args)
+ else:
+ return lambda f: _interact(f, **kwds)
+
+def _interact(f,**kwds):
r"""
Use interact as a decorator to create interactive Sage notebook
cells with sliders, text boxes, radio buttons, check boxes, and
@@ -2281,7 +2298,9 @@
i = args.index('auto_update')
controls[i] = UpdateButton(SAGE_CELL_ID)
- C = InteractCanvas(controls, SAGE_CELL_ID, auto_update=auto_update)
+ layout = kwds.get('layout',None)
+
+ C = InteractCanvas(controls, SAGE_CELL_ID, auto_update=auto_update,
layout=layout)
html(C.render())
def _():
}}}
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7379#comment:1>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---