Python in winIDEA

Parent Previous Next

Introduction

This document describes usage of Python in winIDEA. Python is connected to winIDEA in both directions. winIDEA can edit and run Python code in interactive and batch mode, and Python programs can control winIDEA via isystem.connect module.

Requirements

winIDEA 9.12 or later

Python 2.7 or 3.3 (recommended)

isystem.connect for Python. It is included in winIDEA's distribution of Python.For custom installations of Python, isystem.connect SDK, which includes an installer, can be downloaded from iSYSTEM web page.

Installation

winIDEA comes with Python 3.3 and isystem.connect as a part of its installation. This distribution is private to winIDEA installation, and includes also modules not provided in standard Python installation, for example numpy, scipy… It is used to run internal scripts such as daqIDEA. You may use it as it is, but installation of custom modules should be avoided, as they may break scripts provided by iSYSTEM. Furthermore, any custom modules added to this instance of Python will be overwritten when newer winIDEA version is installed.

If you need Python with modules not provided in winIDEA, then isystem.connect SDK with installers for several Python versions can be downloaded from iSYSTEM web page, or click Help / SDK / Download Python SDK from winIDEA main menu. Download the SDK package, unzip it and run installer in the folder called installers. If upgrading the module, please make sure that no Python script using previous version of isystem.connect is running at the time of installation

winIDEA Configuration

If you are using one fo supported versions ofPython, which already includes isystem.connect module and its directory is already added to system PATH, then winIDEA default settings are OK. Otherwise start winIDEA and select Tools / Options, tab Script. The following dialog opens:


If you did not add Python directory to the system PATH variable (Python installer does not automatically do this), then either select the option Internal Python 3.3 or select User option and enter the path to your Python installation. Make sure that this installation contains the isystem.connect module.

Python is now ready to be run by winIDEA.

To see the installed version of isystem.connect for Python, create a new Python file (from winIDEA) and enter the following code:

import isystem.connect as ic
print ic.getModuleVersion()

now select Tools / Run Script or press F6 to run the script.

Batch mode

Python scripts can be executed as child processes of winIDEA. They launch in new console window as new instance of Python interpreter. There can be more than one script executed in batch mode at the same time. WinIDEA does not interact with these processes, except when we exit winIDEA, when it terminates all of them.

To start python script in batch mode, create or open a file with extension .py. Then press F6 or select menu option Tools / Run script.

This mode is useful for background tasks, for example if we'd like to read value of variable on a target and log it to file.

During development it is often useful to have access to Python in interactive mode, just after the script has executed. This can be achieved with menu command Tools | Run Script and Wait. When we execute the script this way, the new console window does not disappear after the script ends, but remains open and we have access to the current state of Python interpreter in interactive mode.

Note: Initially the command  Tools / Run Script and Wait has no shortcut key combination assigned, but if we use it often, we can do it manually with menu command Tools / Customize tab Keyboard.

Interactive mode

If you want to test bits of Python code, perform quick unit tests, or repeatedly execute sequence of actions use the interactive mode.

To execute Python code in interactive mode, open new or existing file with extension .py (menu option File / New or File / Open). Specific lines of code can be executed in one of the following ways:

press Ctrl + Enter. The line with caret is executed and the cursor moves to the next line, or to the end of block, if the line is the first line of Python code block.

press Shift + Enter. The line with caret position is executed and the cursor remains on the same line. This is useful, when we want to execute the same command several times. If we press these keys on the first line of code block, the cursor moves to the end of the block.

Select a block of code and press either of the above key combinations. The block of code is executed.

In all cases the script output window opens and prints results. Example is shown below.

Terminating scripts

To terminate scripts started in batch mode, we have to set focus to the console window running the script and press Ctrl+Break.

If we want to restart Python interpreter used for interactive mode, we can use menu option Reset Script from the context menu of Python document.

Sometimes we want to terminate the execution of the code run in interactive mode. An example of such situation is endless loop. This can be done by selecting the option Break Script in the context menu of Python document.


Other ways of running Python scripts

Python scripts that use isystem.connect module do not have to be run from winIDEA. It is possible to start a script from system command prompt or from some third party IDE, for example Eclipse with PyDev plug-in.

If the script is not started from winIDEA, then it should start winIDEA if it is not yet running, or connect to an existing instance of winIDEA. This needs to be implemented in the script by the use of isystem.connect module.

isystem.connect Documentation and Examples

isystem.connect module gives you full control over your target:

target execution control

breakpoint management

reading/writing from/to target memory

document handling

workspace management

modification of winIDEA options

trace

profiling

coverage

testing interface

HIL interface

For Python users there are two documents to use, isystem.connect for Python and isystem.connect. The first one contains description of Python specifics and examples in Python, while the second one contains description of the complete API. This description contains C++ data types, but conversion to Python data types is simple. All C++ integers map to Python integers and the same is true for string and float values. Both documents can be found in winIDEA Help / SDK menu, and in the SDK package, which can be found at http://www.isystem.com/download. Online API documentation can also be found at http://www.isystem.com.