【发布时间】: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