/
ace.py
59 lines (44 loc) · 1.9 KB
/
ace.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
51
52
53
54
55
56
57
58
59
"""
Defines the Ace code editor widget.
"""
import param
from pyviz_comms import JupyterComm
from ..models.enums import ace_themes
from ..util import lazy_load
from .base import Widget
class Ace(Widget):
"""
Ace widget allow editing text in an Ace editor.
"""
annotations = param.List(default=[], doc="""
List of annotations to add to the editor.""")
filename = param.String(doc="Filename from which to deduce language")
language = param.String(default='text', doc="Language of the editor")
print_margin = param.Boolean(default=False, doc="""
Whether to show the a print margin.""")
readonly = param.Boolean(default=False, doc="""
Define if editor content can be modified. Alias for disabled.""")
theme = param.ObjectSelector(default="chrome", objects=list(ace_themes),
doc="Theme of the editor")
value = param.String(doc="State of the current code in the editor")
_rename = {"value": "code", "name": None}
def __init__(self, **params):
if 'readonly' in params:
params['disabled'] = params['readonly']
elif 'disabled' in params:
params['readonly'] = params['disabled']
super().__init__(**params)
self.param.watch(self._update_disabled, ['disabled', 'readonly'])
self.jslink(self, readonly='disabled', bidirectional=True)
def _get_model(self, doc, root=None, parent=None, comm=None):
if self._widget_type is None:
self._widget_type = lazy_load(
'panel.models.ace', 'AcePlot', isinstance(comm, JupyterComm), root
)
return super()._get_model(doc, root, parent, comm)
def _update_disabled(self, *events):
for event in events:
if event.name == 'disabled':
self.readonly = event.new
elif event.name == 'readonly':
self.disabled = event.new