Skip to main content

Class Widgets 2 Plugin SDK Development tools and type stubs

Project description

Class Widgets 2

Class Widgets SDK

适用于 Class Widgets 2 插件开发的完整 SDK、工具和类型提示。

中文 | English

PyPI version 星标 License

[!CAUTION]

本项目还处在开发阶段,API 接口可能随时发生变化,敬请谅解。

This project is still in development. The API may change at any time, so please bear with us.

概述

class-widgets-sdk 为创建 Class Widgets 2 插件提供了核心基类开发工具(如脚手架和打包)以及完整的类型提示

该包提供了开发所需的核心 SDK,必须安装在你的插件环境中。插件将在 Class Widgets 2 主应用程序中运行。

安装

pip install class-widgets-sdk

快速开始

1. 创建新插件

使用附带的 CLI 工具生成新的插件项目结构:

cw-plugin-init com.example.myplugin

2. 安装依赖

进入插件目录并以可编辑模式安装 SDK:

cd com.example.myplugin
pip install -e .

3. 使用(基类和类型)

SDK 提供了基类 CW2Plugin 和配置模型,支持完整的 IDE 自动补全和静态分析。

from ClassWidgets.SDK import CW2Plugin, ConfigBaseModel, PluginAPI

class MyConfig(ConfigBaseModel):
    enabled: bool = True
    text: str = "你好,世界"

class MyPlugin(CW2Plugin):
    
    def __init__(self, api: PluginAPI):
        super().__init__(api)
        self.config = MyConfig()
    
    def on_load(self):
        self.api.config.register_plugin_model(self.pid, self.config)
        # 你的 IDE 将提供完整的自动补全
        self.api.widgets.register(
            widget_id="com.example.mywidget",
            name="My Widget",
            qml_path="path/to/mywidget.qml"
        )

4. 打包

使用附带的 CLI 工具构建并打包插件为可分发的 .cwplugin.zip 文件:

cw-plugin-pack

工具

SDK 包含了强大的命令行工具,用于插件开发和分发:

命令 描述
cw-plugin-init 生成新的插件项目脚手架。
cw-plugin-pack 构建并打包插件为可分发的 .cwplugin.zip 文件。
cw-plugin-publish 将插件发布到 Class Widgets 插件注册中心。
了解更多 >

cw-plugin-init

使用交互式设置向导初始化一个新的 Class Widgets 插件项目。

用法:

# 在当前目录创建插件(交互式)
cw-plugin-init

# 在指定目录创建插件
cw-plugin-init my-plugin

# 强制覆盖已有文件
cw-plugin-init my-plugin --force

流程:

  1. 选择位置(当前目录或新文件夹)
  2. 输入插件元数据(名称、作者、ID 等)
  3. 确认并生成文件

cw-plugin-pack

构建并打包插件为可分发的 .cwplugin.zip 文件。

# 打包当前目录(默认格式:.cwplugin)
cw-plugin-pack

# 指定格式(.cwplugin 或 .zip)
cw-plugin-pack --format zip

# 指定输出路径
cw-plugin-pack -o ./dist/my-plugin.cwplugin

# 打包指定目录
cw-plugin-pack ./my-plugin

格式

  • .cwplugin - 推荐的插件格式
  • .zip - 标准归档格式

cw-plugin-publish

将插件发布到 Class Widgets 插件注册中心。该命令会读取 cwplugin.json 并将插件元数据发送到注册中心 API。

# 发布当前目录插件(从 CWPT_TOKEN 环境变量读取令牌)
cw-plugin-publish

# 使用显式令牌发布
cw-plugin-publish --token cwpt_xxxxxxxxxxxxxxxxxxxx

# 试运行 — 验证和预览(不发布到插件广场)
cw-plugin-publish --dry-run

# 使用自定义 API URL 进行调试
cw-plugin-publish --api-url http://localhost:1145 

# 指定分支(默认从 git 自动检测)
cw-plugin-publish --branch dev

选项:

  • --token, -t — 发布令牌(或设置 CWPT_TOKEN 环境变量)
  • --api-url — API 基础 URL(默认:https://plaza.cw.rinlit.cn/
  • --branch, -b — 仓库分支(从 git 自动检测,回退:main
  • --dry-run — 验证和预览而不实际发布

cwplugin.json 发布字段:

字段 必需 描述
id 插件 ID
name 插件显示名称
version 插件版本
api_version 所需 API 版本
url 仓库 URL
description 插件描述
readme README 文件路径(默认:README.md
icon 图标文件路径(默认:icon.png

工作原理

  1. 开发:安装此 SDK 包后,你可以在 IDE 中获得基类、类型提示、自动补全和静态类型检查(使用 mypy/pyright)。
  2. 运行时:当你的插件被 Class Widgets 2 主应用程序加载时,你的 CW2Plugin 子类将被实例化并执行。

[!IMPORTANT]

  • 该包是插件的开发工具包。插件必须在 Class Widgets 2 主应用程序中测试。
  • SDK 的导入路径为 ClassWidgets.SDK

链接

许可证

本项目基于 MIT 许可证 授权 - 详见 LICENSE.md 文件。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

class_widgets_sdk-0.4.2.tar.gz (235.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

class_widgets_sdk-0.4.2-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

Details for the file class_widgets_sdk-0.4.2.tar.gz.

File metadata

  • Download URL: class_widgets_sdk-0.4.2.tar.gz
  • Upload date:
  • Size: 235.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for class_widgets_sdk-0.4.2.tar.gz
Algorithm Hash digest
SHA256 b402c757ad109cf280a03d75f10ecae97f7d4b48d384bfa17c98ecb5f8449f43
MD5 25d07c6e3e70ab6529d56fd2b13aa49e
BLAKE2b-256 960397580a3becdbbacf0b0e2ee2b068a1848b6e6f09824d0f12c042301eef9e

See more details on using hashes here.

Provenance

The following attestation bundles were made for class_widgets_sdk-0.4.2.tar.gz:

Publisher: python-publish.yml on Class-Widgets/class-widgets-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file class_widgets_sdk-0.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for class_widgets_sdk-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9cf40a10ce93a22992ae4594413b60b1e3bdf78783d638ade3a6a9bcfd2c11a1
MD5 4d0964fc56c8ad8b3db3bc3abf20b1f6
BLAKE2b-256 7a3fc5dac2c4e9dd53701921d091ab67c7a85330d0e9f15730ba0e2d2c3df8a1

See more details on using hashes here.

Provenance

The following attestation bundles were made for class_widgets_sdk-0.4.2-py3-none-any.whl:

Publisher: python-publish.yml on Class-Widgets/class-widgets-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page