The script editor is one of the main windows of itom and allows creating, modifying and executing one or several python scripts.
Every script editor window can display one or multiple script files that are separated in different tabs at the bottom of the window. Click a tab to show the corresponding script in the center of the window. You can close, save, reorder or (un-)dock every single tab by its context menu.
The content of the current script file is displayed in the center of the script editor window. Use this text editor to write or modify a script that can then be run or debugged. The menus of the script editor window provide many possibilities to edit and finally run or debug the script. The most important functions are also accessible via the toolbar and / or the context menu of the script area.
The file menu gives the opportunity to open an existing script or create a new one, to save the current script or to print or close the script.
Basic and advanced functions to edit the current script are contained in the edit menu. These are:
In order to run or debug the script, use the functions given in the script menu.
These are:
The functions continue, step, step over, step out and stop are only active if a script is currently debugged or run (stop only). These functions are also accessible via the script menu of the itom main window.
More information about breakpoints are given in the next section.
Breakpoints are red or gray points in the right side of the margin of a script window. In every valid script line, there can be at most one breakpoint. A breakpoint is added to a specific line by clicking the margin at the right side of the line numbers. You cannot add a breakpoint to a commented or empty line. If you clear or comment a line that already contains a breakpoint, the script debugger will fail with a corresponding error message.
There are three different types of breakpoints:
The edit breakpoint dialog allows configuring the following properties of a breakpoint:
The breakpoints of this and other scripts are all listed in the breakpoint toolbox of itom. If itom is closed, all current active and inactive breakpoints are saved and restored once itom is started again. Breakpoints are also active if the corresponding script is currently not visible in any script editor window.
Note
In order to stop the script execution in a debug-mode in any method that is for instance called by clicking a button in an user-defined interface or via a timer event, you need to set a breakpoint in the corresponding line in the script and toggle the button Run Python in debug mode in the main window of itom (toolbar or menu script). The same holds for a method that you call from the command line. Toggle this button and set a breakpoint in the method in order to run this method in debug-mode and let the debugger stop in the line marked with the breakpoint.
A script highlighting mechanism is implemented to simplify the reading and programming of the script. You can change the styles of the syntax highlighting in the property dialog (tab styles) of itom.
Another big feature is the right handling and help for working with indentations using spaces or tabs. The python language is structured using indentation. Each indentation level always needs to consist of the same amount of spaces or tabs; additionally you must not switch between tabs and spaces for the indentation within your scripts. The script editor has a feature to automatically replace tabs by a certain amount of spaces (it is recommended to set this feature and use four spaces for one tab). Additionally, you can display spaces or tabs and be warned if you switch between both. All these features are configurable in the tab general of the property dialog.
When you start typing a new command in the editor window or the command line, it is possible to display either an auto completion list or calltips. The auto completion list appears after having typed a certain amount of characters of a new word and displays similar commands or keywords. You can choose from this list using the tab-key. It is possible to choose the sources for this list:
The auto completion list settings are listed in the tab auto completion of the property dialog.
Calltips always appear if you open a rounded bracket to give the arguments of a function call. Then the first line of the docstring of all functions that are listed in any loaded API file and have the same name than the written function are displayed. Configure the calltip behaviour in the tab calltips of the property dialog.
If desired, the current script can be checked for syntax and other errors or hints. This is done using the python package frosted (https://pypi.python.org/pypi/frosted/). You need to have this package installed in order to benefit from this service. If frosted is not installed, the syntax check is automatically disabled.
If frosted is installed, the syntax and style check can be dis- or enabled and configured via the property dialog of itom. Syntax bugs or other hints, warnings or errors detected by frosted will be displayed via a bug symbol in the left margin of the script editor window:
The tooltip text of every bug icon displays the reason for the bug. Since the bug icon is displayed in the same margin column than the bookmarks, there is also a combined icon for a bug and a bookmark in one line. Please note, that one line can also contain multiple syntax hints, they are displayed in multiple lines in the tooltip text.
Note
You can automatically download and install frosted using the tool pip from python (part of python 3.4 or later, for older version of pythons see https://pip.pypa.io/en/latest/installing.html to install pip. The executable of pip (pip.exe) is located in the scripts subfolder of your Python installation. Open a command line and browse to this folder. Then execute:
pip install frosted
to install frosted and restart itom. Try to call:
import frosted
to check if frosted is installed correctly.
To help adding icons to user defined buttons, menus or user interfaces, the icon browser of the script editor window shows a list of icons that come with itom or loaded plugins. The icon browser is opened via the menu edit >> icon browser... of any script editor window or the keyboard shortcut Ctrl + B.
These icons can directly be used inside of any script by their virtual icon path. If you choose a specific icon, you have the following options via the buttons on the right side: