CTemplates - Template Management

From STX Wiki
Jump to navigationJump to search
File: Classes.STX, linked to library STX.LIB
Parent class: CObj

A class to manage templates. In STx templates are used to define attributes for specific data types. The most important data type using a template is ASeg, this is type of elements storing audio segment definitions. Templates of type ASegTemplate are used to define additional segment attributes for a specific application. Templates are also used to define the content variables and the layout of dialogs managed by the class ModalDialog. The available templates are stored as xml-files in the subdirectory templates of the STx installation directory. To install it is only necessary to copy the xml-file containing the definitions into this directory. The template name (id) is the name of the xml-file and the type is the tag of the root element of the file (see section Example).


Create Instance

Usage
ctemplates [ type ]
cobj new ctemplates [ type ]
type
selects the type of templates to be managed (default: ASegTemplate)
Result
an initialized instance

Delete Instance

Usage
instance destroy
Result
none (void)

GetTable

Usage
instance gettable
Result
an extended table containing the id's of the available templates of the selected type (one per entry, field id)

GetList

Usage
instance getlist
Result
a semi-colon separated list of the id's of the available templates of the selected type

GetAttributeList

Usage
instance getattributelist id
id
the id of the template
Result
an blank separated list of attributes defined in the selected template

GetValueListForAttribute

Usage
instance getvaluelistforattribute type ; id ; attr
type
selects type of result
table: return a simple table containing on value per line; the default value is stored in the first line
list: return a blank separated list of values
id
the id of the template
attr
the name of the attribute
Result
an blank separated list of defined values or a simple table containing one value per line (see argument type)

GetDefaultValueForAttribute

Usage
instance getdefaultvalueforattribute id ; attr
id
the id of the template
attr
the name of the attribute
Result
the default value

GetFlags

Usage
instance getflags id ; attr
id
the id of the template
attr
the name of the attribute
Result
get the dialog flags defined for the attribute

CheckFlag

Usage
instance checkflag id ; attr ; flag
id
the id of the template
attr
the name of the attribute
flag
the flag to be tested
Result
1 if the flag is set, 0 otherwise

Manage

Usage
instance manage
Result
none (void)
Description
Display the template management dialog. This dialog implements functions to view, edit (using a text editor), rename and delete templates.

GetVars

Usage
instance getvars id
id
the id of the template
Result
An extended table contains all definitions of all variables of the selected template. The returns table has the string fields Type, Name, Default, Values and Flags.

Example

This is an example of a template file. This example contains the defintions of the default audio segment template (id: DefaultASegTemplate, type: ASegTemplate).

<?xml version="1.0" encoding="UTF-8"?>
<!--

	Templates
	=========

	(1) Each xml-file in the template directory contains one template. The template type is the defined
		by the root element tag of the xml-file. The name of the template is the name of the xml-file
		without the extension.
		
			<DialogTemplate>		general dialog templates
			<ASegTemplate>			segment attributes dialog template (used by Viewer1/2 and segment Edit dialoges)
			<attrTemplate>			set attributes dialog template

	(2)	The element inside the xml-file defines the properties of the template. Currently following elements are
		defined:

			<Control    Type="controltype" Name="variablename" Text="controlcaption" Window="row col width height"
						Default="defaultvalue" Values="value1 value2 ..." Flags="controloptions"/>
				...

				controltype     Static, CheckBox, Edit, ComboBox
				variablename    Name of variable bound to the control. For segment-dialogs (ASeg) this name is
								also used as segment attribute name. This attribute is not used for controls of
								type Static and is required for all other control types.
				controlcaption  Caption of the control. If not specified, no caption is displayed.
				row, col        Position of upper left corner.
				width, height   Width and height of control.
				defaultvalue    Default value for the control variable.
								CheckBox        0 or 1
								Edit            any text
								ComboBox        a value from the valuelist
				valueX          list of choices for controls of type ComboBox
				controloptions  List of options to configure the control.
								Static      /L|/R|/C        align text left|right|centered
								Edit        /I|/N           input must be an integer (/I) or float (/N) number
											/L|/R|/A        show caption on left|right (/L|/R) side or above (/A)
											/M              multi-line edit box
						        		    /U				if editable in an editable table, use the most recently
						        							entered value as a default
								ComboBox    /L|/R|/A        show caption on left|right (/L|/R) side or above (/A)
						        		    /E				combobox is editable
						        		    /U				if editable in an editable table, use the most recently
						        							entered value as a default
								all types:  /W=xywh         Controls the change of x/y-pos and width/height of the
															control if the dialog window is resized.
															*       no change
															a       automatic
															h       half
															f       full
															e.g.: /W=**f*   only the width is changed (full)


-->
<ASegTemplate>
	<Control Type="Static" Text="Type" Window="0  0  4 1" Flags="/R"/>
	<Control Type="ComboBox" Name="Type" Window="0  4  9 1" Flags="/E/U" Default="uncl" Values="uttr phon word syll uncl"/>
	<Control Type="Static" Text="Speaker" Window="1  0  7 1" Flags="/R"/>
	<Control Type="ComboBox" Name="Spk" Window="1  7  6 1" Flags="/E/U" Default="f1" Values="m1 m2 m3 f1 f2 f3 uncl"/>
	<Control Type="Static" Text="Anonymize" Window="2  0  7 1" Flags="/R"/>
	<Control Type="ComboBox" Name="Anonymize" Window="2  7  6 1" Flags="/E/U" Default="no" Values="no yes"/>
	<Control Type="Static" Text="TR1" Window="2 13  3 1" Flags="/R"/>
	<Control Type="Edit" Name="TR1" Window="2 16 37 3" Flags="/M/W=**ff" Font="Userfont"/>
	<Control Type="Static" Text="TR2" Window="1 13  3 1" Flags="/R"/>
	<Control Type="Edit" Name="TR2" Window="1 16 37 1" Flags="/W=**f*" Font="Userfont"/>
	<Control Type="Static" Text="TR3" Window="0 13  3 1" Flags="/R"/>
	<Control Type="Edit" Name="TR3" Window="0 16 37 1" Flags="/W=**f*" Font="Userfont"/>
</ASegTemplate>

Navigation menu

Personal tools