58 lines
2.0 KiB
Python
Executable File
58 lines
2.0 KiB
Python
Executable File
import curses
|
|
from curses.textpad import Textbox, rectangle
|
|
class Window():
|
|
def __init__(self, height, width, starty, startx, titolo):
|
|
self.height = height
|
|
self.width = width
|
|
self.starty = starty
|
|
self.startx = startx
|
|
self.contorno=curses.newwin(height+2, width+2, starty-1, startx-1)
|
|
self.win = curses.newwin(height, width, starty, startx)
|
|
self.label={}
|
|
self.contorno.box()
|
|
curses.start_color()
|
|
curses.init_color(100,235, 236, 240)
|
|
# Imposta i colori
|
|
curses.init_pair(1, curses.COLOR_WHITE, 100)
|
|
curses.init_pair(2, curses.COLOR_BLACK, 100)
|
|
curses.init_pair(3, 100, 100)
|
|
# Imposta l'ombreggiatura grigia
|
|
self.win.bkgd(curses.color_pair(2))
|
|
# Imposta il colore del testo
|
|
self.win.attron(curses.color_pair(1))
|
|
self.win.addstr(0, 0, titolo)
|
|
|
|
def addstr(self, nome:str, y=1, x=1):
|
|
self.label[nome]={'x':x,'y':y,'testo':""}
|
|
|
|
def label_caption(self,nome,testo):
|
|
self.win.attron(curses.color_pair(3))
|
|
tmp=self.label[nome]['testo']
|
|
x=self.label[nome]['x']
|
|
y=self.label[nome]['y']
|
|
self.win.addstr(y, x, tmp)
|
|
self.win.attron(curses.color_pair(1))
|
|
self.label[nome]['testo']=testo
|
|
|
|
def refresh(self):
|
|
for l in self.label:
|
|
stringa = f"{self.label[l]['testo']}"
|
|
x=self.label[l]['x']
|
|
y=self.label[l]['y']
|
|
self.win.addstr(y, x, stringa)
|
|
# stringa = f"{string:>{len(string)}}"
|
|
# self.win.addstr(y, x, stringa)
|
|
self.contorno.refresh()
|
|
self.win.refresh()
|
|
|
|
def clear(self):
|
|
self.contorno.bkgd(curses.color_pair(3))
|
|
self.contorno.clear()
|
|
|
|
def add_input(self,y,x, caratteri:int):
|
|
editwin = curses.newwin(1, caratteri, self.starty+ y, self.startx+x)
|
|
textbox = Textbox(editwin)
|
|
curses.curs_set(1)
|
|
return textbox.edit().rstrip()
|
|
|
|
|