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按钮的所有可配置属性,包括显示文本、图标、工具提示和样式等.

参数:
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
action: str = ''

对应 certflow.actions.registry 中的 action 名(如 nav.settings); 由 main_windowdispatch() 派发到对应 _nav_* 方法;空串表示不派发。

class certflow.config.ui_config.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]
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={})[源代码]

基类:BaseModel

ui.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 注释),本模型仅作加载期校验闸门。

参数:
model_config = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

main_window: dict[str, Any]
window: dict[str, Any]
title_bar: dict[str, Any]
nav_buttons: list
welcome_page: dict[str, Any]
import_page: dict[str, Any]
query_page: dict[str, Any]
log_page: dict[str, Any]
print_page: dict[str, Any]
correction_queue: dict[str, Any]
status_bar: dict[str, Any]
styles: dict[str, Any]
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)[源代码]

基类: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]
window: dict[str, Any]
title_bar: dict[str, Any]
nav_buttons: list
welcome_page: dict[str, Any]
import_page: dict[str, Any]
query_page: dict[str, Any]
log_page: dict[str, Any]
print_page: dict[str, Any]
correction_queue: 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", "")
get_view_context_menu(view_name)[源代码]

获取指定查询视图的右键菜单配置。

读取 ui.yamlquery_page.views.<view_name>.context_menu, 作为动态 UI 配置源(§17):用户编辑 ui.yaml 即可增删右键菜单项, 由 query_view 在构建菜单时合并(叠加在 VIEWS 基础菜单之上)。

参数:

view_name (str) -- 视图键名(如 "production""certificate")。

返回:

右键菜单项列表;视图或配置缺失时返回空列表。

返回类型:

list

get_view_toolbar_actions(view_name)[源代码]

获取指定查询视图的工具栏动作配置。

读取 ui.yamlquery_page.views.<view_name>.toolbar_actions

参数:

view_name (str) -- 视图键名。

返回:

工具栏动作列表;视图或配置缺失时返回空列表。

返回类型:

list

get_correction_queue_actions()[源代码]

获取校正队列隔离表工具栏动作配置(Phase 2.2,经注册表 dispatch 驱动)。

读取 ui.yamlcorrection_queue.actions;项含 action (对应 certflow.actions.registry 中的 action 名)、labeldanger

返回:

工具栏动作列表;配置缺失时返回空列表。

返回类型:

list

get_correction_queue_context_menu()[源代码]

获取校正队列隔离表右键菜单配置(Phase 2.2,经注册表 dispatch 驱动)。

读取 ui.yamlcorrection_queue.context_menu;项含 actionlabeldanger

返回:

右键菜单项列表;配置缺失时返回空列表。

返回类型:

list

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样式字符串,包含正常、悬停、按下状态

返回类型:

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;"