Friday 4 March 2011

Tips for Python Processing on Windows

Since our method of running python processing code on windows is far from ideal, I struggled through improving a few things about the experience and thought I might share them. This stuff is in addition to Richard's initial setup document.

Setup jEdit to recognise .pyp files as Python files.
This is so you will get properly highlighted code when opening your .pyp files in jEdit.
  • Go to Utilities > Global Options
  • Editing
  • Select 'python' in the first drop down box
  • It might be useful to turn on Soft Tabs while you are in here (not related)
  • Add 'pyp' to the 'File name glob:' area, so it now says '*.{py,pyp,pyw,sc,jy}'
  • Apply
  • Ok
Make a macro to run your code.
Running it by navigating through that menu is tedious for me. I made a macro that does the same console commands as the pyp.xml, so you can run them with one shortcut key. Here's how:
  • Grab my macro file (Download)
  • Put it in your .jedit\macros\ folder (see Richard's tut, this is in C:\Documents and Settings\Username\ for me on XP)
  • Open the macro in jEdit.
  • Edit the pyp variable to be the path to your processing-py
  • Save
  • The macro will now show up at the bottom of your Macros list.
To assign a keyboard shortcut to your macro:
  • Utilities > Global Options
  • Shortcuts
  • Choose Macros in the 'Edit Shortcuts:' dropdown
  • Find your macro
  • Click in the Primary Shortcut box next to it
  • Enter a shortcut
  • Ok, Apply, Ok
Now you just need to use your shortcut to run the code, much faster!

Beware that it saves the file before running it. This is because making changes to the file without saving will result in you running the old version of the code, so you really always need to save before running anyway. It's a dangerous way to work in some ways, but things are setup like this at school on TextMate anyway, so get used to it.

Hope this helped!

1 comment: