SeparatorWidget API¶
SeparatorWidget(widget_id=None)
¶
Bases: BaseWidget
Create a separator for dividing different content blocks in emails.
This widget can create different styles of separator lines, including solid, dashed, and dotted lines, helping organize email content hierarchy and improve readability.
Core features
- Multiple styles: Supports solid, dashed, and dotted separator styles.
- Color themes: Supports theme color configuration based on StatusType.
- Flexible configuration: Customizable color, thickness, width, and margin.
- Email compatibility: Uses email client compatible CSS implementation.
Attributes:
Name | Type | Description |
---|---|---|
separator_type |
SeparatorType
|
Separator type. |
color |
str
|
Separator color. |
thickness |
str
|
Separator thickness. |
width |
str
|
Separator width. |
margin |
str
|
Top and bottom margin. |
Examples:
Create a basic solid separator:
from email_widget.widgets import SeparatorWidget
from email_widget.core.enums import SeparatorType
separator = SeparatorWidget().set_type(SeparatorType.SOLID)
# Assuming email is an Email object
# email.add_widget(separator)
Create a colored dashed separator:
colorful_separator = (SeparatorWidget()
.set_type(SeparatorType.DASHED)
.set_color("#ff8c00")
.set_thickness("3px"))
Create a dotted separator with 50% width:
narrow_separator = (SeparatorWidget()
.set_type(SeparatorType.DOTTED)
.set_width("50%")
.set_margin("30px"))
初始化SeparatorWidget.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
widget_id
|
Optional[str]
|
可选的Widget ID. |
None
|
Attributes¶
separator_type
property
¶
获取分隔符类型
color
property
¶
获取分隔符颜色
thickness
property
¶
获取分隔符粗细
width
property
¶
获取分隔符宽度
margin
property
¶
获取分隔符边距
Functions¶
set_type(separator_type)
¶
设置分隔符类型.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
separator_type
|
SeparatorType
|
分隔符类型枚举值. |
required |
Returns:
Name | Type | Description |
---|---|---|
SeparatorWidget |
SeparatorWidget
|
返回self以支持链式调用. |
Examples:
set_color(color)
¶
设置分隔符颜色.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color
|
str
|
CSS颜色值,支持十六进制、RGB、颜色名称等. |
required |
Returns:
Name | Type | Description |
---|---|---|
SeparatorWidget |
SeparatorWidget
|
返回self以支持链式调用. |
Examples:
set_thickness(thickness)
¶
设置分隔符粗细.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
thickness
|
str
|
CSS长度值,如 "1px", "2px", "3px" 等. |
required |
Returns:
Name | Type | Description |
---|---|---|
SeparatorWidget |
SeparatorWidget
|
返回self以支持链式调用. |
Examples:
set_width(width)
¶
设置分隔符宽度.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
width
|
str
|
CSS宽度值,如 "100%", "50%", "200px" 等. |
required |
Returns:
Name | Type | Description |
---|---|---|
SeparatorWidget |
SeparatorWidget
|
返回self以支持链式调用. |
Examples:
set_margin(margin)
¶
设置分隔符上下边距.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
margin
|
str
|
CSS边距值,如 "16px", "20px", "1em" 等. |
required |
Returns:
Name | Type | Description |
---|---|---|
SeparatorWidget |
SeparatorWidget
|
返回self以支持链式调用. |
Examples:
set_theme_color(status_type)
¶
根据状态类型设置主题颜色.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
status_type
|
StatusType
|
状态类型枚举值. |
required |
Returns:
Name | Type | Description |
---|---|---|
SeparatorWidget |
SeparatorWidget
|
返回self以支持链式调用. |
Examples:
set_style(separator_type=None, color=None, thickness=None, width=None, margin=None)
¶
一次性设置分隔符的多个样式属性.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
separator_type
|
SeparatorType
|
分隔符类型. |
None
|
color
|
str
|
分隔符颜色. |
None
|
thickness
|
str
|
分隔符粗细. |
None
|
width
|
str
|
分隔符宽度. |
None
|
margin
|
str
|
上下边距. |
None
|
Returns:
Name | Type | Description |
---|---|---|
SeparatorWidget |
SeparatorWidget
|
返回self以支持链式调用. |
Examples:
reset_to_default()
¶
Enum Types¶
SeparatorType¶
SeparatorType
¶
Bases: Enum
Separator type enumeration