Code cell masks
Working with code cell masks is also discussed in detail in the example Masking code cells of interactive scripts. |
Interactive controls are often used for more convenient parameterization and visual representation of code. They can be various data input fields, lists, sliders, etc. In Engee such elements are implemented in script editor using code cell masks.
The Code Cell Mask is a tool that turns variables in code cells of Engee scripts into interactive controls. Masking allows you to completely hide the code of the cells while keeping them fully functional.
Creating a code cell mask
To create a code cell mask, hover over a code cell and select Mask and Add field in the tools:
Adding a field will open an interactive menu. Depending on the field type, the add menu changes its options (the available variable types change and/or additional settings appear). A total of four types are available:
-
Select (dropdown) is a dropdown list of options with a single option selection. When you click on the dropdown list, you are given the option you want to select.
Drop-down list example
Create an empty code cell and add a drop-down list mask with the following settings:
After saving, the code cell will change its appearance:
The contents of the code cell will fill in the following code:
dropdown_variable = "1" # @param ["1","2","3"] {allow-input:true}
By modifying this code you can change the contents of the mask without accessing the tool Mask
.
-
Input (input) is a window for entering data.
Example of input field
Create an empty code cell and add an input field mask with the following settings:
Here playholder is the text that is displayed inside the input field until any data is entered. It is usually used to give a hint as to what information needs to be entered. For example, for a date field,
Enter the date in the format YYYYY-MM-DD
would work fine.We get the following option:
The contents of the code cell will fill the following code:
date_of_birth = "2025-01-16" # @param {type:"date",placeholder:"Введите дату в формате ГГГГ-ММ-ДД"}
Based on the name of the variable, we need the date of birth, not today’s date (set automatically by the system), so let’s change the date to the correct one. You can change the date both in the mask and in the code cell itself, just by setting the correct date instead of the specified
"2025-01-16"
.By removing the mask date, you can see that the placeholder works correctly and improves the user experience:
-
Markdown - is a Markdown markup representation for implementing code masks.
Example Markdown
Create an empty code cell and add a Markdown mask with the following settings:
# Построение синусойды Для построения простой синусойды используйте следующие блоки: |Блоки в модели|Описание| | --------- | -------- | |[Sine wave](https://engee.com/helpcenter/stable/ru/base-lib-sources/sine-wave.html)|Генератор синусоидального сигнала.| |[Terminator](https://engee.com/helpcenter/stable/ru/base-lib-sinks/terminator.html)|Заглушка выходного порта.|
We get the following variant:
The contents of the code cell will fill the following code:
# @markdown # Построение синусойды # @markdown # @markdown Для построения простой синуосойды используйте следующие блоки: # @markdown # @markdown |Блоки в модели|Описание| # @markdown | --------- | -------- | # @markdown |[Sine wave](https://engee.com/helpcenter/stable/ru/base-lib-sources/sine-wave.html)|Генератор синусоидального сигнала.| # @markdown |[Terminator](https://engee.com/helpcenter/stable/ru/base-lib-sinks/terminator.html)|Заглушка выходного порта.|
-
Slider (slider) is a representation of a slider with selection of values from a specified range. Selection of a value from the range is realised by moving the slider along the scale.
Slider example
Create an empty code cell and add a slider mask with the following settings:
Get the following option:
The contents of the code cell will fill the following code:
уровень_громкости = 0 # @param {type:"slider",min:0,max:100,step:1}
To edit a superimposed mask, move the mouse cursor over it and click the icon . Since the code of masked cells is fully working - you can edit not only the mask, but also the cell code.
To add a new field, hide the code or hide the mask again use the context menu of the mask :
Creating masks without the editor interface
This section describes some features of masked cells syntax that may be useful in your practice. It is recommended to read this section even if you do not plan to create masks manually. |
In some cases, it may be more convenient to create a mask without resorting to the mask creation context menu , so let’s look at this process in more detail.
To create masks manually, you need to recreate the syntax yourself, consisting of:
-
The name of the control. Some of the elements have their own parameters to configure the behaviour..;
-
A
#
comment and parameters starting with@
.
The code cell mask controls are already described above, there are four of them in total. Each element has its own approach for manual creation. Let’s consider examples for each of them:
Description of dropdown list types and subtypes
|
Description of input window typesYou can use different types of input fields to collect information, and each type is suitable for a particular kind of data.
|
Description of slider types
|
Description of markdown featuresThe
|