ShotGrid Python Console
A Python console for ShotGrid Toolkit
This application provides an interactive python console for any environment that runs Toolkit applications.
This is a python console panel for use in DCCs with access to a python interpreter that have limited or no support for interacting with said interpreter.
Python Console in Photoshop CC 2017
Python Console in Flame
Once installed, the console is registered as a panel in the DCC and is available in the Shotgun menu. In apps that support embedded Toolkit panels (maya, nuke, houdini), the console will display in a docked panel. When using with older versions of these DCCs or in a DCC that does not support panels, the console will simply be shown as a regular Toolkit dialog.
The python console displays one or more tabs, each containing an editor and an
output window. New tabs can be created by clicking the
+ button in the bottom
right hand corner. Tabs have an
x button next to the tab name that allow you
to delete the tab. Double clicking the tab itself will prompt you to enter a
new name for the tab. Tabs can be rearranged via drag and drop. The state of the
tabs is saved when the DCC is closed and restored on the next launch.
The console has an input area for editing python. The editor includes line numbers, highlights the cursor's current line, and does some basic syntax highlighting. The console attempts to use the palette of the DCC to give it an integrated look and feel.
Block indenting and unindenting is supported. Select one or more lines and press
tab to indent by four spaces or
shift + tab to unindent by four spaces. It tries to keep the indentation in blocks of four so it will indent/unindent to the nearest whole block of four spaces.
Block commenting and uncommenting is also supported. Select one or more lines and press
cmd + / on Mac,
ctrl + / for Windows and Linux. If any of the selected lines don't have a
# at the start it will add one to all selected lines. If all the lines do have a
#, then it will remove them.
The output area displays the results of the executed python. Echoing the source
python commands is turned on by default and is differentiated in the output by
being prefixed with
>>>. Each execution is also marked with a timestamp. There
is a toggle for turning the echo off. Syntax and Runtime errors are shown in red
with a full stack trace for debugging.
- Clear - Clear the contents of the output browser.
- Echo - Toggle echoing the executed commands in the output browser.
- Execute - Execute the contents of the editor
- Save - Save the current contents of the editor to a file.
- Open - Open a file in the editor.
- Clear - Clear the contents of the editor.
- Lines - Toggle line numbers for the current tab
Some Shotgun/Toolkit globals are pre-defined in the console, similar to what is available in the Shotgun Engine for the shell.
- Tk API handle is available via the
- Shotgun API handle is available via the
- The current context is stored in the
- The shell engine can be accessed via the
The app comes with a hook that can be implemented to load python source from an
external location. The hook is called
external_sources_hook and requires
implementing a method called
get_external_source_actions. The method should
return a list of
QActions that, when triggered, add a new tab (with content)
to the console. An example implementation is provided that loads gists from
github for a list of predefined users. The actions returned by the hook are
shown in the popup menu displayed when the Open button is pressed and held.
- Execute selected with
Ctrl + Enter
- Create a new tab with
Ctrl + T
- Navigate tabs with
Ctrl + Shift + [or
Ctrl + Shift + ]
- Resize input/output font via
Ctrl + Wheel
NOTE: These hotkeys may not be available in all DCCs.
- In some older versions of DCCs, leaving the python console open when closing the session may cause a crash. We believe this may be a bug in some older versions of PySide. More recent versions of DCCs, bundled with newer versions of PySide, do not appear to crash on exit. If you encounter this issue with a recent DCC release, please submit a ticket so that we can investigate further.
Installation and Updates
Adding this App to the Shotgun Pipeline Toolkit
If you want to add this app to Project XYZ, in an environment named asset, execute the following command:
> tank Project XYZ install_app asset tk-maya tk-multi-pythonconsole
Updating to the latest version
If you already have this item installed in a project and you want to get the latest
version, you can run the
update command. You can either navigate to the
tank command that comes with that specific project, and run it there:
> cd /my_tank_configs/project_xyz > ./tank updates
Alternatively, you can run your studio
tank command and specify the project
name to tell it which project to run the update check for:
> tank Project XYZ updates
Collaboration and Evolution
If you have access to the Shotgun Pipeline Toolkit, you also have access to the source code for all apps, engines and frameworks in Github where we store and manage them. Feel free to evolve these items; use them as a base for further independent development, make changes (and submit pull requests back to us!) or simply tinker with them to see how they have been built and how the toolkit works. You can access this code repository at https://github.com/shotgunsoftware/tk-multi-pythonconsole.
- You need Shotgun version v6.2.0 or higher to use this.
- You need Shotgun Pipeline Toolkit Core API version v0.19.1 or higher to use this.
Below is a summary of all the configuration settings used. These settings need to be defined in the environment file where you want to enable this App or Engine.
Description: Supplies information about external sources for new tabs.
Welcome to the release notes for this App. Below you will find an overview of all the changes we did for each release. We try to be as detailed as possible and include all bugs we have fixed, features we have added and things that may have changed. If you have questions about a particular release, don't hesitate to contact our support team!
Rebranded to ShotGrid
Fixes an issue with the stack trace not being displayed when the executed code errors in the Python console. This only occurred when running the Python console outside of a Shotgun Engine.
Fixes a crash in RV when an exception is thrown in the python console. Updates the colour scheme to fixed colour values to keep the look consistent across DCCs.
Fixes the comment hotkey.
Now only comments the line out when holding
ctrl/cmd + / instead of just
- Adds block indenting and unindenting. You can select multiple and press
shift + tabto indent and unindent the selected lines without removing the contents.
- Adds block commenting and uncommenting. You can select multiple lines and press
cmd + /on Mac, or
ctrl + /on Linux to add or remove
#characters from the start of each line. If at least one of the selected lines doesn't start with a
#then it will comment the selection, otherwise if all selected lines have a
#it will uncomment the lines.
- Pressing return on a line will start the next line at the same level of indentation, unless you are pressing return after a
:character, in which case it will indent the next line by an additional four spaces.
- Saving a script now defaults to a
- The selected line highlight has been now toned down a little and the comments brightened a little to make the text more readable.
Fixes a bug with the global scope of executed code.
Fixes a bug where methods run in the Python console could not access the global scoped variables.
For example, importing a module and then using it within a method would throw a
NameError before the fix. Huge thanks to Joe Hultgren for providing this fix.
Python 3 support
- It now works in Python 3. As a result, the required core has been bumped to
v0.19.1 and it now requires Shotgun utils v5 up from v4.
- Small bug fix for situations where the open file button would throw an error.
- Using the python console standalone, (without
sgtk being present,) is still supported but it is recommended that you install the module
six so that it can better handle strings.
Changes to allow the app to run independently of toolkit
Moves the python console menu item from the main menu to the context menu.
Removes problematic profiles from png files used as icons.
This will silence libpng warnings from Qt when the png files are loaded as pixmaps. This is a second attempt as this profile stripping, and uses ImageMagick's "mogrify" command to achieve the desired result, which maintains color consistency.
Use active window for dialog parenting
Bug fix for both echo output and show lines toggles
QA fixes for toggle echo and line numbers
QA fixes for dialog parenting
Removed unnecessary minimum width
Do not use native file dialogs. Fixes issues in photoshopcc engine
Updated docs, external sources hook is no-op by default
Bug fixes, tabs, external resources, and more
bug fixes, tabs, external resources, and more