Skip to main content

用 Python 构建 PCL XAML 模板的轻量库

Project description

PCLTheme

一个用 Python 构建 PCL(个人启动页/主页)XAML 模板的轻量库,目标是让用户无需编写 XAML,就能通过 Python 语法快速构建并输出 PCL 自定义主页(Custom.xaml)。

:star:主要特点

  • 用 Python API 构建 XAML,降低学习 XAML 的门槛
  • 支持容器(Grid、StackPanel、Card 等)与PCL控件(TextBlock、MyButton、MyImage、MyHint 等)
  • 支持嵌套容器与栈式渲染,按添加顺序拼接输出
  • 可直接保存为 PCL 本地自定义主页路径(例如保存为 Custom.xaml)

:rocket: 快速开始

:memo: 前提要求

  • Python 3.6 或更高版本

:computer: 安装方式

从 PyPI 安装

pip install PCLTheme

:coffee: 示例代码

下面示例展示了一个最小的使用流程:创建容器与控件,然后调用 build() 获取生成的 XAML。

import PCLTheme as pt

if __name__ == "__main__":
    path = "D:\-shot 2.9.2\PCL" # 替换为 PCL 主页路径
    file_name = "Custom.xaml" # 本地自定义主页文件名

    with pt.my_card(title="PCLTheme",
                    can_swap=False):
        with pt.stack_panel():
            pt.text_block(
                margin=[0, 0, 0, 30],
                text="PCLTheme",
                font_size=36,
                font_weight="Bold",
                foreground="T2",
                background="T6",
                horizontal_alignment="Center", )

            pt.text_block(
                margin=[0, 0, 0, 30],
                text="一个用 Python 构建 PCL(个人启动页/主页)XAML 模板的轻量库
目标是让用户无需编写 XAML,就能通过 Python 语法快速构建并输出 PCL 自定义主页(Custom.xaml)",
                text_wrapping="Wrap",
                font_size=16,
                horizontal_alignment="Left",
            )

            pt.text_block(
                margin=[0, 0, 0, 10],
                text="该库亦可用于自动化批量生成 PCL 主页,实现一些高级功能",
                text_wrapping="Wrap",
                font_size=16,
                horizontal_alignment="Left",
            )

            pt.my_button(
                text="前往GitHub主页",
                color_type="Highlight",
                event_type="打开网页",
                event_data1="https://github.com/just-ugly/PCLTheme",
                height=35,
            )

    print(pt.build(path, file_name))

:book: 常用控件速览

目前已包含除 “进阶:高级自定义事件” 板块外所有存在于《自定义主页与帮助 XAML格式》帮助文档中的控件

具体有(按字母顺序排列,已省略 local 前缀):

  • Grid
  • MyButton
  • MyCard
  • MyHint
  • MyIconButton
  • MyIconTextButton
  • MyImage
  • MyListItem
  • MyTextButton
  • StackPanel
  • TextBlock
  • WarpPanel

:pen: 自定义默认样式与全局设置

项目在 PCLTheme.global_var 中维护了若干全局默认值(如默认 margin/padding/文本大小等),并导出了 getter/setter,示例:

import PCLTheme as pt

pt.set_default_text_size(14)
pt.set_default_panel_margin([20, 30, 20, 12])

:question: 错误检查与常见异常

  • 大多数控件会对 margin/padding 长度(只接受长度 1~4)做检查。
  • 当控件需要在 Grid 中指定 row/column 时,如果当前并不在有 row/column 的容器内部,会抛出 ValueError。
  • 请按照控件函数签名提供正确类型与取值范围,会在运行时抛出有意义的异常提示。
  • 在 MyCard 中使用 MyCard 会被警告(:alien:邪修)

:next_track_button: TODOLIST

  • 实现无法寻找到文件时,自动创建文件
  • 实现“进阶:高级自定义事件”中的控件
  • 实现所有方法的Opacity属性
  • 实现所有方法的Visibility属性
  • 为所有有padding属性的控件实现padding属性
  • 为属性的插入顺序排序

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

pcltheme-0.2.2.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

pcltheme-0.2.2-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file pcltheme-0.2.2.tar.gz.

File metadata

  • Download URL: pcltheme-0.2.2.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for pcltheme-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4c7a666bd6bcdfb7c3060509b3ec9e7d98393a2ad0dd49ee5e6f6a1fc7a34883
MD5 ab66fe9462f64334e9ebfcac964a038d
BLAKE2b-256 ff6a1397e75bb96f3585533f840ca1334729c96595e46cd176e0620fa3820556

See more details on using hashes here.

File details

Details for the file pcltheme-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: pcltheme-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for pcltheme-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f860807fc32472a261db2498dd6c69ad227d3a72ec0b8aeb7f5f55a280995d38
MD5 4159d47884c72fd6136b931ada3f039d
BLAKE2b-256 9167ece060e3cc13fe0f8a1fdec3606652bbcd14170c51353b230ce75551c668

See more details on using hashes here.

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