26 Feb 2010
(updated 10 Mar 2010 at 05:12 UTC) »
Easy form building for terminal windows: jsonwidget-python
I’ve been working on a project to make building forms really simple. My latest work is “jsonwidget-python” for terminal-based applications (like you would use via SSH or local terminal on Linux and Mac). It’s all very retro, but terminal windows are still very much in use for buzzword-compliant activities like configuring virtual machines for cloud computing, in addition to being the preferred user interface for a lot of people out there (*cough* nerds *cough*).
Here’s a simple screenshot to show what’s going on:
Simple Address Entry in jsonwidget-python
There’s nothing too fancy in this screenshot, but this is probably the most typical case. What you see there is deceptively simple, but there’s a lot of complicated stuff going on under the hood. Most of the complicated parts (drawing the fields, handling focus, handling keyboard shortcuts) is being provided by urwid
, an excellent Python-based library for building terminal-based user interfaces. jsonwidget is providing a further abstraction that hopefully makes it even simpler to provide this type of interface, though sacrificing much of the flexibility of programming directly against urwid. Here is the complete configuration file (the schema) describing that address entry form
, as well as the documentation for the schema format
One nice feature on display even in the simple demo is the ability to have arrays as fields. You’ll notice that the phone number field has two phone numbers, and offers to let you add a third. There’s no artificial limit on the number of phone numbers that one can enter using this tool, beyond the usual limits of computer memory, patience, etc.
It also handles more complicated schemas if your application calls for it. For example, let’s say that one wanted to build a real address book application. Clearly a lot more flexibility would be needed than merely allowing multiple phone numbers. Here’s a screenshot showing a much more sophisticated schema that’s more like what real address book applications allow:
More complicated data entry with jsonwidget-python
So, what is this good for? Well, I think it’ll be good for a lot of stuff. I suspect it might be a very good user interface to stick in front of a augeas-based user interface. I think it might also be a good tool for building a terminal-based frontend for editing CouchDB and similar databases. In particular, I’m thinking about making a desktop-couch interface for contact editing. Another idea I’ve dabbled with is automatically building a UI based on parameters to Python’s optparse. Yet another thought is an editor for Python’s ConfigParser or alternatively ConfigObj. Lots of different possibilities here.
I’m particularly interested in suggestions for applications that people would use. So, if you have an application for this type of thing that you’re reasonably sure you’d use if I did a good enough job implementing, let me know.
Of course, that’s probably getting a little ahead of myself. There’s a number of things on the roadmap to do, such as more kosher packaging for easy_install and for Linux distros, as well as the ability to edit arbitrary JSON. I also need to investigate SitePen’s JSON schema work, which they appear to be well along toward some sort of RFC (probably informational, but that can be enough for something like this).
Anyway, if this sort of thing is up your alley, please give it a whirl and let me know what you think. You can download jsonwidget-python and give it a spin. I’ve set up a jsonwidget mailing list which you’re more than welcome to use, but you can also just post a comment here or contact me via email.
Update: March 9 – there’s now several ways of getting jsonwidget:
Syndicated 2010-02-26 05:51:28 (Updated 2010-03-10 04:20:26) from Roblag » Tech