Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPEP 23: Backbone.js Widgets #4374

Merged
merged 474 commits into from
Jan 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
474 commits
Select commit Hold shift + click to select a range
428a8bf
- ModalView can now be docked and undocked
jdfreder Dec 6, 2013
2cf5ad7
- Fixed CSS so it also applies to widgets within modals
jdfreder Dec 6, 2013
108ab2b
Fab CSS
jdfreder Dec 6, 2013
8160877
s/LabelView/HTMLView
jdfreder Dec 6, 2013
09112f4
Added LatexView
jdfreder Dec 6, 2013
73f786b
Remove uneccessary lines in String.js
jdfreder Dec 7, 2013
36f8d83
Add ImageWidget
jdfreder Dec 7, 2013
c633979
Added float range widget tests
jdfreder Dec 9, 2013
8995edf
Fixed flushed messages not getting sent with new 'method' message tag
jdfreder Dec 9, 2013
cc21fe3
Added float widget tests
jdfreder Dec 9, 2013
7ea0c5b
Added ImageWidget tests
jdfreder Dec 10, 2013
b8242a9
Added int range and int widget tests.
jdfreder Dec 10, 2013
6f24736
Fixed backbone event handling for accordion view
jdfreder Dec 11, 2013
60d945e
Added multicontainer widget tests
jdfreder Dec 11, 2013
0678a52
jshint widget.js
jdfreder Dec 11, 2013
400ef7d
Partially implemented selection widget tests
jdfreder Dec 11, 2013
6ba0bab
Removed js test utils commit and rebased with master.
jdfreder Dec 11, 2013
ab1a8d2
Added selection widget tests
jdfreder Dec 11, 2013
4e15ad1
Added list modification test to selection widget.
jdfreder Dec 11, 2013
69edada
Added StringWidget tests
jdfreder Dec 12, 2013
8861e54
Added throttling test
jdfreder Dec 12, 2013
e86db29
Organized tests.
jdfreder Dec 12, 2013
8af19c3
Removed button.close() test because it caused the test framework to hang
jdfreder Dec 12, 2013
c25f02e
jslint /widgets
jdfreder Dec 12, 2013
57bb760
Fixed context of onclick callbacks selection widget views
jdfreder Dec 12, 2013
20fe605
Fixed some spacing in widget.js
jdfreder Dec 13, 2013
8245b9b
Removed comm dependency of widget model and view
jdfreder Dec 18, 2013
5d84782
Moved base widget model and view into widgets/base.js
jdfreder Dec 18, 2013
a09d70a
renamed: widget.js -> widgetmanager.js
jdfreder Dec 18, 2013
e785146
Fix, require.js needs return of widget manager for other widgets
jdfreder Dec 18, 2013
90f97b8
Made display_view a public method.
jdfreder Dec 18, 2013
3f5f27b
Made widget model state update function public
jdfreder Dec 18, 2013
577ee63
Fixed nonregistered model bug in wiget manager
jdfreder Dec 18, 2013
ab24918
Removed unused that from widget manager
jdfreder Dec 19, 2013
45a7ef8
Added parent parameter to on_display callback
jdfreder Dec 20, 2013
6135b20
Added event for widget construction
jdfreder Dec 20, 2013
8ec7166
Decoupled Python Widget from Comm
jdfreder Dec 21, 2013
318baad
Remove redundent _handle_close method
jdfreder Dec 21, 2013
47fda15
s/display/created for display_view stuff
jdfreder Dec 30, 2013
c102908
Moved touch logic out of model into view.
jdfreder Dec 30, 2013
6e353ea
Added require.js shims for underscore and backbone
jdfreder Dec 30, 2013
81257c2
Display handler now supports full kwargs
jdfreder Dec 30, 2013
9811ba7
Separate the display from the models on the python side, creating a B…
Dec 29, 2013
66c8209
Intermediate changes to javascript side of backbone widgets
Dec 31, 2013
a1d2451
Remove the automatic _children_attr and _children_lists_attr.
Dec 31, 2013
793dcac
Remove unused code and debugging statements
Dec 31, 2013
9a1f2d3
Change accordion to use a children attribute
Dec 31, 2013
af63861
Delete unnecessary check for comm object
Dec 31, 2013
e3803e4
Move all references to cells to the view objects.
Dec 31, 2013
4441be8
Make updates more granular for widgets
Dec 31, 2013
010861f
Store views in the models and store child views in the views
Dec 31, 2013
3925c2a
Delete the snapshot message handler
Dec 31, 2013
a20d81a
Note todos for widgets
Dec 31, 2013
8dc15ec
fix a handle_status handler
Dec 31, 2013
4a084cc
Fix visible attribute for the very first render
Dec 31, 2013
2a81271
Make sure containers transmit the children; take care of case where c…
Dec 31, 2013
c691a7b
log the error stack for a kernel javascript error message
Dec 31, 2013
49d1da2
Move some Widget class references to BaseWidget
Jan 1, 2014
46d68b6
General cleanup of base.js, including indentation fixes and adding vi…
Jan 1, 2014
0137755
Get the add/remove css classes working
Jan 1, 2014
e234b21
Live updates for children automatically change container views.
Jan 1, 2014
a5d454b
Fix the python side of the add/remove class functions to send custom …
Jan 2, 2014
0aa8d33
Example notebooks updated.
Jan 2, 2014
48132d8
Converted tabs to spaces
jdfreder Jan 2, 2014
ebf151f
Added `update_children` pattern to remaining parent widgets
jdfreder Jan 2, 2014
a1aa8a3
Revert 2853eb41 's changes to traitlets
jdfreder Jan 2, 2014
14b278e
Fixed JS tests to reflect Jason's changes
jdfreder Jan 2, 2014
313cb90
renamed: wigets_container.js -> widgets_container.js
jdfreder Jan 2, 2014
250e4f8
Added ViewWidget
jdfreder Jan 2, 2014
49568c8
Re-decoupled comm_id from widget models
jdfreder Jan 2, 2014
72af074
Removed console.log, unused
jdfreder Jan 2, 2014
48deda6
Further indentation cleanup
jdfreder Jan 2, 2014
60a426d
Fixed indent of line 450
jdfreder Jan 2, 2014
7eeebf9
Moved view widget into widget.py
jdfreder Jan 2, 2014
43c7823
Fixed indentation in widgetmanager.js
jdfreder Jan 2, 2014
3fb7c52
Added line to dump page html casperjs
jdfreder Jan 3, 2014
adcd464
Enabled IPython Server output for Travis debugging
jdfreder Jan 3, 2014
c9888ee
Fixed static_url call which is no longer optionally 1 param
jdfreder Jan 3, 2014
14459cf
Revert "Added line to dump page html casperjs"
jdfreder Jan 3, 2014
5f99aad
Revert "Enabled IPython Server output for Travis debugging"
jdfreder Jan 3, 2014
239f408
deleted: wigets_container.js
jdfreder Jan 3, 2014
10a25b0
Print cell output
jdfreder Jan 3, 2014
b8e7ee9
Output one more for debugging
jdfreder Jan 3, 2014
61db77c
Remove debug print statements in container tests
jdfreder Jan 3, 2014
4d3ff81
Fixed typo in model_id property
jdfreder Jan 3, 2014
84c0d03
Add widget view options in creating child views
Jan 4, 2014
f32e48c
Make the widget keys property traverse the superclasses and accumulat…
Jan 4, 2014
2451833
Get rid of keys magic; make the keys very explicit
Jan 5, 2014
075fab9
Make widget keys have more explicit inheritance
Jan 6, 2014
5e611bf
s/comm_id/model_id (left over from before)
jdfreder Jan 6, 2014
52963fb
Updated comm id comments in view to model id
jdfreder Jan 6, 2014
b60a6f9
Completely remove cell from model and view.
jdfreder Jan 6, 2014
2105d1a
Missing view argument when recursively calling widgetmanager.callback…
jdfreder Jan 6, 2014
a1286a4
Renamed widget js files
jdfreder Jan 7, 2014
c1bdf44
Updated require.js references
jdfreder Jan 7, 2014
032f65b
Removed ViewWidget
jdfreder Jan 7, 2014
b4e4da3
add/remove_class now can accept a list of classes
jdfreder Jan 7, 2014
6aabc0c
s/Widget/DOMWidget s/BaseWidget/Widget
jdfreder Jan 7, 2014
1d180d4
s/default_view_name/view_name
jdfreder Jan 7, 2014
888af91
s/_handle_widget_constructed/_call_widget_constructed
jdfreder Jan 7, 2014
e141746
Removed sync_method parameter from backbone msg spec
jdfreder Jan 7, 2014
9c567f4
Added callbacks method to view
jdfreder Jan 7, 2014
5334cab
s/widget.js/init.js
jdfreder Jan 7, 2014
a165819
renamed: basic_widgets.js -> init.js
jdfreder Jan 7, 2014
6dd1ffd
Remove first three lines of repr widgets
jdfreder Jan 7, 2014
e73528c
Fixed _send so it can open a comm if needed.
jdfreder Jan 7, 2014
311bda4
Remove view_name from display
jdfreder Jan 7, 2014
b67870c
remove 3rd callback type from on_displayed
jdfreder Jan 7, 2014
dfb0eb9
Fixed comments for optional kwargs so they are redundant.
jdfreder Jan 7, 2014
f3f38c8
send_state only once for dict signature of set_css
jdfreder Jan 7, 2014
cf2d9c4
_model_types, _view_types, _models - and document what keys and value…
jdfreder Jan 7, 2014
ed3d721
move backbone sync outside the widget manager class
jdfreder Jan 7, 2014
310f261
remove msg.content.data.view_name and corrosponding create_view param
jdfreder Jan 8, 2014
9877ef3
remove on_create_widget and handle_create_widget callback
jdfreder Jan 8, 2014
33de470
Added note in widget manager why Backbone.sync is there rather
jdfreder Jan 8, 2014
17ae963
re-order handle custom msg and handle recieve state
jdfreder Jan 8, 2014
6d7f1c7
handle_msg a display_model method.
jdfreder Jan 8, 2014
742e09b
Added missing comma
jdfreder Jan 8, 2014
d43ea71
Add constructor comment for widget model.
jdfreder Jan 8, 2014
4369d73
Update option-passing for creating child views.
Jan 8, 2014
d0e1f9e
this.updating should be a key specific lock
jdfreder Jan 8, 2014
6fe7aad
s/BaseWidgetView/WidgetView and s/WidgetView/DOMWidgetView
jdfreder Jan 8, 2014
37f98c1
un-nest options.options
jdfreder Jan 8, 2014
592da7d
Removed get_kernel method.
jdfreder Jan 8, 2014
25f40ff
remove length test add_class and remove_class
jdfreder Jan 8, 2014
515cf55
make JS update comment more descriptive (english)
jdfreder Jan 8, 2014
500d8a3
comment model.set, so we know that it triggers update on other views
jdfreder Jan 8, 2014
4e85339
add locks to update everywhere by using options to pass this
jdfreder Jan 8, 2014
af3cb8e
toggle button, set $el to button (removing extra div)
jdfreder Jan 8, 2014
bdf9a53
add comment views are in *_range
jdfreder Jan 8, 2014
9139587
document _keys function and rename to jquery_slider_keys
jdfreder Jan 8, 2014
8d175cf
s/image_format/format
jdfreder Jan 8, 2014
4139a38
s/flaot/float
jdfreder Jan 8, 2014
a8db290
remove .html('');
jdfreder Jan 8, 2014
404faa0
renamed: ../static/notebook/js/widgets/widget_multicontainer.js ->…
jdfreder Jan 8, 2014
10a84ac
Finished renaming Multicontainer to SelectionContainer
jdfreder Jan 8, 2014
f0c9c00
Implement a context manager as a property locking mechanism in Widget.
jdfreder Jan 8, 2014
92f4bb5
Add a helper method that acts on the changes made to a list.
jdfreder Jan 8, 2014
304e2e4
Add a comment that explains the notion of the default element
jdfreder Jan 8, 2014
1e8bd2e
Use .apply for calling base with not proto-type.
jdfreder Jan 8, 2014
ecbe638
Many checks off the todo list, test fixes
jdfreder Jan 13, 2014
27be0fb
remove unused imports
ivanov Jan 14, 2014
daa3b6a
fix typos
ivanov Jan 14, 2014
e5dbb96
Dev meeting widget review day 1
jdfreder Jan 14, 2014
d8f5efb
Dev meeting Jan 2014, widget review day 2
jdfreder Jan 14, 2014
f1c3742
sync=True isntead of a keys list
jdfreder Jan 14, 2014
1da6d0e
Added sync= attr to DOMWidget
jdfreder Jan 14, 2014
bff850b
Added sync=True to all view name attrs
jdfreder Jan 14, 2014
a76124e
Everyone uses one model
jdfreder Jan 14, 2014
a8368df
1-to-1 widget / view mapping
jdfreder Jan 14, 2014
f795cc3
Renamed *range test files to match other widget files
jdfreder Jan 14, 2014
b6908b1
A lot of bug fixes...
jdfreder Jan 14, 2014
597c46c
More fixes
jdfreder Jan 14, 2014
5cd3303
Fixed *almost* all of the test-detected bugs
jdfreder Jan 15, 2014
e1fdcc9
Fix test for selection widgets
jdfreder Jan 15, 2014
ed52e82
Got containers and mutlicontainers working! Yay
jdfreder Jan 16, 2014
f8345e1
Fab CSS
jdfreder Jan 16, 2014
071fae6
Fix rebase issues
jdfreder Jan 16, 2014
a57e02d
Make widget views work with new keyboard manager.
jdfreder Jan 16, 2014
be029cd
Update component submodule to point to master
jdfreder Jan 16, 2014
0311a8c
s/Int/CInt s/Float/CFloat
jdfreder Jan 16, 2014
c04aab1
Remove O(N) cell by msg-id lookup
jdfreder Jan 16, 2014
0acd418
Added value validation on Python side.
jdfreder Jan 16, 2014
0e56b40
Change orientation to Enum
jdfreder Jan 16, 2014
32716dc
More PEP8 changes
jdfreder Jan 16, 2014
bb79d34
containers and selectioncontainers now only allow one of any single c…
jdfreder Jan 16, 2014
af37dd3
Added PEP8 style comments to all of the JS code.
jdfreder Jan 16, 2014
b25d6b3
Halign dict colons
jdfreder Jan 16, 2014
603e41a
Fix bug in all children containing views
jdfreder Jan 16, 2014
2b9fe45
Make dropdown view DOM swap elements on update.
jdfreder Jan 17, 2014
6d0b62e
Fix the cell reference in views
Jan 10, 2014
df4f733
make the saving to python a method of the model, called with callbacks
Jan 10, 2014
eea2b79
update example notebooks
Jan 11, 2014
bd1ba86
Pass the whole message into the widget manager display_view call
Jan 12, 2014
c3a0818
Delete unnecessary save
Jan 9, 2014
43cee97
Cherry pick of @jasongrout 's 2bc2f96.
jdfreder Jan 17, 2014
94a5aed
Added support for multiple kernels.
jdfreder Jan 17, 2014
676624e
Fixed widget_manager instance test.
jdfreder Jan 17, 2014
f9ac12e
Widget require.js fix
jdfreder Jan 17, 2014
3527bb2
Repr style out for widgets
jdfreder Jan 17, 2014
c92edbc
Better implementation of widget _repr_ style display logic.
jdfreder Jan 17, 2014
92e9682
Added a line that was accidently deleted during merge of 4e813c5
jdfreder Jan 21, 2014
262451e
Use is to compare NotImplemented
jdfreder Jan 21, 2014
4e813c5
Rewrite widget syncing
Jan 11, 2014
e15e352
Change the callback logic so the order makes more sense:
jdfreder Jan 21, 2014
a6ff4f4
Remove residual tabs
jdfreder Jan 21, 2014
ff01af6
Reorganized attrs in widget.py
jdfreder Jan 21, 2014
63d2f7a
Added doc strings to properties in widget.py
jdfreder Jan 21, 2014
fc964e6
s/custom_content/content
jdfreder Jan 21, 2014
07dc2a7
ict comprehension and list comprehension in pack/unpack widgets
jdfreder Jan 21, 2014
585885a
Document in widget packing that vaues must be JSON-able.
jdfreder Jan 21, 2014
70a076d
Added new CallbackDispatcher class
jdfreder Jan 21, 2014
11ca541
Fixed name conflict with _property_lock
jdfreder Jan 21, 2014
b15593f
Remove todo in apply update
jdfreder Jan 21, 2014
5f40d5d
'create' should be handled in sync
jdfreder Jan 21, 2014
c6b69b2
Prefer JQuery to Underscore
jdfreder Jan 21, 2014
77e364d
Replace .html with .text everywhere possible
jdfreder Jan 21, 2014
9d49e0e
Removed for () loops where necessary. Replaced with _.each
jdfreder Jan 22, 2014
201886e
Explicitly return null if there aren't any results
jdfreder Jan 22, 2014
07e2df5
- remove second line in create_child_view
jdfreder Jan 22, 2014
1e0859f
Added some small comments to widget code
jdfreder Jan 22, 2014
a811539
Use CUnicode for width and height in ImageWidget
jdfreder Jan 22, 2014
3644592
Create base widget classes
jdfreder Jan 22, 2014
1b8ed2a
deleted: widget_float_range.py
jdfreder Jan 22, 2014
2798de1
Move js *RangeWidget code into *Widget
jdfreder Jan 22, 2014
19e4b58
deleted: widget_float_range.js
jdfreder Jan 22, 2014
1d5afc3
Made tests reflect changes to widget naming scheme.
jdfreder Jan 22, 2014
71765e9
deleted: widgets_float_range.js
jdfreder Jan 22, 2014
25a9d02
s/ModalView/PopupView
jdfreder Jan 22, 2014
094e02a
Fixed typo - else -> elif
jdfreder Jan 22, 2014
442154d
Fixed some typos related to _.each loops
jdfreder Jan 22, 2014
ddb2afa
Fixed context errors and a couple of typos to get the tests working a…
jdfreder Jan 22, 2014
6ceec8d
Fixed a couple more context typos
jdfreder Jan 22, 2014
a341ba2
Updated subcomponents
jdfreder Jan 22, 2014
29cac5a
Fixed bug where views child to other views would not have cell inform…
jdfreder Jan 22, 2014
287a0a7
Removed float widget bound tests,
jdfreder Jan 22, 2014
e952756
Adjusted throttling
jdfreder Jan 22, 2014
2af96a6
Float widget views now inherit from int counterparts
jdfreder Jan 22, 2014
f3b6c24
Support multiple types in selection widget.
jdfreder Jan 22, 2014
48fcdd1
Replace O(N^2) algorithm with a faster one.
jdfreder Jan 23, 2014
53b368b
s/view_name/_view_name
jdfreder Jan 23, 2014
719d9ac
Added code that removes the views when a model/widget is closed.
jdfreder Jan 23, 2014
615ab9a
Updated widget tutorials 1-2
jdfreder Jan 23, 2014
eab8dac
Changed selection widget API to use labels list
jdfreder Jan 23, 2014
6413603
Fixed type in container
jdfreder Jan 23, 2014
4817003
Updated examples 3-6
jdfreder Jan 23, 2014
91c7760
Callback dispatcher return callback value.
jdfreder Jan 23, 2014
e4f69ed
Fixed bug in selection widget tests.
jdfreder Jan 23, 2014
796c0ed
Cleanup examples
jdfreder Jan 23, 2014
86eac83
Removed Dialogs example, since PopupWidgets are available.
jdfreder Jan 23, 2014
4c316a8
Moved keyboard_manager logic into a sep. function.
jdfreder Jan 24, 2014
3c96e03
Fixed bug in throttling code.
jdfreder Jan 24, 2014
c70540b
Fixed some more example files (see list below)...
jdfreder Jan 24, 2014
65caa63
Updated cell numbering in console example.
jdfreder Jan 24, 2014
fac8110
Prevent TextBox from blurring unless explicity by user.
jdfreder Jan 24, 2014
9ab757f
Simplified variable inspector example
jdfreder Jan 25, 2014
c8996c4
Fixed bug that prevented popup widget from displaying
jdfreder Jan 25, 2014
217ad48
Removed D3 and Widget Tester examples for now, until they are fixed..
jdfreder Jan 25, 2014
4ebd115
review pass on widgetmanager.js
minrk Jan 26, 2014
de90ea1
quick review pass on javascript
minrk Jan 26, 2014
9cf2bba
review pass on Python-side of widgets
minrk Jan 26, 2014
6721e7f
catch NotImplementedError, not NotImplemented
minrk Jan 26, 2014
ce69b63
Document _ipython_display_ in custom display logic
minrk Jan 27, 2014
85a0de3
first review pass on widget tests
minrk Jan 27, 2014
ae6ac19
review pass on widget examples
minrk Jan 27, 2014
4c141af
Merge pull request #11 from minrk/widgets
jdfreder Jan 28, 2014
27b06ff
Removed blame comment
jdfreder Jan 28, 2014
42d6b44
Simplify get_msg_cell function of notebook.js
jdfreder Jan 28, 2014
5ed9376
Renamed widgets...
jdfreder Jan 28, 2014
d661486
Fixed Accordion test broken by last commit
jdfreder Jan 28, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions IPython/core/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,23 @@ def display(*objs, **kwargs):

