Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
__all__ = ['ButtonInnotation']
from ipywidgets import Button
from .data import Innotation
from .mixins import DataChangeNotifierMixin
class ButtonInnotation(Innotation, DataChangeNotifierMixin):
"""
Allow embedding of an arbitrary widget object, e.g. for text display
Must still have a data attribute of correct len, even if dummy values
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.on_click_hook = kwargs.get('on_click', None)
self.uindex = None
def _create_widget(self):
btn = Button(description=self.desc, disabled=self.disabled, layout=self.layout)
if self.on_click_hook:
btn.on_click(lambda b: self.call_on_click_hook(b))
return btn
def _observe_targets(self, targets):
for dw in targets:
dw.widget_observe(self.update_data, names='value')
if isinstance(dw, ChildrenChangeNotifierMixin):
dw.on_children_changed(self.new_children_handler)
if isinstance(dw, DataChangeNotifierMixin):
dw.on_data_changed(self.updated_data_handler)