我正在为了娱乐和实用而编写一个基于文本的十六进制文件查看器(我打算为许多不同的文件类型添加语法高亮功能),想知道是否有任何curses工具包可供使用。
虽然我可能会自己编写一些东西来熟悉GUI工具包的工作方式,但知道未来我和其他人可以使用的有用库会很好。
我正在为了娱乐和实用而编写一个基于文本的十六进制文件查看器(我打算为许多不同的文件类型添加语法高亮功能),想知道是否有任何curses工具包可供使用。
虽然我可能会自己编写一些东西来熟悉GUI工具包的工作方式,但知道未来我和其他人可以使用的有用库会很好。
Npyscreen是一个Python小部件库和应用程序框架,用于编程终端或控制台应用程序。它建立在标准库的ncurses
之上。
该库的重点是提供一种快速开发控制台应用程序的方法。通常,将控件添加到屏幕只需要一行代码。
这个框架应该足够强大,可以创建从快速简单的程序到复杂的多屏应用程序的所有东西。
#!/usr/bin/env python
# encoding: utf-8
import npyscreen
class TestApp(npyscreen.NPSApp):
def main(self):
# These lines create the form and populate it with widgets.
# A fairly complex screen in only 8 or so lines of code - a line for each control.
F = npyscreen.Form(name = "Welcome to Npyscreen",)
t = F.add(npyscreen.TitleText, name = "Text:",)
fn = F.add(npyscreen.TitleFilename, name = "Filename:")
fn2 = F.add(npyscreen.TitleFilenameCombo, name="Filename2:")
dt = F.add(npyscreen.TitleDateCombo, name = "Date:")
s = F.add(npyscreen.TitleSlider, out_of=12, name = "Slider")
ml = F.add(npyscreen.MultiLineEdit,
value = """try typing here!\nMutiline text, press ^R to reformat.\n""",
max_height=5, rely=9)
ms = F.add(npyscreen.TitleSelectOne, max_height=4, value = [1,], name="Pick One",
values = ["Option1","Option2","Option3"], scroll_exit=True)
ms2= F.add(npyscreen.TitleMultiSelect, max_height =-2, value = [1,], name="Pick Several",
values = ["Option1","Option2","Option3"], scroll_exit=True)
# This lets the user interact with the Form.
F.edit()
print(ms.get_selected_objects())
if __name__ == "__main__":
App = TestApp()
App.run()