Код: Выделить всё
import curses
import sys
import npyscreen
def main():
app = App()
app.run()
class App(npyscreen.NPSApp):
def main(self):
form = npyscreen.FormBaseNew(name = "COMMUNICATIONS")
column_height = terminal_dimensions()[0] - 9
wgtree = form.add(
npyscreen.MLTreeMultiSelect, # HERE replace with ColumnWithTree
name = "TREE",
relx = 2,
rely = 2,
max_width = 20,
max_height = column_height
)
treedata = npyscreen.NPSTreeData(content='Root', selectable=True,ignoreRoot=False)
c1 = treedata.newChild(content='Child 1', selectable=True, selected=True)
c2 = treedata.newChild(content='Child 2', selectable=True)
g1 = c1.newChild(content='Grand-child 1', selectable=True)
g2 = c1.newChild(content='Grand-child 2', selectable=True)
g3 = c1.newChild(content='Grand-child 3')
gg1 = g1.newChild(content='Great Grand-child 1', selectable=True)
gg2 = g1.newChild(content='Great Grand-child 2', selectable=True)
gg3 = g1.newChild(content='Great Grand-child 3')
wgtree.values = treedata
widget_messages = form.add(
Column,
name = "MESSAGES",
relx = 23,
rely = 2,
max_height = column_height
)
widget_messages.values = ["a", "b"]
form.edit()
class Column(npyscreen.BoxTitle):
def resize(self):
self.max_height = int(0.73 * terminal_dimensions()[0])
class ColumnWithTree(Column, npyscreen.MLTreeMultiSelect):
def __init__(self, *args, **keywords):
super().__init__(*args, **keywords)
self._myFullValues = None
self._last_filter = None
self._last_values = None
self._filter = None
def update(self, clear=True):
npyscreen.MLTreeMultiSelect.update(self, clear=clear)
def resize(self):
self.max_height = int(0.73 * terminal_dimensions()[0])
def _print_line(self, line, value_indexer):
return npyscreen.MLTreeMultiSelect._print_line(self, line, value_indexer)
@property
def values(self):
return self._myFullValues
@values.setter
def values(self, val):
self._myFullValues = val
self.display()
def terminal_dimensions():
return curses.initscr().getmaxyx()
if __name__ == "__main__":
main()
Подробнее здесь: https://stackoverflow.com/questions/793 ... a-boxtitle