Wiki

Clone wiki

urwid-demo / Home

This is the tutorial used for OSCON. This tutorial centers around revisions 18 through 35 of paster-demo.py. The revisions have been ordered to deliberately start from a very simple working example (revision 18) and build it incrementally into something more capable, with almost every intermediate version being a respectable starting point for a new project.

Stage 1: Very basic version

The absolute simplest version of the program:

This version doesn't do anything other than provide field editing. We have to hit ctrl-c to exit out of this version.

Stage 2: Making it minimally useful

The goal of this step is to get the basics of the form implemented.

At this point, it's not very pretty, but it does most of what you'd want the software to do. All of the fields are rendered, and the values are captured in a way that they can be retrieved.

Stage 3: Some initial refactoring

Up until now, the program was one big "main" function.

At the end of this stage, a couple functions have been split out.

Stage 4: abstracting away field value management

Attempting to make some simple visual changes makes it obvious that a little more refactoring will probably be needed.

Creating the FieldManager class liberates us from worrying about how to retrieve the field values in the end. Without it, we mess up our ability to get the field values every time we move the widget around or nest it inside of some other widget.

Stage 5: Adding a frame, and providing ESC to exit

Now we can add a frame to give ourselves a persistent title at the top of the window, even when the top of our form scrolls out of view. We take advantage of the opportunity to do one last bit of refactoring here, then add the ability to exit using the ESC key.

Stage 6: Spacing

Stage 7: Color

Updated