certflow.config.ui_config module

UI配置加载模块

提供用户界面的配置数据结构和加载功能,支持从YAML文件动态加载UI配置, 包括窗口设置、按钮样式、页面配置和主题样式等.

class ButtonConfig(name, text, icon='', tooltip='', page_index=None, style=<factory>, enabled=True)[源代码]

基类:object

按钮配置数据类

定义UI按钮的所有可配置属性,包括显示文本、图标、工具提示和样式等.

参数:
name

按钮唯一标识名称

Type:

str

text

按钮显示的文本

Type:

str

icon

按钮图标路径或资源标识,默认为空字符串

Type:

str

tooltip

鼠标悬停时显示的工具提示文本,默认为空字符串

Type:

str

page_index

点击按钮后切换到的页面索引,None表示不切换页面

Type:

int | None

style

按钮样式配置字典,如{"padding": "10px", "font_size": "14px"}

Type:

dict[str, str]

enabled

按钮是否可用,默认为True

Type:

bool

name: str
text: str
icon: str = ''
tooltip: str = ''
page_index: int | None = None
style: dict[str, str]
enabled: bool = True
__init__(name, text, icon='', tooltip='', page_index=None, style=<factory>, enabled=True)
参数:
返回类型:

None

class PageConfig(title, buttons=<factory>, custom_config=<factory>)[源代码]

基类:object

页面配置数据类

定义应用程序中单个页面的完整配置信息.

参数:
title

页面标题配置,包含text、font_size、alignment等属性

Type:

dict[str, Any]

buttons

页面内按钮配置字典,键为按钮名称,值为ButtonConfig对象

Type:

dict[str, certflow.config.ui_config.ButtonConfig]

custom_config

页面特定的自定义配置,用于扩展功能

Type:

dict[str, Any]

title: dict[str, Any]
buttons: dict[str, ButtonConfig]
custom_config: dict[str, Any]
__init__(title, buttons=<factory>, custom_config=<factory>)
参数:
返回类型:

None

class UIConfig(main_window, title_bar, nav_buttons, welcome_page, import_page, log_page, status_bar, styles)[源代码]

基类:object

UI完整配置数据类

聚合应用程序所有UI相关的配置,包括主窗口、标题栏、导航按钮、 各个页面、状态栏和样式定义.

参数:
main_window

主窗口配置,包含标题、尺寸、最小尺寸等

Type:

dict[str, Any]

title_bar

标题栏配置,包含文本、字体、颜色、对齐方式等

Type:

dict[str, Any]

nav_buttons

导航按钮配置列表,每个元素为按钮配置字典

Type:

list

welcome_page

欢迎页面配置

Type:

dict[str, Any]

import_page

导入页面配置

Type:

dict[str, Any]

log_page

日志页面配置

Type:

dict[str, Any]

status_bar

状态栏配置,包含默认消息、超时时间等

Type:

dict[str, Any]

styles

样式配置字典,包含全局样式和各组件样式

Type:

dict[str, str]

示例

>>> from pathlib import Path
>>> config = UIConfig.load(Path("config/ui.yaml"))
>>> buttons = config.get_nav_buttons()
>>> style = config.get_style("button.default")
main_window: dict[str, Any]
title_bar: dict[str, Any]
nav_buttons: list
welcome_page: dict[str, Any]
import_page: dict[str, Any]
log_page: dict[str, Any]
status_bar: dict[str, Any]
styles: dict[str, str]
classmethod load(config_path)[源代码]

从YAML文件加载UI配置

读取指定的YAML配置文件,解析并构建UIConfig实例.

参数:

config_path (Path) -- UI配置文件路径(YAML格式)

返回:

加载完成的UI配置实例

返回类型:

UIConfig

抛出:
  • FileNotFoundError -- 配置文件不存在时抛出

  • yaml.YAMLError -- YAML格式错误或解析失败时抛出

示例

>>> config = UIConfig.load(Path("config/ui.yaml"))
>>> print(config.main_window.get("title"))
"CertFlow - 证书管理系统"
get_nav_buttons()[源代码]

获取导航按钮配置列表

将原始字典格式的导航按钮配置转换为ButtonConfig对象列表.

返回:

ButtonConfig对象列表,每个元素对应一个导航按钮的配置

返回类型:

list

示例

>>> buttons = config.get_nav_buttons()
>>> for btn in buttons:
...     print(f"{btn.name}: {btn.text}")
get_style(style_name, default='')[源代码]

获取指定名称的样式配置

支持使用点号分隔的路径访问嵌套样式配置.

参数:
  • style_name (str) -- 样式名称,支持嵌套路径如"button.default"

  • default (str) -- 样式不存在时返回的默认值,默认为空字符串

返回:

样式字符串,如果样式不存在则返回默认值

返回类型:

str

示例

>>> # 获取默认按钮样式
>>> btn_style = config.get_style("button.default")
>>> # 获取全局样式
>>> global_style = config.get_style("global", "")
__init__(main_window, title_bar, nav_buttons, welcome_page, import_page, log_page, status_bar, styles)
参数:
返回类型:

None

class StyleBuilder[源代码]

基类:object

样式构建器

提供静态方法,用于根据配置字典动态生成Qt CSS样式字符串. 支持按钮样式、标题样式等常见UI组件的样式生成.

示例

>>> style_config = {"padding": "15px", "font_size": "16px"}
>>> css = StyleBuilder.build_button_style(style_config)
static build_button_style(config)[源代码]

构建按钮样式CSS

根据配置生成包含正常、悬停、按下三种状态的按钮样式.

参数:

config (dict[str, str]) -- 按钮样式配置字典,支持以下键: - padding: 内边距,默认为"10px" - font_size: 字体大小,默认为"14px" - min_width: 最小宽度,默认为"100px"

返回:

完整的按钮CSS样式字符串,包含正常、悬停、按下状态

返回类型:

str

示例

>>> config = {"padding": "20px", "font_size": "18px", "min_width": "150px"}
>>> css = StyleBuilder.build_button_style(config)
>>> print(css[:50])
"QPushButton {
    padding: 20px;..."
static build_title_style(config)[源代码]

构建标题样式CSS

根据配置生成标题栏或页面标题的样式字符串.

参数:

config (dict[str, Any]) -- 标题样式配置字典,支持以下键: - font_size: 字体大小(像素),默认为18 - font_weight: 字体粗细(normal/bold),默认为"normal" - padding: 内边距,默认为"10px" - background_color: 背景颜色,默认为"#2c7be5" - text_color: 文字颜色,默认为"white"

返回:

标题CSS样式字符串,适用于QLabel或QWidget

返回类型:

str

示例

>>> config = {"font_size": 24, "font_weight": "bold", "text_color": "#333"}
>>> css = StyleBuilder.build_title_style(config)
>>> print(css)
"font-size: 24px; font-weight: bold; padding: 10px; background-color: #2c7be5; color: #333;"