Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any toolkit libraries for curses with Python bindings?

I'm writing a text-based hex viewer for fun and usefulness(I intend to add syntax highlighting for many different filetypes), and am wondering if there are any curses toolkits I could use.

I will probably write something myself anyway as to familiarize myself with the way gui toolkits work, but it would be nice to know of useful libraries for future reference for myself and others.

like image 354
Llamageddon Avatar asked Dec 25 '11 19:12

Llamageddon


2 Answers

Urwid is the best library to work with curses and python that I know.

Altenatively, you might find also interesting snack (newt-based library).

For more information, please have a look at this question.

like image 171
jcollado Avatar answered Oct 15 '22 22:10

jcollado


npyscreen

Npyscreen is a Python widget library and application framework for programming terminal or console applications. It is built on top of ncurses, which is part of the standard library.

The focus of this library is to provide a rapid way to develop console applications. In general, adding a control to the screen requires only one line of code.

This framework should be powerful enough to create everything from quick, simple programs to complex, multi-screen applications.

npyscreen screenshot

#!/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()
like image 6
Serge Stroobandt Avatar answered Oct 15 '22 22:10

Serge Stroobandt