- How to proceed?
- Importing the ".py" file
- Using Python functions in WLanguage code
WLanguage allows for native Python calls.
The principle is very simple:
- Import the ".py" file into the WINDEV project.
- In the WLanguage code:
- Load the Python DLL.
- Call Python functions.
Importing the ".py" file
Importing the ".py" file into the environment allows for the automatic recognition of all the functions of the ".py" script. Each function in the script is then considered as a WLanguage native function.
To import the ".py" file:
- Set up a Python interpreter. This interpreter will read the information contained in the ".py" file.
- On the "Home" tab, in the "Environment" group, expand "Options" and select "General options of WINDEV/WEBDEV".
- Go to the "Directories" tab and enter the path of the interpreter (python*.dll file) in "Python interpreter".
Remark: This Python version can be different from the version used at runtime. However, it must be compatible with Python 3.9, the reference Python ABI used in WINDEV and WEBDEV. The Python interpreter must be the same architecture as WINDEV or WEBDEV (32 or 64-bit).
- Validate the configuration window.
- Import the ".py" files via the "Project explorer" pane using one of the following methods:
- Open the context menu of "External descriptions" and select "Import a Python module into this project". Select the file that corresponds to the module and validate.
Remark: You can import all the Python modules from a given directory via "Import all Python modules from a directory into this project".
- Open the context menu of "Other" and select "Add elements". Select the file that corresponds to the module and validate.
- Drag the ".py" file from the Windows explorer and drop it onto the "Project explorer" pane.
- The Python file is in the project folder, and the module (with its functions) will appear in the "Project explorer" pane, in the "External descriptions" folder.
Remark: When developing the application, it is also necessary to indicate the path of the Python libraries used in the current project configuration:
- On the "Project" tab, in the "Project configuration" group, click "Current configuration".
- In the "Components" tab, specify the external Python libraries.
Using Python functions in WLanguage code
To use Python functions in WLanguage code:
- Initialize the Python engine using PythonInitialize. This function defines the Python interpreter used for the execution. You can use an interpreter different from the one used for the import, but it must be compatible with Python ABI 3.9.
- Enter the name of the Python function to execute, with its parameters if necessary.
Caution: not all types can be passed as parameters. The default values of the parameters are not taken into account. Parameters are passed by value only. In addition, only the following types can be used to pass parameters, and for the return value:
- Integer (signed or unsigned),
- Character string.
- The ".py" modules must be accessible on disk, in the folder of the deployed executable, or in the location specified with PythonAddPath. The ".py" modules cannot be found if they are embedded in the executable library.
- Python is case-sensitive. The module and function names must be written using correct upper and lower case characters.
This page is also available for…