certflow.config.ui_config module¶
UI配置加载模块
提供用户界面的配置数据结构和加载功能,支持从YAML文件动态加载UI配置, 包括窗口设置、按钮样式、页面配置和主题样式等.
- class ButtonConfig(name, text, icon='', tooltip='', page_index=None, style=<factory>, enabled=True)[源代码]¶
基类:
object按钮配置数据类
定义UI按钮的所有可配置属性,包括显示文本、图标、工具提示和样式等.
- 参数:
- class PageConfig(title, buttons=<factory>, custom_config=<factory>)[源代码]¶
基类:
object页面配置数据类
定义应用程序中单个页面的完整配置信息.
- buttons¶
页面内按钮配置字典,键为按钮名称,值为ButtonConfig对象
- buttons: dict[str, ButtonConfig]¶
- class UIConfig(main_window, title_bar, nav_buttons, welcome_page, import_page, log_page, status_bar, styles)[源代码]¶
基类:
objectUI完整配置数据类
聚合应用程序所有UI相关的配置,包括主窗口、标题栏、导航按钮、 各个页面、状态栏和样式定义.
- 参数:
导航按钮配置列表,每个元素为按钮配置字典
- Type:
示例
>>> from pathlib import Path >>> config = UIConfig.load(Path("config/ui.yaml")) >>> buttons = config.get_nav_buttons() >>> style = config.get_style("button.default")
- classmethod load(config_path)[源代码]¶
从YAML文件加载UI配置
读取指定的YAML配置文件,解析并构建UIConfig实例.
- 参数:
config_path (Path) -- UI配置文件路径(YAML格式)
- 返回:
加载完成的UI配置实例
- 返回类型:
- 抛出:
FileNotFoundError -- 配置文件不存在时抛出
yaml.YAMLError -- YAML格式错误或解析失败时抛出
示例
>>> config = UIConfig.load(Path("config/ui.yaml")) >>> print(config.main_window.get("title")) "CertFlow - 证书管理系统"
获取导航按钮配置列表
将原始字典格式的导航按钮配置转换为ButtonConfig对象列表.
- 返回:
ButtonConfig对象列表,每个元素对应一个导航按钮的配置
- 返回类型:
示例
>>> buttons = config.get_nav_buttons() >>> for btn in buttons: ... print(f"{btn.name}: {btn.text}")
- get_style(style_name, default='')[源代码]¶
获取指定名称的样式配置
支持使用点号分隔的路径访问嵌套样式配置.
- 参数:
- 返回:
样式字符串,如果样式不存在则返回默认值
- 返回类型:
示例
>>> # 获取默认按钮样式 >>> 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)¶
- 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样式字符串,包含正常、悬停、按下状态
- 返回类型:
示例
>>> 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
- 返回类型:
示例
>>> 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;"