# eric3.Scripting.ScriptManager

Module implementing the scripting component of the eric3 IDE.

### Classes

CompilationError | Class implementing an exception, which is raised, if a script couldn't be compiled.
ExecutionError | Class implementing an exception, which is raised, if a script couldn't be executed.
NoSuchScriptError | Class implementing an exception, which is raised, if a script couldn't be found.
ScriptAction | Class implementing the script action.
ScriptError | Base class for all scripting related exceptions.
ScriptManager | Class implementing the script manager.

### Functions

None

## CompilationError

Class implementing an exception, which is raised, if a script couldn't be compiled.

### Derived from

ScriptError

### Methods

CompilationError | Constructor
__repr__ | Private method returning a representation of the exception.
__str__ | Private method returning a string representation of the exception.

### CompilationError (Constructor)

CompilationError(error)

Constructor

### CompilationError.__repr__

__repr__()

Private method returning a representation of the exception.

Returns:
  string representing the error message

### CompilationError.__str__

__str__()

Private method returning a string representation of the exception.

Returns:
  string representing the error message

Up

## ExecutionError

Class implementing an exception, which is raised, if a script couldn't be executed.

### Derived from

ScriptError

### Methods

ExecutionError | Constructor
__repr__ | Private method returning a representation of the exception.
__str__ | Private method returning a string representation of the exception.

### ExecutionError (Constructor)

ExecutionError(error)

Constructor

### ExecutionError.__repr__

__repr__()

Private method returning a representation of the exception.

Returns:
  string representing the error message

### ExecutionError.__str__

__str__()

Private method returning a string representation of the exception.

Returns:
  string representing the error message

Up

## NoSuchScriptError

Class implementing an exception, which is raised, if a script couldn't be found.

### Derived from

ScriptError

### Methods

NoSuchScriptError | Constructor
__repr__ | Private method returning a representation of the exception.
__str__ | Private method returning a string representation of the exception.

### NoSuchScriptError (Constructor)

NoSuchScriptError(script)

Constructor

### NoSuchScriptError.__repr__

__repr__()

Private method returning a representation of the exception.

Returns:
  string representing the error message

### NoSuchScriptError.__str__

__str__()

Private method returning a string representation of the exception.

Returns:
  string representing the error message

Up

## ScriptAction

Class implementing the script action.

This class is subclassed from QAction to have the possibility to attach it to menus and toolbars.

Raises CompilationError:
  raised, if script compilation fails
Raises ExecutionError:
  raised, if script execution failed

#### Signals

activated
  signal emitted when this script action is activated

### Derived from

QAction

### Methods

ScriptAction | Constructor
__compile | Private method to compile the code string.
activated | Private method connected to the QAction activated signal.
addTo | Public method to add this action to a widget.
execute | Public method to execute this script.
remove | Public method to remove this action.
removeFrom | Public method to remove this action from a widget.

### ScriptAction (Constructor)

ScriptAction(code, *args)

Constructor

code
  the script code (string or QString)
*args
  arguments passed on to QAction

### ScriptAction.__compile

__compile(code)

Private method to compile the code string.

ode
  string containing the code (string)

Returns:
  the compiled bytecode as a string

Raises CompilationError:
  raised, if compilation fails

### ScriptAction.activated

activated()

Private method connected to the QAction activated signal.

### ScriptAction.addTo

addTo(widget)

Public method to add this action to a widget.

Overloaded from QAction in order to keep a list of widgets we are added to.

widget
  widget to add this action to (QWidget)

### ScriptAction.execute

execute(out, err, globals, locals)

Public method to execute this script.

out
  redirect for sys.stdout
err
  redirect for sys.stderr
globals
  dictionary containing global scope
locals
  dictionary containing local scope

### ScriptAction.remove

remove()

Public method to remove this action.

### ScriptAction.removeFrom

removeFrom(widget)

Public method to remove this action from a widget.

Overloaded from QAction in order to keep a list of widgets we are added to.

widget
  widget to remove this action from (QWidget)

Up

## ScriptError

Base class for all scripting related exceptions.

### Derived from

Exception

### Methods

None

Up

## ScriptManager

Class implementing the script manager.

#### Signals

firstScriptAdded
  emitted after the first script was added
lastScriptDeleted
  emitted after the last script was deleted

### Derived from

QObject

### Methods

ScriptManager | Constructor
addScript | Public method to add a new script.
deleteScript | Public method to delete a script.
executeAction | Public slot to execute a script action.
executeScript | Public method to execute a script.
getScriptName | Private method to select a script name from the list of scripts.
getScriptNames | Public method to retrieve the names of all scripts.

### ScriptManager (Constructor)

ScriptManager(parent = None, g = None, l = None, *args)

Constructor

parent
  parent of this scriptmanager (QObject)
g
  dictionary for global scope
l
  dictionary for local scope
*args
  arguments passed on to QObject

### ScriptManager.addScript

addScript(scriptName, scriptString)

Public method to add a new script.

scriptName
  name of the script to be added (string or QString)
scriptString
  the script code (string or QString)

Returns:
  a ScriptAction object

### ScriptManager.deleteScript

deleteScript(scriptName)

Public method to delete a script.

scriptName
  name of the script to be deleted (string or QString)

### ScriptManager.executeAction

executeAction(action)

Public slot to execute a script action.

action
  script action to be executed (ScriptAction)

### ScriptManager.executeScript

executeScript(scriptName, out = sys.stdout, err = sys.stderr)

Public method to execute a script.

scriptName
  name of the script to be executed (string or QString)
out
  redirect for stdout
err
  redirect for stderr

Raises NoSuchScriptError:
  raised, if the named script cannot be found

### ScriptManager.getScriptName

getScriptName()

Private method to select a script name from the list of scripts.

Returns:
  Tuple of script name and a flag, indicating, if the user pressed ok or canceled the operation. (QString, boolean)

### ScriptManager.getScriptNames

getScriptNames()

Public method to retrieve the names of all scripts.

Returns:
  list of all script names (list of strings)

Up