Frage

I'm trying to segment one window in curses into several sub-windows (with derwin()).

The code creates two sub-windows and I can add a string; no problem with the first function. The second one is pretty much exactly the same but gives me an error when I try to add a string with addstr()

class Window(GUI):
'''
Window-object
'''

def __init__(self, y_max , x_max, y_pos , x_pos, Target, screen):
    self.Win_Count = 0
    self.y_pos = y_pos
    self.x_pos = x_pos
    self.y_max = y_max
    self.x_max = x_max
    self.parent = screen 
    self.Target = Target

    #Window-Objects
    self.Win = self.create_win_parent(y_pos)
    self.Name_Win = self.create_name_win(self.Win)
    self.IP_Win = self.create_ip_win(self.Win)

def create_win_parent(self, y_pos):
    y_size = 1
    x_size = self.x_max - self.x_pos
    new_win_obj = self.parent.derwin(y_size, x_size, self.y_pos, 0)
    self.Win_Count += 1
    return new_win_obj

def create_name_win(self, Win_Obj):
    x = Win_Obj.derwin(1,40, 0,0)
    x.box()
    x.addstr(0,5," CUSTOMER NAME ")
    return x

def create_ip_win(self, Win_Obj):
    x = Win_Obj.derwin(1,15, 0,41)
    x.box()
    x.addstr(0,5," IP-ADDRESS ")
    return x

I'm getting this vague error:

    Traceback (most recent call last):
  File "./2pollng.py", line 229, in <module>
    wrapper(main)                    # Enter the main loop
  File "/usr/lib/python2.6/curses/wrapper.py", line 43, in wrapper
    return func(stdscr, *args, **kwds)
  File "./2pollng.py", line 222, in main
    Main_App.Run(screen)
  File "./2pollng.py", line 106, in Run
    self.Create_Win(self.Inv.index(e), e)
  File "./2pollng.py", line 90, in Create_Win
    Win_Obj = Window(self.y_max, self.x_max, y_pos, x_pos, Target_x, self.screen)
  File "./2pollng.py", line 141, in __init__
    self.IP_Win = self.create_ip_win(self.Win)
  File "./2pollng.py", line 160, in create_ip_win
    x.addstr(0,5," IPADDRESS ")
_curses.error: addstr() returned ERR
War es hilfreich?

Lösung

def create_ip_win(self, Win_Obj):
    x = Win_Obj.derwin(1,15, 0,41)
    x.box()
    x.addstr(0,5," IP-ADDRESS ")
    return x

In this function Win_Obj.derwin(1,15, 0,41) shows that x-pos should between 0 and 14. While in the code addstr(0,5," IP-ADDRESS ") x starts at 5 and the length of string " IP-ADDRESS " is greater than (15-5). So you got the ERROR.

Andere Tipps

Not really sure about the specifics but it had ( as indicated by the interpreter, duh) something to do with the strings and them not having enough space in the subwindows i created.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top