October 02, 2007 Archives

Tue Oct 2 00:09:23 EDT 2007

Ubuntu Programming Secrets

Ever since Ubuntu Linux arrived on the scene three years ago, it has become the most popular distribution in the world, and perhaps the one to bring Linux to the completely non-geek masses. But even though Ubuntu seems to be a desktop-only distribution at first glance, there's a lot of programming power built-in even before the first time the "Add/Remove..." app or Synaptic is run. Here's the rundown of Ubuntu's three hidden programming gems:

GUI programming with Python
While many open source programs are written in C or C++, those languages are too cryptic for average users to grasp. Ubuntu ships with the interpreted and easy to learn Python language, along with full GUI programming modules(Gtk/Gnome or Qt for Kubuntu). Hidden away in Ubuntu's menu editor is an entry to run a Python shell interactively. To activate the entry, right-click the Applications menu and select "Edit Menus". In the "Menus:" section of the editor, go to Applications->Programming. You'll see two items show up in the "Items:" section. Check the box next to "Python (v2.5)", and close the menu editor. Now you will find the entry activated under Applications->Programming->Python, and an interactive Python terminal will pop up for you to learn and experiment.

Extending The File Manager
On Ubuntu, you can easily extend the functionality of the file manager, Nautilus, through executable scripts. They can be written in Python, Perl, and even bash. To use a Nautilus Script, place the script in the $HOME/.gnome2/nautilus-scripts directory, select any files/folders to be passed to the script, then right-click your selection and navigate to Scripts->YourScript. To get a good idea of what scripting Nautilus can do for you, I've created a collection of scripts used for programming, multimedia conversion, and even blogging(I'm using my "BlogShell.sh" script right now to make this entry). Kubuntu users have a similar feature called "service menus". You can find an excellent source of service menu scripts here.

Creating GUI dialogs on the command-line
Going hand-in-hand with file manager extensions are the tools zenity(for Gnome/XFCE) and kdialog(for KDE). These comman-line tools can create several GUI-based dialogs that are used within shell scripts. Ubuntu has excellent documentation for zenity, obtainable by clicking the "?" icon next to the main desktop menu and entering "zenity" in the search box. Kubuntu users need only enter "man:kdialog" within Konqueror.