This topic covers how to get started using the Python language from the Python Language Add-on, implemented by the Python
It is very important to follow the steps in this topic to configure the language correctly so that its advanced features operate as expected.
Configure the Ambient Parse Request Dispatcher
The language's parser does a lot of processing when text changes occur. To ensure that these parsing operations are offloaded into a worker thread that won't affect the UI performance, you must set up a parse request dispatcher for your application.
The ambient parse request dispatcher should be set up in your application startup code as described in the Parse Requests and Dispatchers topic.
Likewise it should be shut down on application exit, also as described in the Parse Requests and Dispatchers topic.
Note
Failure to set up an ambient parse request dispatcher when using the language will result in unnecessary UI slowdown since parse operations will be performed in the UI thread instead of in a worker thread.
Configure the Ambient Package Repository
An ambient package repository should always be set up to ensure that the application is able to use and cache package data from all packages within the Python project's search paths. A Python project (see below) normally adds search paths for the root of your project's *.py files, along with external libraries such as the Python standard library's Lib
folder. When a search path is added to a project, it will search the cache path to see if the cached data there is up-to-date with the related source package. If not, cache data is added to the package repository via a worker thread.
The ambient package repository should be set up in your application startup code. The File
Note
Failure to set up an ambient package repository provider will result in IntelliPrompt features not working for module internals.
Create the PythonSyntaxLanguage
The next step is to create an instance of the Python
This code creates a Python
Configure the Python Project
Each language has a IProject registered as a service on it that provides information such as which modules are actively being edited in a SyntaxEditor and the collection of paths to search for external packages.
If you wish to support automated IntelliPrompt for external modules, it is important to add search paths to the project. This tells the resolver where to look for *.py files. Note that the resolver will recursively search through child folders of specified paths as long as the folder names are valid Python identifiers.
It is common practice to specify these paths:
- The root path of your Python project code
- The path to the Python standard library
Lib
folder - The path to the Python standard library's
Lib\site-packages
folder - The path to any other folders that contain external libraries that are used by code in your project
This code gets the language's default project, and adds several search paths to where external packages can be located and used for IntelliPrompt:
Use the PythonSyntaxLanguage
Next, use the language on the ICode
This code applies the language to a document in a Syntaxeditor
variable:
Note
We recommend reusing your Python
Documents Should Have an Appropriate FileName and Tab Settings
It is a good practice to set the File
Note
If the filename is left empty, relative paths can't be used in from...import
statements and some other IntelliPrompt feature might not work properly.
Python also generally prefers that spaces are used in place of tabs for indentation. Set the ITexttrue
to force the use of spaces.
This code sets the filename and tab options for a document in a Syntaxeditor
variable:
Assembly Requirements
The following list indicates the assemblies that are used with the Python syntax language implementation in this add-on.
Assembly | Required | Author | Licensed With | Description |
---|---|---|---|---|
ActiproSoftware.Text.WinForms.dll | Yes | Actipro | SyntaxEditor | Core text/parsing framework for WinForms |
ActiproSoftware.Text.LLParser.WinForms.dll | Yes | Actipro | SyntaxEditor | LL parser framework implementation |
ActiproSoftware.Shared.WinForms.dll | Yes | Actipro | SyntaxEditor | Core framework for all Actipro WinForms controls |
ActiproSoftware.SyntaxEditor.WinForms.dll | Yes | Actipro | SyntaxEditor | SyntaxEditor for WinForms control |
ActiproSoftware.Text.Addons.Python.WinForms.dll | Yes | Actipro | Python Language Add-on | Core text/parsing for the Python languages |
ActiproSoftware.SyntaxEditor.Addons.Python.WinForms.dll | Yes | Actipro | Python Language Add-on | SyntaxEditor for WinForms advanced Python syntax language implementations |