Opened 11 years ago

Closed 11 years ago

#8959 closed enhancement (fixed)

interact layouts with arbitrary html

Reported by: jason Owned by: itolkov, jason
Priority: major Milestone: sage-4.5
Component: interact Keywords:
Cc: was, timdumol, mhampton Merged in: SageNB 0.8.1
Authors: Jason Grout Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

The layout argument of an interact should also accept a string, maybe a string in the format of either standard python formats (i.e., "<table><tr><td>{a}</td></tr></table>"), or using the simple template classes that come with python (i.e., "<table><tr><td>$a</td></tr></table>"). Whichever convention is chosen, the string is given the dictionary of {'variable name': 'html for variable control'}, or maybe {'variable name': {'label': HTML label, 'control': 'html for control'}}, so you could do "<td>{a.label}</td><td>{a.control}</td>".

Attachments (3)

Interact Layouts.png (72.6 KB) - added by jason 11 years ago.
trac-8959-interact-layout-align.patch (7.8 KB) - added by jason 11 years ago.
for SAGENB repository
trac-8959-handle-update-button.patch (2.6 KB) - added by jason 11 years ago.
apply on top of previous patches

Download all attachments as: .zip

Change History (11)

comment:1 Changed 11 years ago by jason

See #7379 for the initial implementation of this feature.

comment:2 Changed 11 years ago by jason

  • Cc was timdumol added

Okay, the attached patch lets you specify controls on each side, as well as the width of the interact. The following code gives the interact in the screenshot attached.

var('x')
@interact(layout=dict(top=[['f'],['r','plot_points']], bottom=[['color','thickness'],['adaptive_recursion','adaptive_tolerance']], left=[['gridlines'],['fill'],['frame'],['axes']], right=[['linestyle']]))
def plot_example(f=sin(x^2),r=range_slider(-5,5,step_size=1/4,default=(-3,3)), 
                 color=color_selector(widget='colorpicker'),
                 thickness=(3,(1..10)),
                 adaptive_recursion=(5,(0..10)), adaptive_tolerance=(0.01,(0.001,1)),
                 plot_points=(20,(1..100)),
                 linestyle=['-','--','-.',':'],
                 gridlines=False, fill=False,
                 frame=False, axes=True
                 ):
    show(plot(f, (x,r[0],r[1]), color=color, thickness=thickness, 
                 adaptive_recursion=adaptive_recursion,
                 adaptive_tolerance=adaptive_tolerance, plot_points=plot_points,
                 linestyle=linestyle, fill=fill if fill else None), 
                 gridlines=gridlines, frame=frame, axes=axes)

Changed 11 years ago by jason

comment:3 Changed 11 years ago by rbeezer

Jason,

Nice work - this will improve the utilization of screen real estate.

Was there a patch to include?

Rob

Changed 11 years ago by jason

for SAGENB repository

comment:4 Changed 11 years ago by jason

  • Authors set to Jason Grout
  • Status changed from new to needs_review

This patch depends on #7379 and extends the functionality there.

Changed 11 years ago by jason

apply on top of previous patches

comment:5 Changed 11 years ago by jason

  • Cc mhampton added

The handle-update-button patch takes care of the auto_update problem mhampton pointed out on #7379. At least, I think it does; the feature seems to work. I don't know how to doctest the notebook after I've done "sage -python setup.py develop" to work on notebook files. When I try to run sage -t, there's just an error about importing jsmath.

comment:6 Changed 11 years ago by mhampton

You can do:

sage -t -sagenb

to test the notebook. I'll try to check the patch out today.

comment:7 Changed 11 years ago by mhampton

  • Status changed from needs_review to positive_review

Tests pass now and a variety of interacts from the wiki work fine as well.

It would be nice if there was an easy way to pack things in various ways. It also makes me desire an option for slider and range_slider to change their lengths, but that's for another day.

comment:8 Changed 11 years ago by timdumol

  • Merged in set to SageNB 0.8.1
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.