Getting Started

Index of All Documentation » Wing Pro Reference Manual » Scripting and Extending Wing »

Scripts are Python modules or packages containing one or more Python functions. When Wing starts up, it will search all directories in the configured Script Search Path for modules (*.py files) and packages ( directories with an file and any number of other *.py files or sub-packages).

Wing will load scripts defined in each file and add them to the command set that is defined internally. The script directories are traversed in the order they are given in the preference and files are loaded in alphabetical order. When multiple scripts with the same name are found, the script that is loaded last overrides any loaded earlier under that name. For package scripts, Wing will load all package modules that are imported in the file.

Functions in scripts are exposed as commands in Wing unless their names start with an underscore. Commands may be bound to keys, added to menus or run via Command by Name on the Edit menu.

Naming Commands

Commands can be referred to either by their short name or their fully qualified name (FQN).

The short name of a command is the same as the function name but with underscores optionally replaced by dashes (cmdname.replace('_', '-')).

The FQN of a command always starts with .user., followed by the module name, followed by the short name.

For example, if a function named xpext_doit is defined inside a module named, then the short name of the command created will be xpext-doit and the FQN will be .user.xpext.xpext-doit.

Reloading Scripts

Once script files have been loaded, Wing watches the files and automatically reloads them when they are edited inside Wing and saved to disk. As a result, there is usually no need to restart Wing when working on a script, except when a new script file is added. In that case, Wing will not load the new script until the reload-scripts command (Reload All Scripts in the Edit menu) is issued or the IDE is restarted.

Reloading will not work for any file that sets _ignore_scripts or for modules outside of the script path. For details on how reloading works, see Advanced Scripting.

Overriding Internal Commands

Wing will not allow a script to override a command that Wing defines internally (those documented in the Command Reference). If a script is named the same as a command in Wing, it can only be invoked using its fully qualified name. This is a safeguard against completely breaking the IDE by adding a script.

One implication of this behavior is that a script may be broken if a future version of Wing ever adds a command with the same name. This can generally be avoided by using appropriately descriptive and unique names and/or by referencing the command from key bindings and menus using only its fully qualified name.