From 250e4f815ff425c2b00af347712aa5c6d7ff4fcb 2014-01-16 10:57:12 From: Jonathan Frederic Date: 2014-01-16 10:57:12 Subject: [PATCH] Added ViewWidget --- diff --git a/IPython/html/widgets/widget.py b/IPython/html/widgets/widget.py index 7257c96..fd8849e 100644 --- a/IPython/html/widgets/widget.py +++ b/IPython/html/widgets/widget.py @@ -27,6 +27,8 @@ from IPython.utils.traitlets import Unicode, Dict, List, Instance, Bool from IPython.display import Javascript, display from IPython.utils.py3compat import string_types +from .widget_view import ViewWidget + #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- @@ -436,3 +438,9 @@ class Widget(BaseWidget): self.send({"msg_type": "remove_class", "class_list": class_name, "selector": selector}) + + + def view(self, view_name=None): + """Return a widget that can be displayed to display this widget using + a non-default view""" + return ViewWidget(self, view_name) diff --git a/IPython/html/widgets/widget_view.py b/IPython/html/widgets/widget_view.py new file mode 100644 index 0000000..06ec40a --- /dev/null +++ b/IPython/html/widgets/widget_view.py @@ -0,0 +1,27 @@ +"""ViewWidget class. + +Used to display another widget using a different view. +""" +#----------------------------------------------------------------------------- +# Copyright (c) 2013, the IPython Development Team. +# +# Distributed under the terms of the Modified BSD License. +# +# The full license is in the file COPYING.txt, distributed with this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- +from .widget import BaseWidget +from IPython.utils.traitlets import Unicode + +#----------------------------------------------------------------------------- +# Classes +#----------------------------------------------------------------------------- +class ViewWidget(BaseWidget): + target_name = Unicode('ViewModel') + + def __init__(self, widget, view): + self.default_view_name = view + self.widget = widget