~ubuntu-branches/ubuntu/trusty/aegisub/trusty

« back to all changes in this revision

Viewing changes to automation/v4-docs/perl-api.txt

  • Committer: Package Import Robot
  • Author(s): Sebastian Reichel
  • Date: 2012-03-16 22:58:00 UTC
  • Revision ID: package-import@ubuntu.com-20120316225800-yfb8h9e5n04rk46a
Tags: upstream-2.1.9
ImportĀ upstreamĀ versionĀ 2.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
------------------------------------
 
2
Quick reference on Perl engine's API
 
3
------------------------------------
 
4
 
 
5
All the packages that form the perl interface to Aegisub are automatically
 
6
loaded, however none of their symbols are exported initially. If you want to
 
7
import them you can use the usual 'use' mechanism; if you call it without a
 
8
list of imports it will import more or less everything in your script's
 
9
package. Wether they are exported or not is indicated in the following
 
10
reference by <--EXPORTED--> (exported by default within a plain 'use'
 
11
statement) and <--EXPORTABLE--> (can be imported specifying them explicitely in
 
12
the 'use' statement) tags. Finally, <--NOT EXPORTABLE--> indicates symbols that
 
13
can't be exported through 'use'.
 
14
 
 
15
 
 
16
====================================
 
17
package Aegisub
 
18
 
 
19
------------------------------------
 
20
Constants defined:
 
21
                               <--EXPORTABLE-->
 
22
 
 
23
LOG_FATAL       ==  0
 
24
LOG_ERROR       ==  1
 
25
LOG_WARNING     ==  2
 
26
LOG_HINT        ==  3
 
27
LOG_DEBUG       ==  4
 
28
LOG_TRACE       ==  5
 
29
LOG_MESSAGE     ==      6
 
30
        Log levels, to be used with the 'log' function.
 
31
 
 
32
LOG_WX  ==      8
 
33
        Flag to force logging through wxWidgets facilites.
 
34
 
 
35
------------------------------------
 
36
Subroutines defined:
 
37
                                <--EXPORTED-->
 
38
 
 
39
text_extents STYLE, TEXT
 
40
        Computes the metric for a string of text, based on a specific style.
 
41
        Arguments:
 
42
                STYLE   The style to use, as a string or ref to a style line.
 
43
                TEXT    Text for which to compute the metrics.
 
44
        Returns:
 
45
                WIDTH   The width of the text (if called in scalar context, only this is returned).
 
46
                ASCENT          The ascent, i.e. the distance from the baseline to the top of the letters.
 
47
                DESCENT         Descent, i.e. the distance from the baseline to the bottom.
 
48
                EXTLEADING      External leading, i.e. the distance between to lines of text.
 
49
 
 
50
log_fatal LIST
 
51
 ...
 
52
log_message LIST
 
53
        These are shortcuts for 'log(LOG_FATAL, LIST)' to 'log(LOG_MESSAGE, LIST)'
 
54
        (see below).
 
55
 
 
56
                               <--EXPORTABLE-->
 
57
 
 
58
log LEVEL, LIST
 
59
log LIST
 
60
        Prints a log message inside the progress window, if LEVEL is less or equal
 
61
        to the tracelevel set inside automation options. If called from outside a
 
62
        callback (i.e. during script loading) prints through the wxWidgets logging
 
63
        mechanism. 'log(LIST)' is equal to 'log(Aegisub::LOG_MESSAGE, LIST)'. The
 
64
        short form is used whenever there are at least two arguments and the first
 
65
        one cannot be read as an integer; it is always used when given only one
 
66
        argument.  This function is not exported by default (review man perlfunc to
 
67
        understand why :).
 
68
 
 
69
        Arguments:
 
70
        LEVEL   The debug level, may be one of the following (the descriptions are
 
71
                indicative):
 
72
                 0      Fatal error, for vital errors;
 
73
                 1      Error, for serious but not too much threatening errors;
 
74
                 2      Warning, for something that's apparently going wrong;
 
75
                 3      Hint, for indicating something peculiar is happening;
 
76
                 4      Debug, for debugging!
 
77
                 5      Trace, for really verbose debugging;
 
