From 810ea87e5b60c817eedddd50c5712b005698204c Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Fri, 1 Nov 2013 00:00:34 +0000 Subject: [PATCH] Added `visible` property to all widgets --- IPython/html/static/notebook/js/widget.js | 11 +++++++++++ IPython/html/widgets/widget.py | 5 +++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/IPython/html/static/notebook/js/widget.js b/IPython/html/static/notebook/js/widget.js index 7ee482555..177b1cd6c 100644 --- a/IPython/html/static/notebook/js/widget.js +++ b/IPython/html/static/notebook/js/widget.js @@ -307,10 +307,21 @@ define(["components/underscore/underscore-min", var WidgetView = Backbone.View.extend({ initialize: function() { + this.visible = true; this.model.on('change',this.update,this); }, update: function() { + if (this.model.get('visible') != undefined) { + if (this.visible != this.model.get('visible')) { + this.visible = this.model.get('visible'); + if (this.visible) { + this.$el.show(); + } else { + this.$el.hide(); + } + } + } if (this.model.css != undefined) { for (var selector in this.model.css) { if (this.model.css.hasOwnProperty(selector)) { diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index 485642847..b3eee7a96 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -21,7 +21,7 @@ import os import IPython from IPython.kernel.comm import Comm from IPython.config import LoggingConfigurable -from IPython.utils.traitlets import Unicode, Dict, List, Instance +from IPython.utils.traitlets import Unicode, Dict, List, Instance, Bool from IPython.display import Javascript, display from IPython.utils.py3compat import string_types @@ -50,6 +50,7 @@ class Widget(LoggingConfigurable): default_view_name = Unicode(help="""Default view registered in the frontend to use to represent the widget.""") parent = Instance('IPython.html.widgets.widget.Widget') + visible = Bool(True, help="Whether or not the widget is visible.") def _parent_changed(self, name, old, new): if self._displayed: @@ -107,7 +108,7 @@ class Widget(LoggingConfigurable): # Properties def _get_keys(self): - keys = ['_css'] + keys = ['_css', 'visible'] keys.extend(self._keys) return keys keys = property(_get_keys)