为什么我写东西的时候输入框在清洗?

2024-06-06 14:05:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我在python上有一个curses程序,我有这个类的片段。我正在从另一个类运行def control_chat(self, sel_chat)。当消息(自我信息列表如[“message”,id\u of \u msg])正在更新,inputbox的窗口会自动清理。但我通过输入emptu行来清除所有屏幕,而不是触摸最后3行(在我的最后3行输入框中)。你知道吗

    def input_validator(self, key):
        if key == 10 or self.new_msg:
            return 7
        else:
            return key

    def get_msg(self):
        while self.chatting:
            win = curses.newwin(2, self.cols, self.lines-2, 0)
            inp = curses.textpad.Textbox(win)
            text = inp.edit(validate=self.input_validator)

            if text != "":
                self.vk.send_message(self.peer_id, text)

    def chat_clear(self):
        lines = self.lines - 3

        for y in range(lines):
            self.wprint(self.empity_line, y=y, x=0)

    def control_chat(self, sel_chat):
        self.sel_chat = sel_chat
        self.peer_id = self.vk.id_to_peer_id(self.sel_chat)

        self.input_thread = Thread(target=self.get_msg)
        self.input_thread.start()

        while self.chatting:
            self.messages = self.vk.list_chat(self.peer_id)
            self.draw_chat()

    def draw_chat(self):
        self.chat_clear()

        self.top_bar_draw()
        for message in self.messages:
            name_line = str(message[1])
            self.stdscr.attron(color_pair(1))
            self.stdscr.addstr(name_line)
            self.stdscr.attroff(color_pair(1))
            self.stdscr.addstr(": "+message[0]+"\n")
        self.wprint(self.screen_line, y=self.lines-3, x=0)

        self.messages = []
        # time.sleep()

    def wprint(self, str, y=-1, x=-1):
        if (y == -1) and (x == -1):
            self.stdscr.addstr(str+"\n")
        else:
            self.stdscr.addstr(y, x, str+"\n")
        self.stdscr.refresh()

Tags: selfidmessageinputdeflinechatmsg