Python Console

Shotgun Python Console

A Python console for Shotgun Toolkit


By: Shotgun Software
Latest Version: v1.1.0 (beta)
For our version numbers, we follow the Semantic Versioning standard.
System Name: tk-multi-pythonconsole

Table of Contents:

Overview Summary

Documentation

            Panel

            Tabs

                  Editor

                  Output

            Buttons

                  Output

                  Editor

            Globals

            External sources

            Hotkeys

            Other notes

Installation, Updates and Development

Configuration Options

Release Notes History

Overview

This application provides an interactive python console for any environment that runs Toolkit applications.

Documentation

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.

Shotgun Python Console
Python Console in Photoshop CC 2017

Shotgun Python Console
Python Console in Flame

Panel

The console docked in Maya

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.

Tabs

Tabs

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.

Editor

Editor

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.

Output

Output

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.

Buttons

Buttons

Output

  • Clear - Clear the contents of the output browser.
  • Echo - Toggle echoing the executed commands in the output browser.

Editor

  • 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

Globals

Globals

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 tk variable
  • Shotgun API handle is available via the shotgun variable
  • The current context is stored in the context variable
  • The shell engine can be accessed via the engine variable

External sources

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.

External sources

Hotkeys

  • 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.

Other notes

  • 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 drop us a line at support@shotgunsoftware.com 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.

Special Requirements

  • 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.

Configuration

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.

external_sources_hook

Type: hook

Default Value: {self}/external_sources.py

Description: Supplies information about external sources for new tabs.

Release Notes

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!

v1.1.0

2017-May-16

Moves the python console menu item from the main menu to the context menu.

v1.0.9

2017-Mar-15

Removes problematic profiles from png files used as icons.

Details:

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.

v1.0.7

2017-Feb-08

Use active window for dialog parenting

v1.0.6

2017-Feb-08

Bug fix for both echo output and show lines toggles

v1.0.5

2017-Feb-07

QA fixes for toggle echo and line numbers

v1.0.4

2017-Feb-07

QA fixes for dialog parenting

v1.0.3

2017-Feb-07

Removed unnecessary minimum width

v1.0.2

2017-Feb-07

Do not use native file dialogs. Fixes issues in photoshopcc engine

v1.0.1

2017-Feb-07

Updated docs, external sources hook is no-op by default

v1.0.0

2017-Feb-06

QA fixes

v0.0.3

2016-Jul-13

Bug fixes, tabs, external resources, and more

v0.0.2

2016-Jun-29

bug fixes, tabs, external resources, and more

v0.0.1

Initial release

Follow

6 Comments

  • 0
    Avatar
    Patrick Macdonald

    This looks great. 

    Can you confirm if this runs on the latest version of Photoshop CC?  (or any adobe application for that matter)

    Thanks!

  • 0
    Avatar
    Josh Tomlinson

    Hi Patrick!

    The console should work in any Toolkit engine. Currently, the Shotgun Engine for Photoshop only supports CS6 and CC ( here's the note in the engine docs). That said, a refresh of the Photoshop integration is slated for the coming months. 

    Let me know if you have any other questions!

    -Josh T.

  • 0
    Avatar
    Robin Dutta

    is it possible to change the interface color?  I'm not sure why but mine is practically unreadable, especially the current line you're typing on.  I'm on linux, and have tried changing the system's window colours, but that had no effect on this console.

  • 0
    Avatar
    Josh Tomlinson

    Hey Robin!

    What SG engine and DCC is this running in? Also, what version of the python console are you running? 

    Currently there's no way to configure the colors unfortunately. It tries to be smart by using the palette of the DCC, but as you've found is not ideal. It works well enough in some but others its just bad (as you've found). Once I know the DCC and have some cycles, I can see about making it look better. I'll also put in an internal ticket to investigate making the colors configurable. 

    If you are comfortable with tweaking the code yourself, you can clone the repo and modify it here: https://github.com/shotgunsoftware/tk-multi-pythonconsole/blob/master/python/app/syntax_highlighter.py#L113-L188

    If you have any questions about how any of that works let me know!

    -Josh T.

  • 0
    Avatar
    Robin Dutta

    Hi Josh, I'm running rv 7.1.1, shotgun v7.0.2.0 (build f9be2f2), and pythonconsole version 1.0.41.

    It's not too big a deal if there's no simple way to configure it, as I just write my code elsewhere and run it in the console, but I thought I'd report it so thanks for submitting the support ticket. 

  • 0
    Avatar
    Satish Goda

    Just installed it to my dev configuration and to the Maya engine. Works well. This app is really gonna help while debugging and developing apps. Thank you!

Please sign in to leave a comment.