Shotgun Python Console
A Python console for Shotgun 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.
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.16.32 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!
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