Wednesday, March 10, 2010

How to: Building a front end for Python help

I'm sure most python programmers out there who have used the Python interpreter's built in help utility and regretted not being able to perform a simple "Find" operation on everything that was visible. So I decided, that it was about time, this was taken care of.

A good front end for an extremely useful help utility was lacking in Python, and so, I named my application "Venom" (something a python doesn't have, but could really do wonders with!). It is a really simple tool that consists of a single widget form that looks something like this:


Its only a text box!!! Its simple design was inspired by the Google desktop search utility. All you have to do is enter the module name (as you would have done at the 'help' utility prompt) and press the enter key.

This tool also remembers all the searches made during every run, and you can scroll through earlier queries simply by using the up/down arrow keys. Another interesting feature is that, this tool can be hidden onto the taskbar or system tray. There is an icon placed in the system tray, clicking which toggles the visibility of the tool.

When you press enter, the query is validated and if the help utility does dish something out, it is stored and displayed to you in your web browser as a simple HTML file. You can then perform simple search/find operations, which were not possible when the interpreter was executed directly from the shell.

The entire utility is built using PyQt4. The application is completely cross platform and I have tested it out on Ubuntu and Windows 7. You must have the PyQt site-packages and a Python 2.6 interpreter installed. PyQt4 is free and may be downloaded from the Riverbank Software Website.

From a programmer's perspective, this utility was a great way to understand how to create and use a system tray icon in PyQt (using the QSystemTrayIcon class). The UI was designed using Qt Designer and converted into Python code using pyuic4.

Click here to download the source!! (look for Venom)

Hope you like it... Its really made searching for help on Python a lot simpler. A funny thing I noticed was that the system tray icon was appearing in full color only when the utility was being run from the terminal. When I ran this application from anywhere else, the system tray icon didn't appear or was vague, but space was made available in the system tray for this icon. In order to prevent more confusion, I added a tooltip. Clicking on the system tray icon will toggle the visibility of this application.

Any ideas on how this may be expanded further...?? Please comment on this post or mail me.

0 comments:

Post a Comment