Question

In an earlier version of this program echo() worked fine but stopped working after some rewrites. The only thing i can think of that could be relevant is that the main window (self.screen) is now a pad instead of stdscr.

Everything else is working as it should adn did before; when i press enter on a selection i can input a string, and when im done, the string is there as i entered it. It just doesnt echo it back when i type or paste and i cant see it until getstr() is finished. I dont understand why. Seems to me this should all be as simple as echo()/noecho()..

Am i missing something or is this a bug?

(i know this code doesnt comly with pep8. I'll fix that eventually)

Working in older version!:

        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()

Not working! :

        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)

This is the whole function

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)
Was it helpful?

Solution

This was just me not reading the documentation well enough.

A pad is like a window, except that it is not restricted by the screen size, and is not necessarily associated with a particular part of the screen. Pads can be used when a large window is needed, and only a part of the window will be on the screen at one time. Automatic refreshes of pads (such as from scrolling or echoing of input) do not occur. The refresh() and noutrefresh() methods of a pad require 6 arguments to specify the part of the pad to be displayed and the location on the screen to be used for the display.

problem solved by just using newwin() for the sections i need to have echo() enabled in instead of rewriting the pad-window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top