當前位置: 首頁>>代碼示例>>Python>>正文


Python traitlets.observe方法代碼示例

本文整理匯總了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] 
開發者ID:cyanogen,項目名稱:uchroma,代碼行數:18,代碼來源:led.py

示例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) 
開發者ID:cyanogen,項目名稱:uchroma,代碼行數:23,代碼來源:anim.py

示例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))) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:22,代碼來源:templateexporter.py

示例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)) 
開發者ID:jupyter-widgets,項目名稱:traittypes,代碼行數:14,代碼來源:test_traittypes.py

示例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) 
開發者ID:jupyter-widgets,項目名稱:traittypes,代碼行數:14,代碼來源:test_traittypes.py

示例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) 
開發者ID:jupyter-widgets,項目名稱:traittypes,代碼行數:14,代碼來源:test_traittypes.py

示例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) 
開發者ID:jupyter-widgets,項目名稱:traittypes,代碼行數:14,代碼來源:test_traittypes.py

示例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) 
開發者ID:cyanogen,項目名稱:uchroma,代碼行數:7,代碼來源:anim.py

示例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) 
開發者ID:Slicer,項目名稱:SlicerJupyter,代碼行數:7,代碼來源:widgets.py

示例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 
開發者ID:Autodesk,項目名稱:notebook-molecular-visualization,代碼行數:62,代碼來源:orbital_viewer.py


注:本文中的traitlets.observe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。