Skip to content

ChecklistWidget API

ChecklistWidget()

Bases: BaseWidget

Checklist component for creating task lists and checklists.

ChecklistWidget is used to display a series of checklist items, each item can have different states (completed, incomplete, skipped, etc.). Suitable for task lists, step guides, checklists, and other scenarios.

Attributes:

Name Type Description
items List[Dict[str, Any]]

List of checklist items

title str

Checklist title

show_progress bool

Whether to show progress statistics

compact_mode bool

Whether to use compact mode

Examples:

Basic usage:

Python
checklist = ChecklistWidget()
checklist.add_item("Complete Requirements Analysis", True)
checklist.add_item("Design Database", True)
checklist.add_item("Write Code", False)
checklist.add_item("Test Functions", False)

Using method chaining:

Python
checklist = (ChecklistWidget()
    .set_title("Project Checklist")
    .add_item("Environment Setup", True)
    .add_item("Code Review", False)
    .show_progress_stats(True))

Custom styling:

Python
checklist = ChecklistWidget()
checklist.add_item("Data Backup", True, "success")
checklist.add_item("Service Check", False, "warning")
checklist.add_item("Performance Test", None, "info")  # None means skip

Initialize checklist component.

Attributes

items property

获取所有清单项目。

Returns:

Type Description
list[dict[str, Any]]

List[Dict[str, Any]]: 清单项目列表

title property

获取清单标题。

Returns:

Name Type Description
str str

清单标题

item_count property

获取清单项目总数。

Returns:

Name Type Description
int int

项目总数

completed_count property

获取已完成项目数量。

Returns:

Name Type Description
int int

已完成项目数量

pending_count property

获取待完成项目数量。

Returns:

Name Type Description
int int

待完成项目数量

skipped_count property

获取跳过项目数量。

Returns:

Name Type Description
int int

跳过项目数量

completion_percentage property

获取完成百分比。

Returns:

Name Type Description
float float

完成百分比 (0-100)

Functions

add_item(text, completed=False, status_type=None, description='', status_text='')

Add checklist item.

Parameters:

Name Type Description Default
text str

Item text content

required
completed Union[bool, None]

Completion status. True=completed, False=incomplete, None=skipped

False
status_type Union[str, StatusType, None]

Status type, see StatusType enum for valid values

None
description str

Item description information

''
status_text str

Custom status text

''

Returns:

Name Type Description
ChecklistWidget ChecklistWidget

Returns self to support method chaining

Examples:

Python
checklist.add_item("Complete Design", True, "success", "UI design completed")
checklist.add_item("Code Review", False, "warning", "Awaiting review")
checklist.add_item("Performance Test", None, "info", "Temporarily skipped")

set_title(title)

设置清单标题。

Parameters:

Name Type Description Default
title str

清单标题

required

Returns:

Name Type Description
ChecklistWidget ChecklistWidget

返回self以支持链式调用

show_progress_stats(show=True)

设置是否显示进度统计。

Parameters:

Name Type Description Default
show bool

是否显示进度条和统计信息

True

Returns:

Name Type Description
ChecklistWidget ChecklistWidget

返回self以支持链式调用

set_compact_mode(compact=True)

设置紧凑模式。

Parameters:

Name Type Description Default
compact bool

是否使用紧凑模式(减少间距和字体大小)

True

Returns:

Name Type Description
ChecklistWidget ChecklistWidget

返回self以支持链式调用

clear_items()

清空所有清单项目。

Returns:

Name Type Description
ChecklistWidget ChecklistWidget

返回self以支持链式调用

remove_item(index)

根据索引移除清单项目。

Parameters:

Name Type Description Default
index int

要移除的项目索引

required

Returns:

Name Type Description
ChecklistWidget ChecklistWidget

返回self以支持链式调用

Raises:

Type Description
IndexError

当索引超出范围时

update_item_status(index, completed, status_type=None)

更新指定项目的完成状态。

Parameters:

Name Type Description Default
index int

项目索引

required
completed Union[bool, None]

新的完成状态

required
status_type Union[str, StatusType, None]

可选的状态类型

None

Returns:

Name Type Description
ChecklistWidget ChecklistWidget

返回self以支持链式调用