Monday, January 28, 2008

Komodo Tip: Launching a Python Shell and Running Code from Komodo Edit 4.2 on Linux

I have been teaching myself python lately and as part of that I have been trying out a few editors including vim, geany, and (most recently) Komodo Edit 4.2 from the folks at Active State (makers of fine cross platform scripting tools and language ports).

Komodo Edit appears to be a stripped down version of Active States more full featured Komodo IDE. Even though it is stripped down, it still has a some nice features.

While the Komodo Edit doesn't have all the built in features of the full-fledged IDE, the inclusion of the extensible Toolbox allows you to approximate some tools and integration that turns out to be quite handy.

Launching a Python Shell

The Komodo IDE has a nice integrated shell for python that makes trying out code quite easy. This is one of the features that was left out of Komodo Edit, but we can make launching a shell a little easier by creating a Toolbox entry that you can then bind to a key combination and launch from within the editor.

To get the entry:
  1. Launch Komodo Edit
  2. Click the Toolbox drop down menu
  3. Choose the Add menu item
  4. Then, click the New Command item
  5. In the Add Command window, type Python Shell in the first feild
  6. Then type, gnome-terminal -x python (or your terminal emulator of choice with the appropriate execute switch)
  7. The choose, No Console (GUI Application) from the Run In: field
  8. Next, click the Key Binding tab at the top and assign a keyboard combo that you can use to easily launch a python shell.


Running a Python File

Similarly you can create a Run Command to use python to execute the current file that you are working with.

To get the entry:
  1. Launch Komodo Edit
  2. Click the Toolbox drop down menu
  3. Choose the Add menu item
  4. Then, click the New Command item
  5. In the Add Command window, type Run Python File in the first feild
  6. Then type, %(python) %F
  7. The choose, Command Output Tab from the Run In: field
  8. Next, click the Key Binding tab at the top and assign a keyboard combo that you can use to easily launch a python shell.
Make sure to save the file before launching the Run Python File tool. If you are successful, your code will appear in a window at the bottom of the editor. If you get a stack trace, you can double click on the error and your cursor will jump back to the editor window to the line that is causing the problem.

I will post any more tricks in Komodo Edit as I come across them. If you have any tips or tricks, please post them to the comments.


CC photo credit: Fred Hsu

1 comment:

GamesBook said...

Thanks for this - helped me out much faster than I expected!

P.S. Your profile is eerily similar to what mine might be ('cept I am not at Linux Admin level yet...)