Aegisub/automation/demos/5-configuration.lua

97 lines
4.1 KiB
Lua
Raw Normal View History

2006-01-16 22:02:54 +01:00
-- Aegisub Automation demonstration script
-- Original written by Niels Martin Hansen
-- Given into the public domain
name = "Configuration demo"
description = "This script allows the user to input some data in the Aegisub Export window. Some of these data are used during the processing, to change the subtitles. (The strings is prepended every dialogue line.)"
version, kind = 3, 'basic_ass'
-- The configuration table defines a number of controls to show in the config window
-- The controls must be numbered from 1 and up with no "holes", the number of controls is automatically detected
2006-01-16 22:02:54 +01:00
configuration = {
[1] = {
-- There are some mandatory fields for evry control defined
-- 'name' is the internal name of the control, it's used to refer to the value the user entered later on
2006-01-16 22:02:54 +01:00
name = "thelabel";
-- 'kind' is the class of control, this is a label which only displays text and can't be edited
2006-01-16 22:02:54 +01:00
kind = "label";
-- 'label' is a short description of the control, displayed ot the left of it.
-- In the case of a label control, it's the entire text displayed
2006-01-16 22:02:54 +01:00
label = "This is a label control. Just for shows.";
-- 'hint' is a tooltip for the control. It doesn't actually work for label controls though
2006-01-16 22:02:54 +01:00
hint = "Tooltip for label?!?";
};
[2] = {
name = "thestring";
-- the "text" class is a regular text input field
2006-01-16 22:02:54 +01:00
kind = "text";
label = "String:";
hint = "The string to insert at the beginning of each line";
-- The 'default' is required for everything but 'label' controls, it simply specifies the default value
2006-01-16 22:02:54 +01:00
default = "foobar "
};
[3] = {
name = "theint";
-- 'int' is a text control that only allows inputting whole numbers (integers)
2006-01-16 22:02:54 +01:00
kind = "int";
label = "Integer:";
hint = "An integer number to display in debug output";
default = 50;
-- If the 'min' and 'max' fields are specified, the control will get a "spin control" attached,
-- which can be used to change the value with the mouse
2006-01-16 22:02:54 +01:00
min = 0;
max = 100;
};
[4] = {
name = "thefloat";
-- 'float' is like int, except you can also put decimal numbers in it
2006-01-16 22:02:54 +01:00
kind = "float";
label = "Float number:";
hint = "Just a random float number";
default = 3.1415927;
-- There are no working spin controls for floats, unfortunately
2006-01-16 22:02:54 +01:00
};
[5] = {
name = "thebool";
-- 'bool' makes a checkbox, which can either be checked or unchecked
2006-01-16 22:02:54 +01:00
kind = "bool";
label = "I accept";
hint = "Check if you accept the terms of the license agreement";
-- false means unchecked, true means checked
2006-01-16 22:02:54 +01:00
default = false;
};
[6] = {
name = "thecolour";
-- 'colour' is currently just a text edit box which allows you to input an ASS format color
-- The idea was to have some kind of graphical control, but that probably won't happen in auto3
2006-01-16 22:02:54 +01:00
kind = "colour";
label = "Favourite color:";
hint = "What color do you want your pantsu?";
default = "&H8080FF";
};
[7] = {
name = "thestyle";
-- 'style' produces a drop down list, where the user can select one of the styles in the file, or no style at all
2006-01-16 22:02:54 +01:00
kind = "style";
label = "Style:";
hint = "Pick a style the effects will apply to, or none to apply to everything";
-- An empty string means that nothing is selected
-- Be careful about assuming any style names that might be available in the subtitle file
2006-01-16 22:02:54 +01:00
default = "";
}
}
function process_lines(meta, styles, lines, config)
-- All the values selected by the user are stored in the 'config' variable
-- For example, control 2 in this example has name "thestring", so you can access the value input by config.thestring
2006-01-16 22:02:54 +01:00
aegisub.output_debug("The string entered is: " .. config.thestring)
for i = 0, lines.n-1 do
aegisub.report_progress(i/lines.n*100)
if lines[i].kind == "dialogue" then
-- So loop over all dialogue lines and append thestring to them all
2006-01-16 22:02:54 +01:00
lines[i].text = config.thestring .. lines[i].text
end
end
return lines
end