Are there any toolkit libraries for curses with Python bindings?
Asked Answered
O

3

11

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.

Opinionative answered 25/12, 2011 at 19:10 Comment(0)
S
12

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.

Sublittoral answered 25/12, 2011 at 19:13 Comment(4)
snack link is brokenInsolvency
@shadi It looks like snack might now be included in newt itself: github.com/mlichvar/newt/blob/master/snack.pySublittoral
I see. The tutorial linked on the wiki page for newt is also broken (tutorial link) and the newt homepage doesn't have any documentation or links. Any idea where I can find docs for newt?Insolvency
@shadi In the internet archive you can still find a backup version of that tutorial? web.archive.org/web/20170124075941/http://gnewt.sourceforge.net/…Sublittoral
E
7

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()
Erythropoiesis answered 16/7, 2017 at 14:6 Comment(0)
A
0

On GitHub there is a free to use, study, modify and re-distribute High Level GUI library, at "https://github.com/rigordo959/tsWxGTUI_PyVx_Repository".

It is implemented in Python 2x & 3x using the "curses" Low Level GUI package.

Your application programs can be programmed using a character-mode subset of the pixel-mode "wxPython" High Level GUI API. It supports displays with keyboard and mouse input and various terminal emulators including the color xterms (8-color with 64-color pairs and 16-color with 256-color pairs) and non-color vt100/vt220.

Affirmation answered 10/9, 2015 at 10:38 Comment(2)
Since it seems like it's your code - it really needs some code examples badly, and honestly, the repo name is kind of off-putting as well. Either way, thanks for the answer, and welcome to Stack Overflow :)Opinionative
Yes it's my code and in the GitHub repository you will find not just the source code for the API but also that for the examples used to test and demonstrate it. Since I'm emulating the wxPython API, you can look at the introduction and tutorial for wxPython. My Announcement provides an overview of the distribution and its usage. The Python 2x code is large and complex (over 100,000 lines of executable Python. My Brochure provides screenshots; My Notebooks include an Introduction and engineering style specification, design and user documents.Affirmation

© 2022 - 2024 — McMap. All rights reserved.