estoy investigando como funciona la librería curses. Tengo una clase madre que me crea ventanas y paneles curses y una clase hija que quiero que me cree como una especie de widgets, mi problema es que no puedo agregar texto en estos widgets desde la clase hija, solo puedo agregar texto al crear la ventana desde la clase madre cuando hago su instancia. Cualquier ayuda se agradece. A continuación dejo código y errores.
Clase madre que llama a curses y a la función curses.newwin()
import curses, curses.panel
class BasicWindow:
Height = 0
Width = 0
Pos_Y = 0
Pos_X = 0
Color = None
Screen = None
Title = ""
TitlePosition = 0
win = None
panel = None
def __init__(self):
pass
def create_window(self):
win = curses.newwin(
self.Height,
self.Width,
self.Pos_Y,
self.Pos_X
)
win.erase()
win.attron(self.Color)
win.bkgd(self.Color)
win.box()
tittle_pos = (self.Width // 2) - (len(self.Title) // 2)
if not self.Title == "":
if self.TitlePosition == 0:
win.addch(0, tittle_pos - 1, curses.ACS_RTEE)
win.attron(curses.A_REVERSE)
win.addstr(0, tittle_pos , self.Title)
win.attroff(curses.A_REVERSE)
win.addch(0, tittle_pos + len(self.Title), curses.ACS_LTEE)
elif self.TitlePosition == 1:
win.addch(0, 1, curses.ACS_RTEE)
win.attron(curses.A_REVERSE)
win.addstr(0, 2 , self.Title)
win.attroff(curses.A_REVERSE)
win.addch(0, 2 + len(self.Title), curses.ACS_LTEE)
else:
win.addch(0, (self.Width - len(self.Title)) - 3, curses.ACS_RTEE)
win.attron(curses.A_REVERSE)
win.addstr(0, (self.Width - len(self.Title) - 2) , self.Title)
win.attroff(curses.A_REVERSE)
win.addch(0, self.Width - 2, curses.ACS_LTEE)
panel = curses.panel.new_panel(win)
self.win = win
return win, panel
def show(self):
self.win, self.panel = self.create_window()
self.win.refresh()
curses.panel.update_panels()
def hide(self):
self.panel.hide()
curses.panel.update_panels()
def printstr(self, y, x, strg):
self.win.addstr(y, x, strg)
Ahora la clase hija que intenta crear "Widget"
from ventanas.BasicWindow import *
import curses, curses.panel
class InfoWidget(BasicWindow): #Hereda de BasicWindow
Label = ""
Text = ""
def __init__(self):
pass
def __create_widget(self):
self.win, self.panel = self.create_window()
self.win.addstr(2, 2, self.Label)
def ShowWitget(self):
self.__create_widget()
Y la instancia, de la clase en cualquier parte de main:
wd_1 = InfoWidget()
wd_1.Screen = win_inicio
wd_1.Title = " Racaudación "
wd_1.TitlePosition = 0
wd_1.Label = "Total: "
wd_1.Pos_X = 2
wd_1.Pos_Y = 2
wd_1.Height = 5
wd_1.Width = 30
wd_1.Color = curses.color_pair(3)
wd_1.ShowWitget()
wd_1.show()
Veo que tampoco me deja usar la función win.addstr(y, x ,string)
con ninguna ventana excepto la principal curses.stdscr()
.
el error:
Traceback (most recent call last):
File "main.py", line 135, in <module>
curses.wrapper(Miapp)
File "/usr/lib/python3.6/curses/__init__.py", line 94, in wrapper
return func(stdscr, *args, **kwds)
File "main.py", line 30, in __init__
self.handle_keybinding()
File "main.py", line 121, in handle_keybinding
self.Inicio()
File "main.py", line 109, in Inicio
wd_Arqueos.Screen.addstr(2, 2, "lñkfdsñlfk")
AttributeError: 'BasicWindow' object has no attribute 'addstr'
Muchas gracias de antemano, solo es con medios educativos aprender a usar esta libreria, en realidad estoy aprendiendo python y me pareció interesante poder crear un entorno texto un poco mas amigable.