Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a "less"-like console pager interface for pysqlite3 database [closed]

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?

like image 892
Eric Avatar asked Mar 26 '10 19:03

Eric


2 Answers

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.

like image 119
nosklo Avatar answered Sep 24 '22 21:09

nosklo


After looking around a bit, I found that less and other pagers actually use curses. When I thought of curses I always imagined the blue-boxed interface with menus and mouse interaction. These are library add-ons for curses, which offer 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.

like image 36
Eric Avatar answered Sep 23 '22 21:09

Eric