-
Notifications
You must be signed in to change notification settings - Fork 20
/
customwidgets.py
50 lines (40 loc) · 1.62 KB
/
customwidgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import ipywidgets as widgets
from ipywidgets.widgets import CallbackDispatcher
from traitlets import Unicode
@widgets.register
class FocusText(widgets.Text):
_view_name = Unicode('FocusTextView').tag(sync=True)
#_model_name = Unicode('FocusTextModel').tag(sync=True)
_view_module = Unicode('jupyter-innotater').tag(sync=True)
#_model_module = Unicode('jupyter-innotater').tag(sync=True)
_view_module_version = Unicode('~0.1.0').tag(sync=True)
#_model_module_version = Unicode('~0.1.0').tag(sync=True)
def __init__(self, **kwargs):
super(FocusText, self).__init__(**kwargs)
self._click_handlers = CallbackDispatcher()
self.on_msg(self._handle_focustext_msg)
def on_click(self, callback, remove=False):
"""Register a callback to execute when the button is clicked.
The callback will be called with one argument, the clicked button
widget instance.
Parameters
----------
remove: bool (optional)
Set to true to remove the callback from the list of callbacks.
"""
self._click_handlers.register_callback(callback, remove=remove)
def click(self):
"""Programmatically trigger a click event.
This will call the callbacks registered to the clicked button
widget instance.
"""
self._click_handlers(self)
def _handle_focustext_msg(self, _, content, buffers):
"""Handle a msg from the front-end.
Parameters
----------
content: dict
Content of the msg.
"""
if content.get('event', '') == 'click':
self.click()