pyface.i_python_shell module

The interface for an interactive Python shell.

class pyface.i_python_shell.IPythonShell(adaptee, default=<class 'traits.adaptation.adaptation_error.AdaptationError'>)[source]

Bases: ILayoutWidget

The interface for an interactive Python shell.

command_executed = Event()

A command has been executed.

key_pressed = Event(KeyPressedEvent)

A key has been pressed.

interpreter()[source]

Get the shell’s interpreter

Returns

interpreter – Returns the InteractiveInterpreter instance.

Return type

InteractiveInterpreter

bind(name, value)[source]

Binds a name to a value in the interpreter’s namespace.

Parameters
  • name (str) – The python idetifier to bind the value to.

  • value (Any) – The python object to be bound into the interpreter’s namespace.

execute_command(command, hidden=True)[source]

Execute a command in the interpreter.

Parameters
  • command (str) – A Python command to execute.

  • hidden (bool) – If ‘hidden’ is True then nothing is shown in the shell - not even a blank line.

execute_file(path, hidden=True)[source]

Execute a file in the interpeter.

Parameters
  • path (str) – The path to the Python file to execute.

  • hidden (bool) – If ‘hidden’ is True then nothing is shown in the shell - not even a blank line.

get_history()[source]

Return the current command history and index.

Returns

  • history (list of str) – The list of commands in the new history.

  • history_index (int from 0 to len(history)) – The current item in the command history navigation.

set_history(history, history_index)[source]

Replace the current command history and index with new ones.

Parameters
  • history (list of str) – The list of commands in the new history.

  • history_index (int) – The current item in the command history navigation.

class pyface.i_python_shell.MPythonShell[source]

Bases: HasTraits

The mixin class that contains common code for toolkit specific implementations of the IPythonShell interface.

Implements: bind(), _on_command_executed()

bind(name, value)[source]

Binds a name to a value in the interpreter’s namespace.

Parameters
  • name (str) – The python idetifier to bind the value to.

  • value (Any) – The python object to be bound into the interpreter’s namespace.