From 2ad57f6f9d93bf754c78bdff23998230098941c3 Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Mon, 21 Oct 2013 09:55:49 -0700 Subject: [PATCH] Attempt 1, HBox and VBox implementation. --- IPython/html/static/notebook/js/widget.js | 36 +++++++++++-------- .../html/static/notebook/js/widgets/bool.js | 2 ++ .../static/notebook/js/widgets/container.js | 19 +++++++--- .../static/notebook/js/widgets/selection.js | 6 ++++ .../html/static/notebook/js/widgets/string.js | 12 +++---- .../html/static/notebook/less/widgetarea.less | 13 +++++++ IPython/html/static/style/ipython.min.css | 15 ++++++++ IPython/html/widgets/widget_container.py | 7 ++-- 8 files changed, 82 insertions(+), 28 deletions(-) diff --git a/IPython/html/static/notebook/js/widget.js b/IPython/html/static/notebook/js/widget.js index 2cd773e14..823939fac 100644 --- a/IPython/html/static/notebook/js/widget.js +++ b/IPython/html/static/notebook/js/widget.js @@ -169,7 +169,7 @@ define(["static/components/underscore/underscore-min.js", // Add the view's element to cell's widget div. widget_area - .append($("
").append(widget_view.$el)) + .append(widget_view.$el) .parent().show(); // Show the widget_area (parent of widget_subarea) // Update the view based on the model contents. @@ -204,6 +204,7 @@ define(["static/components/underscore/underscore-min.js", // Handle when a widget is updated via the python side. WidgetManager.prototype.handle_update = function (comm, state) { + this.updating = true; for (var key in state) { if (state.hasOwnProperty(key)) { if (key=="_css"){ @@ -214,6 +215,7 @@ define(["static/components/underscore/underscore-min.js", } } comm.model.save(); + this.updating = false; } // Handle when a widget is closed. @@ -233,21 +235,25 @@ define(["static/components/underscore/underscore-min.js", // Send widget state to python backend. WidgetManager.prototype.send_sync = function (method, model) { - - // Create a callback for the output if the widget has an output area associate with it. - var callbacks = {}; - var comm = model.comm; - var outputarea = this._get_comm_outputarea(comm); - if (outputarea != null) { - callbacks = { - iopub : { - output : $.proxy(outputarea.handle_output, outputarea), - clear_output : $.proxy(outputarea.handle_clear_output, outputarea)} - }; - }; var model_json = model.toJSON(); - var data = {sync_method: method, sync_data: model_json}; - comm.send(data, callbacks); + + // Only send updated state if the state hasn't been changed during an update. + if (!this.updating) { + // Create a callback for the output if the widget has an output area associate with it. + var callbacks = {}; + var comm = model.comm; + var outputarea = this._get_comm_outputarea(comm); + if (outputarea != null) { + callbacks = { + iopub : { + output : $.proxy(outputarea.handle_output, outputarea), + clear_output : $.proxy(outputarea.handle_clear_output, outputarea)} + }; + }; + var data = {sync_method: method, sync_data: model_json}; + comm.send(data, callbacks); + } + return model_json; } diff --git a/IPython/html/static/notebook/js/widgets/bool.js b/IPython/html/static/notebook/js/widgets/bool.js index 104ec7c71..af5a2b5fe 100644 --- a/IPython/html/static/notebook/js/widgets/bool.js +++ b/IPython/html/static/notebook/js/widgets/bool.js @@ -10,6 +10,7 @@ require(["notebook/js/widget"], function(){ render : function(){ this.$el .html('') + .addClass('widget_item') .addClass(this.model.comm.comm_id); var $label = $('