Python Menu System

 

Eaily build Text-Based Menu Systems in Python

DOWNLOAD

Here's a link to download the most recent version of this library. Download Now

PAST VERSIONS

Version 1.2

Version 1.1

Version 1.0

WHAT YOU GET

In case you are wondering "What does this package do?", wonder no more. It creates simple menuing systems. Here's an example of what a menu might look like.

    Menu Name
        1.) Do Something
        2.) Do Something Else
        3.) Do Another Something Else
    Enter your choice .>

As you can see basic text menus aren't the prettiest things in the world, but they are easy and effective. Here is what is included with this module.

  • Basic Menu, Data Menu, & Choice Clases
  • MenuGenie Interface
  • XMLMenuGenie Implementation
  • Working Example

Menu is the basic menu class that represents a menu object. Multiple menu objects can be stacked in a heirarchial manner to create a menu system. The basic menu represents a question to the user, that can be answered by selecting option from a list of possibilities. A 'Yes or No' question could be represented by this object.

A Menu object is used to group Choice objects. Choice object represent one possible course of action for a menu. If a Menu asks a 'Yes or No' question, 'Yes' and 'No' would each be choice objects.

DataMenu is a subclass of Menu that allow the you to gather free form data from the user. DataMenu is interchangable with Menu.

The MenuGenie interface is a way that you can create you own menu storage classes. For instance you may want to save menus a MySQL database (or any other database), XML, or anything else might like.

Done for you already is XML storage. The XMLMenuGenie allows you to save and load menu systems from XML. This will alow you to keep you display code seperate from you controller code.

FAQ

Q. How can install this software?

You can install this package like any standard Python package. Type the following.

    tar zxf MenuSystem-1.3.tar.gz
    cd MenuSystem-1.3/
    python setup.py install

In addition, I would recommend running the samples to make sure everything works ok

Q. What systems / processors does this code work on?

Since the code is pure Python, it should run fine on any system capable of running Python. I have confirmed it running correctly on Win32, Linux 2.6 kernel 32bit & 64bit, and FreeBSD 6.2 (thanks Andrew).

MORE INFORMATION

If you need more information I suggest you take a look at the code. There are loads of comments and, of course, there's the code.

Conceptually the module isn't very tough. The Menu class contains a list of choices. Each choice is passed a handler. The handler is called when a choice is selected. To give your menu system depth, you can give a choice object a submenu. The submenu is just like any other menu and contains it's own choices which can also be submenus. This can continue on to any depth that you like.

The MenuGenie class is a generic interface that can be sub-classed to create any number of XXXMenuGenie sub classes. As long as you implement the MenuGenie interface correctly, all of these sub classes will be interchangable. The XMLMenuGenie sub class has already been created, if you are trying to make your own sub class I suggest you use that as an example.

Questions and comments are always welcome, shoot me an email.

CHANGES

Version 1.3

- Fixed bug in XMLMenuGenie that forced selector to be an integer
- Fixed bug in Men's waitForInput that threw an exception because of a missing 'data' property
- Thanks Peter for pointing out these bugs

Version 1.2

- Fixed error in example.py, save function call had incorrect module name.

LICENSE

Copyright (C) 2008 Daniel Mikusa

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA