跳转至

pyguiadapter.adapter.uoutput

模块级方法

uprint(*args: Any, sep: str = ' ', end: str = '\n', html: bool = False, scroll_to_bottom: bool = True) -> None

打印信息到输出浏览器

Parameters:

Name Type Description Default
*args Any

要打印的信息

()
sep str

每条信息之间的分隔字符串

' '
end str

添加到最后一条信息后面的字符串

'\n'
html bool

要打印的信息是否为html格式

False
scroll_to_bottom bool

打印信息后是否将输出浏览器滚动到最底部

True

Returns:

Type Description
None

无返回值

clear_output() -> None

清除输出浏览器中所有内容

Returns:

Type Description
None

无返回值

print_image(img: Union[str, bytes], img_type: str = 'jpeg', embed_base64: bool = False, width: Optional[int] = None, height: Optional[int] = None, centered: bool = True) -> None

模块级函数。打印图片。

Parameters:

Name Type Description Default
img Union[str, bytes]

待打印的图片。可以为图片文件的路径(str)或图片的二进制数据(bytes

required
img_type str

图片类型。

'jpeg'
embed_base64 bool

是否使用data urlbase64格式)嵌入图片。传入二进制图片数据时,将忽略此参数。

False
width Optional[int]

图片的宽度。若未指定,则显示图片的原始宽度。

None
height Optional[int]

图片的高度。若未指定,则显示图片的原始高度。

None
centered bool

是否将图片居中显示。

True

Returns:

Type Description
None

无返回值。

info(msg: str) -> None

模块级函数。打印info级别的消息。info消息颜色值默认为:#00FF00

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

debug(msg: str) -> None

模块级函数。打印debug级别的消息。debug消息颜色值默认为:#909399

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

warning(msg: str) -> None

模块级函数。打印warning级别的消息。warning消息颜色值默认为:#FFFF00

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

critical(msg: str) -> None

模块级函数。打印critical级别的消息。critical消息颜色值默认为:#A61C00

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

fatal(msg: str) -> None

模块级函数。打印fatal级别的消息。fatal消息颜色值默认为:#FF0000

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值


Logger

Bases: object

该类用于向函数执行窗口的输出浏览器区域打印日志消息。不同级别的日志消息,主要以颜色进行区分。可以使用LoggerConfig实例指定各消息级别的颜色值。

示例:

from pyguiadapter.adapter import GUIAdapter
from pyguiadapter.adapter.uoutput import Logger, LoggerConfig

logger = Logger(
    config=LoggerConfig(
        info_color="green",
        debug_color="blue",
        warning_color="yellow",
        critical_color="red",
        fatal_color="magenta",
    )
)


def output_log_msg(
    info_msg: str = "info message",
    debug_msg: str = "debug message",
    warning_msg: str = "warning message",
    critical_msg: str = "critical message",
    fatal_msg: str = "fatal message",
):

    logger.info(info_msg)
    logger.debug(debug_msg)
    logger.warning(warning_msg)
    logger.critical(critical_msg)
    logger.fatal(fatal_msg)

if __name__ == "__main__":
    adapter = GUIAdapter()
    adapter.add(output_log_msg)
    adapter.run()

结果: logger example

critical(msg: str) -> None

打印critical级别的消息。

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

debug(msg: str) -> None

打印debug级别的消息。

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

fatal(msg: str) -> None

打印fatal级别的消息。

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

info(msg: str) -> None

打印info级别的消息。

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

warning(msg: str) -> None

打印warning级别的消息。

Parameters:

Name Type Description Default
msg str

要打印的消息

required

Returns:

Type Description
None

无返回值

LoggerConfig dataclass

Bases: object

Logger的配置类,用于配置Logger的颜色等属性。

Source code in pyguiadapter\adapter\uoutput.py
@dataclasses.dataclass
class LoggerConfig(object):
    """
    `Logger`的配置类,用于配置`Logger`的颜色等属性。
    """

    info_color: str = COLOR_INFO
    """`info`级别消息的颜色值"""

    debug_color: str = COLOR_DEBUG
    """`debug`级别消息的颜色值"""

    warning_color: str = COLOR_WARNING
    """`warning`级别消息的颜色值"""

    critical_color: str = COLOR_CRITICAL
    """`critical`级别消息的颜色值"""

    fatal_color: str = COLOR_FATAL
    """`fatal`级别消息的颜色值"""

critical_color: str = COLOR_CRITICAL class-attribute instance-attribute

critical级别消息的颜色值

debug_color: str = COLOR_DEBUG class-attribute instance-attribute

debug级别消息的颜色值

fatal_color: str = COLOR_FATAL class-attribute instance-attribute

fatal级别消息的颜色值

info_color: str = COLOR_INFO class-attribute instance-attribute

info级别消息的颜色值

warning_color: str = COLOR_WARNING class-attribute instance-attribute

warning级别消息的颜色值