Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Support setting a link on traits

未关闭
#641 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
30/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python

调研方向

从 HasTraits 和 Float 入口以及提议的 SourceLink/FloatText 示例开始,然后阅读链接的 ipywidgets 讨论,了解之前的设计背景。定义向后兼容的 API,并验证设置 trait link 后是否能按预期绑定 view,而无需保留字段引用。

由索引模型根据 Issue 内容生成。

描述

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.

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.

主要语言
Python
星标
653
派生
217
平均合并
2 天 21 小时
30 天内合并 PR
2

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ipython/traitlets 的其他 Issue

查看 ipython/traitlets 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。