【问题标题】:Add a popup dailog in fullscreen app in python prompt_toolkit在 python prompt_toolkit 中的全屏应用程序中添加弹出对话框
【发布时间】:2023-02-21 14:58:16
【问题描述】:

我正在创建一个终端聊天应用程序,其中有一个带有 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 应用程序中添加该对话,但每次它都显示 Exception This event loop is already running

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

Git url 到我的REPO

【问题讨论】:

    标签: python python-3.x command-line-interface chat prompt-toolkit


    【解决方案1】:

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

    GITHUBPyPI 的链接

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多