widget_link.py
61 lines
| 1.9 KiB
| text/x-python
|
PythonLexer
Jason Grout
|
r18051 | """Link and DirectionalLink classes. | ||
Jason Grout
|
r19390 | Propagate changes between widgets on the javascript side | ||
Jason Grout
|
r18051 | """ | ||
#----------------------------------------------------------------------------- | ||||
Jason Grout
|
r19390 | # Copyright (c) 2014, the IPython Development Team. | ||
Jason Grout
|
r18051 | # | ||
# 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 Widget | ||||
Sylvain Corlay
|
r18052 | from IPython.utils.traitlets import Unicode, Tuple, Any | ||
Jason Grout
|
r18051 | |||
#----------------------------------------------------------------------------- | ||||
# Classes | ||||
#----------------------------------------------------------------------------- | ||||
class Link(Widget): | ||||
"""Link Widget""" | ||||
_model_name = Unicode('LinkModel', sync=True) | ||||
widgets = Tuple(sync=True, allow_none=False) | ||||
def __init__(self, widgets=(), **kwargs): | ||||
kwargs['widgets'] = widgets | ||||
super(Link, self).__init__(**kwargs) | ||||
Jason Grout
|
r19390 | # for compatibility with traitlet links | ||
def unlink(self): | ||||
self.close() | ||||
Sylvain Corlay
|
r18052 | |||
Jason Grout
|
r18051 | def link(*args): | ||
return Link(widgets=args) | ||||
Sylvain Corlay
|
r18052 | |||
class DirectionalLink(Widget): | ||||
"""Directional Link Widget""" | ||||
_model_name = Unicode('DirectionalLinkModel', sync=True) | ||||
targets = Any(sync=True) | ||||
source = Tuple(sync=True) | ||||
# Does not quite behave like other widgets but reproduces | ||||
# the behavior of IPython.utils.traitlets.directional_link | ||||
def __init__(self, source, targets=(), **kwargs): | ||||
kwargs['source'] = source | ||||
kwargs['targets'] = targets | ||||
super(DirectionalLink, self).__init__(**kwargs) | ||||
Jason Grout
|
r19390 | # for compatibility with traitlet links | ||
def unlink(self): | ||||
self.close() | ||||
Sylvain Corlay
|
r18052 | |||
def dlink(source, *targets): | ||||
return DirectionalLink(source, targets) | ||||