Scripting hooks¶
About scripting hooks¶
The scripting hooks are functions that can be added to a widget/view definition. In this way they can be used to extend /customize the behavior of the widget/view. In principle, the hook is called when certain event occurs in the application and before the corresponding action is executed. It is possible to cancel the relevant action by returning false from a hook, for example when a condition is not met.
The list of available scripting hooks and their description¶
onDeleteRows¶
This scripting hook is available for views. The event is called when ‘delete row’ action is invoked. If the scripts associated with this event signal that they have handled the event the actions would stop there. If there is no script or the script decides not to consume the event the actions would proceed with their default behavior.
An example of the onDeleteRows scripting hook use is shown below.
beforeInsertWindow¶
The scripting hook is called before the “New Row” dialog is invoked. It can be used for instance to validate whether certain user can insert rows at all. The following sample script asks user a password. If it is correctly entered, the “New Row” dialog is rendered. Otherwise, the hook is not consumed and nothing happens.
beforeInsert¶
This scripting hook is available for views. The event is called when new row is inserted. It means all the options about inserting new row are filled, the user clicks ‘OK’ and the action is invoked. We can for instance state some condition on substructure, formula or IUPAC name. The hook was formerly called onInsertRows
An example of the beforeInsert scripting hook use is shown below. The script uses demo project and is run under “Pubchem grid view”. It allows the user to insert new row if and only if the DB Name field is “MOLI”. Otherwise the action is not invoked and the row is not inserted.
afterInsert¶
The script is invoked once new row is inserted. The following example fills two additional fields, username and textDate with the name of the user logged in and the date. It allows to track which user and when inserts some molecule.
onDoubleClick¶
This scripting hook is available for widgets. It is the first event which is called when double-clicking a widget and it is common to all scriptable form widgets. This event is available to all user roles.
An example of the implementation of onDoubleClick hook can be found below.
beforeEdit¶
This scripting hook is available for widgets. When the user starts to edit the data in any way (Edit option in right click menu, F2 shortcut or double-clicking), the beforeEdit event is triggered. It can be used to run a script before editing a value in text field widget and e.g. control the editability of fields more precisely than just by using user roles.
An example of the use of beforeEdit hook can be found below.
afterEdit¶
This scripting hook is available for widgets. When the user finishes editing the data in a widget, the afterEdit event is called. It allows to run the script after editing, but yet before storing the value in the text field. This option can be used for example for normalization, auditing etc.
An example of the use of afterEdit hook can be found below.
The overview of scripting hooks and their availability for widgets¶
| Scripting hooks - summary | |
|---|---|
| **Containers ** | |
| Panel | no support |
| Tabbed Pane | no support |
| **Widgets ** | |
| Single line text field | onDoubleClick, beforeEdit, afterEdit |
| Multi line text field | onDoubleClick, beforeEdit, afterEdit |
| Molecule pane | onDoubleClick, beforeEdit, afterEdit |
| Check box (for boolean fields) | onDoubleClick, beforeEdit, afterEdit |
| Date pane (for date fields) | onDoubleClick, beforeEdit, afterEdit |
| Label | no support |
| Button | no support |
| Browser pane | no support |
| List (for list fields) | onDoubleClick, beforeEdit, afterEdit |
| **Tables ** | |
| Table | onDoubleClick, beforeEdit, afterEdit |
| Sheet | onDoubleClick, beforeEdit, afterEdit |
| Molecules matrix | onDoubleClick, beforeEdit, afterEdit |
| Tree table (experimental) | no support |
| **Charts ** | |
| Box plot | no support |
| Histogram | no support |
| Radar chart | no support |
| Scatter plot | no support |
Known issue
In the case of table widgets that utilize an external editor of values ( e.g. molecules matrix that uses Marvin Sketch), the afterEdit event is called when the editor opens and not when the new data is going to be inserted.