在 python prompt_toolkit 中的全屏应用程序中添加弹出对话框

问题描述 投票:0回答:1

我正在创建一个终端聊天应用程序,其中有一个带有 prompt_toolkit 的 UI。 在消息框中,我添加了一些命令来执行某些操作。 为了创建仪表板,我使用了

prompt_toolkit.Application
并在此之上应用我的功能。

class Dashboard(Application):
    """Implemented Dashboard"""

    def __init__(self):
        super().__init__(full_screen=True)
        self.key_bindings = KeyBindings()    
        self.__layout = None
        self.create_layout()
        self.set_layout()
        self.set_key_bind()

    def create_layout(self):
        """Implemented Dashboard.create_layout"""
        self.__layout = VSplit(
            [
                HSplit(
                    [self.__screen_area, self.__message_box]
                ),
                self.__user_section
            ], padding=1, width=2)

    def set_layout(self):
        """Setting the dashboard layout"""
        self.layout = Layout(self.__layout)

    def process_message(self):
        """Implemented send message method"""
        buffer = self.__message_box.buffer
        if buffer:
            if '/' in buffer[0]:
                # INFO: Clear the message box
                self.__message_box.clear()
                buffer = buffer[1:]
                # INFO: Perform the operation
                if buffer in ['clear', 'cls', 'c']:
                    self.__screen_area.clear()
                elif buffer in ['exit', 'quit', 'q']:
                    # add confirm dailog here
                    self.exit()
            else:
                message = self.__message_box.message
                self.__screen_area.send(message)

我想像这样弹出确认对话框

并在 prompt_toolkit 中提供docs

我试图在 py 应用程序中添加那个 dailog,但每次它都说

Exception This event loop is already running

问题似乎是我的仪表板是一个循环,我不能在现有的内部有另一个循环。我被困在这一点上。任何帮助或建议都将是有益的

我的 REPO

的 Git url
python python-3.x command-line-interface chat prompt-toolkit
1个回答
0
投票

我认为

prompt-toolkit
已经过时了。我找到了另一个 python 包
textual
。使用
texual
,您可以使用简单的 Python API 构建复杂的 TUI。

GITHUBPyPI

的链接

Textual 通过受现代 Web 开发启发的 API 为 Rich 添加交互性。

在现代终端软件(大多数系统默认安装)上,文本应用程序可以使用 1670 万种颜色,支持鼠标和流畅的无闪烁动画。强大的布局引擎和可重复使用的组件使构建可与桌面和 Web 体验相媲美的应用程序成为可能。 兼容性

Textual 在 Linux、macOS 和 Windows 上运行。文本需要 Python 3.7 或更高版本。

© www.soinside.com 2019 - 2024. All rights reserved.