views:

56

answers:

2

I would like to add some interactive capability to a python CLI application I've writen that stores data in a SQLite3 database. Currently, my app reads-in a certain type of file, parses and analyzes, puts the analysis data into the db, and spits the formatted records to stdout (which I generally pipe to a file). There are on-the-order-of a million records in this file. Ideally, I would like to eliminate that text file situation altogether and just loop after that "parse and analyze" part, displaying a screen's worth of records, and allowing the user to page through them and enter some commands that will edit the records. The backend part I know how to do.

Can anyone suggest a good starting point for creating that pager frontend either directly in the console (like the pager "less"), through ncurses, or some other system?

+1  A: 

You might want to take a look at urwid. It is a console user interface library for Python. The examples should be more than enough to convince you that this is what you want, if you really want to go text-console UI.

I'd use something like pygtk instead though.

nosklo
Wow, that's very nice. I like all the coloring options! For simplicity I'll probably go with curses to start, but I'll definitely do something with urwid soon! Gtk would be great, but I actually love urwid's retro look. Thanks!
Eric
@Eric: urwid also uses curses, you just don't have to write most of the code yourself.
nosklo
+1  A: 

After looking around a bit, I found that less and other pagers actually use curses. When I thought of curses I always thought imagined the blue-boxed interface with menus and mouse interaction. These are library add-ons for curses, which offers exactly the basic terminal selection and editing control functionality I'm looking for.

Tutorial on Python Curses Programming

Curses Programming with Python

On the backend, when the user attempts to move the cursor above or below the currently displayed records, I'll have sqlite fetch me the next appropriate set of records for display.

Eric