ipython / ipython/traitlets

Support setting a link on traits

オープン
#641 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
653
フォーク
217
平均マージ
2日 21時間
マージ済み PR(30日)
2

説明

I'm looking to start using a standard pattern in our UIs to split our model and views, similar to the points discussed in https://github.com/jupyter-widgets/ipywidgets/issues/2296. However when extending to more complex or nested views it's rather inconvenient to have to define all the links separately as we need to hold a reference to every field.

Instead I'd been keen to introduce the ability to set links directly on traits. This way I can bind to the view's traits without needing to hold a reference to the object. Proposing something along the following lines so that it's backwards compatible with current traitlet usage.

```python
from traitlets import SourceLink, Float, HasTraits
import ipywidgets as widgets

class Model(HasTraits):
a = Float()

def view(model):
return widgets.HBox([
widgets.Label("Value A"),
widgets.FloatText(value = SourceLink(model, "a"))
])

x1 = Model()
view(x1)
```

Having tested locally I think this is easily achievable with minimal changes. However before submitting a PR I wanted to check if any views or comments on the idea or how to approach it.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。