Uploaded Test files
This commit is contained in:
parent
f584ad9d97
commit
2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions
50
venv/Lib/site-packages/ipywidgets/widgets/domwidget.py
Normal file
50
venv/Lib/site-packages/ipywidgets/widgets/domwidget.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
"""Contains the DOMWidget class"""
|
||||
|
||||
from traitlets import Unicode
|
||||
from .widget import Widget, widget_serialization
|
||||
from .trait_types import InstanceDict, TypedTuple
|
||||
from .widget_layout import Layout
|
||||
from .widget_style import Style
|
||||
|
||||
|
||||
class DOMWidget(Widget):
|
||||
"""Widget that can be inserted into the DOM"""
|
||||
|
||||
_model_name = Unicode('DOMWidgetModel').tag(sync=True)
|
||||
_dom_classes = TypedTuple(trait=Unicode(), help="CSS classes applied to widget DOM element").tag(sync=True)
|
||||
layout = InstanceDict(Layout).tag(sync=True, **widget_serialization)
|
||||
|
||||
def add_class(self, className):
|
||||
"""
|
||||
Adds a class to the top level element of the widget.
|
||||
|
||||
Doesn't add the class if it already exists.
|
||||
"""
|
||||
if className not in self._dom_classes:
|
||||
self._dom_classes = list(self._dom_classes) + [className]
|
||||
return self
|
||||
|
||||
def remove_class(self, className):
|
||||
"""
|
||||
Removes a class from the top level element of the widget.
|
||||
|
||||
Doesn't remove the class if it doesn't exist.
|
||||
"""
|
||||
if className in self._dom_classes:
|
||||
self._dom_classes = [c for c in self._dom_classes if c != className]
|
||||
return self
|
||||
|
||||
def _repr_keys(self):
|
||||
for key in super(DOMWidget, self)._repr_keys():
|
||||
# Exclude layout if it had the default value
|
||||
if key == 'layout':
|
||||
value = getattr(self, key)
|
||||
if repr(value) == '%s()' % value.__class__.__name__:
|
||||
continue
|
||||
yield key
|
||||
# We also need to include _dom_classes in repr for reproducibility
|
||||
if self._dom_classes:
|
||||
yield '_dom_classes'
|
Loading…
Add table
Add a link
Reference in a new issue