Skip to content

Cookbook: Styling the QtConsole

ellisonbg edited this page Feb 13, 2013 · 1 revision

I love IPython but really enjoy IDE syntax highlighting and custom colors. This functionality is now available with the qtconsole in IPython 0.11! Multi-line editing and syntax highlighting IPython is my go-to editor.

Here are basic instructions to create a custom style theme for IPython.

Happy theming! :)


Syntax highlighting depends on the Pygments package.

Styles are a .py file stored in: site-packages/pygments/styles/

The element you want to color is called a "token". See the list of available tokens

Make sure to include all the tokens in a line:

 from pygments.token import <your tokens>

The name of the style class is particular. Use the same name as your file name, first letter capitalized + "Style" Example: - darkblue.py, class DarkblueStyle(Style)

CAUTION! I don't think all file names work. Using underscores gave me problems. I don't know what else may be prohibited. This doesn't work: dark_blue.py, class Dark_blueStyle(Style)

Example: Create file:

  mycolors.py 

Stored in:

  site-packages/pygments/styles/
  class MycolorsStyle(Style):
  
    background_color = '#000'
    highlight_color = '#ffff55'
  
    styles = {
        Text: "#A7ADDB",
        Number.Float: "#2200FF",
        Number.Integer: "#E5FF00"
    }

Run the style with this line:

  ipython qtconsole --style=mycolors

or, set the option in your ipython_qtconsole_config.py file:

  # If not empty, use this Pygments style for syntax highlighting. Otherwise, the
  # style sheet is queried for Pygments style information.
  c.IPythonWidget.syntax_style = u'mycolors'
Clone this wiki locally