William Stein wrote: > On Tue, Nov 3, 2009 at 1:04 AM, Jason Grout <jason-s...@creativetrax.com> > wrote: >> I just spent some time thinking about how to specify layouts for >> interact controls. Here's a possible syntax: >> >> @interact(layout=[['a','b'],['c','d']]) >> def _(a=1,b=(2,3),c="hi",d=x+1): >> print a,b,c,d >> >> >> This would lay out a table with a and b in the same row, then c and d in >> the same row. >> >> More generally, we can use templates (jinja2?) and html: >> >> @interact(layout=""" >> some template code, containing variables a, b, c, d, that are each set >> to the html representation of the control >> """) >> def _(a=1,b=(2,3),c="hi",d=x+1): >> print a,b,c,d >> >> >> What do people think? I think these changes would be fairly easy to >> implement, and would be backwards-compatible with what we have now. >> >> Another option would be having the layout a parameter of the actual >> function: >> >> @interact >> def _(a=1,b=(2,3),c="hi",d=x+1, layout=""" >> some template code, containing variables a, b, c, d, that are each set >> to the html representation of the control >> """)): >> print a,b,c,d >> >> Or we could do things more like mathematica does, and let you just >> specify the layout when you specify the variables: >> >> @interact >> def _(row(('a',1),('b',(2,3))),row(['c',"hi"],['d',x+1])): >> print a,b,c,d >> >> or something. This sort of obscures the variables you are using, >> though, and makes it hard to change layouts; it greatly confuses the >> content and presentation. It also makes it difficult to use the >> function outside of interacts, whereas separately specifying the layout >> as above makes it easy to use the function outside of the interact >> framework. > > What do other systems do to specify layout? The interact controls > are based on the Mathematica's "Manipulate", so that users of > Manipulate will have less trouble transition to Sage's interact. > Surely mathematica has a system for laying out controls. Is your > design above informed at all by that/ Also, I like the idea of just > using HTML (e.g., your jinja suggestions), since HTML/CSS is a > standard way to layout web pages.
In the end, of course, everything would be html. That means that in the end, you can have your draggable controls by just writing the right jquery/whatever html as containers for the controls. The nested list layout above is just a convenience for constructing a grid of controls. Mathematica definitely does have a system for laying out things. The "row" example above mirrors that. See http://reference.wolfram.com/mathematica/tutorial/GridsRowsAndColumns.html for documentation, for example. Basically, you can use any layout functionality in Mathematica for the controls, since the Manipulate is just a wrapper around Dynamic and DynamicModule functionality. So Mathematica allows, in place of a specifying a control, a layout specification: "Possible annotations given in place of controls include expressions with heads String, Style, Row, Item, Text, ExpressionCell, TextCell as well as views and layout constructs such as TabView and Grid." We don't have a rich layout language, but we could make such a layout language and convert grid, row, column, tabview, etc. constructs to bits of html code, or to qt code if we did an Envisage frontend, etc. Thanks, Jason -- Jason Grout --~--~---------~--~----~------------~-------~--~----~ To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---