我希望我的 npyscreen 应用程序中一些小部件的高度在终端调整大小时调整大小。
具体来说,我希望这两个列小部件在调整终端大小时继续占据终端高度的大约相同部分,而在调整终端大小时,底部的行小部件保持在终端的底部。
我有一些工作,但是当终端调整大小时,整体渲染出现问题,比如小部件不知道我希望在哪里绘制它们。可能出了什么问题?这应该如何正确完成?
import curses
import sys
import npyscreen
npyscreen.disableColor()
def main():
app = App()
app.run()
class App(npyscreen.NPSApp):
def main(self):
form = npyscreen.FormBaseNew(name = "COMMUNICATIONS")
column_height = terminal_dimensions()[0] - 9
widget_contacts = form.add(
Column,
name = "CONTACTS",
relx = 2,
rely = 2,
max_width = 20,
max_height = column_height
)
widget_messages = form.add(
Column,
name = "MESSAGES",
relx = 23,
rely = 2,
max_height = column_height
)
widget_input = form.add(
npyscreen.BoxTitle,
name = "INPUT",
max_height = 5
)
widget_input.resize
widget_contacts.values = ["alice", "bob"]
widget_messages.values = ["2018-09-19T2001Z a message", "2018-09-19T2002Z another message"]
widget_input.values = ["sup"]
#exit_button = form.add(
# ExitButton,
# name = "EXIT",
# #relx = 78,
# rely = 23
#)
widget_contacts.max_height = 5
form.edit()
class Column(npyscreen.BoxTitle):
def resize(self):
self.max_height = int(0.73 * terminal_dimensions()[0])
class ExitButton(npyscreen.ButtonPress):
def whenPressed(self):
sys.exit(0)
def terminal_dimensions():
return curses.initscr().getmaxyx()
if __name__ == "__main__":
main()