78
                 6      Message, always printed.
 
79
                If you OR one of these values with the flag LOG_WX the log message will
 
80
                be delivered though wxWidgets regardless of wether there is a progress
 
81
                window displayed (you won't normally need this feature, though).
 
82
        LIST    List of arguments to print.
 
83
 
 
84
warn LIST
 
85
        Prints a warning through the GUI log facilities (it is equivalent to
 
86
        'log(Aegisub::LOG_WARNING, LIST)'). It is automatically hooked to the
 
87
        global 'warn' function during script execution, thus it is not exported by
 
88
        default.
 
89
        Arguments:
 
90
                LIST    List of arguments to print.
 
91
 
 
92
                             <--NOT EXPORTABLE-->
 
93
 
 
94
wxlog LEVEL, LIST
 
95
wxlog LIST
 
96
        Similar to 'log', but with the LOG_WX flag implicitely set. This function
 
97
        is top-secret.
 
98
 
 
99
 
 
100
====================================
 
101
package Aegisub::PerlConsole
 
102
------------------------------------
 
103
This package contains the perl console, a debug tool not intended for normal
 
104
use by normal users (it's not even enabled in release builds). They are shown
 
105
here for completeness.
 
106
 
 
107
------------------------------------
 
108
Subroutines defined:
 
109
                                <--EXPORTED-->
 
110
 
 
111
echo LIST
 
112
        Prints a list of arguments on the console, or on STDOUT if no console is
 
113
        registered, a trailing \n is printed too.
 
114
        Arguments:
 
115
        LIST    List of arguments to print.
 
116
 
 
117
register_console NAME, DESC
 
118
        Registers an instance of the console, as a macro. You don't want to know
 
119
        any more because in fact you'll never have to do with this. >:)
 
120
        Arguments:
 
121
        NAME    Set the name for the macro. (optional)
 
122
        DESC    Set the macro's description. (optional)
 
123
 
 
124
 
 
125
====================================
 
126
package Aegisub::Progress
 
127
------------------------------------
 
128
This package provides an interface to the progress window automatically showed
 
129
during the execution of a feature. Its functions are somewhat different to
 
130
those available in lua because of clarity, however aliases are given.
 
131
 
 
132
------------------------------------
 
133
Subroutines defined:
 
134
                                <--EXPORTED-->
 
135
 
 
136
set_progress VALUE
 
137
        Sets the value of the progress bar. It accepts values comprised in [0, 1]
 
138
        OR (1, 100] (for instance, a value of 0.86 is equivalent to a value of 86:
 
139
        they both represent '86%'). You should really always use values in the
 
140
        range [0, 1] if you don't wanna be mocked by your friends and relatives
 
141
        (and normally they're more immediately computable).
 
142
        Arguments:
 
143
                VALUE   The value for the progress bar.
 
144
 
 
145
set_task DESC
 
146
        Sets the description for the current task inside progress window (just
 
147
        below the progress bar).
 
148
        Arguments:
 
149
                DESC    The description for the current task.
 
150
 
 
151
set_title TITLE
 
152
        Sets the title for the progress window (which is not actually the window's
 
153
        title, but a flashier label below it). The default title is 'Executing ...'
 
154
        (with the ellpsis possibly replaced by the feature's name).
 
155
        Arguments:
 
156
                TITLE   The title to set.
 
157
 
 
158
is_cancelled
 
159
        Returns: A boolean indicating wether the cancel button on the progress
 
160
                window where pressed in the near past.
 
161
 
 
162
                               <--EXPORTABLE-->
 
163
 
 
164
set VALUE
 
165
        Synonym for 'set_progress(VALUE)'.
 
166
 
 
167
task DESC
 
168
        Synonym for 'set_desc(DESC)',
 
169
 
 
170
title TITLE
 
171
        Synonym for 'set_title(TITLE)'.
 
172
 
 
173
 
 
174
====================================
 
175
package Aegisub::Script
 
176
 
 
177
------------------------------------
 
178
Subroutines defined:
 
179
                                <--EXPORTED-->
 
180
 
 
181
register_macro NAME, DESC, PROC_SUB, VAL_SUB
 
182
        Register a new macro.
 
183
        Arguments:
 
184
        NAME    The name of the macro.
 
185
        DESC    A description for the macro.
 
186
        PROC_SUB        A ref to a subroutine to be used as the macro processing function
 
187
                (see the callbacks section). Please, really use a reference and not
 
188
                just the name of the sub, because of the script 'pacakging' described
 
189
                below.
 
190
        VAL_SUB A ref to a subroutine to be used as the macro validation function
 
191
                (see callbacks)(optional, if not defined will be considered as always true).
 
192
 
 
193
set_info NAME, DESC, AUTHOR, VERSION
 
194
        You can set all of the script's info values with a call to this
 
195
        function. (Otherwise you can set the corresponding predefined script
 
196
        variables individually.)
 
197
        Arguments: see the parts about script variables, anything is optional.
 
198
 
 
199
 
 
200
====================================
 
201
package Aegisub::Script::pxxxxxxxx
 
202
------------------------------------
 
203
Every script that's loaded gets its code evaluated inside a different package -
 
204
whose name is chosen at 'random' - whereas the perl interpreter is unique, so
 
205
all the scripts see the same global package, and can possibly access other
 
206
scripts' packages. Therefore is recommended to ALWAYS declare all of the
 
207
script's local variables with 'my', and of course to 'use strict' to check on
 
208
this. You can still declare another package for your script; the script's
 
209
predefined variables should be still visible from it without any change in the
 
210
code (they're declared as 'our'), however this is discouraged.
 
211
 
 
212
------------------------------------
 
213
Variables defined:
 
214
 
 
215
$script_author
 
216
        Holds the script author's name. Default is the user executing aegisub.
 
217
 
 
218
$script_description
 
219
        Holds a description for the script. Default is 'Perl script'.
 
220
 
 
221
$script_name
 
222
        Holds the script's name. Default is the script's filename.
 
223
 
 
224
$script_version
 
225
        Holds the script's version. Default is current aegisub version.
 
226
 
 
227
$_script_path
 
228
        The full path to the script's file. Any change to this variable is ignored
 
229
        and overwritten.
 
230
 
 
231
$_script_package
 
232
        The full script package as a string. Any change to this variable is
 
233
        currently ignored and overwritten, and may be so forever.
 
234
 
 
235
 
 
236
------------------------------------
 
237
Callbacks definable:
 
238
 
 
239
macro_processing_function LINES, SELECTED, ACTIVE
 
240
        A function to be used as a callback for Aegisub::Script::register_macro().
 
241
        This function will be called when the user selects the corresponding macro
 
242
        in the Automation menu. The first two arguments can be modified, and the
 
243
        modifications will be reflected in the subtitles file.
 
244
        Arguments:
 
245
        LINES   A reference to the list containing the subtitle file lines.
 
246
                Each element of the list is a reference to a hash that represents a
 
247
                single subtitle line. For the hash keys refer to lua documentation,
 
248
                they are basically the same.
 
249
                Example:
 
250
 
 
251
                        my $lines = $_[0]; # DON'T shift @_ (unless you reconstruct it
 
252
                                           # afterwards) or you'll break everything and
 
253
                                   # your hard disk be erased >:)
 
254
                        # The first selected line's index
 
255
                        my $first = $_[1][0];
 
256
                        # An entire line
 
257
                        my $l = $lines->[$first];
 
258
                        # The text field of a dialogue line
 
259
                        my $text = $lines->[$first]->{"text"};
 
260
 
 
261
        SELECTED        A ref to an array of ints, showing the currently selected
 
262
                lines in the file.
 
263
        ACTIVE  Index of the currently active line in the subtitle file (sic).
 
264
 
 
265
macro_validation_function LINES, SELECTED, ACTIVE
 
266
        A function to be used as a callback for Aegisub::Script::register_macro().
 
267
        This function will be called whenever the Automation menu is opened to
 
268
        decide what macros are applicable to the current script.
 
269
        Arguments: same as macro_processing_function; however any change to the
 
270
                first two ones will be ignored upon function return.
 
271
        Returns:
 
272
        VALID   A 'boolean' value to indicate if the macro is applicable to this
 
273
                particular subtitles file.