certflow.config.ui_config module¶
UI配置加载模块
提供用户界面的配置数据结构和加载功能,支持从YAML文件动态加载UI配置, 包括窗口设置、按钮样式、页面配置和主题样式等.
- class certflow.config.ui_config.ButtonConfig(name, text, icon='', tooltip='', page_index=None, style=<factory>, enabled=True, action='')[源代码]¶
基类:
object按钮配置数据类
定义UI按钮的所有可配置属性,包括显示文本、图标、工具提示和样式等.
- 参数:
- class certflow.config.ui_config.PageConfig(title, buttons=<factory>, custom_config=<factory>)[源代码]¶
基类:
object页面配置数据类
定义应用程序中单个页面的完整配置信息.
- buttons¶
页面内按钮配置字典,键为按钮名称,值为ButtonConfig对象
- buttons: dict[str, ButtonConfig]¶
- class certflow.config.ui_config.UIConfigModel(*, main_window={}, window={}, title_bar={}, nav_buttons=[], welcome_page={}, import_page={}, query_page={}, log_page={}, print_page={}, correction_queue={}, status_bar={}, styles={})[源代码]¶
基类:
BaseModelui.yaml 顶层严格模型(Phase 2.4,顶层 UI 键 forbid 闭环)。
仅声明 ui.yaml 的顶层键(main_window / window / title_bar / nav_buttons / correction_queue / welcome_page / import_page / log_page / status_bar / styles / query_page / print_page),
extra=forbid从机制上 杜绝顶层键拼写错误 / 死配置静默失效(见 §15.3 阶段3)。嵌套结构(如
query_page.views)保持松散 dict,不在本模型深校验;UIConfig数据类仍保持extra=allow作为运行时兜底容器(见 models.py 注释),本模型仅作加载期校验闸门。- 参数:
nav_buttons (list)
- model_config = {'extra': 'forbid'}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class certflow.config.ui_config.UIConfig(main_window, window, title_bar, nav_buttons, welcome_page, import_page, query_page, log_page, print_page, correction_queue, status_bar, styles)[源代码]¶
基类:
objectUI完整配置数据类
聚合应用程序所有UI相关的配置,包括主窗口、标题栏、导航按钮、 各个页面、状态栏和样式定义.
- 参数:
nav_buttons (list)
导航按钮配置列表,每个元素为按钮配置字典
- 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", "")
获取指定查询视图的右键菜单配置。
读取
ui.yaml的query_page.views.<view_name>.context_menu, 作为动态 UI 配置源(§17):用户编辑ui.yaml即可增删右键菜单项, 由query_view在构建菜单时合并(叠加在 VIEWS 基础菜单之上)。
- get_view_toolbar_actions(view_name)[源代码]¶
获取指定查询视图的工具栏动作配置。
读取
ui.yaml的query_page.views.<view_name>.toolbar_actions。
- get_correction_queue_actions()[源代码]¶
获取校正队列隔离表工具栏动作配置(Phase 2.2,经注册表 dispatch 驱动)。
读取
ui.yaml的correction_queue.actions;项含action(对应certflow.actions.registry中的 action 名)、label、danger。- 返回:
工具栏动作列表;配置缺失时返回空列表。
- 返回类型:
获取校正队列隔离表右键菜单配置(Phase 2.2,经注册表 dispatch 驱动)。
读取
ui.yaml的correction_queue.context_menu;项含action、label、danger。- 返回:
右键菜单项列表;配置缺失时返回空列表。
- 返回类型:
- class certflow.config.ui_config.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;"