Up | Editing scripts | Script Details | RS232 | TCP/IP | System | Scheduler | HistoryList | ImageView

 

  

 
Script Details
Event handlers

All events exported from the contained ActiveX controls, and most events from the built-in components, get a wrapper function defined in Python with the (Handle_) name defined in the Scripts page. Normally you will not call these scripts yourself (they are really event handlers), but you are of course free to do so. Parameters are typed, but everything is converted to strings before the function is called. Even so, things work mostly as expected – for example, you can do maths on numeric variables without converting anything.

The built-in components also raise events and have callable functions; these are slightly different and in some cases more powerful – see the description below.


ActiveX Dispatch Functions

Each exported function from an ActiveX control is also wrapped in a Python function. The real name of such a function is for example Calendar_SetYear, but for convenience, an alias name of Calendar.SetYear is also made. To access any of these from a Python script, simply follow this convention:
  • The page name is converted to a python class (case sensitive in Python)
  • The function name is unaltered (but also case sensitive in Python)
  • The function name is therefore Page.Function

All parameters are sent as a long string with Name=Value;…


Example 1: Setting an ActiveX property Calender.Month

  • Calendar.SetMonth(“Value=6”)

This Python call is transformed to a call to the Delphi callback Central.Execute. It should be of little importance here, but you can also call that method directly yourself. This function should be given a single parameter, specifying a TDVCmdProtocol string. To do the same as above, you may call:

  • ExecuteCmd("Script",“Calendar.SetMonth;Value=6”)

The return value from such a call is a TDVCmdProtocol formatted string. The examples above would both result in this string returned to your Python function:

  • Calendar.SetMonthResponse;Value=6;Result=OK


Example 2: Getting the ActiveX property Calender.Month

  • Calendar.GetMonth()

returns this

  • Calendar.GetMonthResponse;Result=6


General scripts


You can generate generic scripts from the Scripts page by pressing New.

A new script skeleton is generated,

The script does nothing by default, but is syntactically legal: 

You can add parameters to this function, for example:

Remember that you have access to all the other generated scripts, including event handlers and control functions, and any global variables you may have defined, e.g., in the Start script (below). Upon Applying this script, it is also available to any other scripts you have.

Note: All scripts generated this way should just be “def” statements – that way, the model works very well. There is nothing stopping you from writing any Python code, defining methods and classes in these scripts.

  • Apply or Close - the contents of the editor are simply executed by the Python engine, notifying you of any syntax (or exec) errors.
  • Run  - the script source is inspected, and if the “def” line has any parameters, you will be prompted to supply them before the function is actually executed.

    All the scripts defined this way are also available from TDVCmdProtocol using the special “Page” name Script. For example, you may call the script defined above by sending this string to TDVCentral2:
  • Script.Double(100)

Note: This is the only place the TDVCmdProtocol commands are case sensitive. You may not call

  • Script.double(100)

although

  • script.Double(100)

is quite OK.

Note also: The string sent here does not conform to the TDVCmdProtocol. You can not enter parameters following a semicolon.


Central Start

The System defined Central Start script is run when Scorpion is started.

The Central Start script is defined in a global scope - this means that global variables are defined and system parameters are initialised. When the startup script is run, all control pages have been initiated, so all functions (like Calendar.SetMonth) are available.


Central Stop

The System defined Central Stop script is run when Scorpion is terminated.

Note: Central Start and Stop are special. They are NOT run when the editor’s Apply or Close buttons are pressed.

Example 3: Restart Central from Python

ExecuteCmd('Script','Central Stop')
ExecuteCmd('Script','Central Start')


Script executed errors


During runtime, if a Python error occurs when a script is run, two things may happen depending on your settings. First, the Python error log may pop up; second, an editor may pop up showing the point of error in your script(s). Again, we have done as much as we could to decode the Python messages, and if you follow the conventions with scripts, the correct script should show up in the editor with the error, even in a nested Python function call. No guarantees, though…

 

Scorpion Vision Version XII : Build 646 - Date: 20170225
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.