from IPython.core.interactiveshell import InteractiveShell

if raw:
for obj in objs:
publish_display_data('display', obj, metadata)
else:
if not raw:
format = InteractiveShell.instance().display_formatter.format
for obj in objs:

for obj in objs:

# If _ipython_display_ is defined, use that to display this object.
display_method = getattr(obj, '_ipython_display_', None)
if display_method is not None:
try:
display_method(**kwargs)
except NotImplementedError:
pass
else:
continue
if raw:
publish_display_data('display', obj, metadata)
else:
format_dict, md_dict = format(obj, include=include, exclude=exclude)
if metadata:
# kwarg-specified metadata gets precedence
Expand Down
8 changes: 8 additions & 0 deletions IPython/core/displayhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ def __call__(self, result=None):
"""
self.check_for_underscore()
if result is not None and not self.quiet():
# If _ipython_display_ is defined, use that to display this object.
display_method = getattr(result, '_ipython_display_', None)
if display_method is not None:
try:
return display_method()
except NotImplementedError:
pass

self.start_displayhook()
self.write_output_prompt()
format_dict, md_dict = self.compute_format_data(result)
Expand Down
18 changes: 18 additions & 0 deletions IPython/html/static/base/less/flexbox.less
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,21 @@
-moz-box-pack: center;
box-pack: center;
}

.align-start {
-webkit-box-align: start;
-moz-box-align: start;
box-align: start;
}

.align-end {
-webkit-box-align: end;
-moz-box-align: end;
box-align: end;
}

.align-center {
-webkit-box-align: center;
-moz-box-align: center;
box-align: center;
}
2 changes: 1 addition & 1 deletion IPython/html/static/components
35 changes: 34 additions & 1 deletion IPython/html/static/notebook/js/codecell.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ var IPython = (function (IPython) {
}
};

CodeCell.msg_cells = {};

CodeCell.prototype = new IPython.Cell();

Expand Down Expand Up @@ -132,8 +133,28 @@ var IPython = (function (IPython) {
$(this.code_mirror.getInputField()).attr("spellcheck", "false");
inner_cell.append(input_area);
input.append(prompt).append(inner_cell);

var widget_area = $('<div/>')
.addClass('widget-area')
.hide();
this.widget_area = widget_area;
var widget_prompt = $('<div/>')
.addClass('prompt')
.appendTo(widget_area);
var widget_subarea = $('<div/>')
.addClass('widget-subarea')
.appendTo(widget_area);
this.widget_subarea = widget_subarea;
var widget_clear_buton = $('<button />')
.addClass('close')
.html('&times;')
.click(function() {
widget_area.slideUp('', function(){ widget_subarea.html(''); });
})
.appendTo(widget_prompt);

var output = $('<div></div>');
cell.append(input).append(output);
cell.append(input).append(widget_area).append(output);
this.element = cell;
this.output_area = new IPython.OutputArea(output, true);
this.completer = new IPython.Completer(this);
Expand Down Expand Up @@ -283,14 +304,26 @@ var IPython = (function (IPython) {
*/
CodeCell.prototype.execute = function () {
this.output_area.clear_output();

// Clear widget area
this.widget_subarea.html('');
this.widget_subarea.height('');
this.widget_area.height('');
this.widget_area.hide();

this.set_input_prompt('*');
this.element.addClass("running");
if (this.last_msg_id) {
this.kernel.clear_callbacks_for_msg(this.last_msg_id);
}
var callbacks = this.get_callbacks();

var old_msg_id = this.last_msg_id;
this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true});
if (old_msg_id) {
delete CodeCell.msg_cells[old_msg_id];
}
CodeCell.msg_cells[this.last_msg_id] = this;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion IPython/html/static/notebook/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
// as injecting require.js make marked not to put itself in the globals,
// which make both this file fail at setting marked configuration, and textcell.js
// which search marked into global.
require(['components/marked/lib/marked'],
require(['components/marked/lib/marked',
'notebook/js/widgets/init'],

function (marked) {

Expand Down
16 changes: 14 additions & 2 deletions IPython/html/static/notebook/js/notebook.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,17 @@ var IPython = (function (IPython) {
return result;
};

/**
* Try to get a particular cell by msg_id.
*
* @method get_msg_cell
* @param {String} msg_id A message UUID
* @return {Cell} Cell or null if no cell was found.
*/
Notebook.prototype.get_msg_cell = function (msg_id) {
return IPython.CodeCell.msg_cells[msg_id] || null;
};

/**
* Count the cells in this notebook.
*
Expand Down Expand Up @@ -1295,7 +1306,8 @@ var IPython = (function (IPython) {


/**
* Once a session is started, link the code cells to the kernel
* Once a session is started, link the code cells to the kernel and pass the
* comm manager to the widget manager
*
*/
Notebook.prototype._session_started = function(){
Expand Down Expand Up @@ -2210,4 +2222,4 @@ var IPython = (function (IPython) {

return IPython;

}(IPython));
}(IPython));
210 changes: 210 additions & 0 deletions IPython/html/static/notebook/js/widgetmanager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
//----------------------------------------------------------------------------
// Copyright (C) 2013 The IPython Development Team
//
// Distributed under the terms of the BSD License. The full license is in
// the file COPYING, distributed as part of this software.
//----------------------------------------------------------------------------

//============================================================================
// WidgetModel, WidgetView, and WidgetManager
//============================================================================
/**
* Base Widget classes
* @module IPython
* @namespace IPython
* @submodule widget
*/

(function () {
"use strict";

// Use require.js 'define' method so that require.js is intelligent enough to
// syncronously load everything within this file when it is being 'required'
// elsewhere.
define(["underscore",
"backbone",
], function (Underscore, Backbone) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be function(_, Backbone), since we are actually using underscore via _ below. This might also be a problem in other files.


//--------------------------------------------------------------------
// WidgetManager class
//--------------------------------------------------------------------
var WidgetManager = function (comm_manager) {
// Public constructor
WidgetManager._managers.push(this);

// Attach a comm manager to the
this.comm_manager = comm_manager;
this._models = {}; /* Dictionary of model ids and model instances */

// Register already-registered widget model types with the comm manager.
var that = this;
_.each(WidgetManager._model_types, function(model_type, model_name) {
that.comm_manager.register_target(model_name, $.proxy(that._handle_comm_open, that));
});
};

//--------------------------------------------------------------------
// Class level
//--------------------------------------------------------------------
WidgetManager._model_types = {}; /* Dictionary of model type names (target_name) and model types. */
WidgetManager._view_types = {}; /* Dictionary of view names and view types. */
WidgetManager._managers = []; /* List of widget managers */

WidgetManager.register_widget_model = function (model_name, model_type) {
// Registers a widget model by name.
WidgetManager._model_types[model_name] = model_type;

// Register the widget with the comm manager. Make sure to pass this object's context
// in so `this` works in the call back.
_.each(WidgetManager._managers, function(instance, i) {
if (instance.comm_manager !== null) {
instance.comm_manager.register_target(model_name, $.proxy(instance._handle_comm_open, instance));
}
});
};

WidgetManager.register_widget_view = function (view_name, view_type) {
// Registers a widget view by name.
WidgetManager._view_types[view_name] = view_type;
};

//--------------------------------------------------------------------
// Instance level
//--------------------------------------------------------------------
WidgetManager.prototype.display_view = function(msg, model) {
// Displays a view for a particular model.
var cell = this.get_msg_cell(msg.parent_header.msg_id);
if (cell === null) {
console.log("Could not determine where the display" +
" message was from. Widget will not be displayed");
} else {
var view = this.create_view(model, {cell: cell});
if (view === null) {
console.error("View creation failed", model);
}
if (cell.widget_subarea) {

cell.widget_area.show();
cell.widget_subarea.append(view.$el);
}
}
};

WidgetManager.prototype.create_view = function(model, options, view) {
// Creates a view for a particular model.
var view_name = model.get('_view_name');
var ViewType = WidgetManager._view_types[view_name];
if (ViewType) {

// If a view is passed into the method, use that view's cell as
// the cell for the view that is created.
options = options || {};
if (view !== undefined) {
options.cell = view.options.cell;
}

// Create and render the view...
var parameters = {model: model, options: options};
view = new ViewType(parameters);
view.render();
model.views.push(view);
model.on('destroy', view.remove, view);

this._handle_new_view(view);
return view;
}
return null;
};

WidgetManager.prototype._handle_new_view = function (view) {
// Called when a view has been created and rendered.

// If the view has a well defined element, inform the keyboard
// manager about the view's element, so as the element can
// escape the dreaded command mode.
if (view.$el) {
IPython.keyboard_manager.register_events(view.$el);
}
};

WidgetManager.prototype.get_msg_cell = function (msg_id) {
var cell = null;
// First, check to see if the msg was triggered by cell execution.
if (IPython.notebook) {
cell = IPython.notebook.get_msg_cell(msg_id);
}
if (cell !== null) {
return cell;
}
// Second, check to see if a get_cell callback was defined
// for the message. get_cell callbacks are registered for
// widget messages, so this block is actually checking to see if the
// message was triggered by a widget.
var kernel = this.comm_manager.kernel;
if (kernel) {
var callbacks = kernel.get_callbacks_for_msg(msg_id);
if (callbacks && callbacks.iopub &&
callbacks.iopub.get_cell !== undefined) {
return callbacks.iopub.get_cell();
}
}

// Not triggered by a cell or widget (no get_cell callback
// exists).
return null;
};

WidgetManager.prototype.callbacks = function (view) {
// callback handlers specific a view
var callbacks = {};
if (view && view.options.cell) {

// Try to get output handlers
var cell = view.options.cell;
var handle_output = null;
var handle_clear_output = null;
if (cell.output_area) {
handle_output = $.proxy(cell.output_area.handle_output, cell.output_area);
handle_clear_output = $.proxy(cell.output_area.handle_clear_output, cell.output_area);
}

// Create callback dict using what is known
var that = this;
callbacks = {
iopub : {
output : handle_output,
clear_output : handle_clear_output,

// Special function only registered by widget messages.
// Allows us to get the cell for a message so we know
// where to add widgets if the code requires it.
get_cell : function () {
return cell;
},
},
};
}
return callbacks;
};

WidgetManager.prototype.get_model = function (model_id) {
// Look-up a model instance by its id.
var model = this._models[model_id];
if (model !== undefined && model.id == model_id) {
return model;
}
return null;
};

WidgetManager.prototype._handle_comm_open = function (comm, msg) {
// Handle when a comm is opened.
var model_id = comm.comm_id;
var widget_type_name = msg.content.target_name;
var widget_model = new WidgetManager._model_types[widget_type_name](this, model_id, comm);
this._models[model_id] = widget_model;
};

IPython.WidgetManager = WidgetManager;
return IPython.WidgetManager;
});
}());
Loading