My favorite Eclipse IDE tips and tricks for Python and Maya tool development.
Panels
Outliner
This great panel shows you all imports, classes and functions of the active resource.
You can filter the resource dynamically with the search box. It also allows for an alphabetical or reversed alphabetical view.
There are also buttons to collapse or expand all classes and functions.
When you click on a class or function, the cursor in the edit pane immediately jumps to that part of your code.
Eclipse Outline
Tasks
Window –> Show View –> Tasks
Tasks allows you to tag your code with #TODO: description or any other key word that you can set up in the preferences for tasks. Turn off Show All to only see tasks relevant to the open resource.
Bookmarks
Window –> Show View –> Other… –> Bookmarks
Bookmarks lets you tag your code so that you can easily refer back to it later. If you come up with a method for doing something and we certainly can’t memorize everything so this lets you find your way back when you need to. Right click in the vertical ruler –> Add Bookmark…
Features
Rulers & Occurences
When selecting a variable in Eclipse, it lights up in the overview ruler. Right click in the overview ruler –> Preferences… –> Occurences (PyDev) and turn on Show in –> Vertical ruler. Now your variables are clearly shown to you when you select them in the editor pane.
You can jump between the occurrences by clicking CTRL + . (Forward) and CTRL + , (Back)
Deleting Lines
When your cursor is on a line click CTRL + D to delete the line in it’s entirety (including the return character).
Renaming Variables
Select any text in your code.
CTRL + F brings up old school find and replace window.
Even cooler, however, is CTRL + 2 which brings up a little action menu. Press r to go into rename occurrences in file mode. Now when you change the variable, all the variables change simultaneously. When you are done renaming, hit enter.
Also handy in the pop up action bar is s, which searches only in open resources.
Duplicating & Shifting Lines
Select any text in your code and execute the hotkeys below. I use these all the time. Might be my most commonly used hotkeys….
Commenting
Second most used hotkey – I comment code in and out all the time.
PyDev Search
PyDev search allows you to quickly find code you are looking for. You can set the scope to include the entire workspace or just certain projects or modules.
Code Awareness
The true power if an IDE. CTRL + LMB click on any function and it will be hyperlinked to the file the function resides in and jump to that part of the code.
You can also just hover over any function and you will get a pop up window, showing the code of the function and where it is. The name of the function is a hyperlink in the pop up window. Clicking on it will open that resource and go to the function.
Code Completion
Available functions, classes and variables get shown to you from the module that you are using so no (human) memory is required.
Just select the class, function or variable that you want from the pop up window and press ENTER.
If you loose focus and the pop up window goes away, you can get it back by pressing CTRL + SPACE BAR.
Running Scripts
You can run a script by right clicking the script in the PyDev package Explorer and select Run As -> Python Run. You can also use the shortcut above . By Default Eclipse will run the selected resource with that shortcut. I like to change the behavior of this to run the last ran resource instead of selected.
Many times you are editing code in many places, but you will likely want to run the same script that sets off the tool that you are working on over and over.
Change the shortcut behavior Window –> Preferences –> Run/Debug –> Launching –> Always launch the previously launched application (check)
Debugging
The sure fire way to track down what is going on at your code at runtime. You can pause the code at any line by inserting a breakpoint by just double clicking a line number. When you debug run the code you will get a special perspective that lets you track any variable and see what is going on within any given function.
Check out the video and let me know if I forgot something in the comments below. Also, let me know if there is anything within tech art that you would like to know more about.
Spread the knowledge