10

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.

Llamageddon
  • 3,306
  • 4
  • 25
  • 44

3 Answers3

11

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.

Jann
  • 1,799
  • 3
  • 21
  • 38
jcollado
  • 39,419
  • 8
  • 102
  • 133
  • snack link is broken – Shadi Sep 26 '19 at 13:11
  • @shadi It looks like snack might now be included in newt itself: https://github.com/mlichvar/newt/blob/master/snack.py – jcollado Sep 26 '19 at 16:22
  • I see. The tutorial linked on the wiki page for newt is also broken ([tutorial link](http://gnewt.sourceforge.net/tutorial.html)) and the newt homepage doesn't have any documentation or links. Any idea where I can find docs for newt? – Shadi Sep 27 '19 at 07:39
  • 1
    @shadi In the internet archive you can still find a backup version of that tutorial? https://web.archive.org/web/20170124075941/http://gnewt.sourceforge.net/tutorial.html – jcollado Sep 27 '19 at 15:47
6

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()
Community
  • 1
  • 1
Serge Stroobandt
  • 28,495
  • 9
  • 107
  • 102
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.

  • 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 :) – Llamageddon Sep 11 '15 at 11:16
  • 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. – Richard Gordon Sep 11 '15 at 14:56