本文整理汇总了Python中traitlets.observe方法的典型用法代码示例。如果您正苦于以下问题:Python traitlets.observe方法的具体用法?Python traitlets.observe怎么用?Python traitlets.observe使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traitlets
的用法示例。
在下文中一共展示了traitlets.observe方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def get(self, led_type: LEDType) -> LED:
"""
Fetches the requested LED interface on this device
:param led_type: The LED type to fetch
:return: The LED interface, if available
"""
if led_type not in self._driver.supported_leds:
return None
if led_type not in self._leds:
self._leds[led_type] = LED(self._driver, led_type)
self._leds[led_type].observe(self._led_changed)
return self._leds[led_type]
示例2: __init__
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def __init__(self, renderer: Renderer, frame: Frame,
blend_mode=None, *args, **kwargs):
super(LayerHolder, self).__init__(*args, **kwargs)
self._renderer = renderer
self._frame = frame
self._blend_mode = blend_mode
self.waiter = None
self.active_buf = None
self.task = None
self.traits_changed = Signal()
self._renderer.observe(self._traits_changed, names=['all'])
self._renderer._flush()
for buf in range(0, NUM_BUFFERS):
layer = self._frame.create_layer()
layer.blend_mode = self._blend_mode
self._renderer._free_layer(layer)
示例3: __init__
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def __init__(self, config=None, **kw):
"""
Public constructor
Parameters
----------
config : config
User configuration instance.
extra_loaders : list[of Jinja Loaders]
ordered list of Jinja loader to find templates. Will be tried in order
before the default FileSystem ones.
template : str (optional, kw arg)
Template to use when exporting.
"""
super(TemplateExporter, self).__init__(config=config, **kw)
self.observe(self._invalidate_environment_cache,
list(self.traits(affects_environment=True)))
self.observe(self._invalidate_template_cache,
list(self.traits(affects_template=True)))
示例4: test_array_equal
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def test_array_equal(self):
notifications = []
class Foo(HasTraits):
bar = Array([1, 2])
@observe('bar')
def _(self, change):
notifications.append(change)
foo = Foo()
foo.bar = [1, 2]
self.assertFalse(len(notifications))
foo.bar = [1, 1]
self.assertTrue(len(notifications))
示例5: test_df_equal
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def test_df_equal(self):
notifications = []
class Foo(HasTraits):
bar = DataFrame([1, 2])
@observe('bar')
def _(self, change):
notifications.append(change)
foo = Foo()
foo.bar = [1, 2]
self.assertEqual(notifications, [])
foo.bar = [1, 1]
self.assertEqual(len(notifications), 1)
示例6: test_series_equal
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def test_series_equal(self):
notifications = []
class Foo(HasTraits):
bar = Series([1, 2])
@observe('bar')
def _(self, change):
notifications.append(change)
foo = Foo()
foo.bar = [1, 2]
self.assertEqual(notifications, [])
foo.bar = [1, 1]
self.assertEqual(len(notifications), 1)
示例7: test_ds_equal
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def test_ds_equal(self):
notifications = []
class Foo(HasTraits):
bar = Dataset({'foo': xr.DataArray([[0, 1, 2], [3, 4, 5]], coords={'x': ['a', 'b']}, dims=('x', 'y')), 'bar': ('x', [1, 2]), 'baz': 3.14})
@observe('bar')
def _(self, change):
notifications.append(change)
foo = Foo()
foo.bar = {'foo': xr.DataArray([[0, 1, 2], [3, 4, 5]], coords={'x': ['a', 'b']}, dims=('x', 'y')), 'bar': ('x', [1, 2]), 'baz': 3.14}
self.assertEqual(notifications, [])
foo.bar = {'foo': xr.DataArray([[0, 1, 2], [3, 4, 5]], coords={'x': ['a', 'b']}, dims=('x', 'y')), 'bar': ('x', [1, 2]), 'baz': 3.15}
self.assertEqual(len(notifications), 1)
示例8: _create_loop
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def _create_loop(self):
if self._loop is None:
self._loop = AnimationLoop(self._driver.frame_control)
self._loop.observe(self._loop_running_changed, names=['running'])
self._loop.layers_changed.connect(self._loop_layers_changed)
示例9: __init__
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def __init__(self, **kwargs):
self.path = None
self.filename = None
self.observe(self._handle_upload, names='data')
super().__init__(**kwargs)
示例10: _make_ui_pane
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import observe [as 别名]
def _make_ui_pane(self, hostheight):
layout = ipy.Layout(width='325px',
height=str(int(hostheight.rstrip('px')) - 50) + 'px')
#element_height = str(int(hostheight.rstrip('px')) - 125) + 'px'
element_height = None
# NOTE - element_height was used for the listbox-style orblist.
# HOWEVER ipywidgets 6.0 only displays those as a dropdown.
# This is therefore disabled until we can display listboxes again. -- AMV 7/16
# Orbital set selector
self.status_element = ipy.HTML(layout=ipy.Layout(width='inherit', height='20px'))
orbtype_label = ipy.Label("Orbital set:")
self.type_dropdown = ipy.Dropdown(options=list(self.wfn.orbitals.keys()))
initialtype = 'canonical'
if initialtype not in self.type_dropdown.options:
initialtype = next(iter(self.type_dropdown.options.keys()))
self.type_dropdown.value = initialtype
self.type_dropdown.observe(self.new_orb_type, 'value')
# List of orbitals in this set
orblist_label = ipy.Label("Orbital:")
self.orblist = ipy.Dropdown(options={None: None},
layout=ipy.Layout(width=layout.width, height=element_height))
traitlets.link((self.orblist, 'value'), (self, 'current_orbital'))
# Isovalue selector
isoval_label = ipy.Label('Isovalue:')
self.isoval_selector = ipy.FloatSlider(min=0.0, max=0.075,
value=0.01, step=0.00075,
readout_format='.4f',
layout=ipy.Layout(width=layout.width))
traitlets.link((self.isoval_selector, 'value'), (self, 'isoval'))
# Opacity selector
opacity_label = ipy.Label('Opacity:')
self.opacity_selector = ipy.FloatSlider(min=0.0, max=1.0,
value=0.8, step=0.01,
readout_format='.2f',
layout=ipy.Layout(width=layout.width))
traitlets.link((self.opacity_selector, 'value'), (self, 'orb_opacity'))
# Resolution selector
resolution_label = ipy.Label("Grid resolution:", layout=ipy.Layout(width=layout.width))
self.orb_resolution = ipy.Text(layout=ipy.Layout(width='75px',
positioning='bottom'))
self.orb_resolution.value = str(self.numpoints)
self.resolution_button = ipy.Button(description='Update resolution')
self.resolution_button.on_click(self.change_resolution)
traitlets.directional_link((self, 'numpoints'), (self.orb_resolution, 'value'),
transform=str)
self.uipane = ipy.VBox([self.status_element,
orbtype_label, self.type_dropdown,
orblist_label, self.orblist,
isoval_label, self.isoval_selector,
opacity_label, self.opacity_selector,
resolution_label, self.orb_resolution, self.resolution_button])
self.new_orb_type()
self.type_dropdown.observe(self.new_orb_type, 'value')
return self.uipane