Using the Python Tab
If you're not using a third-party Python interpreter, you can type scripts into Katana's Python tab. Open the Python tab by clicking the tabs dropdown button or clicking the Tabs menu, and selecting Python from the list.
Input and Output Panes
The Python tab is divided into two parts: the input pane and the output pane. The input pane, the lower part of the tab, is used to type in and execute your Python statements. When you've done this, the statement and the output appears in the output pane, the upper part of the tab.
To adjust the size of either the input or output panes, click and hold the divider between the two and drag it to the desired height. Alternatively, to completely hide either of the panes, click and hold the divider between the two and either drag it all the way to the top or bottom of the tab.
Entering a Statement
To enter a statement in the Python tab:
1. | Click on the input pane of the editor to insert the cursor there. |
2. | Type in your statement. To use the usual editing functions, such as copy and paste: |
• Right-click on the editor and select the desired function from the dropdown menu,
• Click the Edit menu in the Python tab, and select the desired function from the dropdown menu, or
• Use the common shortcut for the editing function (for example, to paste a previously-copied statement, press Ctrl+P).
When entering the statement, you may notice that any words that are Python's keywords, such as print and import, turn purple, while strings and comments (content in quotation marks or following a #) become green.
3. | If your statement includes several lines, or you want to enter several statements at once, press Return to move to the next line. |
4. | Execute the statement by pressing Ctrl+Return. |
Tip: You can also execute statements by pressing Ctrl+Enter on the numeric keypad.
By default, successful statements disappear from the input pane, and appear in the output pane. If you enter an invalid statement Katana produces an error in the output pane and clears the statement from the input pane.
Note: Sometimes you may get an error if you copy ad paste statements into the Python tab from another source, like an e-mail. This may be caused by the mark-up or encoding of the source you copied the statement from. To fix the problem, re-enter the statement manually.
To only execute part of a script, enter the script in the input pane and select the part you want to execute. Press Ctrl+Return. Katana runs the selected part of the script, leaving the script in the input pane.
If you want to repeat a statement, click Script > History Previous at the top of the tab, or press Alt+Up. This moves back to the previous statement. You can do this repeatedly until you reach the statement you want to execute again. Alternatively, if you are further up the script history stack and you want to move back down to a more-recent statement, click Script > History Next at the top of the tab, or press Alt+Down. This moves to the next statement down, and you can do this repeatedly until you reach the statement you want to execute. If you are on the last statement in the stack, the input pane is cleared.
To increase the indentation in the input window, press Tab. To decrease the indentation in the input window, press Shift+Tab.
Auto-completion
The Python tab provides auto-completion so that you can quickly finish statement tokens. If you write a partial token but are unsure how to complete it or want to fill in the token automatically, press Tab while the cursor is still in the input pane.
There are two options for the way in which the auto-completion is handled. You can opt to use the Shell or IDE auto-completion methods.
• Shell - auto-completes the token based on matches with possible completions, when Tab is pressed. If there are multiple match possibilities, a list of possibilities is printed to the output pane.
• IDE - provides options for possible auto-completion in a pop-up widget as you type. If you want to use a possible match for auto-completion, press the Up or Down arrows to choose the specific match and then press Tab or Return/Enter to auto-complete. If you want to close the IDE pop-widget, press Esc.
To set the auto-completion method, click Edit > Preferences, and select the python heading in the Preferences dialog. Click the autoCompletionBehavior dropdown and choose Shell or IDE.
Clearing the Output Pane
To clear everything that appears in the output pane, click Edit > Clear at the top of the Python tab.