窗口成为填充后,curses.echo()停止在curses中工作

时间:2013-05-13 14:00:48

标签: python curses python-curses

在该程序的早期版本中,echo()工作正常,但在重写后停止工作。 我能想到的唯一可能是相关的是主窗口(self.screen)现在是一个垫而不是stdscr。

其他所有工作都应该像以前一样工作;当我在选择上按Enter键时我可以输入一个字符串,当我完成时,字符串就在我输入的时候。当我输入或粘贴时,它不会回复它,直到getstr()完成后我才能看到它。我不明白为什么。在我看来,这一切都应该像echo()/ noecho()..

一样简单

我错过了什么或这是一个错误吗?

(我知道这段代码与pep8并不相符。我最终会解决这个问题)

使用旧版本!:

        if q == ord("\n"):
            if selection >= 0:
                target_value = values[selection][0]
                screen.timeout(-1)
                curs_set(1)
                curs_pos = values[selection][1]
                screen.move(curs_pos[0], curs_pos[1])
                screen.clrtoeol()
                echo()
                if selection == 0:
                    self.TargetDict[Target].Name = screen.getstr()
                if selection == 1:
                    new_ip = screen.getstr()
                if selection == 2:
                    self.TargetDict[Target].CPE = screen.getstr()
                if selection == 3:
                    self.TargetDict[Target].Inc = screen.getstr()
                if selection == 4:
                    self.TargetDict[Target].Inst_ID = screen.getstr()
                if selection == 5:
                    self.TargetDict[Target].Span_ID = screen.getstr()
                noecho()
                curs_set(0)
                screen.timeout(300)    

        self.screen.addstr(0,0, str(counter))
        counter += 1
        self.screen.refresh()

不工作! :

        if q == ord("\n"):

            if selection >= 0:
                target_value = values[selection][0]
                self.screen.timeout(-1)
                curs_set(1)
                self.screen.move(values[selection][1][0], values[selection][1][1])
                self.screen.clrtoeol()
                curses.echo()
                self.screen.refresh(0, 0, 0, 0, self.y_max-1, self.x_max-1)

                if selection == 0:
                    self.TargetDict[Target].Name = self.screen.getstr()
                if selection == 1:
                    #not used. Can't change target address
                    new_ip = self.screen.getstr()
                if selection == 2:
                    self.TargetDict[Target].CPE = self.screen.getstr()
                if selection == 3:
                    self.TargetDict[Target].Inc = self.screen.getstr()
                if selection == 4:
                    self.TargetDict[Target].Inst_ID = self.screen.getstr()
                if selection == 5:
                    self.TargetDict[Target].Span_ID = self.screen.getstr()

                noecho()
                curs_set(0)
                self.screen.timeout(300)
                self.update_details(Target, option)
                self.screen.refresh(0, 0, 0, 0, self.y_max-1, self.x_max-1)

这是整个功能

def Details(self, scr, Target):

    self.screen.clear()
    screen = scr
    curs_set(0)        

    #This list is used to control the highlight of selected item in the program. 
    option = [0]*6

    # valuesList is [Targetvalue, (co-ordinates), max-lenght of string]
    values = [
              [self.TargetDict[Target].Name, (1,0), 38],
              [self.TargetDict[Target].IP, (3,12), 15],
              [self.TargetDict[Target].CPE, (4,12), 15],
              [self.TargetDict[Target].Inc, (5,12), 10],
              [self.TargetDict[Target].Inst_ID, (6,12), 10],
              [self.TargetDict[Target].Span_ID, (7,12), 6],
            ]
    counter = 0     #For testing

    selection = -1
    curs_pos = (0,0)

    Details = True

    self.update_details(Target, option)

    while Details:

        q = self.screen.getch()

        if q == ord("b") or q == ord("q"):
            Details = False

        if q == KEY_DOWN:
            if selection < 5 :
                selection += 1
                option[selection] = A_REVERSE
                if selection > 0 :
                    option[selection-1] = 0
            self.update_details(Target, option)

        if q == KEY_UP:
            if selection >= 0 :
                selection -= 1
                if selection == -1:
                    option[0] = 0
                else:
                    option[selection] = A_REVERSE
                    option[selection + 1] = 0
            self.update_details(Target, option)

        if q == ord("\n"):

            if selection >= 0:
                target_value = values[selection][0]
                self.screen.timeout(-1)
                curs_set(1)
                self.screen.move(values[selection][1][0], values[selection][1][1])
                self.screen.clrtoeol()
                curses.echo()
                self.screen.refresh(0, 0, 0, 0, self.y_max-1, self.x_max-1)

                if selection == 0:
                    self.TargetDict[Target].Name = self.screen.getstr()
                if selection == 1:
                    #not used. Can't change target address
                    new_ip = self.screen.getstr()
                if selection == 2:
                    self.TargetDict[Target].CPE = self.screen.getstr()
                if selection == 3:
                    self.TargetDict[Target].Inc = self.screen.getstr()
                if selection == 4:
                    self.TargetDict[Target].Inst_ID = self.screen.getstr()
                if selection == 5:
                    self.TargetDict[Target].Span_ID = self.screen.getstr()

                noecho()
                curs_set(0)
                self.screen.timeout(300)
                self.update_details(Target, option)
                self.screen.refresh(0, 0, 0, 0, self.y_max-1, self.x_max-1)

        self.update_details(Target, option)            
        self.screen.addstr(0,0, str(counter))
        counter += 1
        self.screen.refresh(0, 0, 0, 0, self.y_max-1, self.x_max-1)

1 个答案:

答案 0 :(得分:0)

这只是我没有充分阅读文档。

  

垫子就像一个窗口,除了它不受屏幕尺寸的限制,而不是   必然与屏幕的特定部分相关联。当需要大窗口时,可以使用垫,并且一次只有窗口的一部分在屏幕上。 不会发生打击垫的自动刷新(例如来自滚动或输入的回显)。打击垫的refresh()和noutrefresh()方法需要6个参数来指定要显示的打击垫部分以及用于显示的屏幕上的位置。

问题通过使用newwin()解决了我需要启用echo()而不是重写pad-window的部分。