跳转到主要内容

Duit是一个用于为Python创建简单用户界面的工具包。

项目描述

Duit (数据UI工具包)

Documentation Duit Test PyPI Github

Duit是一个Python库,提供了一套用于以结构化和高效方式处理数据的工具。Duit的目的是让开发者能够轻松创建和管理数据模型,并为数据输入和显示创建简单的用户界面。其实现基于cansik/bildspur-basecansik/bildspur-ui的理念。

gui-demo

使用Open3D(左)、tkinter(中)和wx(右)渲染的示例UI.

功能

  • 数据建模:duit提供灵活的数据建模框架以创建结构化数据模型和字段。

  • 注释:使用注释将元数据附加到数据字段,使其更容易处理。

  • 命令行参数:根据数据字段轻松解析和配置您的应用程序中的命令行参数。

  • 设置序列化:从数据字段到json以及从json到数据字段进行序列化和反序列化设置。

  • 用户界面:为数据字段创建简单的用户界面。

安装

默认情况下,仅安装数据建模、注释、参数和设置模块。

pip install duit

要支持数据字段的用户界面创建,可以安装以下后端之一

  • open3d - 支持三维可视化的跨平台UI框架。
  • tkinter - 更稳定的UI框架,目前功能尚未完善。

目前推荐使用open3d作为GUI后端。

pip install "duit[open3d]"

要安装tkinter,请使用以下命令

pip install "duit[tk]"

要安装wx,请使用以下命令

pip install "duit[wx]"

要安装具有所有后端的duit,请像这样调用pip

pip install "duit[all]"

示例

这是一个如何使用duit的非常基础的示例。阅读文档以获取更多关于核心概念的信息。

import argparse

from open3d.visualization import gui

from duit import ui
from duit.arguments.Argument import Argument
from duit.arguments.Arguments import DefaultArguments
from duit.model.DataField import DataField
from duit.settings.Settings import DefaultSettings
from duit.ui.ContainerHelper import ContainerHelper
from duit.ui.open3d.Open3dPropertyPanel import Open3dPropertyPanel
from duit.ui.open3d.Open3dPropertyRegistry import init_open3d_registry


class Config:
    def __init__(self):
        container_helper = ContainerHelper(self)

        with container_helper.section("User"):
            self.name = DataField("Cat") | ui.Text("Name")
            self.age = DataField(21) | ui.Slider("Age", limit_min=18, limit_max=99)

        with container_helper.section("Application"):
            self.enabled = DataField(True) | ui.Boolean("Enabled") | Argument()


def main():
    # create initial config
    config = Config()

    # register a custom listener for the enabled flag
    config.enabled.on_changed += lambda e: print(f"Enabled: {e}")

    # add arguments and parse
    parser = argparse.ArgumentParser()
    args = DefaultArguments.add_and_configure(parser, config)

    # store current config
    DefaultSettings.save("config.json", config)

    # create open3d gui for to display config
    init_open3d_registry()

    app = gui.Application.instance
    app.initialize()

    window: gui.Window = gui.Application.instance.create_window("Demo Window", 400, 200)
    panel = Open3dPropertyPanel(window)
    window.add_child(panel)
    panel.data_context = config

    app.run()


if __name__ == "__main__":
    main()

这将导致以下GUI。

example-window

开发

为了开发,建议克隆此存储库并按以下方式安装依赖项

# in the duit directory
pip install -e ".[all]"

生成文档

# create documentation into "./docs
python setup.py doc

# launch pdoc webserver
python setup.py doc --launch

关于

MIT许可 - 版权(c)2024 Florian Bruggisser

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

此版本没有提供源代码分发文件。请参阅生成分发存档的教程。

构建分发

duit-0.1.13.1-py3-none-any.whl (96.8 kB 查看哈希值)

上传时间 Python 3

由以下提供支持