Debian Codegraph @

flowblade-trunk/Flowblade/res/help/fluxity.html

raw
1 <!doctype html>
2 <html lang="en">
3 <head>
4 <meta charset="utf-8">
5 <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
6 <meta name="generator" content="pdoc 0.10.0" />
7 <title>fluxity API documentation</title>
8 <meta name="description" content="GPL Licence text …" />
9 <link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
10 <link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
11 <link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
12 <style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
13 <style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
14 <style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
15 <script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
16 <script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
17 </head>
18 <body>
19 <main>
20 <article id="content">
21 <header>
22 <h1 class="title">Module <code>fluxity</code></h1>
23 </header>
24 <section id="section-intro">
25 <h3 id="gpl-licence-text">GPL Licence text</h3>
26 <p>Flowblade Movie Editor is a nonlinear video editor.
27 Copyright 2021 Janne Liljeblad.</p>
28 <p>This file is part of Flowblade Movie Editor <a href="https://github.com/jliljebl/flowblade/">https://github.com/jliljebl/flowblade/</a>.</p>
29 <p>Flowblade Movie Editor is free software: you can redistribute it and/or modify
30 it under the terms of the GNU General Public License as published by
31 the Free Software Foundation, either version 3 of the License, or
32 (at your option) any later version.</p>
33 <p>Flowblade Movie Editor is distributed in the hope that it will be useful,
34 but WITHOUT ANY WARRANTY; without even the implied warranty of
35 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
36 See the
37 GNU General Public License for more details.</p>
38 <p>You should have received a copy of the GNU General Public License
39 along with Flowblade Movie Editor. If not, see <a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>.</p>
40 <h1 id="fluxity-scripting">FLUXITY SCRIPTING AND API</h1>
41 <p>Fluxity scripting is a <strong>Python scripting solution</strong> created to provide <strong>Flowblade Movie Editor</strong> with a <em>Plugin API</em>.
42 Currently <em>Fluxity API</em>
43 is used by Flowblade <em>Generators</em> feature.</p>
44 <p><em>Fluxity API</em> is made available to scripts mainly by <em>fluxity.FluxityContext</em> object and its methods.
45 This object is created to communicate with the script before calling any of the methods of the script.</p>
46 <p>Some constants mentioned in this source file - such as <code><a title="fluxity.EDITOR_FLOAT" href="#fluxity.EDITOR_FLOAT">EDITOR_FLOAT</a></code> or <code><a title="fluxity.PROFILE_WIDTH" href="#fluxity.PROFILE_WIDTH">PROFILE_WIDTH</a></code> - can also be used by scripts. </p>
47 <p>See below for <em>fluxity.FluxityContext</em> object API details.</p>
48 <h2 id="script-interface">SCRIPT INTERFACE</h2>
49 <p>A Python script needs to have the following functions to load and run without crashing as a Fluxity API conforming script.</p>
50 <pre><code>def init_script(fctx):
51 pass
52
53 def init_render(fctx):
54 pass
55
56 def render_frame(frame, fctx, w, h):
57 pass
58 </code></pre>
59 <h2 id="script-lifecycle">SCRIPT LIFECYCLE</h2>
60 <p><strong><code>init_script(fctx):</code></strong> This method is called when script is first loaded by Flowblade to create data structures with info on editors and script metadata. </p>
61 <p><strong><code>init_render(fctx):</code></strong> This method is called before a render is started to get user input from editors and possibly to create some additional data structures.</p>
62 <p><strong><code>render_frame(frame, fctx, w, h):</code></strong> This method is called for each frame rendered to create an output image for that frame.</p>
63 <p>Object <strong><code>fctx</code></strong> is object of class <strong><code>fluxity.FluxityContext</code></strong>.</p>
64 <h2 id="example-script">EXAMPLE SCRIPT</h2>
65 <h3 id="init_script">init_script()</h3>
66 <pre><code>import cairo
67 import numpy as np
68 import random
69 import math
70
71 import fluxity
72
73 def init_script(fctx):
74 fctx.set_name(&quot;Floating Balls&quot;)
75 fctx.set_version(1)
76 fctx.set_author(&quot;Janne Liljeblad&quot;)
77
78 fctx.add_editor(&quot;Hue&quot;, fluxity.EDITOR_COLOR, (0.8, 0.50, 0.3, 1.0))
79 fctx.add_editor(&quot;Speed&quot;, fluxity.EDITOR_FLOAT_RANGE, (1.0, -5.0, 5.0))
80 fctx.add_editor(&quot;Speed Variation %&quot;, fluxity.EDITOR_INT_RANGE, (40, 0, 99))
81 fctx.add_editor(&quot;Number of Items&quot;, fluxity.EDITOR_INT_RANGE, (50, 10, 500))
82 fctx.add_editor(&quot;Size&quot;, fluxity.EDITOR_INT_RANGE, (330, 10, 800))
83 fctx.add_editor(&quot;Size Variation %&quot;, fluxity.EDITOR_INT_RANGE, (0, 0, 80))
84 fctx.add_editor(&quot;Opacity&quot;, fluxity.EDITOR_INT_RANGE, (100, 5, 100))
85 fctx.add_editor(&quot;Random Seed&quot;, fluxity.EDITOR_INT, 42)
86 </code></pre>
87 <p>In <em>init_script()</em> we define the editors that will be presented to the user and set some metadata like the name of the script displayed to the user and the script author.</p>
88 <p>Object <strong><code>fctx</code></strong> is object of class <strong><code>fluxity.FluxityContext</code></strong>.</p>
89 <h3 id="init_render">init_render()</h3>
90 <pre><code>def init_render(fctx):
91 # The script is possibly rendered using multiple processes and we need to have the
92 # same sequence of random numbers in all processes. If we don't set seed we'll get completely different
93 # ball positions, colors and speeds in different rendering processes.
94 random.seed(fctx.get_editor_value(&quot;Random Seed&quot;))
95
96 # Ball colors data structure
97 hue = fctx.get_editor_value(&quot;Hue&quot;)
98 hr, hg, hb, alpha = hue
99 fctx.set_data_obj(&quot;hue_tuple&quot;, hue)
100 color_array = list(hue)
101 ball_colors = []
102 color_mult = 1.05
103 opacity = float(fctx.get_editor_value(&quot;Opacity&quot;)) / 100.0
104
105 for i in range(0, 10):
106 array = np.array(color_array) * color_mult
107 r, g, b, a = array
108 ball_colors.append(cairo.SolidPattern(_clamp(r), _clamp(g), _clamp(b), opacity))
109 color_array = array
110 fctx.set_data_obj(&quot;ball_colors&quot;, ball_colors)
111
112 # Ball animations data structure
113 ball_data = []
114 number_of_balls = fctx.get_editor_value(&quot;Number of Items&quot;)
115 speed = fctx.get_editor_value(&quot;Speed&quot;)
116 speed_var_size_precentage = fctx.get_editor_value(&quot;Speed Variation %&quot;)
117 speed_var_max = speed * (speed_var_size_precentage / 100.0)
118 size = fctx.get_editor_value(&quot;Size&quot;)
119 size_var_size_precentage = fctx.get_editor_value(&quot;Size Variation %&quot;)
120 size_var_max = size * (size_var_size_precentage / 100.0)
121 size_max = size + size_var_max
122 fctx.set_data_obj(&quot;size_max&quot;, size_max)
123
124 for i in range(0, number_of_balls):
125 path_pos = random.uniform(0.0, 1.0)
126 y = random.randint(-330, 1080 + 330)
127 speed_var = random.uniform(-1.0, 1.0)
128
129 ball_speed = speed + (speed_var * speed_var_max)
130 size_var = random.uniform(-1.0, 1.0)
131 ball_size = size + (size_var * size_var_max)
132 color_index = random.randint(0, 9)
133 ball_data.append((path_pos, y, ball_speed, ball_size, color_index))
134
135 fctx.set_data_obj(&quot;ball_data&quot;, ball_data)
136 </code></pre>
137 <p>In <em>init_render() </em> we read editor values set by the user and create some data structures for moving ball animations based on that data.</p>
138 <p>Also note that <strong>we need to set seed for Pythom module 'random'</strong> because when a frame sequence is rendered using multiple processes we need the exact same sequence of random numbers produced in every process. </p>
139 <p>Object <strong><code>fctx</code></strong> is object of class <strong><code>fluxity.FluxityContext</code></strong>.</p>
140 <h3 id="render_frame">render_frame()</h3>
141 <pre><code>def render_frame(frame, fctx, w, h):
142 cr = fctx.get_frame_cr()
143
144 # Draw bg
145 bg_color = cairo.SolidPattern(*fctx.get_data_obj(&quot;hue_tuple&quot;))
146 ball_colors = fctx.get_data_obj(&quot;ball_colors&quot;)
147 ball_data = fctx.get_data_obj(&quot;ball_data&quot;)
148
149 cr.set_source(bg_color)
150 cr.rectangle(0, 0, w, h)
151 cr.fill()
152
153 # Draw balls
154 number_of_balls = fctx.get_editor_value(&quot;Number of Items&quot;)
155 size_max = fctx.get_data_obj(&quot;size_max&quot;)
156 path_start_x = - size_max
157 path_end_x = w + size_max
158 path_len = path_end_x - path_start_x
159 SPEED_NORM_PER_FRAME = 15.0 / float(w) # Speed value 1.0 gets 15 pixels of movement per frame.
160 for i in range(0, number_of_balls):
161 path_pos, y, ball_speed, ball_size, color_index = ball_data[i]
162 xc = ball_size / 2.0
163 yc = ball_size / 2.0
164 xpos_norm = path_pos + (float(frame) * ball_speed * SPEED_NORM_PER_FRAME)
165 while xpos_norm &gt; 1.0:
166 xpos_norm = xpos_norm - 1.0
167 x = path_start_x + path_len * xpos_norm
168 cr.save()
169 cr.translate(x, y)
170 cr.arc(xc, yc, ball_size / 4.0, 0.0, 2.0 * math.pi)
171 cr.set_source(ball_colors[color_index])
172 cr.fill()
173 cr.restore()
174
175 # ----------------------- helper func
176 def _clamp(v):
177 return max(min(v, 1.0), 0.0)
178
179 </code></pre>
180 <p>In <em>render_frame()</em> we first acquire <em>Cairo.Context</em> object that can be drawn onto to create output for the frame.</p>
181 <p>After that the data structures created in <em>init_render()</em> are accessed and image is drawn.</p>
182 <p>There is a helper function <em>_clamp(v)</em> used to make sure that all color values are in range 0-1. Any number of helper functions, objects and data structures can be created.</p>
183 <h2 id="developing-fluxity-scripts">DEVELOPING FLUXITY SCRIPTS</h2>
184 <p><strong>Flowblade</strong> comes with a simple GUI tool for developing Fluxity scripts. It can be accessed from menu <strong>Tools-&gt;Generator Script Editor</strong>.</p>
185 <p>Using the development tool you can edit scripts, render output from them, and get receive error messages when something goes wrong. From hamburger menu you can open and save your own scripts, access this document, and open and inspect example code of the <em>Generators</em> distributed with Flowblade. </p>
186 <p>Since the text editor in the development tool is quite rudimentary <em>(with a future GTK4 port we may get improvement here)</em>, it can be a useful workflow to use an external text editor to edit the scripts, and press <em>Reload Script</em> button to update text area contents before attempting render.</p>
187 <h1 id="fluxity-api_1">FLUXITY API</h1>
188 <details class="source">
189 <summary>
190 <span>Expand source code</span>
191 </summary>
192 <pre><code class="python">&#34;&#34;&#34;
193 ### GPL Licence text
194
195 Flowblade Movie Editor is a nonlinear video editor.
196 Copyright 2021 Janne Liljeblad.
197
198 This file is part of Flowblade Movie Editor &lt;https://github.com/jliljebl/flowblade/&gt;.
199
200 Flowblade Movie Editor is free software: you can redistribute it and/or modify
201 it under the terms of the GNU General Public License as published by
202 the Free Software Foundation, either version 3 of the License, or
203 (at your option) any later version.
204
205 Flowblade Movie Editor is distributed in the hope that it will be useful,
206 but WITHOUT ANY WARRANTY; without even the implied warranty of
207 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
208 GNU General Public License for more details.
209
210 You should have received a copy of the GNU General Public License
211 along with Flowblade Movie Editor. If not, see &lt;http://www.gnu.org/licenses/&gt;.
212
213
214 # FLUXITY SCRIPTING
215
216 Fluxity scripting is a **Python scripting solution** created to provide **Flowblade Movie Editor** with a *Plugin API*.
217
218 Currently *Fluxity API* is used by Flowblade *Generators* feature.
219
220 ## FLUXITY API
221
222 *Fluxity API* is made available to scripts mainly by *fluxity.FluxityContext* object and its methods.
223
224 This object is created to communicate with the script before calling any of the methods of the script.
225
226 Some constants mentioned in this source file - such as `EDITOR_FLOAT` or `PROFILE_WIDTH` - can also used by scripts.
227
228 See this document below for *fluxity.FluxityContext* object API details.
229
230 ## SCRIPT INTERFACE
231
232 A Python script needs to have the following functions to load and run without crashing as a Fluxity API conforming script.
233
234 ```
235 def init_script(fctx):
236 pass
237
238 def init_render(fctx):
239 pass
240
241 def render_frame(frame, fctx, w, h):
242 pass
243 ```
244
245 ## SCRIPT LIFECYCLE
246
247 **`init_script(fctx):`** This method is called when script is first loaded by Flowblade to create data structures with info on editors and script metadata.
248
249 **`init_render(fctx):`** This method is called before a render is started to get user input from editors and possibly to create some additional data structures.
250
251 **`render_frame(frame, fctx, w, h):`** This method is called for each frame rendered to create an output image for that frame.
252
253
254 ## EXAMPLE SCRIPT
255
256 Here we have an example script called *&#39;Floating Balls&#39;*.
257
258 ### init_script()
259
260 ```
261 import cairo
262 import numpy as np
263 import random
264 import math
265
266 import fluxity
267
268 def init_script(fctx):
269 fctx.set_name(&#34;Floating Balls&#34;)
270 fctx.set_version(1)
271 fctx.set_author(&#34;Janne Liljeblad&#34;)
272
273 fctx.add_editor(&#34;Hue&#34;, fluxity.EDITOR_COLOR, (0.8, 0.50, 0.3, 1.0))
274 fctx.add_editor(&#34;Speed&#34;, fluxity.EDITOR_FLOAT_RANGE, (1.0, -5.0, 5.0))
275 fctx.add_editor(&#34;Speed Variation %&#34;, fluxity.EDITOR_INT_RANGE, (40, 0, 99))
276 fctx.add_editor(&#34;Number of Items&#34;, fluxity.EDITOR_INT_RANGE, (50, 10, 500))
277 fctx.add_editor(&#34;Size&#34;, fluxity.EDITOR_INT_RANGE, (330, 10, 800))
278 fctx.add_editor(&#34;Size Variation %&#34;, fluxity.EDITOR_INT_RANGE, (0, 0, 80))
279 fctx.add_editor(&#34;Opacity&#34;, fluxity.EDITOR_INT_RANGE, (100, 5, 100))
280 fctx.add_editor(&#34;Random Seed&#34;, fluxity.EDITOR_INT, 42)
281 ```
282 In *init_script()* we define the editors that will be presented to the user and set some metadata like the name of the script displayed to the user and the script author.
283
284 ### init_render()
285 ```
286 def init_render(fctx):
287 # The script is possibly rendered using multiple processes and we need to have the
288 # same sequence of random numbers in all processes. If we don&#39;t set seed we&#39;ll get completely different
289 # ball positions, colors and speeds in different rendering processes.
290 random.seed(fctx.get_editor_value(&#34;Random Seed&#34;))
291
292 # Ball colors data structure
293 hue = fctx.get_editor_value(&#34;Hue&#34;)
294 hr, hg, hb, alpha = hue
295 fctx.set_data_obj(&#34;hue_tuple&#34;, hue)
296 color_array = list(hue)
297 ball_colors = []
298 color_mult = 1.05
299 opacity = float(fctx.get_editor_value(&#34;Opacity&#34;)) / 100.0
300
301 for i in range(0, 10):
302 array = np.array(color_array) * color_mult
303 r, g, b, a = array
304 ball_colors.append(cairo.SolidPattern(_clamp(r), _clamp(g), _clamp(b), opacity))
305 color_array = array
306 fctx.set_data_obj(&#34;ball_colors&#34;, ball_colors)
307
308 # Ball animations data structure
309 ball_data = []
310 number_of_balls = fctx.get_editor_value(&#34;Number of Items&#34;)
311 speed = fctx.get_editor_value(&#34;Speed&#34;)
312 speed_var_size_precentage = fctx.get_editor_value(&#34;Speed Variation %&#34;)
313 speed_var_max = speed * (speed_var_size_precentage / 100.0)
314 size = fctx.get_editor_value(&#34;Size&#34;)
315 size_var_size_precentage = fctx.get_editor_value(&#34;Size Variation %&#34;)
316 size_var_max = size * (size_var_size_precentage / 100.0)
317 size_max = size + size_var_max
318 fctx.set_data_obj(&#34;size_max&#34;, size_max)
319
320 for i in range(0, number_of_balls):
321 path_pos = random.uniform(0.0, 1.0)
322 y = random.randint(-330, 1080 + 330)
323 speed_var = random.uniform(-1.0, 1.0)
324
325 ball_speed = speed + (speed_var * speed_var_max)
326 size_var = random.uniform(-1.0, 1.0)
327 ball_size = size + (size_var * size_var_max)
328 color_index = random.randint(0, 9)
329 ball_data.append((path_pos, y, ball_speed, ball_size, color_index))
330
331 fctx.set_data_obj(&#34;ball_data&#34;, ball_data)
332 ```
333 In *init_render()* we read editor values set by the user and create the data structures for moving ball animations based on that data.
334
335 Also note that **we need to set seed for Pythom module &#39;random&#39;** because when a frame sequence is rendered using multiple processes we need the exact same sequence of random numbers produced in every process.
336
337 ### render_frame()
338 ```
339 def render_frame(frame, fctx, w, h):
340 cr = fctx.get_frame_cr()
341
342 # Draw bg
343 bg_color = cairo.SolidPattern(*fctx.get_data_obj(&#34;hue_tuple&#34;))
344 ball_colors = fctx.get_data_obj(&#34;ball_colors&#34;)
345 ball_data = fctx.get_data_obj(&#34;ball_data&#34;)
346
347 cr.set_source(bg_color)
348 cr.rectangle(0, 0, w, h)
349 cr.fill()
350
351 # Draw balls
352 number_of_balls = fctx.get_editor_value(&#34;Number of Items&#34;)
353 size_max = fctx.get_data_obj(&#34;size_max&#34;)
354 path_start_x = - size_max
355 path_end_x = w + size_max
356 path_len = path_end_x - path_start_x
357 SPEED_NORM_PER_FRAME = 15.0 / float(w) # Speed value 1.0 gets 15 pixels of movement per frame.
358 for i in range(0, number_of_balls):
359 path_pos, y, ball_speed, ball_size, color_index = ball_data[i]
360 xc = ball_size / 2.0
361 yc = ball_size / 2.0
362 xpos_norm = path_pos + (float(frame) * ball_speed * SPEED_NORM_PER_FRAME)
363 while xpos_norm &gt; 1.0:
364 xpos_norm = xpos_norm - 1.0
365 x = path_start_x + path_len * xpos_norm
366 cr.save()
367 cr.translate(x, y)
368 cr.arc(xc, yc, ball_size / 4.0, 0.0, 2.0 * math.pi)
369 cr.set_source(ball_colors[color_index])
370 cr.fill()
371 cr.restore()
372
373 # ----------------------- helper func
374 def _clamp(v):
375 return max(min(v, 1.0), 0.0)
376
377 ```
378 In *render_frame()* we first get access to *Cairo.Context* object that can be drawn onto to create output for the frame.
379
380 After that the data structures created in *init_render()* are accessed and image is drawn.
381
382 There is a helper function *_clamp(v)* used to make sure that all color values are in range 0-1. Any number of helper functions, objects and data structures can be created.
383
384
385 ## DEVELOPING FLUXITY SCRIPTS
386
387 **Flowblade** comes with a simple development GUI tool for developing Fluxity scripts. It can be accessed from menu **Tools-&gt;Generator Script Editor**.
388
389 You can edit scripts, render output from them, and receive error messages using the development tool. From hamburger menu you can open and save your own scripts, access this document, and open and inspect example code of the *Generators* distributed with Flowblade.
390
391 Since the text editor in the development tool is quite rudimentary *(with a future GTK4 port we can get improvement here)*, it can be a useful workflow to use an external text editor to edit the scripts, and press *Reload Script* button to update text area contents before attempting render.
392
393 # FLUXITY API
394 &#34;&#34;&#34;
395 __pdoc__ = {}
396 __pdoc__[&#39;FluxityError&#39;] = False
397 __pdoc__[&#39;FluxityContextPrivate&#39;] = False
398 __pdoc__[&#39;FluxityScript&#39;] = False
399 __pdoc__[&#39;FluxityProfile&#39;] = False
400 __pdoc__[&#39;FluxityEmptyClass&#39;] = False
401 __pdoc__[&#39;render_frame_sequence&#39;] = False
402 __pdoc__[&#39;render_preview_frame&#39;] = False
403
404 import gi
405 gi.require_version(&#39;PangoCairo&#39;, &#39;1.0&#39;)
406 from gi.repository import Pango
407 from gi.repository import PangoCairo
408
409 import array
410 import cairo
411 import json
412 import math
413 import multiprocessing
414 import os
415 from PIL import Image, ImageFilter
416 import sys
417 import traceback
418
419
420 # Default length in frames for script duration.
421 DEFAULT_LENGTH = 200
422
423 METHOD_INIT_SCRIPT = 0
424 METHOD_INIT_RENDER = 1
425 METHOD_RENDER_FRAME = 2
426
427 # Pango font constants.
428 FACE_REGULAR = &#34;Regular&#34;
429 FACE_BOLD = &#34;Bold&#34;
430 FACE_ITALIC = &#34;Italic&#34;
431 FACE_BOLD_ITALIC = &#34;Bold Italic&#34;
432 DEFAULT_FONT_SIZE = 40
433
434 FLUXITY_ERROR_MSG = &#34;ERROR&#34;
435 FLUXITY_LOG_MSG = &#34;LOG&#34;
436
437 VERTICAL = 0
438 HORIZONTAL = 1
439
440 # The script displayed by Flowblade Script tool on open.
441 DEFAULT_SCRIPT = \
442 &#34;&#34;&#34;
443 import cairo
444 import math
445
446 import fluxity
447
448
449 SIDE_LENGTH = 200
450 SPEED_CONSTANT = 30.0 / 360.0
451
452
453 def init_script(fctx):
454 fctx.set_name(&#34;Editor Default Plugin&#34;)
455
456 fctx.add_editor(&#34;BG Color&#34;, fluxity.EDITOR_COLOR, (0.8, 0.2, 0.2, 1.0))
457 fctx.add_editor(&#34;FG Color&#34;, fluxity.EDITOR_COLOR, (1.0, 1.0, 1.0, 1.0))
458 fctx.add_editor(&#34;Rotation Speed&#34;, fluxity.EDITOR_FLOAT_RANGE, (3.0, 0.0, 10.0))
459
460 def init_render(fctx):
461 hue_bg = fctx.get_editor_value(&#34;BG Color&#34;)
462 hue_fg = fctx.get_editor_value(&#34;FG Color&#34;)
463
464 fctx.set_data_obj(&#34;bg_color&#34;, cairo.SolidPattern(*hue_bg))
465 fctx.set_data_obj(&#34;fg_color&#34;, cairo.SolidPattern(*hue_fg))
466
467 def render_frame(frame, fctx, w, h):
468 cr = fctx.get_frame_cr()
469
470 bg_color = fctx.get_data_obj(&#34;bg_color&#34;)
471 cr.set_source(bg_color)
472 cr.rectangle(0, 0, w, h)
473 cr.fill()
474
475 affine = fluxity.AffineTransform()
476
477 affine.x.add_keyframe_at_frame(0, w / 2, fluxity.KEYFRAME_LINEAR)
478 affine.y.add_keyframe_at_frame(0, h / 2, fluxity.KEYFRAME_LINEAR)
479
480 side_half = SIDE_LENGTH / 2
481 affine.anchor_x.add_keyframe_at_frame(0, side_half, fluxity.KEYFRAME_LINEAR)
482 affine.anchor_y.add_keyframe_at_frame(0, side_half, fluxity.KEYFRAME_LINEAR)
483
484 rotation_speed = fctx.get_editor_value(&#34;Rotation Speed&#34;, frame) # Value is constant, so frame is optional here
485 rotation = frame * 2 * math.pi * rotation_speed * SPEED_CONSTANT
486 affine.rotation.add_keyframe_at_frame(0, rotation, fluxity.KEYFRAME_LINEAR)
487
488 affine.apply_transform(cr, frame)
489
490 fg_color = fctx.get_data_obj(&#34;fg_color&#34;)
491 cr.set_source(fg_color)
492 cr.rectangle(0, 0, SIDE_LENGTH, SIDE_LENGTH)
493 cr.fill()
494 &#34;&#34;&#34;
495
496 EDITOR_TEXT = 1
497 &#34;&#34;&#34; Editor for strings.&#34;&#34;&#34;
498 EDITOR_FLOAT = 2
499 &#34;&#34;&#34; Editor for float values.&#34;&#34;&#34;
500 EDITOR_INT = 3
501 &#34;&#34;&#34; Editor for integer values.&#34;&#34;&#34;
502 EDITOR_COLOR = 4
503 &#34;&#34;&#34; Editor for colors. Value is a *(R,G,B,A)* tuple with values in range 0-1.&#34;&#34;&#34;
504 EDITOR_FILE_PATH = 5
505 &#34;&#34;&#34; Editor for selecting a file path. Value is Python pathname or *None*.&#34;&#34;&#34;
506 EDITOR_OPTIONS = 6
507 &#34;&#34;&#34; Editor for selecting between 2 - N string options. Value is tuple *(selected_index,[option_str_1, option_str_2, ...])*.&#34;&#34;&#34;
508 EDITOR_CHECK_BOX = 7
509 &#34;&#34;&#34; Editor for boolean value. Value is either *True* or *False*&#34;&#34;&#34;
510 EDITOR_FLOAT_RANGE = 8
511 &#34;&#34;&#34; Editor for float values with a defined range of accepted values. Value is a 3-tuple *(default_val, min_val, max_val)*.&#34;&#34;&#34;
512 EDITOR_INT_RANGE = 9
513 &#34;&#34;&#34; Editor for integer values with a defined range of accepted values. Value is a 3-tuple *(default_val, min_val, max_val)*&#34;&#34;&#34;
514 EDITOR_PANGO_FONT = 10
515 &#34;&#34;&#34; Editor for setting pango font properties.&#34;&#34;&#34;
516 EDITOR_TEXT_AREA = 11
517 &#34;&#34;&#34; Editor for creating multiline text.&#34;&#34;&#34;
518
519 EDITOR_PANGO_FONT_DEFAULT_VALUES = (&#34;Liberation Serif&#34;, &#34;Regular&#34;, 80, Pango.Alignment.LEFT, (1.0, 1.0, 1.0, 1.0), \
520 True, (0.3, 0.3, 0.3, 1.0) , False, 2, False, (0.0, 0.0, 0.0), \
521 100, 3, 3, 0.0, None, VERTICAL)
522 &#34;&#34;&#34; Pango Font Editor default values.&#34;&#34;&#34;
523
524 PROFILE_DESCRIPTION = &#34;description&#34;
525 &#34;&#34;&#34;MLT Profile descriptiption string.&#34;&#34;&#34;
526 PROFILE_FRAME_RATE_NUM = &#34;frame_rate_num&#34;
527 &#34;&#34;&#34;Frame rate numerator.&#34;&#34;&#34;
528 PROFILE_FRAME_RATE_DEN = &#34;frame_rate_den&#34;
529 &#34;&#34;&#34;Frame rate denominator.&#34;&#34;&#34;
530 PROFILE_WIDTH = &#34;width&#34;
531 &#34;&#34;&#34;Output image width in pixels.&#34;&#34;&#34;
532 PROFILE_HEIGHT = &#34;height&#34;
533 &#34;&#34;&#34;Output image height in pixels.&#34;&#34;&#34;
534 PROFILE_PROGRESSIVE = &#34;progressive&#34;
535 &#34;&#34;&#34;
536 MLT Profile image is progressive if value is *True*, if value is *False* image is interlaced.
537 &#34;&#34;&#34;
538 PROFILE_SAMPLE_ASPECT_NUM = &#34;sample_aspect_num&#34;
539 &#34;&#34;&#34;
540 Pixel size fraction numerator.
541 &#34;&#34;&#34;
542 PROFILE_SAMPLE_ASPECT_DEN = &#34;sample_aspect_den&#34;
543 &#34;&#34;&#34;
544 Pixel size fraction denominator.
545 &#34;&#34;&#34;
546 PROFILE_DISPLAY_ASPECT_NUM = &#34;display_aspect_num&#34;
547 &#34;&#34;&#34;Output image size fraction numerator.&#34;&#34;&#34;
548 PROFILE_DISPLAY_ASPECT_DEN = &#34;display_aspect_den&#34;
549 &#34;&#34;&#34;Output image size fraction denominator.&#34;&#34;&#34;
550 PROFILE_COLORSPACE = &#34;colorspace&#34;
551 &#34;&#34;&#34;Profile colorspace, value is either 709, 601 or 2020.&#34;&#34;&#34;
552
553 KEYFRAME_LINEAR = 0
554 &#34;&#34;&#34;Value after keyframe of this type is linearly interpolated using two surrounding keyframe values.&#34;&#34;&#34;
555 KEYFRAME_SMOOTH = 1
556 &#34;&#34;&#34;Value after keyframe of this type is calculated using a Catmull-Rom curve created from four surrounding keyframe values.&#34;&#34;&#34;
557 KEYFRAME_DISCRETE = 2
558 &#34;&#34;&#34;Value after keyframe of this type is value at keyframe.&#34;&#34;&#34;
559
560 # ---------------------------------------------------------- script object
561 class FluxityScript:
562 &#34;&#34;&#34;
563 Compiles script to an executable object and calls methods *init_script()*, *init_render()*, *render_frame()* on it.
564
565 Internal class, do not use objects of this class directly in scripts.
566 &#34;&#34;&#34;
567
568 def __init__(self, script_str):
569 self.script = script_str
570 self.code = None
571 self.namespace = {}
572
573 def compile_script(self):
574 &#34;&#34;&#34;
575 Compiles user script.
576 &#34;&#34;&#34;
577 try:
578 self.code = compile(self.script, &#34;&lt;fluxityscript&gt;&#34;, &#34;exec&#34;)
579 except Exception as e:
580 _raise_compile_error(str(e))
581
582 code_names = sorted(self.code.co_names)
583 required_names = sorted([&#34;init_script&#34;,&#34;init_render&#34;,&#34;render_frame&#34;])
584 contains_all = all(elem in code_names for elem in required_names)
585 if contains_all == False:
586 _raise_fluxity_error(&#34;Functions names &#34; + str(required_names) + &#34; all required to be in script, you have: &#34; + str(code_names))
587
588 try:
589 exec(self.code, self.namespace)
590 except Exception as e:
591 _raise_exec_error(str(e))
592
593 def call_init_script(self, fctx):
594 &#34;&#34;&#34;
595 Calls method *init_script()* on script.
596 &#34;&#34;&#34;
597 try:
598 self.namespace[&#39;init_script&#39;](fctx)
599 except Exception as e:
600 _raise_fluxity_error(&#34;error calling function &#39;init_script()&#39;:&#34; + str(e))
601
602 def call_init_render(self, fctx):
603 &#34;&#34;&#34;
604 Calls method *init_render()* on script.
605 &#34;&#34;&#34;
606 try:
607 self.namespace[&#39;init_render&#39;](fctx)
608 except Exception as e:
609 _raise_fluxity_error(&#34;error calling function &#39;init_render()&#39;:\n\n&#34; + str(e))
610
611 def call_render_frame(self, frame, fctx, w, h):
612 &#34;&#34;&#34;
613 Calls method *render_frame()* on script.
614 &#34;&#34;&#34;
615 try:
616 self.namespace[&#39;render_frame&#39;](frame, fctx, w, h)
617 except Exception as e:
618 _raise_fluxity_error(&#34;error calling function &#39;render_frame()&#39;:\n\n&#34; + str(e))
619
620
621 # ---------------------------------------------------------- Data structure corresponding with mlt.Profile
622 class FluxityProfile:
623 &#34;&#34;&#34;
624 Properties of this class correspond MLT profile objects.
625
626 Internal class, do not use objects of this class directly in scripts.
627 &#34;&#34;&#34;
628
629 def __init__(self, profile_data):
630 self.profile_data = profile_data
631
632 def get_profile_property(self, prop):
633 return self.profile_data[prop]
634
635 def _read_profile_prop_from_lines(lines, prop):
636 for line in lines:
637 sides = line.split(&#34;=&#34;)
638 if sides[0] == prop:
639 return sides[1]
640
641 return None
642
643
644 # ---------------------------------------------------------- context object
645 class FluxityContext:
646
647 def __init__(self, script_file, output_folder):
648 self.priv_context = FluxityContextPrivate(output_folder)
649 self.script_file = script_file
650 self.data = {}
651 self.editors = {} # editors and script length
652 self.editor_tooltips = {}
653 self.length = DEFAULT_LENGTH
654 self.name = &#34;Name Not Set&#34;
655 self.version = 1
656 self.author = &#34;Author Not Set&#34;
657 self.error = None
658 self.log_msg = &#34;&#34;
659
660 def get_frame_cr(self):
661 &#34;&#34;&#34;
662 For every rendered frame method *`render_frame()`* is called and a new **`cairo.ImageSurface`** object is created.
663
664 This method provides access to **`cairo.Context`** object that can be used to draw onto that image surface. This is the way that output is achieved with **Flowblade Media Plugins**.
665
666 After method *`render_frame()`* exits, **`cairo.Context`** object is no longer valid and contents of **`cairo.ImageSurface`** are saved to disk.
667
668 Must be called in script method *`render_frame()`*.
669
670 **Returns:** (**`cairo.Context`**) Context object that can be drawn onto.
671 &#34;&#34;&#34;
672 return self.priv_context.frame_cr
673
674 def get_dimensions(self):
675 &#34;&#34;&#34;
676 Pixel size of output image.
677
678 **Returns:** (int, int) Tuple (width, height) of output image size.
679 &#34;&#34;&#34;
680 w = self.priv_context.profile.get_profile_property(PROFILE_WIDTH)
681 h = self.priv_context.profile.get_profile_property(PROFILE_HEIGHT)
682 return (w, h)
683
684 def get_profile_property(self, p_property):
685 &#34;&#34;&#34;
686 **`p_property(str):`** propertyr identyfier, e.g. `fluxity.PROFILE_PROGRESSIVE`.
687
688 Used to access properties of MLT profile set before running the script that defines e.g. output image size.
689
690 **Returns:** (int || boolean || string) Value depends on which profile property is being accessed.
691 &#34;&#34;&#34;
692 return self.priv_context.profile.get_profile_property(p_property)
693
694 def set_name(self, name):
695 &#34;&#34;&#34;
696 **`name(str):`** name of script displayed to user.
697
698 Sets name of the script displayed to the user. Must be called in script method *`init_script()`*.
699 &#34;&#34;&#34;
700 self.priv_context.error_on_wrong_method(&#34;set_name()&#34;, METHOD_INIT_SCRIPT)
701 self.name = name
702
703
704 def set_version(self, version):
705 &#34;&#34;&#34;
706 **`version(int):`** version of script, use increasing integer numbering. Default value is *1*.
707
708 Sets version of script. Must be called in script method *`init_script()`*.
709 &#34;&#34;&#34;
710 self.priv_context.error_on_wrong_method(&#34;set_version()&#34;, METHOD_INIT_SCRIPT)
711 self.version = version
712
713 def set_author(self, author):
714 &#34;&#34;&#34;
715 **`author(str):`** name of script creator.
716
717 Sets author of the script. Must be called in script method *init_script()*.
718 &#34;&#34;&#34;
719 self.author = author
720
721 def set_frame_name(self, frame_name):
722 &#34;&#34;&#34;
723 **`frame_name(str):`** name used before number part in rendered frame files.
724 &#34;&#34;&#34;
725 self.priv_context.frame_name = frame_name
726
727 def set_data_obj(self, label, item):
728 &#34;&#34;&#34;
729 **`label(str):`** label used to access data later using *`get_data_obj(self, label)`*.
730
731 **`item(obj):`** data item being saved.
732
733 Saves data to be used later during execution of script. Using **global** would obviously be possible to replace this, but this is made available as a more clean solution.
734 &#34;&#34;&#34;
735 self.data[label] = item
736
737 def get_data_obj(self, label):
738 &#34;&#34;&#34;
739 **`label(str):`** label of saved data item.
740
741 Gives access to previously saved data.
742
743 **Returns:** (obj) Saved data item.
744 &#34;&#34;&#34;
745 return self.data[label]
746
747 def set_length(self, length):
748 &#34;&#34;&#34;
749 **`length(int):`** New length of script in frames.
750
751 Sets length of script output in frames.
752
753 Must *not* be called in *`render_frames()`*.
754 &#34;&#34;&#34;
755 self.length = length
756
757 def get_length(self):
758 &#34;&#34;&#34;
759 **Returns:** (int) Length of script in frames.
760 &#34;&#34;&#34;
761 return self.length
762
763 def add_editor(self, name, type, default_value, tooltip=None):
764 &#34;&#34;&#34;
765 **`name(str):`** Name for editor.
766
767 **`type(int):`** Value either *`EDITOR_FLOAT`, `EDITOR_INT`, `EDITOR_COLOR`, `EDITOR_FILE_PATH`, `EDITOR_OPTIONS`, `EDITOR_CHECK_BOX`, `EDITOR_FLOAT_RANGE`, `EDITOR_INT_RANGE`.*
768
769 **`default_value(str||int||float||tuple):`** Data type depends on editor type:
770
771 * `EDITOR_TEXT`(str),
772
773 * `EDITOR_TEXT_AREA`(str),
774
775 * `EDITOR_FLOAT`(float),
776
777 * `EDITOR_INT`(int),
778
779 * `EDITOR_COLOR`(4-tuple with float values in range 0-1, (R,G,B,A)),
780
781 * `EDITOR_FILE_PATH`(str),
782
783 * `EDITOR_OPTIONS`(2-tuple (int, [str]), (selected_index,[option_str_1, option_str_2, ...]),
784
785 * `EDITOR_CHECK_BOX`(bool),
786
787 * `EDITOR_FLOAT_RANGE`(3-tuple with float values, (default, min, max)),
788
789 * `EDITOR_INT_RANGE`(3-tuple with int values, (default, min, max))
790
791 * `EDITOR_PANGO_FONT` (17-tuple (font_family, font_face, font_size, alignment, color_rgba,
792 fill_on, outline_color_rgba, outline_on, outline_width, shadow_on, shadow_color_rgb,
793 shadow_opacity, shadow_xoff, shadow_yoff, shadow_blur,
794 gradient_color_rgba, gradient_direction))
795
796 **`tooltip(str, optional):`** Tooltip for editor if presented in GUI.
797
798 Defines possible GUI editors used to affect script rendering. Edited value is accessed with method *get_editor_value(self, name, frame=0)*.
799
800 Data describing editors can be accessed with *get_script_data(self)*. Edited values are made available for script with *set_editors_data(self, editors_data_json)*.
801
802 Must be called in script method *init_script()*.
803 &#34;&#34;&#34;
804 self.priv_context.error_on_wrong_method(&#34;add_editor()&#34;, METHOD_INIT_SCRIPT)
805 self.editors[name] = (type, default_value)
806 if tooltip != None:
807 self.editor_tooltips[name] = tooltip
808
809 def get_editor_value(self, name, frame=0):
810 &#34;&#34;&#34;
811 **`name(str):`** Name of editor.
812
813 **`frame(int):`** Frame in range 0 - (script length - 1).
814
815 Value of edited data at given frame. We currently have no animated values, but they will added with future API updates.
816
817 **Returns:** (obj) Value at frame.
818
819 Data type depends on editor type:
820
821 * `EDITOR_TEXT`(str),
822
823 * `EDITOR_TEXT_AREA`(str),
824
825 * `EDITOR_FLOAT`(float),
826
827 * `EDITOR_INT`(int),
828
829 * `EDITOR_COLOR`(4-tuple with float values in range 0-1, (R,G,B,A)),
830
831 * `EDITOR_FILE_PATH`(str),
832
833 * `EDITOR_OPTIONS`(selection index int),
834
835 * `EDITOR_CHECK_BOX`(bool),
836
837 * `EDITOR_FLOAT_RANGE`(3-tuple with float values, (default, min, max)),
838
839 * `EDITOR_INT_RANGE`(3-tuple with int values, (default, min, max))
840
841 * `EDITOR_PANGO_FONT`(17-tuple (font_family, font_face, font_size, alignment, color_rgba,
842 fill_on, outline_color_rgba, outline_on, outline_width, shadow_on, shadow_color_rgb,
843 shadow_opacity, shadow_xoff, shadow_yoff, shadow_blur,
844 gradient_color_rgba, gradient_direction))
845 &#34;&#34;&#34;
846 try:
847 type, value = self.editors[name]
848 if type == EDITOR_INT_RANGE or type == EDITOR_FLOAT_RANGE:
849 val, min, max = value
850 return val
851 elif type == EDITOR_OPTIONS:
852 selected_index, options = value
853 return selected_index
854 return value
855 except Exception as e:
856 exception_msg = &#34;No editor for name &#39;&#34; + name + &#34;&#39; found.&#34;
857 _raise_fluxity_error(exception_msg)
858
859 def get_script_data(self):
860 &#34;&#34;&#34;
861 Returns data of all editors and their default values, and script metadata like script author and version.
862
863 Output can be turned into Python object tree using *json.loads()* method.
864
865 **Returns:** (str) string representation of JSON object.
866 &#34;&#34;&#34;
867 script_data = {}
868 script_data[&#34;length&#34;] = self.length
869 script_data[&#34;name&#34;] = self.name
870 script_data[&#34;version&#34;] = self.version
871 script_data[&#34;author&#34;] = self.author
872
873 editors_list = []
874 for name in self.editors:
875 type, value = self.editors[name]
876 json_obj = [name, type, value]
877 editors_list.append(json_obj)
878
879 script_data[&#34;editors_list&#34;] = editors_list # this is dict inside FluxityContext object, but is given out as list for convenience of Flowblade app integration.
880 script_data[&#34;tooltips_list&#34;] = self.editor_tooltips
881
882 return json.dumps(script_data)
883
884 def get_script_dir(self):
885 &#34;&#34;&#34;
886 Returns path to directory where the script being executed is located.
887
888 Sometimes script directory information is not available (e.g. when executing a non-saved script in Flowblade *Script Tool* application) and *None* is returned. It is recommended that all Fluxity scripts handle getting *None* gracefully.
889
890 This functionality is useful when script is being distributed with some associated media files.
891
892 **Returns:** (str) script directory path or *None*.
893 &#34;&#34;&#34;
894 if self.script_file == None:
895 return None
896
897 dir_path = os.path.dirname(self.script_file) + &#34;/&#34;
898 return dir_path
899
900 def set_editors_data(self, editors_data_json):
901 &#34;&#34;&#34;
902 **`editors_data_json(str):`** string representation of JSON object.
903
904 Sets edited data to be used when rendering.
905
906 Input string must describe JSON object that can be turned into usable editor data.
907
908 Example with `EDITOR_FLOAT` and `EDITOR_COLOR`:
909
910 ```
911 [
912 [&#34;Position X&#34;, 2, 1.0],
913 [&#34;BG Color&#34;, 4, [0.8, 0.2, 0.2, 1.0]]
914 ]
915 ```
916
917 General form:
918
919 ```
920 [
921 [&lt;name&gt;, &lt;type&gt;, &lt;value&gt;],
922 ...
923 ]
924 ```
925
926 Using this method is not needed when writing **Flowblade Media Plugins**, application handles setting editors data.
927
928 Should be called in script method *init_render()*.
929 &#34;&#34;&#34;
930 new_editors_list = json.loads(editors_data_json)
931 for editor in new_editors_list:
932 name, type, value = editor
933 self.editors[name] = (type, value)
934
935 def create_text_layout(self, font_data):
936 &#34;&#34;&#34;
937 **`font_data(tuple)`** this tuple can be acquired by calling *FluxityContext.get_editor_value()* on editors of type *EDITOR_PANGO_FONT*.
938
939 Creates objects used to draw text.
940
941 **Returns:** (fluxity.PangoTextLayout) object for drawing text.
942 &#34;&#34;&#34;
943 return PangoTextLayout(font_data)
944
945 def log_line(self, log_line):
946 &#34;&#34;&#34;
947 **`log_line(str):`** line of text.
948
949 Adds a line of text to log message displayed after render completion or error.
950 &#34;&#34;&#34;
951 self.log_msg = self.log_msg + log_line + &#34;\n&#34;
952
953 def set_prints_to_log_file(self, log_file):
954 &#34;&#34;&#34;
955 **`log_file(str):`** File path.
956
957 Save output from &#39;print()&#39; to file at given path. Must be called in script method *init_script()*.
958 &#34;&#34;&#34;
959 self.priv_context.error_on_wrong_method(&#34;add_editor()&#34;, METHOD_INIT_SCRIPT)
960 _prints_to_log_file(log_file)
961
962 class FluxityContextPrivate:
963 # This class exists to keep FluxityContext API clean for script developers.
964 #
965 # Internal class, do not use objects of this class directly in scripts.
966 def __init__(self, output_folder):
967
968 self.profile = None
969
970 self.output_folder = output_folder
971 self.start_out_from_frame_one = False
972 self.in_frame = -1
973
974 self.frame = -1
975
976 self.frame_surface = None
977 self.frame_cr = None
978
979 self.frame_name = &#34;frame&#34;
980 self.first_rendered_frame_path = None # This is cleared by rendering routines.
981
982 self.current_method = None
983 self.method_name = {METHOD_INIT_SCRIPT:&#34;init_script()&#34;, METHOD_INIT_RENDER:&#34;init_render()&#34;, METHOD_RENDER_FRAME:&#34;render_frame()&#34;}
984
985 self.repo = None
986
987 self.process_id = None # Used for de-bugging, scripts normally would not access this.
988
989 def load_profile(self, mlt_profile_path):
990 lines = []
991 with open(mlt_profile_path, &#34;r&#34;) as f:
992 for line in f:
993 lines.append(line.strip())
994 data = {}
995 data[PROFILE_DESCRIPTION] = _read_profile_prop_from_lines(lines, PROFILE_DESCRIPTION)
996 data[PROFILE_FRAME_RATE_NUM] = _read_profile_prop_from_lines(lines, PROFILE_FRAME_RATE_NUM)
997 data[PROFILE_FRAME_RATE_DEN] = _read_profile_prop_from_lines(lines, PROFILE_FRAME_RATE_DEN)
998 data[PROFILE_WIDTH] = int(_read_profile_prop_from_lines(lines, PROFILE_WIDTH))
999 data[PROFILE_HEIGHT] = int(_read_profile_prop_from_lines(lines, PROFILE_HEIGHT))
1000 data[PROFILE_PROGRESSIVE] = _read_profile_prop_from_lines(lines, PROFILE_PROGRESSIVE)
1001 data[PROFILE_SAMPLE_ASPECT_NUM] = _read_profile_prop_from_lines(lines, PROFILE_SAMPLE_ASPECT_NUM)
1002 data[PROFILE_SAMPLE_ASPECT_DEN] = _read_profile_prop_from_lines(lines, PROFILE_SAMPLE_ASPECT_DEN)
1003 data[PROFILE_DISPLAY_ASPECT_NUM] = _read_profile_prop_from_lines(lines, PROFILE_DISPLAY_ASPECT_NUM)
1004 data[PROFILE_DISPLAY_ASPECT_DEN] = _read_profile_prop_from_lines(lines, PROFILE_DISPLAY_ASPECT_DEN)
1005 data[PROFILE_COLORSPACE] = _read_profile_prop_from_lines(lines, PROFILE_COLORSPACE)
1006
1007 self.profile = FluxityProfile(data)
1008
1009 return self.profile.profile_data
1010
1011 def create_frame_surface(self, frame):
1012 self.frame = frame
1013 w = self.profile.profile_data[PROFILE_WIDTH]
1014 h = self.profile.profile_data[PROFILE_HEIGHT]
1015 self.frame_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
1016 self.frame_cr = cairo.Context(self.frame_surface)
1017
1018 def write_out_frame(self, is_preview_frame=False):
1019 if self.output_folder == None or os.path.isdir(self.output_folder) == False:
1020 exception_msg = &#34;Output folder &#34; + self.output_folder + &#34; does not exist.&#34;
1021 _raise_fluxity_error(exception_msg)
1022
1023 out_frame_number = self.frame
1024 if self.start_out_from_frame_one == True:
1025 out_frame_number = self.frame - self.in_frame + 1
1026
1027 filepath = self.output_folder + &#34;/&#34; + self.frame_name + &#34;_&#34; + str(out_frame_number).rjust(5, &#34;0&#34;) + &#34;.png&#34;
1028 if is_preview_frame == True:
1029 filepath = self.output_folder + &#34;/preview.png&#34;
1030 self.frame_surface.write_to_png(filepath)
1031
1032 if self.first_rendered_frame_path == None:
1033 self.first_rendered_frame_path = filepath
1034
1035 def get_preview_frame_path(self):
1036 return self.output_folder + &#34;/preview.png&#34;
1037
1038 def error_on_wrong_method(self, method_name, required_method):
1039 if required_method == self.current_method:
1040 return
1041
1042 error_str = &#34;&#39;FluxityContext.&#34; + method_name + &#34;&#39; has to called in script method &#39;&#34; + self.method_name[required_method] + &#34;&#39;.&#34;
1043 _raise_contained_error(error_str)
1044
1045 class FluxityEmptyClass:
1046 &#34;&#34;&#34;
1047 Internal class, do not use objects of this class directly in scripts.
1048 &#34;&#34;&#34;
1049 pass
1050
1051 class PangoTextLayout:
1052
1053 &#34;&#34;&#34;
1054 **`font_data(tuple)`** this tuple can be acquired by calling *`FluxityContext.get_editor_value()`* on editors of type *`EDITOR_PANGO_FONT`*.
1055
1056 Object for drawing text. Uses internally Pango.
1057
1058 Instances of this object can be created using *`FluxityContext.create_text_layout()`*.
1059 &#34;&#34;&#34;
1060 def __init__(self, font_data):
1061 self.font_family, self.font_face, self.font_size, self.alignment, \
1062 self.color_rgba, self.fill_on, self.outline_color_rgba, self.outline_on, \
1063 self.outline_width, self.shadow_on, self.shadow_color_rgb, self.shadow_opacity, \
1064 self.shadow_xoff, self.shadow_yoff, self.shadow_blur, self.gradient_color_rgba, \
1065 self.gradient_direction = font_data
1066 self.font_desc = None
1067 self.pango_layout = None
1068 self.opacity = 1.0
1069 self.pixel_size = None
1070
1071 def create_pango_layout(self, cr, text):
1072 &#34;&#34;&#34;
1073 **`cr(cairo.Context)`** frame cairo context acquired with *`FluxityContext.get_frame_cr()`*.
1074
1075 **`text(str)`** displayed text.
1076
1077 Creates internally *`PangoCairo`* layout object. Calling this is required before calling *`PangoTextLayout.get_pixel_size()`*.
1078 &#34;&#34;&#34;
1079 self.text = text
1080 self.pango_layout = PangoCairo.create_layout(cr)
1081 self.pango_layout.set_text(self.text, -1)
1082 font_desc = Pango.FontDescription(self.font_family + &#34; &#34; + self.font_face + &#34; &#34; + str(self.font_size))
1083 self.pango_layout.set_font_description(font_desc)
1084 self.pango_layout.set_alignment(self.alignment)
1085 if self.pixel_size == None:
1086 metrics = self.pango_layout.get_context().get_metrics(font_desc, None)
1087 self.ascent = metrics.get_ascent() / Pango.SCALE
1088 self.descent = metrics.get_descent() / Pango.SCALE
1089 self.height = metrics.get_height() / Pango.SCALE
1090 w, h = self.pango_layout.get_size()
1091 self.pixel_size = (w / Pango.SCALE, self.height)
1092
1093 def get_top_pad(self):
1094 &#34;&#34;&#34;
1095 Returns pixel distance from layout top to highest possible pixel drawn for any font.
1096
1097 **Returns:** (int)(pad) Top pad size in pixels.
1098 &#34;&#34;&#34;
1099 return self.height - self.descent - self.ascent
1100
1101
1102 def get_pixel_size(self):
1103 &#34;&#34;&#34;
1104 Returns size of layout.
1105
1106 Before calling this PangoCairo layout object needs to created *`PangoTextLayout.create_pango_layout()`* or *`PangoTextLayout.draw_layout()`.*
1107
1108 **Returns:** (int, int)(width, height) pixel size of layout.
1109 &#34;&#34;&#34;
1110 return self.pixel_size
1111
1112 def set_opacity(self, opacity):
1113 &#34;&#34;&#34;
1114 **`opacity(float)`** Opacity in range 0.0 - 1.0.
1115
1116 Sets opacity for the text to be drawn. Default value is 1.0
1117 &#34;&#34;&#34;
1118 if opacity &lt; 0.0:
1119 opacity = 0.0
1120 if opacity &gt; 1.0:
1121 opacity = 1.0
1122
1123 self.opacity = opacity
1124
1125 # called from vieweditor draw vieweditor-&gt; editorlayer-&gt;here
1126 def draw_layout(self, fctx, text, cr, x, y, rotation=0.0, xscale=1.0, yscale=1.0):
1127 &#34;&#34;&#34;
1128 ** fctx(fluxity.FluxityContext ** context object.
1129
1130 **`text(str)`** displayed text.
1131
1132 **`cr(cairo.Context)`** frame cairo context acquired with *`FluxityContext.get_frame_cr()`*.
1133
1134 **`x(float)`** Text X position.
1135
1136 **`y(float)`** Text Y position.
1137
1138 **`rotation(float)`** Text rotation.
1139
1140 **`xscale(float)`** Text X scaling.
1141
1142 **`yscale(float)`** Text Y scaling.
1143
1144 Draws text on provided *`cairo.Context`*.
1145
1146 Calls internally *`PangoTextLayout.create_pango_layout()`* so *`PangoTextLayout.get_pixel_size()`* can be called after this.
1147 &#34;&#34;&#34;
1148 self.text = text
1149 cr.save() # Created each frame
1150
1151 self.create_pango_layout(cr, text)
1152 layout = self.pango_layout # this just artifact of dev. history, create_pango_layout() was added later then draw_layout()
1153 # to be used in typewriter plugin.
1154 # Shadow
1155 if self.shadow_on:
1156 cr.save()
1157
1158 # Get colors.
1159 r, g, b = self.shadow_color_rgb
1160 a = (self.shadow_opacity / 100.0) * self.opacity
1161
1162 # Blurred shadow need its own ImageSurface
1163 if self.shadow_blur != 0.0:
1164 w, h = fctx.get_dimensions()
1165 blurred_img = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
1166 cr_blurred = cairo.Context(blurred_img)
1167 transform_cr = cr_blurred # Set draw transform_cr to context for newly created image.
1168 else:
1169 transform_cr = cr # Set draw transform_cr to out context.
1170
1171 # Transform and set color.
1172 transform_cr.set_source_rgba(r, g, b, a)
1173 effective_shadow_xoff = self.shadow_xoff * xscale
1174 effective_shadow_yoff = self.shadow_yoff * yscale
1175 transform_cr.move_to(x + effective_shadow_xoff, y + effective_shadow_yoff)
1176 transform_cr.scale(xscale, yscale)
1177 transform_cr.rotate(rotation)
1178
1179 # If no blur for shadow, just draw layout on out context.
1180 if self.shadow_blur == 0.0:
1181 PangoCairo.update_layout(cr, layout)
1182 PangoCairo.show_layout(cr, layout)
1183 cr.restore()
1184 else:
1185 # If we have blur - draw shadow, blur it and then draw on out context.
1186 PangoCairo.update_layout(cr_blurred, layout)
1187 PangoCairo.show_layout(cr_blurred, layout)
1188
1189 img2 = Image.frombuffer(&#34;RGBA&#34;, (blurred_img.get_width(), blurred_img.get_height()), blurred_img.get_data(), &#34;raw&#34;, &#34;RGBA&#34;, 0, 1)
1190 effective_blur = xscale * self.shadow_blur # This is not going to be exact
1191 # on non-100% scales but let&#39;s try to get approximation.
1192 img2 = img2.filter(ImageFilter.GaussianBlur(radius=int(effective_blur)))
1193 imgd = img2.tobytes()
1194 a = array.array(&#39;B&#39;,imgd)
1195
1196 stride = blurred_img.get_width() * 4
1197 draw_surface = cairo.ImageSurface.create_for_data (a, cairo.FORMAT_ARGB32,
1198 blurred_img.get_width(), blurred_img.get_height(), stride)
1199 cr.restore()
1200 cr.set_source_surface(draw_surface, 0, 0)
1201 cr.paint()
1202
1203 # Text
1204 if self.fill_on:
1205 if self.gradient_color_rgba == None:
1206 cr.set_source_rgba(*self._get_opacity_rgba(self.color_rgba))
1207 else:
1208 w, h = self.pixel_size
1209 w = float(w) * xscale
1210 h = float(h) * yscale
1211 if self.gradient_direction == HORIZONTAL:
1212 grad = cairo.LinearGradient (x, 0, x + w, 0)
1213 else:
1214 grad = cairo.LinearGradient (0, y, 0, y + h)
1215
1216 r, g, b, a = self.color_rgba
1217 rg, gg, bg, ag = self.gradient_color_rgba
1218
1219 CLIP_COLOR_GRAD_1 = (0, r, g, b, 1.0)
1220 CLIP_COLOR_GRAD_2 = (1, rg, gg, bg, 1.0)
1221 grad.add_color_stop_rgba(*CLIP_COLOR_GRAD_1)
1222 grad.add_color_stop_rgba(*CLIP_COLOR_GRAD_2)
1223 cr.set_source(grad)
1224
1225 cr.move_to(x, y)
1226 cr.scale(xscale, yscale)
1227 cr.rotate(rotation)
1228
1229 PangoCairo.update_layout(cr, layout)
1230 PangoCairo.show_layout(cr, layout)
1231
1232 # Outline
1233 if self.outline_on:
1234 if self.fill_on == False: # case when user only wants outline we need to transform here
1235 cr.move_to(x, y)
1236 cr.scale(xscale, yscale)
1237 cr.rotate(rotation)
1238 PangoCairo.layout_path(cr, layout)
1239 cr.set_source_rgba(*self._get_opacity_rgba(self.outline_color_rgba))
1240 cr.set_line_width(self.outline_width)
1241 cr.stroke()
1242
1243 cr.restore()
1244
1245 def get_pango_alignment(self):
1246 &#34;&#34;&#34;
1247 Returns alignment for his layout.
1248
1249 To interpret enums script must do import *`from gi.repository import Pango`*
1250
1251 **Returns:** (int) alignment enum, either *`Pango.Alignment.CENTER`*, *`Pango.Alignment.LEFT`* or *`Pango.Alignment.RIGHT`*.
1252 &#34;&#34;&#34;
1253 return self.alignment
1254
1255 def _get_opacity_rgba(self, rbga):
1256 r, g, b, a = rbga
1257 return (r, g, b, a * self.opacity)
1258
1259 class AnimatedValue:
1260
1261 &#34;&#34;&#34;
1262 Object for animating a float value.
1263
1264 Changing value is controlled by adding keyframes.
1265
1266 A keyframe has *frame position, value* and *type*. There are three types of keyframes: `KEYFRAME_LINEAR`, `KEYFRAME_SMOOTH` and `KEYFRAME_DISCRETE`.
1267
1268 * **`KEYFRAME_LINEAR`** Value after keyframe is linearly interpolated using two surrounding keyframe values.
1269
1270 * **`KEYFRAME_SMOOTH`** Value after keyframe is calculated using a Catmull-Rom curve created from four surrounding keyframe values.
1271
1272 * **`KEYFRAME_DISCRETE`** Value after keyframe is value at keyframe.
1273
1274 Implementation assumes there always being a keyframe at frame 0, and removing that will result in undefined behaviour. It is of course possible to overwrite existing keyframe at frame 0 using method *add_keyframe_at_frame().*
1275 &#34;&#34;&#34;
1276 def __init__(self, value=0.0):
1277 # We enforce a keyframe always existing in frame 0
1278 self.keyframes = [(0, value, KEYFRAME_LINEAR)]
1279
1280 def add_keyframe_at_frame(self, frame, value, kf_type):
1281 &#34;&#34;&#34;
1282 **`frame(int)`** Frame number in range 0 - (plugin length).
1283
1284 **`value(float)`** A float value.
1285
1286 **`kf_type(KEYFRAME_LINEAR|KEYFRAME_SMOOTH|KEYFRAME_DISCRETE)`** Type of added keyframe.
1287
1288 Adds or overwrites a keyframe.
1289
1290 If frame is on existing keyframe that keyframe is replaced.
1291
1292 If frame is between two keyframes a new keyframe is added between keyframes.
1293
1294 If frame is after last keyframe a new keyframe is appended.
1295 &#34;&#34;&#34;
1296
1297 # Replace if kf in frame exists.
1298 new_kf = (frame, value, kf_type)
1299 kf_index_on_frame = self._frame_has_keyframe(frame)
1300 if kf_index_on_frame != -1:
1301 self.keyframes.pop(kf_index_on_frame)
1302 self.keyframes.insert(kf_index_on_frame, new_kf)
1303 return
1304
1305 # Insert between if frame between two kfs.
1306 for i in range(0, len(self.keyframes)):
1307 kf_frame, kf_value, kf_type = self.keyframes[i]
1308 if kf_frame &gt; frame:
1309 prev_frame, prev_value, prev_type = self.keyframes[i - 1]
1310 self.keyframes.insert(i, new_kf)
1311 self.active_kf_index = i
1312 return
1313
1314 # Append last if after last kf.
1315 self.keyframes.append(new_kf)
1316
1317 def _frame_has_keyframe(self, frame):
1318 for i in range(0, len(self.keyframes)):
1319 kf_frame, kf_value, type = self.keyframes[i]
1320 if frame == kf_frame:
1321 return i
1322
1323 return -1
1324
1325 def get_value(self, frame):
1326 &#34;&#34;&#34;
1327 **`frame(int)`** Frame number in range 0 - (plugin length).
1328
1329 Computes and returns value at frame using current keyframe values, positions and types.
1330
1331 **Returns:** (float) value at frame.
1332 &#34;&#34;&#34;
1333 last_frame, last_value, last_type = self.keyframes[-1]
1334 if frame &gt;= last_frame: # This also handles case len(self.keyframes) == 1 because first keyframe always at frame 0.
1335 return last_value
1336
1337 for i in range(0, len(self.keyframes) - 1):
1338 kf_frame, kf_value, kf_type = self.keyframes[i]
1339 if frame == kf_frame:
1340 return kf_value
1341 next_frame, next_value, next_type = self.keyframes[i + 1]
1342 if frame == next_frame:
1343 return next_value
1344 if frame &gt; kf_frame and frame &lt; next_frame:
1345 if kf_type == KEYFRAME_LINEAR:
1346 fract = (frame - kf_frame) / (next_frame - kf_frame)
1347 return kf_value + fract * (next_value - kf_value)
1348 elif kf_type == KEYFRAME_SMOOTH:
1349 return self._get_smooth_value(i, frame)
1350 else: # KEYFRAME_DISCRETE
1351 return kf_value
1352
1353 return None # We absolutely want to crash if somehow we hit this.
1354
1355 def _get_smooth_value(self, i, frame):
1356 # Get indexes of the four keyframes that affect the drawn curve.
1357 prev = i
1358 if i == 0:
1359 prev_prev = 0
1360 else:
1361 prev_prev = i - 1
1362
1363 next = i + 1
1364 if next &gt;= len(self.keyframes):
1365 next = len(self.keyframes) - 1
1366
1367 next_next = next + 1
1368 if next_next &gt;= len(self.keyframes):
1369 next_next = len(self.keyframes) - 1
1370
1371 # Get keyframes.
1372 frame_pp, val0, kf_type = self.keyframes[prev_prev]
1373 frame_p, val1, kf_type = self.keyframes[prev]
1374 frame_n, val2, kf_type = self.keyframes[next]
1375 frame_nn, val3, kf_type = self.keyframes[next_next]
1376
1377 # Get value`
1378 fract = (frame - frame_p) / (frame_n - frame_p)
1379 smooth_val = self._catmull_rom_interpolate(val0, val1, val2, val3, fract)
1380 return smooth_val
1381
1382 # These all need to be doubles.
1383 def _catmull_rom_interpolate(self, y0, y1, y2, y3, t):
1384 t2 = t * t
1385 a0 = -0.5 * y0 + 1.5 * y1 - 1.5 * y2 + 0.5 * y3
1386 a1 = y0 - 2.5 * y1 + 2 * y2 - 0.5 * y3
1387 a2 = -0.5 * y0 + 0.5 * y2
1388 a3 = y1
1389 return a0 * t * t2 + a1 * t2 + a2 * t + a3
1390
1391
1392 class AffineTransform:
1393
1394 &#34;&#34;&#34;
1395 Object for describing animated affine transforms and applying them on *`cairo.Context`*.
1396
1397 On creation object creates following instance *`fluxity.AnimatedValue`* attributes:
1398
1399 **`x`** X position in pixels.
1400
1401 **`y`** Y position in pixels.
1402
1403 **`anchor_x`** Rotation and scaling offset from *`source`* top left corner in x axis pixels.
1404
1405 **`anchor_y`** Rotation and scaling offset from *`source`* top left corner in y axis pixels.
1406
1407 **`scale_x`** Scaling in x-axis as float value.
1408
1409 **`scale_y`** Scaling in y-axis as float value.
1410
1411 **`rotation`** Rotation in degrees.
1412
1413 Default value for all attributes is value 0.0 at keyframe 0, except `scale_x` and `scale_y` which have default value of 1.0 at keyframe 0.
1414
1415 The intended usage pattern:
1416
1417 * create *`fluxity.AffineTransform`* object and set values to needed attributes to create animations.
1418
1419 * for each frame first call method *`fluxity.AffineTransform.apply_transform()`* to apply the affine transform.
1420
1421 * draw *`source`* in `origo(0,0)` position.
1422 &#34;&#34;&#34;
1423
1424 def __init__(self):
1425 self.x = AnimatedValue()
1426 self.y = AnimatedValue()
1427 self.anchor_x = AnimatedValue()
1428 self.anchor_y = AnimatedValue()
1429 self.scale_x = AnimatedValue(1.0)
1430 self.scale_y = AnimatedValue(1.0)
1431 self.rotation = AnimatedValue()
1432
1433 def apply_transform(self, cr, frame):
1434 &#34;&#34;&#34;
1435 **`cr(cairo.Context)`** a `cairo.Context` object.
1436
1437 **`frame(int)`** Frame number in range 0 - (plugin length).
1438
1439 Applies affine transform defined by object instance at given frame on `cairo.Context` object.
1440 &#34;&#34;&#34;
1441 scale_x = self.scale_x.get_value(frame)
1442 scale_y = self.scale_y.get_value(frame)
1443 rotation_angle = self.rotation.get_value(frame)
1444
1445 anchor_x = scale_x * self.anchor_x.get_value(frame)
1446 anchor_y = scale_y * self.anchor_y.get_value(frame)
1447
1448 axr, ayr = self._rotate_point_around_origo(rotation_angle, (anchor_x, anchor_y))
1449
1450 tx = self.x.get_value(frame) - axr
1451 ty = self.y.get_value(frame) - ayr
1452
1453 cr.translate(tx, ty)
1454 cr.rotate(math.radians(rotation_angle))
1455 cr.scale(scale_x, scale_y)
1456
1457 def _rotate_point_around_origo(self, rotation_angle, p):
1458 px, py = p
1459 angle_rad = math.radians(rotation_angle)
1460 sin_val = math.sin(angle_rad)
1461 cos_val = math.cos(angle_rad)
1462 new_x = px * cos_val - py * sin_val
1463 new_y = px * sin_val + py * cos_val
1464 return (new_x, new_y)
1465
1466
1467 # ---------------------------------------------------------- Errors
1468 class FluxityError(Exception):
1469 &#34;&#34;&#34;
1470 Errors specific to using Fluxity API.
1471
1472 Internal class, do not use objects of this class directly in scripts.
1473 &#34;&#34;&#34;
1474 def __init__(self, msg):
1475 self.message = msg
1476 super().__init__(self.message)
1477
1478 def _raise_contained_error(exception_msg):
1479 raise FluxityError(exception_msg)
1480
1481 def _raise_fluxity_error(exception_msg):
1482 raise FluxityError(&#34;Fluxity Error: &#34; + exception_msg)
1483
1484 def _raise_compile_error(exception_msg):
1485 raise FluxityError(&#34;Error compiling Fluxity script:\n&#34; + exception_msg)
1486
1487 def _raise_exec_error(exception_msg):
1488 raise FluxityError(&#34;Error on doing exec() to create script code object:\n&#34; + exception_msg)
1489
1490 # ------------------------------------------------------ rendering
1491 def render_preview_frame(script, script_file, frame, out_folder, profile_file_path, editors_data_json=None):
1492 &#34;&#34;&#34;
1493 **script(str)** Script to be rendered as a string.
1494
1495 **script_file(str)** Absolute path to file containing script. If this is not provided methods some like *FluxityContext.get_script_dir()* will not function as intended.
1496
1497 **frame(int)** Frame to be rendered in range 0 - *(script_length - 1)*.
1498
1499 **out_folder(str)** Path to folder where rendered frame will be saved.
1500
1501 **profile_file_path(str)** Path to a file containing a file describing MLT profile used to when rendering the script.
1502
1503 **editors_data_json(str)** String representation of JSON object containing editors described in the script and their values. This is optional, not providing this will use default values given in script when rendering.
1504
1505 Renders a single frame from provided script.
1506
1507 **Returns:** (FluxityContext) Object created during rendering. This object has attributes *error* and *log_msg* providing error and logging information.
1508 &#34;&#34;&#34;
1509
1510 try:
1511 # Init script and context.
1512 error_msg, results = _init_script_and_context(script, script_file, out_folder, profile_file_path)
1513 if error_msg != None:
1514 fake_fctx = FluxityEmptyClass()
1515 fake_fctx.error = error_msg
1516 fake_fctx.log_msg = &#34;&#34;
1517 return fake_fctx
1518
1519 fscript, fctx = results
1520
1521 # Execute script to render a preview frame.
1522 fctx.priv_context.current_method = METHOD_INIT_SCRIPT
1523 fscript.call_init_script(fctx)
1524
1525 if editors_data_json != None:
1526 fctx.set_editors_data(editors_data_json)
1527
1528 fctx.priv_context.current_method = METHOD_INIT_RENDER
1529 fscript.call_init_render(fctx)
1530
1531 fctx.priv_context.current_method = METHOD_RENDER_FRAME
1532 fctx.priv_context.create_frame_surface(frame)
1533 w, h = fctx.get_dimensions()
1534 fscript.call_render_frame(frame, fctx, w, h)
1535
1536 return fctx
1537 except Exception as e:
1538 fctx.error = str(e) + traceback.format_exc(6,True)
1539 return fctx
1540
1541 def render_frame_sequence(script, script_file, in_frame, out_frame, out_folder, profile_file_path, editors_data_json=None, start_out_from_frame_one=False):
1542 &#34;&#34;&#34;
1543 **script(str)** Script to be rendered as a string.
1544
1545 **script_file(str)** Absolute path to file containing script. If this is not provided methods some like *FluxityContext.get_script_dir()* will not function as intended.
1546
1547 **in_frame(int)** First frame of rendered range.
1548
1549 **out_frame(int)** Last frame of rendered range, exclusive.
1550
1551 **out_folder(str)** Path to folder where rendered frame will be saved.
1552
1553 **profile_file_path(str)** Path to a file containing a file describing MLT profile used to when rendering the script.
1554
1555 **editors_data_json(str)** String representation of JSON object containing editors described in the script and their values. This is optional, not providing this will use default values given in script when rendering.
1556
1557 **start_out_from_frame_one(boolean)** Setting this *True* will cause numbering of rendered frame sequence to start from *1*, otherwise it will start from *in_frame*.
1558
1559 Renders a range of frames from provided script.
1560
1561 **Returns:** (dict) Dictionary object created during rendering with the following information:
1562
1563 * for each process it has *key -&gt; value* pair *process number(str) -&gt; path to first frame rendered by process(str)*.
1564 * if errors occurred during rendering it has *key -&gt; value* pair *fluxity.FLUXITY_ERROR_MSG -&gt; error message(str)*.
1565 * if script created log messages it has *key -&gt; value* pair *fluxity.FLUXITY_LOG_MSG -&gt; log message(str)*.
1566 &#34;&#34;&#34;
1567 # Some simple heuristics to decide how many processes will be used for rendering
1568 cpu_count = multiprocessing.cpu_count()
1569 threads = cpu_count - 2
1570 # Computer does not have that many cores, let&#39;s only use one.
1571 if threads &lt; 2:
1572 threads = 1
1573 # This gets diminshing returns so let&#39;s cap it at 8.
1574 if threads &gt; 8:
1575 threads = 8
1576 # If we are rendering a very small amount of frames, there isn&#39;t much benefit to use multiple processes.
1577 if out_frame - in_frame &lt; threads * 2:
1578 threads = 1
1579
1580 result_queue = multiprocessing.Queue()
1581
1582 jobs = []
1583 for i in range(threads):
1584
1585 render_data = ( script, script_file, in_frame, out_frame, out_folder, \
1586 profile_file_path, editors_data_json, start_out_from_frame_one)
1587
1588 proc_info = (i, threads, result_queue)
1589 p = multiprocessing.Process(target=_render_process_launch, args=(render_data, proc_info))
1590 jobs.append(p)
1591 p.start()
1592
1593 proc_fctx_dict = {}
1594 for proc in jobs:
1595 results_dict = result_queue.get()
1596 proc.join()
1597 proc_fctx_dict.update(results_dict)
1598
1599 return proc_fctx_dict
1600
1601 def _render_process_launch(render_data, proc_info):
1602
1603 try:
1604 script, script_file, in_frame, out_frame, out_folder, \
1605 profile_file_path, editors_data_json, start_out_from_frame_one = render_data
1606
1607 procnum, threads_count, result_queue = proc_info
1608
1609 # Used to communicate to app what happened.
1610 results_dict = {}
1611
1612 # Init script and context.
1613 error_msg, results = _init_script_and_context(script, script_file, out_folder, profile_file_path)
1614 if error_msg != None:
1615 results_dict[str(FLUXITY_ERROR_MSG) ] = str(error_msg)
1616 result_queue.put(results_dict)
1617 return
1618
1619 fscript, fctx = results
1620
1621 # Execute script to write frame sequence.
1622 fctx.priv_context.current_method = METHOD_INIT_SCRIPT
1623 fscript.call_init_script(fctx)
1624
1625 if editors_data_json != None:
1626 fctx.set_editors_data(editors_data_json)
1627
1628 fctx.priv_context.current_method = METHOD_INIT_RENDER
1629 fscript.call_init_render(fctx)
1630
1631 fctx.priv_context.first_rendered_frame_path = None # Should be clear but let&#39;s make sure.
1632 fctx.priv_context.current_method = METHOD_RENDER_FRAME
1633 fctx.priv_context.start_out_from_frame_one = start_out_from_frame_one
1634 fctx.priv_context.in_frame = in_frame
1635 fctx.priv_context.process_id = procnum
1636
1637 for frame in range(in_frame + procnum, out_frame, threads_count):
1638 fctx.priv_context.create_frame_surface(frame)
1639 w, h = fctx.get_dimensions()
1640 fscript.call_render_frame(frame, fctx, w, h)
1641 fctx.priv_context.write_out_frame()
1642
1643 results_dict[str(procnum)] = str(fctx.priv_context.first_rendered_frame_path)
1644 if len(fctx.log_msg) &gt; 0:
1645 results_dict[str(FLUXITY_LOG_MSG)] = str(fctx.log_msg)
1646
1647 result_queue.put(results_dict)
1648
1649 except Exception as e:
1650 fctx.error = str(e) + traceback.format_exc(6,True)
1651 results_dict[str(FLUXITY_ERROR_MSG)] = str(fctx.error)
1652 result_queue.put(results_dict)
1653
1654 def get_script_default_edit_data(script, script_file, out_folder, profile_file_path):
1655 &#34;&#34;&#34;
1656 **script(str)** Script to be rendered as a string.
1657
1658 **script_file(str)** Absolute path to a file containing script. If this is not provided, some methods like *FluxityContext.get_script_dir()* will not function as intended.
1659
1660 **out_folder(str)** Path to the folder where rendered frame will be saved.
1661
1662 **profile_file_path(str)** Path to a file containing a file describing a MLT profile used when rendering the script.
1663
1664 Creates a *FluxityContext* object, calls *init_script()* on it
1665
1666 **Returns:** (str, dict) Tuple of error message string and Python dict representation of Json object created with *FluxityContext.get_script_data()*. Error message string will be *None* if no error occurred.
1667 &#34;&#34;&#34;
1668
1669 # Init script and context.
1670 try:
1671 error_msg, results = _init_script_and_context(script, script_file, out_folder, profile_file_path)
1672 if error_msg != None:
1673 return (error_msg, None)
1674
1675 fscript, fctx = results
1676
1677 # Execute init script to create data structures.
1678 fctx.priv_context.current_method = METHOD_INIT_SCRIPT
1679 fscript.call_init_script(fctx)
1680
1681 data_json = fctx.get_script_data()
1682 edit_data = json.loads(data_json) # we want this as Python dict
1683 except Exception as e:
1684 return (str(e) + traceback.format_exc(6,True), None)
1685
1686 return (None, edit_data)
1687
1688 def _init_script_and_context(script, script_file, out_folder, profile_file_path):
1689 try:
1690
1691 fscript = FluxityScript(script)
1692 fscript.compile_script()
1693
1694 fctx = FluxityContext(script_file, out_folder)
1695 fctx.priv_context.load_profile(profile_file_path)
1696
1697 return (None, (fscript, fctx))
1698 except Exception as e:
1699 msg = str(e)
1700 return (msg, None)
1701
1702 # ---- Debug helper
1703 def _prints_to_log_file(log_file):
1704 so = se = open(log_file, &#39;w&#39;, buffering=1)
1705
1706 sys.stdout = os.fdopen(sys.stdout.fileno(), &#39;w&#39;, buffering=1)
1707
1708 os.dup2(so.fileno(), sys.stdout.fileno())
1709 os.dup2(se.fileno(), sys.stderr.fileno())
1710
1711
1712 </code></pre>
1713 </details>
1714 </section>
1715 <section>
1716 </section>
1717 <section>
1718 <h2 class="section-title" id="header-variables">Global variables</h2>
1719 <dl>
1720 <dt id="fluxity.EDITOR_CHECK_BOX"><code class="name">var <span class="ident">EDITOR_CHECK_BOX</span></code></dt>
1721 <dd>
1722 <div class="desc"><p>Editor for boolean value. Value is either <em>True</em> or <em>False</em></p></div>
1723 </dd>
1724 <dt id="fluxity.EDITOR_COLOR"><code class="name">var <span class="ident">EDITOR_COLOR</span></code></dt>
1725 <dd>
1726 <div class="desc"><p>Editor for colors. Value is a <em>(R,G,B,A)</em> tuple with values in range 0-1.</p></div>
1727 </dd>
1728 <dt id="fluxity.EDITOR_FILE_PATH"><code class="name">var <span class="ident">EDITOR_FILE_PATH</span></code></dt>
1729 <dd>
1730 <div class="desc"><p>Editor for selecting a file path. Value is Python pathname or <em>None</em>.</p></div>
1731 </dd>
1732 <dt id="fluxity.EDITOR_FLOAT"><code class="name">var <span class="ident">EDITOR_FLOAT</span></code></dt>
1733 <dd>
1734 <div class="desc"><p>Editor for float values.</p></div>
1735 </dd>
1736 <dt id="fluxity.EDITOR_FLOAT_RANGE"><code class="name">var <span class="ident">EDITOR_FLOAT_RANGE</span></code></dt>
1737 <dd>
1738 <div class="desc"><p>Editor for float values with a defined range of accepted values. Value is a 3-tuple <em>(default_val, min_val, max_val)</em>.</p></div>
1739 </dd>
1740 <dt id="fluxity.EDITOR_INT"><code class="name">var <span class="ident">EDITOR_INT</span></code></dt>
1741 <dd>
1742 <div class="desc"><p>Editor for integer values.</p></div>
1743 </dd>
1744 <dt id="fluxity.EDITOR_INT_RANGE"><code class="name">var <span class="ident">EDITOR_INT_RANGE</span></code></dt>
1745 <dd>
1746 <div class="desc"><p>Editor for integer values with a defined range of accepted values. Value is a 3-tuple <em>(default_val, min_val, max_val)</em></p></div>
1747 </dd>
1748 <dt id="fluxity.EDITOR_OPTIONS"><code class="name">var <span class="ident">EDITOR_OPTIONS</span></code></dt>
1749 <dd>
1750 <div class="desc"><p>Editor for selecting between
1751 2 - N
1752 string options. Value is tuple <em>(selected_index,[option_str_1, option_str_2, &hellip;])</em>.</p></div>
1753 </dd>
1754 <dt id="fluxity.EDITOR_PANGO_FONT"><code class="name">var <span class="ident">EDITOR_PANGO_FONT</span></code></dt>
1755 <dd>
1756 <div class="desc"><p>Editor for setting pango font properties.</p></div>
1757 </dd>
1758 <dt id="fluxity.EDITOR_PANGO_FONT_DEFAULT_VALUES"><code class="name">var <span class="ident">EDITOR_PANGO_FONT_DEFAULT_VALUES</span></code></dt>
1759 <dd>
1760 <div class="desc"><p>Pango Font Editor default values.</p></div>
1761 </dd>
1762 <dt id="fluxity.EDITOR_TEXT"><code class="name">var <span class="ident">EDITOR_TEXT</span></code></dt>
1763 <dd>
1764 <div class="desc"><p>Editor for strings.</p></div>
1765 </dd>
1766 <dt id="fluxity.EDITOR_TEXT_AREA"><code class="name">var <span class="ident">EDITOR_TEXT_AREA</span></code></dt>
1767 <dd>
1768 <div class="desc"><p>Editor for creating multiline text.</p></div>
1769 </dd>
1770 <dt id="fluxity.KEYFRAME_DISCRETE"><code class="name">var <span class="ident">KEYFRAME_DISCRETE</span></code></dt>
1771 <dd>
1772 <div class="desc"><p>Value after keyframe of this type is value at keyframe.</p></div>
1773 </dd>
1774 <dt id="fluxity.KEYFRAME_LINEAR"><code class="name">var <span class="ident">KEYFRAME_LINEAR</span></code></dt>
1775 <dd>
1776 <div class="desc"><p>Value after keyframe of this type is linearly interpolated using two surrounding keyframe values.</p></div>
1777 </dd>
1778 <dt id="fluxity.KEYFRAME_SMOOTH"><code class="name">var <span class="ident">KEYFRAME_SMOOTH</span></code></dt>
1779 <dd>
1780 <div class="desc"><p>Value after keyframe of this type is calculated using a Catmull-Rom curve created from four surrounding keyframe values.</p></div>
1781 </dd>
1782 <dt id="fluxity.PROFILE_COLORSPACE"><code class="name">var <span class="ident">PROFILE_COLORSPACE</span></code></dt>
1783 <dd>
1784 <div class="desc"><p>Profile colorspace, value is either 709, 601 or 2020.</p></div>
1785 </dd>
1786 <dt id="fluxity.PROFILE_DESCRIPTION"><code class="name">var <span class="ident">PROFILE_DESCRIPTION</span></code></dt>
1787 <dd>
1788 <div class="desc"><p>MLT Profile descriptiption string.</p></div>
1789 </dd>
1790 <dt id="fluxity.PROFILE_DISPLAY_ASPECT_DEN"><code class="name">var <span class="ident">PROFILE_DISPLAY_ASPECT_DEN</span></code></dt>
1791 <dd>
1792 <div class="desc"><p>Output image size fraction denominator.</p></div>
1793 </dd>
1794 <dt id="fluxity.PROFILE_DISPLAY_ASPECT_NUM"><code class="name">var <span class="ident">PROFILE_DISPLAY_ASPECT_NUM</span></code></dt>
1795 <dd>
1796 <div class="desc"><p>Output image size fraction numerator.</p></div>
1797 </dd>
1798 <dt id="fluxity.PROFILE_FRAME_RATE_DEN"><code class="name">var <span class="ident">PROFILE_FRAME_RATE_DEN</span></code></dt>
1799 <dd>
1800 <div class="desc"><p>Frame rate denominator.</p></div>
1801 </dd>
1802 <dt id="fluxity.PROFILE_FRAME_RATE_NUM"><code class="name">var <span class="ident">PROFILE_FRAME_RATE_NUM</span></code></dt>
1803 <dd>
1804 <div class="desc"><p>Frame rate numerator.</p></div>
1805 </dd>
1806 <dt id="fluxity.PROFILE_HEIGHT"><code class="name">var <span class="ident">PROFILE_HEIGHT</span></code></dt>
1807 <dd>
1808 <div class="desc"><p>Output image height in pixels.</p></div>
1809 </dd>
1810 <dt id="fluxity.PROFILE_PROGRESSIVE"><code class="name">var <span class="ident">PROFILE_PROGRESSIVE</span></code></dt>
1811 <dd>
1812 <div class="desc"><p>MLT Profile image is progressive if value is <em>True</em>, if value is <em>False</em> image is interlaced.</p></div>
1813 </dd>
1814 <dt id="fluxity.PROFILE_SAMPLE_ASPECT_DEN"><code class="name">var <span class="ident">PROFILE_SAMPLE_ASPECT_DEN</span></code></dt>
1815 <dd>
1816 <div class="desc"><p>Pixel size fraction denominator.</p></div>
1817 </dd>
1818 <dt id="fluxity.PROFILE_SAMPLE_ASPECT_NUM"><code class="name">var <span class="ident">PROFILE_SAMPLE_ASPECT_NUM</span></code></dt>
1819 <dd>
1820 <div class="desc"><p>Pixel size fraction numerator.</p></div>
1821 </dd>
1822 <dt id="fluxity.PROFILE_WIDTH"><code class="name">var <span class="ident">PROFILE_WIDTH</span></code></dt>
1823 <dd>
1824 <div class="desc"><p>Output image width in pixels.</p></div>
1825 </dd>
1826 </dl>
1827 </section>
1828 <section>
1829 <h2 class="section-title" id="header-functions">Functions</h2>
1830 <dl>
1831 <dt id="fluxity.get_script_default_edit_data"><code class="name flex">
1832 <span>def <span class="ident">get_script_default_edit_data</span></span>(<span>script, script_file, out_folder, profile_file_path)</span>
1833 </code></dt>
1834 <dd>
1835 <div class="desc"><p><strong>script(str)</strong> Script to be rendered as a string.</p>
1836 <p><strong>script_file(str)</strong> Absolute path to a file containing script. If this is not provided, some methods like <em>FluxityContext.get_script_dir()</em> will not function as intended.</p>
1837 <p><strong>out_folder(str)</strong> Path to the folder where rendered frame will be saved.</p>
1838 <p><strong>profile_file_path(str)</strong> Path to a file containing a file describing a MLT profile used when rendering the script.</p>
1839 <p>Creates a <em>FluxityContext</em> object, calls <em>init_script()</em> on it </p>
1840 <p><strong>Returns:</strong> (str, dict) Tuple of error message string and Python dict representation of Json object created with <em>FluxityContext.get_script_data()</em>. Error message string will be <em>None</em> if no error occurred.</p></div>
1841 <details class="source">
1842 <summary>
1843 <span>Expand source code</span>
1844 </summary>
1845 <pre><code class="python">def get_script_default_edit_data(script, script_file, out_folder, profile_file_path):
1846 &#34;&#34;&#34;
1847 **script(str)** Script to be rendered as a string.
1848
1849 **script_file(str)** Absolute path to a file containing script. If this is not provided, some methods like *FluxityContext.get_script_dir()* will not function as intended.
1850
1851 **out_folder(str)** Path to the folder where rendered frame will be saved.
1852
1853 **profile_file_path(str)** Path to a file containing a file describing a MLT profile used when rendering the script.
1854
1855 Creates a *FluxityContext* object, calls *init_script()* on it
1856
1857 **Returns:** (str, dict) Tuple of error message string and Python dict representation of Json object created with *FluxityContext.get_script_data()*. Error message string will be *None* if no error occurred.
1858 &#34;&#34;&#34;
1859
1860 # Init script and context.
1861 try:
1862 error_msg, results = _init_script_and_context(script, script_file, out_folder, profile_file_path)
1863 if error_msg != None:
1864 return (error_msg, None)
1865
1866 fscript, fctx = results
1867
1868 # Execute init script to create data structures.
1869 fctx.priv_context.current_method = METHOD_INIT_SCRIPT
1870 fscript.call_init_script(fctx)
1871
1872 data_json = fctx.get_script_data()
1873 edit_data = json.loads(data_json) # we want this as Python dict
1874 except Exception as e:
1875 return (str(e) + traceback.format_exc(6,True), None)
1876
1877 return (None, edit_data)</code></pre>
1878 </details>
1879 </dd>
1880 </dl>
1881 </section>
1882 <section>
1883 <h2 class="section-title" id="header-classes">Classes</h2>
1884 <dl>
1885 <dt id="fluxity.AffineTransform"><code class="flex name class">
1886 <span>class <span class="ident">AffineTransform</span></span>
1887 </code></dt>
1888 <dd>
1889 <div class="desc"><p>Object for describing animated affine transforms and applying them on <em><code>cairo.Context</code></em>.</p>
1890 <p>On creation object creates following instance <em><code><a title="fluxity.AnimatedValue" href="#fluxity.AnimatedValue">AnimatedValue</a></code></em> attributes:</p>
1891 <p><strong><code>x</code></strong> X position in pixels.</p>
1892 <p><strong><code>y</code></strong> Y position in pixels.</p>
1893 <p><strong><code>anchor_x</code></strong> Rotation and scaling offset from <em><code>source</code></em> top left corner in x axis pixels.</p>
1894 <p><strong><code>anchor_y</code></strong> Rotation and scaling offset from <em><code>source</code></em> top left corner in y axis pixels.</p>
1895 <p><strong><code>scale_x</code></strong> Scaling in x-axis as float value.</p>
1896 <p><strong><code>scale_y</code></strong> Scaling in y-axis as float value.</p>
1897 <p><strong><code>rotation</code></strong> Rotation in degrees.</p>
1898 <p>Default value for all attributes is value 0.0 at keyframe 0, except <code>scale_x</code> and <code>scale_y</code> which have default value of 1.0 at keyframe 0.</p>
1899 <p>The intended usage pattern:</p>
1900 <ul>
1901 <li>
1902 <p>create <em><code><a title="fluxity.AffineTransform" href="#fluxity.AffineTransform">AffineTransform</a></code></em> object and set values to needed attributes to create animations.</p>
1903 </li>
1904 <li>
1905 <p>for each frame first call method <em><code><a title="fluxity.AffineTransform.apply_transform" href="#fluxity.AffineTransform.apply_transform">AffineTransform.apply_transform()</a></code></em> to apply the affine transform.</p>
1906 </li>
1907 <li>
1908 <p>draw <em><code>source</code></em> in <code>origo(0,0)</code> position.</p>
1909 </li>
1910 </ul></div>
1911 <details class="source">
1912 <summary>
1913 <span>Expand source code</span>
1914 </summary>
1915 <pre><code class="python">class AffineTransform:
1916
1917 &#34;&#34;&#34;
1918 Object for describing animated affine transforms and applying them on *`cairo.Context`*.
1919
1920 On creation object creates following instance *`fluxity.AnimatedValue`* attributes:
1921
1922 **`x`** X position in pixels.
1923
1924 **`y`** Y position in pixels.
1925
1926 **`anchor_x`** Rotation and scaling offset from *`source`* top left corner in x axis pixels.
1927
1928 **`anchor_y`** Rotation and scaling offset from *`source`* top left corner in y axis pixels.
1929
1930 **`scale_x`** Scaling in x-axis as float value.
1931
1932 **`scale_y`** Scaling in y-axis as float value.
1933
1934 **`rotation`** Rotation in degrees.
1935
1936 Default value for all attributes is value 0.0 at keyframe 0, except `scale_x` and `scale_y` which have default value of 1.0 at keyframe 0.
1937
1938 The intended usage pattern:
1939
1940 * create *`fluxity.AffineTransform`* object and set values to needed attributes to create animations.
1941
1942 * for each frame first call method *`fluxity.AffineTransform.apply_transform()`* to apply the affine transform.
1943
1944 * draw *`source`* in `origo(0,0)` position.
1945 &#34;&#34;&#34;
1946
1947 def __init__(self):
1948 self.x = AnimatedValue()
1949 self.y = AnimatedValue()
1950 self.anchor_x = AnimatedValue()
1951 self.anchor_y = AnimatedValue()
1952 self.scale_x = AnimatedValue(1.0)
1953 self.scale_y = AnimatedValue(1.0)
1954 self.rotation = AnimatedValue()
1955
1956 def apply_transform(self, cr, frame):
1957 &#34;&#34;&#34;
1958 **`cr(cairo.Context)`** a `cairo.Context` object.
1959
1960 **`frame(int)`** Frame number in range 0 - (plugin length).
1961
1962 Applies affine transform defined by object instance at given frame on `cairo.Context` object.
1963 &#34;&#34;&#34;
1964 scale_x = self.scale_x.get_value(frame)
1965 scale_y = self.scale_y.get_value(frame)
1966 rotation_angle = self.rotation.get_value(frame)
1967
1968 anchor_x = scale_x * self.anchor_x.get_value(frame)
1969 anchor_y = scale_y * self.anchor_y.get_value(frame)
1970
1971 axr, ayr = self._rotate_point_around_origo(rotation_angle, (anchor_x, anchor_y))
1972
1973 tx = self.x.get_value(frame) - axr
1974 ty = self.y.get_value(frame) - ayr
1975
1976 cr.translate(tx, ty)
1977 cr.rotate(math.radians(rotation_angle))
1978 cr.scale(scale_x, scale_y)
1979
1980 def _rotate_point_around_origo(self, rotation_angle, p):
1981 px, py = p
1982 angle_rad = math.radians(rotation_angle)
1983 sin_val = math.sin(angle_rad)
1984 cos_val = math.cos(angle_rad)
1985 new_x = px * cos_val - py * sin_val
1986 new_y = px * sin_val + py * cos_val
1987 return (new_x, new_y)</code></pre>
1988 </details>
1989 <h3>Methods</h3>
1990 <dl>
1991 <dt id="fluxity.AffineTransform.apply_transform"><code class="name flex">
1992 <span>def <span class="ident">apply_transform</span></span>(<span>self, cr, frame)</span>
1993 </code></dt>
1994 <dd>
1995 <div class="desc"><p><strong><code>cr(cairo.Context)</code></strong> a <code>cairo.Context</code> object.</p>
1996 <p><strong><code>frame(int)</code></strong> Frame number in range 0 - (plugin length).</p>
1997 <p>Applies affine transform defined by object instance at given frame on <code>cairo.Context</code> object.</p></div>
1998 <details class="source">
1999 <summary>
2000 <span>Expand source code</span>
2001 </summary>
2002 <pre><code class="python">def apply_transform(self, cr, frame):
2003 &#34;&#34;&#34;
2004 **`cr(cairo.Context)`** a `cairo.Context` object.
2005
2006 **`frame(int)`** Frame number in range 0 - (plugin length).
2007
2008 Applies affine transform defined by object instance at given frame on `cairo.Context` object.
2009 &#34;&#34;&#34;
2010 scale_x = self.scale_x.get_value(frame)
2011 scale_y = self.scale_y.get_value(frame)
2012 rotation_angle = self.rotation.get_value(frame)
2013
2014 anchor_x = scale_x * self.anchor_x.get_value(frame)
2015 anchor_y = scale_y * self.anchor_y.get_value(frame)
2016
2017 axr, ayr = self._rotate_point_around_origo(rotation_angle, (anchor_x, anchor_y))
2018
2019 tx = self.x.get_value(frame) - axr
2020 ty = self.y.get_value(frame) - ayr
2021
2022 cr.translate(tx, ty)
2023 cr.rotate(math.radians(rotation_angle))
2024 cr.scale(scale_x, scale_y)</code></pre>
2025 </details>
2026 </dd>
2027 </dl>
2028 </dd>
2029 <dt id="fluxity.AnimatedValue"><code class="flex name class">
2030 <span>class <span class="ident">AnimatedValue</span></span>
2031 <span>(</span><span>value=0.0)</span>
2032 </code></dt>
2033 <dd>
2034 <div class="desc"><p>Object for animating a float value.</p>
2035 <p>Changing value is controlled by adding keyframes.</p>
2036 <p>A keyframe has <em>frame position, value</em> and <em>type</em>. There are three types of keyframes: <code><a title="fluxity.KEYFRAME_LINEAR" href="#fluxity.KEYFRAME_LINEAR">KEYFRAME_LINEAR</a></code>, <code><a title="fluxity.KEYFRAME_SMOOTH" href="#fluxity.KEYFRAME_SMOOTH">KEYFRAME_SMOOTH</a></code> and <code><a title="fluxity.KEYFRAME_DISCRETE" href="#fluxity.KEYFRAME_DISCRETE">KEYFRAME_DISCRETE</a></code>.</p>
2037 <ul>
2038 <li>
2039 <p><strong><code><a title="fluxity.KEYFRAME_LINEAR" href="#fluxity.KEYFRAME_LINEAR">KEYFRAME_LINEAR</a></code></strong> Value after keyframe is linearly interpolated using two surrounding keyframe values.</p>
2040 </li>
2041 <li>
2042 <p><strong><code><a title="fluxity.KEYFRAME_SMOOTH" href="#fluxity.KEYFRAME_SMOOTH">KEYFRAME_SMOOTH</a></code></strong> Value after keyframe is calculated using a Catmull-Rom curve created from four surrounding keyframe values.</p>
2043 </li>
2044 <li>
2045 <p><strong><code><a title="fluxity.KEYFRAME_DISCRETE" href="#fluxity.KEYFRAME_DISCRETE">KEYFRAME_DISCRETE</a></code></strong> Value after keyframe is value at keyframe.</p>
2046 </li>
2047 </ul>
2048 <p>Implementation assumes there always being a keyframe at frame 0, and removing that will result in undefined behaviour. It is of course possible to overwrite existing keyframe at frame 0 using method <em>add_keyframe_at_frame().</em></p></div>
2049 <details class="source">
2050 <summary>
2051 <span>Expand source code</span>
2052 </summary>
2053 <pre><code class="python">class AnimatedValue:
2054
2055 &#34;&#34;&#34;
2056 Object for animating a float value.
2057
2058 Changing value is controlled by adding keyframes.
2059
2060 A keyframe has *frame position, value* and *type*. There are three types of keyframes: `KEYFRAME_LINEAR`, `KEYFRAME_SMOOTH` and `KEYFRAME_DISCRETE`.
2061
2062 * **`KEYFRAME_LINEAR`** Value after keyframe is linearly interpolated using two surrounding keyframe values.
2063
2064 * **`KEYFRAME_SMOOTH`** Value after keyframe is calculated using a Catmull-Rom curve created from four surrounding keyframe values.
2065
2066 * **`KEYFRAME_DISCRETE`** Value after keyframe is value at keyframe.
2067
2068 Implementation assumes there always being a keyframe at frame 0, and removing that will result in undefined behaviour. It is of course possible to overwrite existing keyframe at frame 0 using method *add_keyframe_at_frame().*
2069 &#34;&#34;&#34;
2070 def __init__(self, value=0.0):
2071 # We enforce a keyframe always existing in frame 0
2072 self.keyframes = [(0, value, KEYFRAME_LINEAR)]
2073
2074 def add_keyframe_at_frame(self, frame, value, kf_type):
2075 &#34;&#34;&#34;
2076 **`frame(int)`** Frame number in range 0 - (plugin length).
2077
2078 **`value(float)`** A float value.
2079
2080 **`kf_type(KEYFRAME_LINEAR|KEYFRAME_SMOOTH|KEYFRAME_DISCRETE)`** Type of added keyframe.
2081
2082 Adds or overwrites a keyframe.
2083
2084 If frame is on existing keyframe that keyframe is replaced.
2085
2086 If frame is between two keyframes a new keyframe is added between keyframes.
2087
2088 If frame is after last keyframe a new keyframe is appended.
2089 &#34;&#34;&#34;
2090
2091 # Replace if kf in frame exists.
2092 new_kf = (frame, value, kf_type)
2093 kf_index_on_frame = self._frame_has_keyframe(frame)
2094 if kf_index_on_frame != -1:
2095 self.keyframes.pop(kf_index_on_frame)
2096 self.keyframes.insert(kf_index_on_frame, new_kf)
2097 return
2098
2099 # Insert between if frame between two kfs.
2100 for i in range(0, len(self.keyframes)):
2101 kf_frame, kf_value, kf_type = self.keyframes[i]
2102 if kf_frame &gt; frame:
2103 prev_frame, prev_value, prev_type = self.keyframes[i - 1]
2104 self.keyframes.insert(i, new_kf)
2105 self.active_kf_index = i
2106 return
2107
2108 # Append last if after last kf.
2109 self.keyframes.append(new_kf)
2110
2111 def _frame_has_keyframe(self, frame):
2112 for i in range(0, len(self.keyframes)):
2113 kf_frame, kf_value, type = self.keyframes[i]
2114 if frame == kf_frame:
2115 return i
2116
2117 return -1
2118
2119 def get_value(self, frame):
2120 &#34;&#34;&#34;
2121 **`frame(int)`** Frame number in range 0 - (plugin length).
2122
2123 Computes and returns value at frame using current keyframe values, positions and types.
2124
2125 **Returns:** (float) value at frame.
2126 &#34;&#34;&#34;
2127 last_frame, last_value, last_type = self.keyframes[-1]
2128 if frame &gt;= last_frame: # This also handles case len(self.keyframes) == 1 because first keyframe always at frame 0.
2129 return last_value
2130
2131 for i in range(0, len(self.keyframes) - 1):
2132 kf_frame, kf_value, kf_type = self.keyframes[i]
2133 if frame == kf_frame:
2134 return kf_value
2135 next_frame, next_value, next_type = self.keyframes[i + 1]
2136 if frame == next_frame:
2137 return next_value
2138 if frame &gt; kf_frame and frame &lt; next_frame:
2139 if kf_type == KEYFRAME_LINEAR:
2140 fract = (frame - kf_frame) / (next_frame - kf_frame)
2141 return kf_value + fract * (next_value - kf_value)
2142 elif kf_type == KEYFRAME_SMOOTH:
2143 return self._get_smooth_value(i, frame)
2144 else: # KEYFRAME_DISCRETE
2145 return kf_value
2146
2147 return None # We absolutely want to crash if somehow we hit this.
2148
2149 def _get_smooth_value(self, i, frame):
2150 # Get indexes of the four keyframes that affect the drawn curve.
2151 prev = i
2152 if i == 0:
2153 prev_prev = 0
2154 else:
2155 prev_prev = i - 1
2156
2157 next = i + 1
2158 if next &gt;= len(self.keyframes):
2159 next = len(self.keyframes) - 1
2160
2161 next_next = next + 1
2162 if next_next &gt;= len(self.keyframes):
2163 next_next = len(self.keyframes) - 1
2164
2165 # Get keyframes.
2166 frame_pp, val0, kf_type = self.keyframes[prev_prev]
2167 frame_p, val1, kf_type = self.keyframes[prev]
2168 frame_n, val2, kf_type = self.keyframes[next]
2169 frame_nn, val3, kf_type = self.keyframes[next_next]
2170
2171 # Get value
2172 fract = (frame - frame_p) / (frame_n - frame_p)
2173 smooth_val = self._catmull_rom_interpolate(val0, val1, val2, val3, fract)
2174 return smooth_val
2175
2176 # These all need to be doubles.
2177 def _catmull_rom_interpolate(self, y0, y1, y2, y3, t):
2178 t2 = t * t
2179 a0 = -0.5 * y0 + 1.5 * y1 - 1.5 * y2 + 0.5 * y3
2180 a1 = y0 - 2.5 * y1 + 2 * y2 - 0.5 * y3
2181 a2 = -0.5 * y0 + 0.5 * y2
2182 a3 = y1
2183 return a0 * t * t2 + a1 * t2 + a2 * t + a3</code></pre>
2184 </details>
2185 <h3>Methods</h3>
2186 <dl>
2187 <dt id="fluxity.AnimatedValue.add_keyframe_at_frame"><code class="name flex">
2188 <span>def <span class="ident">add_keyframe_at_frame</span></span>(<span>self, frame, value, kf_type)</span>
2189 </code></dt>
2190 <dd>
2191 <div class="desc"><p><strong><code>frame(int)</code></strong> Frame number in range 0 - (plugin length).</p>
2192 <p><strong><code>value(float)</code></strong> A float value.</p>
2193 <p><strong><code>kf_type(KEYFRAME_LINEAR|KEYFRAME_SMOOTH|KEYFRAME_DISCRETE)</code></strong> Type of added keyframe.</p>
2194 <p>Adds or overwrites a keyframe.</p>
2195 <p>If frame is on existing keyframe that keyframe is replaced.</p>
2196 <p>If frame is between two keyframes a new keyframe is added between keyframes.</p>
2197 <p>If frame is after last keyframe a new keyframe is appended.</p></div>
2198 <details class="source">
2199 <summary>
2200 <span>Expand source code</span>
2201 </summary>
2202 <pre><code class="python">def add_keyframe_at_frame(self, frame, value, kf_type):
2203 &#34;&#34;&#34;
2204 **`frame(int)`** Frame number in range 0 - (plugin length).
2205
2206 **`value(float)`** A float value.
2207
2208 **`kf_type(KEYFRAME_LINEAR|KEYFRAME_SMOOTH|KEYFRAME_DISCRETE)`** Type of added keyframe.
2209
2210 Adds or overwrites a keyframe.
2211
2212 If frame is on existing keyframe that keyframe is replaced.
2213
2214 If frame is between two keyframes a new keyframe is added between keyframes.
2215
2216 If frame is after last keyframe a new keyframe is appended.
2217 &#34;&#34;&#34;
2218
2219 # Replace if kf in frame exists.
2220 new_kf = (frame, value, kf_type)
2221 kf_index_on_frame = self._frame_has_keyframe(frame)
2222 if kf_index_on_frame != -1:
2223 self.keyframes.pop(kf_index_on_frame)
2224 self.keyframes.insert(kf_index_on_frame, new_kf)
2225 return
2226
2227 # Insert between if frame between two kfs.
2228 for i in range(0, len(self.keyframes)):
2229 kf_frame, kf_value, kf_type = self.keyframes[i]
2230 if kf_frame &gt; frame:
2231 prev_frame, prev_value, prev_type = self.keyframes[i - 1]
2232 self.keyframes.insert(i, new_kf)
2233 self.active_kf_index = i
2234 return
2235
2236 # Append last if after last kf.
2237 self.keyframes.append(new_kf)</code></pre>
2238 </details>
2239 </dd>
2240 <dt id="fluxity.AnimatedValue.get_value"><code class="name flex">
2241 <span>def <span class="ident">get_value</span></span>(<span>self, frame)</span>
2242 </code></dt>
2243 <dd>
2244 <div class="desc"><p><strong><code>frame(int)</code></strong> Frame number in range 0 - (plugin length).</p>
2245 <p>Computes and returns value at frame using current keyframe values, positions and types.</p>
2246 <p><strong>Returns:</strong> (float) value at frame.</p></div>
2247 <details class="source">
2248 <summary>
2249 <span>Expand source code</span>
2250 </summary>
2251 <pre><code class="python">def get_value(self, frame):
2252 &#34;&#34;&#34;
2253 **`frame(int)`** Frame number in range 0 - (plugin length).
2254
2255 Computes and returns value at frame using current keyframe values, positions and types.
2256
2257 **Returns:** (float) value at frame.
2258 &#34;&#34;&#34;
2259 last_frame, last_value, last_type = self.keyframes[-1]
2260 if frame &gt;= last_frame: # This also handles case len(self.keyframes) == 1 because first keyframe always at frame 0.
2261 return last_value
2262
2263 for i in range(0, len(self.keyframes) - 1):
2264 kf_frame, kf_value, kf_type = self.keyframes[i]
2265 if frame == kf_frame:
2266 return kf_value
2267 next_frame, next_value, next_type = self.keyframes[i + 1]
2268 if frame == next_frame:
2269 return next_value
2270 if frame &gt; kf_frame and frame &lt; next_frame:
2271 if kf_type == KEYFRAME_LINEAR:
2272 fract = (frame - kf_frame) / (next_frame - kf_frame)
2273 return kf_value + fract * (next_value - kf_value)
2274 elif kf_type == KEYFRAME_SMOOTH:
2275 return self._get_smooth_value(i, frame)
2276 else: # KEYFRAME_DISCRETE
2277 return kf_value
2278
2279 return None # We absolutely want to crash if somehow we hit this.</code></pre>
2280 </details>
2281 </dd>
2282 </dl>
2283 </dd>
2284 <dt id="fluxity.FluxityContext"><code class="flex name class">
2285 <span>class <span class="ident">FluxityContext</span></span>
2286 <span>(</span><span>script_file, output_folder)</span>
2287 </code></dt>
2288 <dd>
2289 <div class="desc"></div>
2290 <details class="source">
2291 <summary>
2292 <span>Expand source code</span>
2293 </summary>
2294 <pre><code class="python">class FluxityContext:
2295
2296 def __init__(self, script_file, output_folder):
2297 self.priv_context = FluxityContextPrivate(output_folder)
2298 self.script_file = script_file
2299 self.data = {}
2300 self.editors = {} # editors and script length
2301 self.editor_tooltips = {}
2302 self.length = DEFAULT_LENGTH
2303 self.name = &#34;Name Not Set&#34;
2304 self.version = 1
2305 self.author = &#34;Author Not Set&#34;
2306 self.error = None
2307 self.log_msg = &#34;&#34;
2308
2309 def get_frame_cr(self):
2310 &#34;&#34;&#34;
2311 For every rendered frame method *`render_frame()`* is called and a new **`cairo.ImageSurface`** object is created.
2312
2313 This method provides access to **`cairo.Context`** object that can be used to draw onto that image surface. This is the way that output is achieved with **Flowblade Media Plugins**.
2314
2315 After method *`render_frame()`* exits, **`cairo.Context`** object is no longer valid and contents of **`cairo.ImageSurface`** are saved to disk.
2316
2317 Must be called in script method *`render_frame()`*.
2318
2319 **Returns:** (**`cairo.Context`**) Context object that can be drawn onto.
2320 &#34;&#34;&#34;
2321 return self.priv_context.frame_cr
2322
2323 def get_dimensions(self):
2324 &#34;&#34;&#34;
2325 Pixel size of output image.
2326
2327 **Returns:** (int, int) Tuple (width, height) of output image size.
2328 &#34;&#34;&#34;
2329 w = self.priv_context.profile.get_profile_property(PROFILE_WIDTH)
2330 h = self.priv_context.profile.get_profile_property(PROFILE_HEIGHT)
2331 return (w, h)
2332
2333 def get_profile_property(self, p_property):
2334 &#34;&#34;&#34;
2335 **`p_property(str):`** propertyr identyfier, e.g. `fluxity.PROFILE_PROGRESSIVE`.
2336
2337 Used to access properties of MLT profile set before running the script that defines e.g. output image size.
2338
2339 **Returns:** (int || boolean || string) Value depends on which profile property is being accessed.
2340 &#34;&#34;&#34;
2341 return self.priv_context.profile.get_profile_property(p_property)
2342
2343 def set_name(self, name):
2344 &#34;&#34;&#34;
2345 **`name(str):`** name of script displayed to user.
2346
2347 Sets name of the script displayed to the user. Must be called in script method *`init_script()`*.
2348 &#34;&#34;&#34;
2349 self.priv_context.error_on_wrong_method(&#34;set_name()&#34;, METHOD_INIT_SCRIPT)
2350 self.name = name
2351
2352
2353 def set_version(self, version):
2354 &#34;&#34;&#34;
2355 **`version(int):`** version of script, use increasing integer numbering. Default value is *1*.
2356
2357 Sets version of script. Must be called in script method *`init_script()`*.
2358 &#34;&#34;&#34;
2359 self.priv_context.error_on_wrong_method(&#34;set_version()&#34;, METHOD_INIT_SCRIPT)
2360 self.version = version
2361
2362 def set_author(self, author):
2363 &#34;&#34;&#34;
2364 **`author(str):`** name of script creator.
2365
2366 Sets author of the script. Must be called in script method *init_script()*.
2367 &#34;&#34;&#34;
2368 self.author = author
2369
2370 def set_frame_name(self, frame_name):
2371 &#34;&#34;&#34;
2372 **`frame_name(str):`** name used before number part in rendered frame files.
2373 &#34;&#34;&#34;
2374 self.priv_context.frame_name = frame_name
2375
2376 def set_data_obj(self, label, item):
2377 &#34;&#34;&#34;
2378 **`label(str):`** label used to access data later using *`get_data_obj(self, label)`*.
2379
2380 **`item(obj):`** data item being saved.
2381
2382 Saves data to be used later during execution of script. Using **global** would obviously be possible to replace this, but this is made available as a more clean solution.
2383 &#34;&#34;&#34;
2384 self.data[label] = item
2385
2386 def get_data_obj(self, label):
2387 &#34;&#34;&#34;
2388 **`label(str):`** label of saved data item.
2389
2390 Gives access to previously saved data.
2391
2392 **Returns:** (obj) Saved data item.
2393 &#34;&#34;&#34;
2394 return self.data[label]
2395
2396 def set_length(self, length):
2397 &#34;&#34;&#34;
2398 **`length(int):`** New length of script in frames.
2399
2400 Sets length of script output in frames.
2401
2402 Must *not* be called in *`render_frames()`*.
2403 &#34;&#34;&#34;
2404 self.length = length
2405
2406 def get_length(self):
2407 &#34;&#34;&#34;
2408 **Returns:** (int) Length of script in frames.
2409 &#34;&#34;&#34;
2410 return self.length
2411
2412 def add_editor(self, name, type, default_value, tooltip=None):
2413 &#34;&#34;&#34;
2414 **`name(str):`** Name for editor.
2415
2416 **`type(int):`** Value either *`EDITOR_FLOAT`, `EDITOR_INT`, `EDITOR_COLOR`, `EDITOR_FILE_PATH`, `EDITOR_OPTIONS`, `EDITOR_CHECK_BOX`, `EDITOR_FLOAT_RANGE`, `EDITOR_INT_RANGE`.*
2417
2418 **`default_value(str||int||float||tuple):`** Data type depends on editor type:
2419
2420 * `EDITOR_TEXT`(str),
2421
2422 * `EDITOR_TEXT_AREA`(str),
2423
2424 * `EDITOR_FLOAT`(float),
2425
2426 * `EDITOR_INT`(int),
2427
2428 * `EDITOR_COLOR`(4-tuple with float values in range 0-1, (R,G,B,A)),
2429
2430 * `EDITOR_FILE_PATH`(str),
2431
2432 * `EDITOR_OPTIONS`(2-tuple (int, [str]), (selected_index,[option_str_1, option_str_2, ...]),
2433
2434 * `EDITOR_CHECK_BOX`(bool),
2435
2436 * `EDITOR_FLOAT_RANGE`(3-tuple with float values, (default, min, max)),
2437
2438 * `EDITOR_INT_RANGE`(3-tuple with int values, (default, min, max))
2439
2440 * `EDITOR_PANGO_FONT` (17-tuple (font_family, font_face, font_size, alignment, color_rgba,
2441 fill_on, outline_color_rgba, outline_on, outline_width, shadow_on, shadow_color_rgb,
2442 shadow_opacity, shadow_xoff, shadow_yoff, shadow_blur,
2443 gradient_color_rgba, gradient_direction))
2444
2445 **`tooltip(str, optional):`** Tooltip for editor if presented in GUI.
2446
2447 Defines possible GUI editors used to affect script rendering. Edited value is accessed with method *get_editor_value(self, name, frame=0)*.
2448
2449 Data describing editors can be accessed with *get_script_data(self)*. Edited values are made available for script with *set_editors_data(self, editors_data_json)*.
2450
2451 Must be called in script method *init_script()*.
2452 &#34;&#34;&#34;
2453 self.priv_context.error_on_wrong_method(&#34;add_editor()&#34;, METHOD_INIT_SCRIPT)
2454 self.editors[name] = (type, default_value)
2455 if tooltip != None:
2456 self.editor_tooltips[name] = tooltip
2457
2458 def get_editor_value(self, name, frame=0):
2459 &#34;&#34;&#34;
2460 **`name(str):`** Name of editor.
2461
2462 **`frame(int):`** Frame in range 0 - (script length - 1).
2463
2464 Value of edited data at given frame. We currently have no animated values, but they will added with future API updates.
2465
2466 **Returns:** (obj) Value at frame.
2467
2468 Data type depends on editor type:
2469
2470 * `EDITOR_TEXT`(str),
2471
2472 * `EDITOR_TEXT_AREA`(str),
2473
2474 * `EDITOR_FLOAT`(float),
2475
2476 * `EDITOR_INT`(int),
2477
2478 * `EDITOR_COLOR`(4-tuple with float values in range 0-1, (R,G,B,A)),
2479
2480 * `EDITOR_FILE_PATH`(str),
2481
2482 * `EDITOR_OPTIONS`(selection index int),
2483
2484 * `EDITOR_CHECK_BOX`(bool),
2485
2486 * `EDITOR_FLOAT_RANGE`(3-tuple with float values, (default, min, max)),
2487
2488 * `EDITOR_INT_RANGE`(3-tuple with int values, (default, min, max))
2489
2490 * `EDITOR_PANGO_FONT`(17-tuple (font_family, font_face, font_size, alignment, color_rgba,
2491 fill_on, outline_color_rgba, outline_on, outline_width, shadow_on, shadow_color_rgb,
2492 shadow_opacity, shadow_xoff, shadow_yoff, shadow_blur,
2493 gradient_color_rgba, gradient_direction))
2494 &#34;&#34;&#34;
2495 try:
2496 type, value = self.editors[name]
2497 if type == EDITOR_INT_RANGE or type == EDITOR_FLOAT_RANGE:
2498 val, min, max = value
2499 return val
2500 elif type == EDITOR_OPTIONS:
2501 selected_index, options = value
2502 return selected_index
2503 return value
2504 except Exception as e:
2505 exception_msg = &#34;No editor for name &#39;&#34; + name + &#34;&#39; found.&#34;
2506 _raise_fluxity_error(exception_msg)
2507
2508 def get_script_data(self):
2509 &#34;&#34;&#34;
2510 Returns data of all editors and their default values, and script metadata like script author and version.
2511
2512 Output can be turned into Python object tree using *json.loads()* method.
2513
2514 **Returns:** (str) string representation of JSON object.
2515 &#34;&#34;&#34;
2516 script_data = {}
2517 script_data[&#34;length&#34;] = self.length
2518 script_data[&#34;name&#34;] = self.name
2519 script_data[&#34;version&#34;] = self.version
2520 script_data[&#34;author&#34;] = self.author
2521
2522 editors_list = []
2523 for name in self.editors:
2524 type, value = self.editors[name]
2525 json_obj = [name, type, value]
2526 editors_list.append(json_obj)
2527
2528 script_data[&#34;editors_list&#34;] = editors_list # this is dict inside FluxityContext object, but is given out as list for convenience of Flowblade app integration.
2529 script_data[&#34;tooltips_list&#34;] = self.editor_tooltips
2530
2531 return json.dumps(script_data)
2532
2533 def get_script_dir(self):
2534 &#34;&#34;&#34;
2535 Returns path to directory where the script being executed is located.
2536
2537 Sometimes script directory information is not available (e.g. when executing a non-saved script in Flowblade *Script Tool* application) and *None* is returned. It is recommended that all Fluxity scripts handle getting *None* gracefully.
2538
2539 This functionality is useful when script is being distributed with some associated media files.
2540
2541 **Returns:** (str) script directory path or *None*.
2542 &#34;&#34;&#34;
2543 if self.script_file == None:
2544 return None
2545
2546 dir_path = os.path.dirname(self.script_file) + &#34;/&#34;
2547 return dir_path
2548
2549 def set_editors_data(self, editors_data_json):
2550 &#34;&#34;&#34;
2551 **`editors_data_json(str):`** string representation of JSON object.
2552
2553 Sets edited data to be used when rendering.
2554
2555 Input string must describe JSON object that can be turned into usable editor data.
2556
2557 Example with `EDITOR_FLOAT` and `EDITOR_COLOR`:
2558
2559 ```
2560 [
2561 [&#34;Position X&#34;, 2, 1.0],
2562 [&#34;BG Color&#34;, 4, [0.8, 0.2, 0.2, 1.0]]
2563 ]
2564 ```
2565
2566 General form:
2567
2568 ```
2569 [
2570 [&lt;name&gt;, &lt;type&gt;, &lt;value&gt;],
2571 ...
2572 ]
2573 ```
2574
2575 Using this method is not needed when writing **Flowblade Media Plugins**, application handles setting editors data.
2576
2577 Should be called in script method *init_render()*.
2578 &#34;&#34;&#34;
2579 new_editors_list = json.loads(editors_data_json)
2580 for editor in new_editors_list:
2581 name, type, value = editor
2582 self.editors[name] = (type, value)
2583
2584 def create_text_layout(self, font_data):
2585 &#34;&#34;&#34;
2586 **`font_data(tuple)`** this tuple can be acquired by calling *FluxityContext.get_editor_value()* on editors of type *EDITOR_PANGO_FONT*.
2587
2588 Creates objects used to draw text.
2589
2590 **Returns:** (fluxity.PangoTextLayout) object for drawing text.
2591 &#34;&#34;&#34;
2592 return PangoTextLayout(font_data)
2593
2594 def log_line(self, log_line):
2595 &#34;&#34;&#34;
2596 **`log_line(str):`** line of text.
2597
2598 Adds a line of text to log message displayed after render completion or error.
2599 &#34;&#34;&#34;
2600 self.log_msg = self.log_msg + log_line + &#34;\n&#34;
2601
2602 def set_prints_to_log_file(self, log_file):
2603 &#34;&#34;&#34;
2604 **`log_file(str):`** File path.
2605
2606 Save output from &#39;print()&#39; to file at given path. Must be called in script method *init_script()*.
2607 &#34;&#34;&#34;
2608 self.priv_context.error_on_wrong_method(&#34;add_editor()&#34;, METHOD_INIT_SCRIPT)
2609 _prints_to_log_file(log_file)</code></pre>
2610 </details>
2611 <h3>Methods</h3>
2612 <dl>
2613 <dt id="fluxity.FluxityContext.add_editor"><code class="name flex">
2614 <span>def <span class="ident">add_editor</span></span>(<span>self, name, type, default_value, tooltip=None)</span>
2615 </code></dt>
2616 <dd>
2617 <div class="desc"><p><strong><code>name(str):</code></strong> Name for editor.</p>
2618 <p><strong><code>type(int):</code></strong> Value either <em><code><a title="fluxity.EDITOR_FLOAT" href="#fluxity.EDITOR_FLOAT">EDITOR_FLOAT</a></code>, <code><a title="fluxity.EDITOR_INT" href="#fluxity.EDITOR_INT">EDITOR_INT</a></code>, <code><a title="fluxity.EDITOR_COLOR" href="#fluxity.EDITOR_COLOR">EDITOR_COLOR</a></code>, <code><a title="fluxity.EDITOR_FILE_PATH" href="#fluxity.EDITOR_FILE_PATH">EDITOR_FILE_PATH</a></code>, <code><a title="fluxity.EDITOR_OPTIONS" href="#fluxity.EDITOR_OPTIONS">EDITOR_OPTIONS</a></code>, <code><a title="fluxity.EDITOR_CHECK_BOX" href="#fluxity.EDITOR_CHECK_BOX">EDITOR_CHECK_BOX</a></code>, <code><a title="fluxity.EDITOR_FLOAT_RANGE" href="#fluxity.EDITOR_FLOAT_RANGE">EDITOR_FLOAT_RANGE</a></code>, <code><a title="fluxity.EDITOR_INT_RANGE" href="#fluxity.EDITOR_INT_RANGE">EDITOR_INT_RANGE</a></code>.</em></p>
2619 <p><strong><code>default_value(str||int||float||tuple):</code></strong> Data type depends on editor type:</p>
2620 <ul>
2621 <li>
2622 <p><code><a title="fluxity.EDITOR_TEXT" href="#fluxity.EDITOR_TEXT">EDITOR_TEXT</a></code>(str),</p>
2623 </li>
2624 <li>
2625 <p><code><a title="fluxity.EDITOR_TEXT_AREA" href="#fluxity.EDITOR_TEXT_AREA">EDITOR_TEXT_AREA</a></code>(str),</p>
2626 </li>
2627 <li>
2628 <p><code><a title="fluxity.EDITOR_FLOAT" href="#fluxity.EDITOR_FLOAT">EDITOR_FLOAT</a></code>(float),</p>
2629 </li>
2630 <li>
2631 <p><code><a title="fluxity.EDITOR_INT" href="#fluxity.EDITOR_INT">EDITOR_INT</a></code>(int), </p>
2632 </li>
2633 <li>
2634 <p><code><a title="fluxity.EDITOR_COLOR" href="#fluxity.EDITOR_COLOR">EDITOR_COLOR</a></code>(4-tuple with float values in range 0-1, (R,G,B,A)), </p>
2635 </li>
2636 <li>
2637 <p><code><a title="fluxity.EDITOR_FILE_PATH" href="#fluxity.EDITOR_FILE_PATH">EDITOR_FILE_PATH</a></code>(str), </p>
2638 </li>
2639 <li>
2640 <p><code><a title="fluxity.EDITOR_OPTIONS" href="#fluxity.EDITOR_OPTIONS">EDITOR_OPTIONS</a></code>(2-tuple (int, [str]), (selected_index,[option_str_1, option_str_2, &hellip;]),</p>
2641 </li>
2642 <li>
2643 <p><code><a title="fluxity.EDITOR_CHECK_BOX" href="#fluxity.EDITOR_CHECK_BOX">EDITOR_CHECK_BOX</a></code>(bool), </p>
2644 </li>
2645 <li>
2646 <p><code><a title="fluxity.EDITOR_FLOAT_RANGE" href="#fluxity.EDITOR_FLOAT_RANGE">EDITOR_FLOAT_RANGE</a></code>(3-tuple with float values, (default, min, max)), </p>
2647 </li>
2648 <li>
2649 <p><code><a title="fluxity.EDITOR_INT_RANGE" href="#fluxity.EDITOR_INT_RANGE">EDITOR_INT_RANGE</a></code>(3-tuple with int values, (default, min, max))</p>
2650 </li>
2651 <li>
2652 <p><code><a title="fluxity.EDITOR_PANGO_FONT" href="#fluxity.EDITOR_PANGO_FONT">EDITOR_PANGO_FONT</a></code> (17-tuple (font_family, font_face, font_size, alignment, color_rgba,
2653 fill_on, outline_color_rgba, outline_on, outline_width, shadow_on, shadow_color_rgb,
2654 shadow_opacity, shadow_xoff, shadow_yoff, shadow_blur,
2655 gradient_color_rgba, gradient_direction))</p>
2656 </li>
2657 </ul>
2658 <p><strong><code>tooltip(str, optional):</code></strong> Tooltip for editor if presented in GUI.</p>
2659 <p>Defines possible GUI editors used to affect script rendering. Edited value is accessed with method <em>get_editor_value(self, name, frame=0)</em>.</p>
2660 <p>Data describing editors can be accessed with <em>get_script_data(self)</em>. Edited values are made available for script with <em>set_editors_data(self, editors_data_json)</em>.</p>
2661 <p>Must be called in script method <em>init_script()</em>.</p></div>
2662 <details class="source">
2663 <summary>
2664 <span>Expand source code</span>
2665 </summary>
2666 <pre><code class="python">def add_editor(self, name, type, default_value, tooltip=None):
2667 &#34;&#34;&#34;
2668 **`name(str):`** Name for editor.
2669
2670 **`type(int):`** Value either *`EDITOR_FLOAT`, `EDITOR_INT`, `EDITOR_COLOR`, `EDITOR_FILE_PATH`, `EDITOR_OPTIONS`, `EDITOR_CHECK_BOX`, `EDITOR_FLOAT_RANGE`, `EDITOR_INT_RANGE`.*
2671
2672 **`default_value(str||int||float||tuple):`** Data type depends on editor type:
2673
2674 * `EDITOR_TEXT`(str),
2675
2676 * `EDITOR_TEXT_AREA`(str),
2677
2678 * `EDITOR_FLOAT`(float),
2679
2680 * `EDITOR_INT`(int),
2681
2682 * `EDITOR_COLOR`(4-tuple with float values in range 0-1, (R,G,B,A)),
2683
2684 * `EDITOR_FILE_PATH`(str),
2685
2686 * `EDITOR_OPTIONS`(2-tuple (int, [str]), (selected_index,[option_str_1, option_str_2, ...]),
2687
2688 * `EDITOR_CHECK_BOX`(bool),
2689
2690 * `EDITOR_FLOAT_RANGE`(3-tuple with float values, (default, min, max)),
2691
2692 * `EDITOR_INT_RANGE`(3-tuple with int values, (default, min, max))
2693
2694 * `EDITOR_PANGO_FONT` (17-tuple (font_family, font_face, font_size, alignment, color_rgba,
2695 fill_on, outline_color_rgba, outline_on, outline_width, shadow_on, shadow_color_rgb,
2696 shadow_opacity, shadow_xoff, shadow_yoff, shadow_blur,
2697 gradient_color_rgba, gradient_direction))
2698
2699 **`tooltip(str, optional):`** Tooltip for editor if presented in GUI.
2700
2701 Defines possible GUI editors used to affect script rendering. Edited value is accessed with method *get_editor_value(self, name, frame=0)*.
2702
2703 Data describing editors can be accessed with *get_script_data(self)*. Edited values are made available for script with *set_editors_data(self, editors_data_json)*.
2704
2705 Must be called in script method *init_script()*.
2706 &#34;&#34;&#34;
2707 self.priv_context.error_on_wrong_method(&#34;add_editor()&#34;, METHOD_INIT_SCRIPT)
2708 self.editors[name] = (type, default_value)
2709 if tooltip != None:
2710 self.editor_tooltips[name] = tooltip</code></pre>
2711 </details>
2712 </dd>
2713 <dt id="fluxity.FluxityContext.create_text_layout"><code class="name flex">
2714 <span>def <span class="ident">create_text_layout</span></span>(<span>self, font_data)</span>
2715 </code></dt>
2716 <dd>
2717 <div class="desc"><p><strong><code>font_data(tuple)</code></strong> this tuple can be acquired by calling <em>FluxityContext.get_editor_value()</em> on editors of type <em>EDITOR_PANGO_FONT</em>.</p>
2718 <p>Creates objects used to draw text.</p>
2719 <p><strong>Returns:</strong> (fluxity.PangoTextLayout) object for drawing text.</p></div>
2720 <details class="source">
2721 <summary>
2722 <span>Expand source code</span>
2723 </summary>
2724 <pre><code class="python">def create_text_layout(self, font_data):
2725 &#34;&#34;&#34;
2726 **`font_data(tuple)`** this tuple can be acquired by calling *FluxityContext.get_editor_value()* on editors of type *EDITOR_PANGO_FONT*.
2727
2728 Creates objects used to draw text.
2729
2730 **Returns:** (fluxity.PangoTextLayout) object for drawing text.
2731 &#34;&#34;&#34;
2732 return PangoTextLayout(font_data)</code></pre>
2733 </details>
2734 </dd>
2735 <dt id="fluxity.FluxityContext.get_data_obj"><code class="name flex">
2736 <span>def <span class="ident">get_data_obj</span></span>(<span>self, label)</span>
2737 </code></dt>
2738 <dd>
2739 <div class="desc"><p><strong><code>label(str):</code></strong> label of saved data item.</p>
2740 <p>Gives access to previously saved data.</p>
2741 <p><strong>Returns:</strong> (obj) Saved data item.</p></div>
2742 <details class="source">
2743 <summary>
2744 <span>Expand source code</span>
2745 </summary>
2746 <pre><code class="python">def get_data_obj(self, label):
2747 &#34;&#34;&#34;
2748 **`label(str):`** label of saved data item.
2749
2750 Gives access to previously saved data.
2751
2752 **Returns:** (obj) Saved data item.
2753 &#34;&#34;&#34;
2754 return self.data[label]</code></pre>
2755 </details>
2756 </dd>
2757 <dt id="fluxity.FluxityContext.get_dimensions"><code class="name flex">
2758 <span>def <span class="ident">get_dimensions</span></span>(<span>self)</span>
2759 </code></dt>
2760 <dd>
2761 <div class="desc"><p>Pixel size of output image.</p>
2762 <p><strong>Returns:</strong> (int, int) Tuple (width, height) of output image size.</p></div>
2763 <details class="source">
2764 <summary>
2765 <span>Expand source code</span>
2766 </summary>
2767 <pre><code class="python">def get_dimensions(self):
2768 &#34;&#34;&#34;
2769 Pixel size of output image.
2770
2771 **Returns:** (int, int) Tuple (width, height) of output image size.
2772 &#34;&#34;&#34;
2773 w = self.priv_context.profile.get_profile_property(PROFILE_WIDTH)
2774 h = self.priv_context.profile.get_profile_property(PROFILE_HEIGHT)
2775 return (w, h)</code></pre>
2776 </details>
2777 </dd>
2778 <dt id="fluxity.FluxityContext.get_editor_value"><code class="name flex">
2779 <span>def <span class="ident">get_editor_value</span></span>(<span>self, name, frame=0)</span>
2780 </code></dt>
2781 <dd>
2782 <div class="desc"><p><strong><code>name(str):</code></strong> Name of editor.</p>
2783 <p><strong><code>frame(int):</code></strong> Frame in range 0 - (script length - 1).</p>
2784 <p>Value of edited data at given frame. We currently have no animated values, but they will added with future API updates.</p>
2785 <p><strong>Returns:</strong> (obj) Value at frame.</p>
2786 <p>Data type depends on editor type:</p>
2787 <ul>
2788 <li>
2789 <p><code><a title="fluxity.EDITOR_TEXT" href="#fluxity.EDITOR_TEXT">EDITOR_TEXT</a></code>(str),</p>
2790 </li>
2791 <li>
2792 <p><code><a title="fluxity.EDITOR_TEXT_AREA" href="#fluxity.EDITOR_TEXT_AREA">EDITOR_TEXT_AREA</a></code>(str),</p>
2793 </li>
2794 <li>
2795 <p><code><a title="fluxity.EDITOR_FLOAT" href="#fluxity.EDITOR_FLOAT">EDITOR_FLOAT</a></code>(float), </p>
2796 </li>
2797 <li>
2798 <p><code><a title="fluxity.EDITOR_INT" href="#fluxity.EDITOR_INT">EDITOR_INT</a></code>(int), </p>
2799 </li>
2800 <li>
2801 <p><code><a title="fluxity.EDITOR_COLOR" href="#fluxity.EDITOR_COLOR">EDITOR_COLOR</a></code>(4-tuple with float values in range 0-1, (R,G,B,A)), </p>
2802 </li>
2803 <li>
2804 <p><code><a title="fluxity.EDITOR_FILE_PATH" href="#fluxity.EDITOR_FILE_PATH">EDITOR_FILE_PATH</a></code>(str),</p>
2805 </li>
2806 <li>
2807 <p><code><a title="fluxity.EDITOR_OPTIONS" href="#fluxity.EDITOR_OPTIONS">EDITOR_OPTIONS</a></code>(selection index int),</p>
2808 </li>
2809 <li>
2810 <p><code><a title="fluxity.EDITOR_CHECK_BOX" href="#fluxity.EDITOR_CHECK_BOX">EDITOR_CHECK_BOX</a></code>(bool), </p>
2811 </li>
2812 <li>
2813 <p><code><a title="fluxity.EDITOR_FLOAT_RANGE" href="#fluxity.EDITOR_FLOAT_RANGE">EDITOR_FLOAT_RANGE</a></code>(3-tuple with float values, (default, min, max)), </p>
2814 </li>
2815 <li>
2816 <p><code><a title="fluxity.EDITOR_INT_RANGE" href="#fluxity.EDITOR_INT_RANGE">EDITOR_INT_RANGE</a></code>(3-tuple with int values, (default, min, max))</p>
2817 </li>
2818 <li>
2819 <p><code><a title="fluxity.EDITOR_PANGO_FONT" href="#fluxity.EDITOR_PANGO_FONT">EDITOR_PANGO_FONT</a></code>(17-tuple (font_family, font_face, font_size, alignment, color_rgba,
2820 fill_on, outline_color_rgba, outline_on, outline_width, shadow_on, shadow_color_rgb,
2821 shadow_opacity, shadow_xoff, shadow_yoff, shadow_blur,
2822 gradient_color_rgba, gradient_direction))</p>
2823 </li>
2824 </ul></div>
2825 <details class="source">
2826 <summary>
2827 <span>Expand source code</span>
2828 </summary>
2829 <pre><code class="python">def get_editor_value(self, name, frame=0):
2830 &#34;&#34;&#34;
2831 **`name(str):`** Name of editor.
2832
2833 **`frame(int):`** Frame in range 0 - (script length - 1).
2834
2835 Value of edited data at given frame. We currently have no animated values, but they will added with future API updates.
2836
2837 **Returns:** (obj) Value at frame.
2838
2839 Data type depends on editor type:
2840
2841 * `EDITOR_TEXT`(str),
2842
2843 * `EDITOR_TEXT_AREA`(str),
2844
2845 * `EDITOR_FLOAT`(float),
2846
2847 * `EDITOR_INT`(int),
2848
2849 * `EDITOR_COLOR`(4-tuple with float values in range 0-1, (R,G,B,A)),
2850
2851 * `EDITOR_FILE_PATH`(str),
2852
2853 * `EDITOR_OPTIONS`(selection index int),
2854
2855 * `EDITOR_CHECK_BOX`(bool),
2856
2857 * `EDITOR_FLOAT_RANGE`(3-tuple with float values, (default, min, max)),
2858
2859 * `EDITOR_INT_RANGE`(3-tuple with int values, (default, min, max))
2860
2861 * `EDITOR_PANGO_FONT`(17-tuple (font_family, font_face, font_size, alignment, color_rgba,
2862 fill_on, outline_color_rgba, outline_on, outline_width, shadow_on, shadow_color_rgb,
2863 shadow_opacity, shadow_xoff, shadow_yoff, shadow_blur,
2864 gradient_color_rgba, gradient_direction))
2865 &#34;&#34;&#34;
2866 try:
2867 type, value = self.editors[name]
2868 if type == EDITOR_INT_RANGE or type == EDITOR_FLOAT_RANGE:
2869 val, min, max = value
2870 return val
2871 elif type == EDITOR_OPTIONS:
2872 selected_index, options = value
2873 return selected_index
2874 return value
2875 except Exception as e:
2876 exception_msg = &#34;No editor for name &#39;&#34; + name + &#34;&#39; found.&#34;
2877 _raise_fluxity_error(exception_msg)</code></pre>
2878 </details>
2879 </dd>
2880 <dt id="fluxity.FluxityContext.get_frame_cr"><code class="name flex">
2881 <span>def <span class="ident">get_frame_cr</span></span>(<span>self)</span>
2882 </code></dt>
2883 <dd>
2884 <div class="desc"><p>For every rendered frame method <em><code>render_frame()</code></em> is called and a new <strong><code>cairo.ImageSurface</code></strong> object is created.</p>
2885 <p>This method provides access to <strong><code>cairo.Context</code></strong> object that can be used to draw onto that image surface. This is the way that output is achieved with <strong>Flowblade Media Plugins</strong>. </p>
2886 <p>After method <em><code>render_frame()</code></em> exits, <strong><code>cairo.Context</code></strong> object is no longer valid and contents of <strong><code>cairo.ImageSurface</code></strong> are saved to disk.</p>
2887 <p>Must be called in script method <em><code>render_frame()</code></em>.</p>
2888 <p><strong>Returns:</strong> (<strong><code>cairo.Context</code></strong>) Context object that can be drawn onto.</p></div>
2889 <details class="source">
2890 <summary>
2891 <span>Expand source code</span>
2892 </summary>
2893 <pre><code class="python">def get_frame_cr(self):
2894 &#34;&#34;&#34;
2895 For every rendered frame method *`render_frame()`* is called and a new **`cairo.ImageSurface`** object is created.
2896
2897 This method provides access to **`cairo.Context`** object that can be used to draw onto that image surface. This is the way that output is achieved with **Flowblade Media Plugins**.
2898
2899 After method *`render_frame()`* exits, **`cairo.Context`** object is no longer valid and contents of **`cairo.ImageSurface`** are saved to disk.
2900
2901 Must be called in script method *`render_frame()`*.
2902
2903 **Returns:** (**`cairo.Context`**) Context object that can be drawn onto.
2904 &#34;&#34;&#34;
2905 return self.priv_context.frame_cr</code></pre>
2906 </details>
2907 </dd>
2908 <dt id="fluxity.FluxityContext.get_length"><code class="name flex">
2909 <span>def <span class="ident">get_length</span></span>(<span>self)</span>
2910 </code></dt>
2911 <dd>
2912 <div class="desc"><p><strong>Returns:</strong> (int) Length of script in frames.</p></div>
2913 <details class="source">
2914 <summary>
2915 <span>Expand source code</span>
2916 </summary>
2917 <pre><code class="python">def get_length(self):
2918 &#34;&#34;&#34;
2919 **Returns:** (int) Length of script in frames.
2920 &#34;&#34;&#34;
2921 return self.length</code></pre>
2922 </details>
2923 </dd>
2924 <dt id="fluxity.FluxityContext.get_profile_property"><code class="name flex">
2925 <span>def <span class="ident">get_profile_property</span></span>(<span>self, p_property)</span>
2926 </code></dt>
2927 <dd>
2928 <div class="desc"><p><strong><code>p_property(str):</code></strong> propertyr identyfier, e.g. <code><a title="fluxity.PROFILE_PROGRESSIVE" href="#fluxity.PROFILE_PROGRESSIVE">PROFILE_PROGRESSIVE</a></code>.</p>
2929 <p>Used to access properties of MLT profile set before running the script that defines e.g. output image size.</p>
2930 <p><strong>Returns:</strong> (int || boolean || string) Value depends on which profile property is being accessed.</p></div>
2931 <details class="source">
2932 <summary>
2933 <span>Expand source code</span>
2934 </summary>
2935 <pre><code class="python">def get_profile_property(self, p_property):
2936 &#34;&#34;&#34;
2937 **`p_property(str):`** propertyr identyfier, e.g. `fluxity.PROFILE_PROGRESSIVE`.
2938
2939 Used to access properties of MLT profile set before running the script that defines e.g. output image size.
2940
2941 **Returns:** (int || boolean || string) Value depends on which profile property is being accessed.
2942 &#34;&#34;&#34;
2943 return self.priv_context.profile.get_profile_property(p_property)</code></pre>
2944 </details>
2945 </dd>
2946 <dt id="fluxity.FluxityContext.get_script_data"><code class="name flex">
2947 <span>def <span class="ident">get_script_data</span></span>(<span>self)</span>
2948 </code></dt>
2949 <dd>
2950 <div class="desc"><p>Returns data of all editors and their default values, and script metadata like script author and version. </p>
2951 <p>Output can be turned into Python object tree using <em>json.loads()</em> method.</p>
2952 <p><strong>Returns:</strong> (str) string representation of JSON object.</p></div>
2953 <details class="source">
2954 <summary>
2955 <span>Expand source code</span>
2956 </summary>
2957 <pre><code class="python">def get_script_data(self):
2958 &#34;&#34;&#34;
2959 Returns data of all editors and their default values, and script metadata like script author and version.
2960
2961 Output can be turned into Python object tree using *json.loads()* method.
2962
2963 **Returns:** (str) string representation of JSON object.
2964 &#34;&#34;&#34;
2965 script_data = {}
2966 script_data[&#34;length&#34;] = self.length
2967 script_data[&#34;name&#34;] = self.name
2968 script_data[&#34;version&#34;] = self.version
2969 script_data[&#34;author&#34;] = self.author
2970
2971 editors_list = []
2972 for name in self.editors:
2973 type, value = self.editors[name]
2974 json_obj = [name, type, value]
2975 editors_list.append(json_obj)
2976
2977 script_data[&#34;editors_list&#34;] = editors_list # this is dict inside FluxityContext object, but is given out as list for convenience of Flowblade app integration.
2978 script_data[&#34;tooltips_list&#34;] = self.editor_tooltips
2979
2980 return json.dumps(script_data)</code></pre>
2981 </details>
2982 </dd>
2983 <dt id="fluxity.FluxityContext.get_script_dir"><code class="name flex">
2984 <span>def <span class="ident">get_script_dir</span></span>(<span>self)</span>
2985 </code></dt>
2986 <dd>
2987 <div class="desc"><p>Returns path to directory where the script being executed is located.
2988 </p>
2989 <p>Sometimes script directory information is not available (e.g. when executing a non-saved script in Flowblade <em>Script Tool</em> application) and <em>None</em> is returned. It is recommended that all Fluxity scripts handle getting <em>None</em> gracefully.</p>
2990 <p>This functionality is useful when script is being distributed with some associated media files.</p>
2991 <p><strong>Returns:</strong> (str) script directory path or <em>None</em>.</p></div>
2992 <details class="source">
2993 <summary>
2994 <span>Expand source code</span>
2995 </summary>
2996 <pre><code class="python">def get_script_dir(self):
2997 &#34;&#34;&#34;
2998 Returns path to directory where the script being executed is located.
2999
3000 Sometimes script directory information is not available (e.g. when executing a non-saved script in Flowblade *Script Tool* application) and *None* is returned. It is recommended that all Fluxity scripts handle getting *None* gracefully.
3001
3002 This functionality is useful when script is being distributed with some associated media files.
3003
3004 **Returns:** (str) script directory path or *None*.
3005 &#34;&#34;&#34;
3006 if self.script_file == None:
3007 return None
3008
3009 dir_path = os.path.dirname(self.script_file) + &#34;/&#34;
3010 return dir_path</code></pre>
3011 </details>
3012 </dd>
3013 <dt id="fluxity.FluxityContext.log_line"><code class="name flex">
3014 <span>def <span class="ident">log_line</span></span>(<span>self, log_line)</span>
3015 </code></dt>
3016 <dd>
3017 <div class="desc"><p><strong><code>log_line(str):</code></strong> line of text.</p>
3018 <p>Adds a line of text to log message displayed after render completion or error.</p></div>
3019 <details class="source">
3020 <summary>
3021 <span>Expand source code</span>
3022 </summary>
3023 <pre><code class="python">def log_line(self, log_line):
3024 &#34;&#34;&#34;
3025 **`log_line(str):`** line of text.
3026
3027 Adds a line of text to log message displayed after render completion or error.
3028 &#34;&#34;&#34;
3029 self.log_msg = self.log_msg + log_line + &#34;\n&#34;</code></pre>
3030 </details>
3031 </dd>
3032 <dt id="fluxity.FluxityContext.set_author"><code class="name flex">
3033 <span>def <span class="ident">set_author</span></span>(<span>self, author)</span>
3034 </code></dt>
3035 <dd>
3036 <div class="desc"><p><strong><code>author(str):</code></strong> name of script creator.</p>
3037 <p>Sets author of the script. Must be called in script method <em>init_script()</em>.</p></div>
3038 <details class="source">
3039 <summary>
3040 <span>Expand source code</span>
3041 </summary>
3042 <pre><code class="python">def set_author(self, author):
3043 &#34;&#34;&#34;
3044 **`author(str):`** name of script creator.
3045
3046 Sets author of the script. Must be called in script method *init_script()*.
3047 &#34;&#34;&#34;
3048 self.author = author</code></pre>
3049 </details>
3050 </dd>
3051 <dt id="fluxity.FluxityContext.set_data_obj"><code class="name flex">
3052 <span>def <span class="ident">set_data_obj</span></span>(<span>self, label, item)</span>
3053 </code></dt>
3054 <dd>
3055 <div class="desc"><p><strong><code>label(str):</code></strong> label used to access data later using <em><code>get_data_obj(self, label)</code></em>.</p>
3056 <p><strong><code>item(obj):</code></strong> data item being saved.</p>
3057 <p>Saves data to be used later during execution of script. Using <strong>global</strong> would obviously be possible to replace this, but this is made available as a more clean solution.</p></div>
3058 <details class="source">
3059 <summary>
3060 <span>Expand source code</span>
3061 </summary>
3062 <pre><code class="python">def set_data_obj(self, label, item):
3063 &#34;&#34;&#34;
3064 **`label(str):`** label used to access data later using *`get_data_obj(self, label)`*.
3065
3066 **`item(obj):`** data item being saved.
3067
3068 Saves data to be used later during execution of script. Using **global** would obviously be possible to replace this, but this is made available as a more clean solution.
3069 &#34;&#34;&#34;
3070 self.data[label] = item</code></pre>
3071 </details>
3072 </dd>
3073 <dt id="fluxity.FluxityContext.set_editors_data"><code class="name flex">
3074 <span>def <span class="ident">set_editors_data</span></span>(<span>self, editors_data_json)</span>
3075 </code></dt>
3076 <dd>
3077 <div class="desc"><p><strong><code>editors_data_json(str):</code></strong> string representation of JSON object.</p>
3078 <p>Sets edited data to be used when rendering.</p>
3079 <p>Input string must describe JSON object that can be turned into usable editor data.</p>
3080 <p>Example with <code><a title="fluxity.EDITOR_FLOAT" href="#fluxity.EDITOR_FLOAT">EDITOR_FLOAT</a></code> and <code><a title="fluxity.EDITOR_COLOR" href="#fluxity.EDITOR_COLOR">EDITOR_COLOR</a></code>:</p>
3081 <pre><code>[
3082 [&quot;Position X&quot;, 2, 1.0],
3083 [&quot;BG Color&quot;, 4, [0.8, 0.2, 0.2, 1.0]]
3084 ]
3085 </code></pre>
3086 <p>General form:</p>
3087 <pre><code>[
3088 [&lt;name&gt;, &lt;type&gt;, &lt;value&gt;],
3089 ...
3090 ]
3091 </code></pre>
3092 <p>Using this method is not needed when writing <strong>Flowblade Media Plugins</strong>, application handles setting editors data.</p>
3093 <p>Should be called in script method <em>init_render()</em>.</p></div>
3094 <details class="source">
3095 <summary>
3096 <span>Expand source code</span>
3097 </summary>
3098 <pre><code class="python">def set_editors_data(self, editors_data_json):
3099 &#34;&#34;&#34;
3100 **`editors_data_json(str):`** string representation of JSON object.
3101
3102 Sets edited data to be used when rendering.
3103
3104 Input string must describe JSON object that can be turned into usable editor data.
3105
3106 Example with `EDITOR_FLOAT` and `EDITOR_COLOR`:
3107
3108 ```
3109 [
3110 [&#34;Position X&#34;, 2, 1.0],
3111 [&#34;BG Color&#34;, 4, [0.8, 0.2, 0.2, 1.0]]
3112 ]
3113 ```
3114
3115 General form:
3116
3117 ```
3118 [
3119 [&lt;name&gt;, &lt;type&gt;, &lt;value&gt;],
3120 ...
3121 ]
3122 ```
3123
3124 Using this method is not needed when writing **Flowblade Media Plugins**, application handles setting editors data.
3125
3126 Should be called in script method *init_render()*.
3127 &#34;&#34;&#34;
3128 new_editors_list = json.loads(editors_data_json)
3129 for editor in new_editors_list:
3130 name, type, value = editor
3131 self.editors[name] = (type, value)</code></pre>
3132 </details>
3133 </dd>
3134 <dt id="fluxity.FluxityContext.set_frame_name"><code class="name flex">
3135 <span>def <span class="ident">set_frame_name</span></span>(<span>self, frame_name)</span>
3136 </code></dt>
3137 <dd>
3138 <div class="desc"><p><strong><code>frame_name(str):</code></strong> name used before number part in rendered frame files.</p></div>
3139 <details class="source">
3140 <summary>
3141 <span>Expand source code</span>
3142 </summary>
3143 <pre><code class="python">def set_frame_name(self, frame_name):
3144 &#34;&#34;&#34;
3145 **`frame_name(str):`** name used before number part in rendered frame files.
3146 &#34;&#34;&#34;
3147 self.priv_context.frame_name = frame_name</code></pre>
3148 </details>
3149 </dd>
3150 <dt id="fluxity.FluxityContext.set_length"><code class="name flex">
3151 <span>def <span class="ident">set_length</span></span>(<span>self, length)</span>
3152 </code></dt>
3153 <dd>
3154 <div class="desc"><p><strong><code>length(int):</code></strong> New length of script in frames.</p>
3155 <p>Sets length of script output in frames.</p>
3156 <p>Must <em>not</em> be called in
3157 <em><code>render_frames()</code></em>.</p></div>
3158 <details class="source">
3159 <summary>
3160 <span>Expand source code</span>
3161 </summary>
3162 <pre><code class="python">def set_length(self, length):
3163 &#34;&#34;&#34;
3164 **`length(int):`** New length of script in frames.
3165
3166 Sets length of script output in frames.
3167
3168 Must *not* be called in *`render_frames()`*.
3169 &#34;&#34;&#34;
3170 self.length = length</code></pre>
3171 </details>
3172 </dd>
3173 <dt id="fluxity.FluxityContext.set_name"><code class="name flex">
3174 <span>def <span class="ident">set_name</span></span>(<span>self, name)</span>
3175 </code></dt>
3176 <dd>
3177 <div class="desc"><p><strong><code>name(str):</code></strong> name of script displayed to user.</p>
3178 <p>Sets name of the script displayed to the user. Must be called in script method <em><code>init_script()</code></em>.</p></div>
3179 <details class="source">
3180 <summary>
3181 <span>Expand source code</span>
3182 </summary>
3183 <pre><code class="python">def set_name(self, name):
3184 &#34;&#34;&#34;
3185 **`name(str):`** name of script displayed to user.
3186
3187 Sets name of the script displayed to the user. Must be called in script method *`init_script()`*.
3188 &#34;&#34;&#34;
3189 self.priv_context.error_on_wrong_method(&#34;set_name()&#34;, METHOD_INIT_SCRIPT)
3190 self.name = name</code></pre>
3191 </details>
3192 </dd>
3193 <dt id="fluxity.FluxityContext.set_prints_to_log_file"><code class="name flex">
3194 <span>def <span class="ident">set_prints_to_log_file</span></span>(<span>self, log_file)</span>
3195 </code></dt>
3196 <dd>
3197 <div class="desc"><p><strong><code>log_file(str):</code></strong> File path.</p>
3198 <p>Save output from 'print()' to file at given path. Must be called in script method <em>init_script()</em>.</p></div>
3199 <details class="source">
3200 <summary>
3201 <span>Expand source code</span>
3202 </summary>
3203 <pre><code class="python">def set_prints_to_log_file(self, log_file):
3204 &#34;&#34;&#34;
3205 **`log_file(str):`** File path.
3206
3207 Save output from &#39;print()&#39; to file at given path. Must be called in script method *init_script()*.
3208 &#34;&#34;&#34;
3209 self.priv_context.error_on_wrong_method(&#34;add_editor()&#34;, METHOD_INIT_SCRIPT)
3210 _prints_to_log_file(log_file)</code></pre>
3211 </details>
3212 </dd>
3213 <dt id="fluxity.FluxityContext.set_version"><code class="name flex">
3214 <span>def <span class="ident">set_version</span></span>(<span>self, version)</span>
3215 </code></dt>
3216 <dd>
3217 <div class="desc"><p><strong><code>version(int):</code></strong> version of script, use increasing integer numbering. Default value is <em>1</em>.</p>
3218 <p>Sets version of script. Must be called in script method <em><code>init_script()</code></em>.</p></div>
3219 <details class="source">
3220 <summary>
3221 <span>Expand source code</span>
3222 </summary>
3223 <pre><code class="python">def set_version(self, version):
3224 &#34;&#34;&#34;
3225 **`version(int):`** version of script, use increasing integer numbering. Default value is *1*.
3226
3227 Sets version of script. Must be called in script method *`init_script()`*.
3228 &#34;&#34;&#34;
3229 self.priv_context.error_on_wrong_method(&#34;set_version()&#34;, METHOD_INIT_SCRIPT)
3230 self.version = version</code></pre>
3231 </details>
3232 </dd>
3233 </dl>
3234 </dd>
3235 <dt id="fluxity.PangoTextLayout"><code class="flex name class">
3236 <span>class <span class="ident">PangoTextLayout</span></span>
3237 <span>(</span><span>font_data)</span>
3238 </code></dt>
3239 <dd>
3240 <div class="desc"><p><strong><code>font_data(tuple)</code></strong> this tuple can be acquired by calling <em><code><a title="fluxity.FluxityContext.get_editor_value" href="#fluxity.FluxityContext.get_editor_value">FluxityContext.get_editor_value()</a></code></em> on editors of type <em><code><a title="fluxity.EDITOR_PANGO_FONT" href="#fluxity.EDITOR_PANGO_FONT">EDITOR_PANGO_FONT</a></code></em>.</p>
3241 <p>Object for drawing text. Uses internally Pango.</p>
3242 <p>Instances of this object can be created using <em><code><a title="fluxity.FluxityContext.create_text_layout" href="#fluxity.FluxityContext.create_text_layout">FluxityContext.create_text_layout()</a></code></em>.</p></div>
3243 <details class="source">
3244 <summary>
3245 <span>Expand source code</span>
3246 </summary>
3247 <pre><code class="python">class PangoTextLayout:
3248
3249 &#34;&#34;&#34;
3250 **`font_data(tuple)`** this tuple can be acquired by calling *`FluxityContext.get_editor_value()`* on editors of type *`EDITOR_PANGO_FONT`*.
3251
3252 Object for drawing text. Uses internally Pango.
3253
3254 Instances of this object can be created using *`FluxityContext.create_text_layout()`*.
3255 &#34;&#34;&#34;
3256 def __init__(self, font_data):
3257 self.font_family, self.font_face, self.font_size, self.alignment, \
3258 self.color_rgba, self.fill_on, self.outline_color_rgba, self.outline_on, \
3259 self.outline_width, self.shadow_on, self.shadow_color_rgb, self.shadow_opacity, \
3260 self.shadow_xoff, self.shadow_yoff, self.shadow_blur, self.gradient_color_rgba, \
3261 self.gradient_direction = font_data
3262 self.font_desc = None
3263 self.pango_layout = None
3264 self.opacity = 1.0
3265 self.pixel_size = None
3266
3267 def create_pango_layout(self, cr, text):
3268 &#34;&#34;&#34;
3269 **`cr(cairo.Context)`** frame cairo context acquired with *`FluxityContext.get_frame_cr()`*.
3270
3271 **`text(str)`** displayed text.
3272
3273 Creates internally *`PangoCairo`* layout object. Calling this is required before calling *`PangoTextLayout.get_pixel_size()`*.
3274 &#34;&#34;&#34;
3275 self.text = text
3276 self.pango_layout = PangoCairo.create_layout(cr)
3277 self.pango_layout.set_text(self.text, -1)
3278 font_desc = Pango.FontDescription(self.font_family + &#34; &#34; + self.font_face + &#34; &#34; + str(self.font_size))
3279 self.pango_layout.set_font_description(font_desc)
3280 self.pango_layout.set_alignment(self.alignment)
3281 if self.pixel_size == None:
3282 metrics = self.pango_layout.get_context().get_metrics(font_desc, None)
3283 self.ascent = metrics.get_ascent() / Pango.SCALE
3284 self.descent = metrics.get_descent() / Pango.SCALE
3285 self.height = metrics.get_height() / Pango.SCALE
3286 w, h = self.pango_layout.get_size()
3287 self.pixel_size = (w / Pango.SCALE, self.height)
3288
3289 def get_top_pad(self):
3290 &#34;&#34;&#34;
3291 Returns pixel distance from layout top to highest possible pixel drawn for any font.
3292
3293 **Returns:** (int)(pad) Top pad size in pixels.
3294 &#34;&#34;&#34;
3295 return self.height - self.descent - self.ascent
3296
3297
3298 def get_pixel_size(self):
3299 &#34;&#34;&#34;
3300 Returns size of layout.
3301
3302 Before calling this PangoCairo layout object needs to created *`PangoTextLayout.create_pango_layout()`* or *`PangoTextLayout.draw_layout()`.*
3303
3304 **Returns:** (int, int)(width, height) pixel size of layout.
3305 &#34;&#34;&#34;
3306 return self.pixel_size
3307
3308 def set_opacity(self, opacity):
3309 &#34;&#34;&#34;
3310 **`opacity(float)`** Opacity in range 0.0 - 1.0.
3311
3312 Sets opacity for the text to be drawn. Default value is 1.0
3313 &#34;&#34;&#34;
3314 if opacity &lt; 0.0:
3315 opacity = 0.0
3316 if opacity &gt; 1.0:
3317 opacity = 1.0
3318
3319 self.opacity = opacity
3320
3321 # called from vieweditor draw vieweditor-&gt; editorlayer-&gt;here
3322 def draw_layout(self, fctx, text, cr, x, y, rotation=0.0, xscale=1.0, yscale=1.0):
3323 &#34;&#34;&#34;
3324 ** fctx(fluxity.FluxityContext ** context object.
3325
3326 **`text(str)`** displayed text.
3327
3328 **`cr(cairo.Context)`** frame cairo context acquired with *`FluxityContext.get_frame_cr()`*.
3329
3330 **`x(float)`** Text X position.
3331
3332 **`y(float)`** Text Y position.
3333
3334 **`rotation(float)`** Text rotation.
3335
3336 **`xscale(float)`** Text X scaling.
3337
3338 **`yscale(float)`** Text Y scaling.
3339
3340 Draws text on provided *`cairo.Context`*.
3341
3342 Calls internally *`PangoTextLayout.create_pango_layout()`* so *`PangoTextLayout.get_pixel_size()`* can be called after this.
3343 &#34;&#34;&#34;
3344 self.text = text
3345 cr.save() # Created each frame
3346
3347 self.create_pango_layout(cr, text)
3348 layout = self.pango_layout # this just artifact of dev. history, create_pango_layout() was added later then draw_layout()
3349 # to be used in typewriter plugin.
3350 # Shadow
3351 if self.shadow_on:
3352 cr.save()
3353
3354 # Get colors.
3355 r, g, b = self.shadow_color_rgb
3356 a = (self.shadow_opacity / 100.0) * self.opacity
3357
3358 # Blurred shadow need its own ImageSurface
3359 if self.shadow_blur != 0.0:
3360 w, h = fctx.get_dimensions()
3361 blurred_img = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
3362 cr_blurred = cairo.Context(blurred_img)
3363 transform_cr = cr_blurred # Set draw transform_cr to context for newly created image.
3364 else:
3365 transform_cr = cr # Set draw transform_cr to out context.
3366
3367 # Transform and set color.
3368 transform_cr.set_source_rgba(r, g, b, a)
3369 effective_shadow_xoff = self.shadow_xoff * xscale
3370 effective_shadow_yoff = self.shadow_yoff * yscale
3371 transform_cr.move_to(x + effective_shadow_xoff, y + effective_shadow_yoff)
3372 transform_cr.scale(xscale, yscale)
3373 transform_cr.rotate(rotation)
3374
3375 # If no blur for shadow, just draw layout on out context.
3376 if self.shadow_blur == 0.0:
3377 PangoCairo.update_layout(cr, layout)
3378 PangoCairo.show_layout(cr, layout)
3379 cr.restore()
3380 else:
3381 # If we have blur - draw shadow, blur it and then draw on out context.
3382 PangoCairo.update_layout(cr_blurred, layout)
3383 PangoCairo.show_layout(cr_blurred, layout)
3384
3385 img2 = Image.frombuffer(&#34;RGBA&#34;, (blurred_img.get_width(), blurred_img.get_height()), blurred_img.get_data(), &#34;raw&#34;, &#34;RGBA&#34;, 0, 1)
3386 effective_blur = xscale * self.shadow_blur # This is not going to be exact
3387 # on non-100% scales but let&#39;s try to get approximation.
3388 img2 = img2.filter(ImageFilter.GaussianBlur(radius=int(effective_blur)))
3389 imgd = img2.tobytes()
3390 a = array.array(&#39;B&#39;,imgd)
3391
3392 stride = blurred_img.get_width() * 4
3393 draw_surface = cairo.ImageSurface.create_for_data (a, cairo.FORMAT_ARGB32,
3394 blurred_img.get_width(), blurred_img.get_height(), stride)
3395 cr.restore()
3396 cr.set_source_surface(draw_surface, 0, 0)
3397 cr.paint()
3398
3399 # Text
3400 if self.fill_on:
3401 if self.gradient_color_rgba == None:
3402 cr.set_source_rgba(*self._get_opacity_rgba(self.color_rgba))
3403 else:
3404 w, h = self.pixel_size
3405 w = float(w) * xscale
3406 h = float(h) * yscale
3407 if self.gradient_direction == HORIZONTAL:
3408 grad = cairo.LinearGradient (x, 0, x + w, 0)
3409 else:
3410 grad = cairo.LinearGradient (0, y, 0, y + h)
3411
3412 r, g, b, a = self.color_rgba
3413 rg, gg, bg, ag = self.gradient_color_rgba
3414
3415 CLIP_COLOR_GRAD_1 = (0, r, g, b, 1.0)
3416 CLIP_COLOR_GRAD_2 = (1, rg, gg, bg, 1.0)
3417 grad.add_color_stop_rgba(*CLIP_COLOR_GRAD_1)
3418 grad.add_color_stop_rgba(*CLIP_COLOR_GRAD_2)
3419 cr.set_source(grad)
3420
3421 cr.move_to(x, y)
3422 cr.scale(xscale, yscale)
3423 cr.rotate(rotation)
3424
3425 PangoCairo.update_layout(cr, layout)
3426 PangoCairo.show_layout(cr, layout)
3427
3428 # Outline
3429 if self.outline_on:
3430 if self.fill_on == False: # case when user only wants outline we need to transform here
3431 cr.move_to(x, y)
3432 cr.scale(xscale, yscale)
3433 cr.rotate(rotation)
3434 PangoCairo.layout_path(cr, layout)
3435 cr.set_source_rgba(*self._get_opacity_rgba(self.outline_color_rgba))
3436 cr.set_line_width(self.outline_width)
3437 cr.stroke()
3438
3439 cr.restore()
3440
3441 def get_pango_alignment(self):
3442 &#34;&#34;&#34;
3443 Returns alignment for his layout.
3444
3445 To interpret enums script must do import *`from gi.repository import Pango`*
3446
3447 **Returns:** (int) alignment enum, either *`Pango.Alignment.CENTER`*, *`Pango.Alignment.LEFT`* or *`Pango.Alignment.RIGHT`*.
3448 &#34;&#34;&#34;
3449 return self.alignment
3450
3451 def _get_opacity_rgba(self, rbga):
3452 r, g, b, a = rbga
3453 return (r, g, b, a * self.opacity)</code></pre>
3454 </details>
3455 <h3>Methods</h3>
3456 <dl>
3457 <dt id="fluxity.PangoTextLayout.create_pango_layout"><code class="name flex">
3458 <span>def <span class="ident">create_pango_layout</span></span>(<span>self, cr, text)</span>
3459 </code></dt>
3460 <dd>
3461 <div class="desc"><p><strong><code>cr(cairo.Context)</code></strong> frame cairo context acquired with <em><code><a title="fluxity.FluxityContext.get_frame_cr" href="#fluxity.FluxityContext.get_frame_cr">FluxityContext.get_frame_cr()</a></code></em>.</p>
3462 <p><strong><code>text(str)</code></strong> displayed text.</p>
3463 <p>Creates internally <em><code>PangoCairo</code></em> layout object. Calling this is required before calling <em><code><a title="fluxity.PangoTextLayout.get_pixel_size" href="#fluxity.PangoTextLayout.get_pixel_size">PangoTextLayout.get_pixel_size()</a></code></em>.</p></div>
3464 <details class="source">
3465 <summary>
3466 <span>Expand source code</span>
3467 </summary>
3468 <pre><code class="python">def create_pango_layout(self, cr, text):
3469 &#34;&#34;&#34;
3470 **`cr(cairo.Context)`** frame cairo context acquired with *`FluxityContext.get_frame_cr()`*.
3471
3472 **`text(str)`** displayed text.
3473
3474 Creates internally *`PangoCairo`* layout object. Calling this is required before calling *`PangoTextLayout.get_pixel_size()`*.
3475 &#34;&#34;&#34;
3476 self.text = text
3477 self.pango_layout = PangoCairo.create_layout(cr)
3478 self.pango_layout.set_text(self.text, -1)
3479 font_desc = Pango.FontDescription(self.font_family + &#34; &#34; + self.font_face + &#34; &#34; + str(self.font_size))
3480 self.pango_layout.set_font_description(font_desc)
3481 self.pango_layout.set_alignment(self.alignment)
3482 if self.pixel_size == None:
3483 metrics = self.pango_layout.get_context().get_metrics(font_desc, None)
3484 self.ascent = metrics.get_ascent() / Pango.SCALE
3485 self.descent = metrics.get_descent() / Pango.SCALE
3486 self.height = metrics.get_height() / Pango.SCALE
3487 w, h = self.pango_layout.get_size()
3488 self.pixel_size = (w / Pango.SCALE, self.height)</code></pre>
3489 </details>
3490 </dd>
3491 <dt id="fluxity.PangoTextLayout.draw_layout"><code class="name flex">
3492 <span>def <span class="ident">draw_layout</span></span>(<span>self, fctx, text, cr, x, y, rotation=0.0, xscale=1.0, yscale=1.0)</span>
3493 </code></dt>
3494 <dd>
3495 <div class="desc"><p><strong> fctx(fluxity.FluxityContext </strong> context object.</p>
3496 <p><strong><code>text(str)</code></strong> displayed text.</p>
3497 <p><strong><code>cr(cairo.Context)</code></strong> frame cairo context acquired with <em><code><a title="fluxity.FluxityContext.get_frame_cr" href="#fluxity.FluxityContext.get_frame_cr">FluxityContext.get_frame_cr()</a></code></em>.</p>
3498 <p><strong><code>x(float)</code></strong> Text X position.</p>
3499 <p><strong><code>y(float)</code></strong> Text Y position.</p>
3500 <p><strong><code>rotation(float)</code></strong> Text rotation.</p>
3501 <p><strong><code>xscale(float)</code></strong> Text X scaling.</p>
3502 <p><strong><code>yscale(float)</code></strong> Text Y scaling.</p>
3503 <p>Draws text on provided <em><code>cairo.Context</code></em>.</p>
3504 <p>Calls internally <em><code><a title="fluxity.PangoTextLayout.create_pango_layout" href="#fluxity.PangoTextLayout.create_pango_layout">PangoTextLayout.create_pango_layout()</a></code></em> so <em><code><a title="fluxity.PangoTextLayout.get_pixel_size" href="#fluxity.PangoTextLayout.get_pixel_size">PangoTextLayout.get_pixel_size()</a></code></em> can be called after this.</p></div>
3505 <details class="source">
3506 <summary>
3507 <span>Expand source code</span>
3508 </summary>
3509 <pre><code class="python">def draw_layout(self, fctx, text, cr, x, y, rotation=0.0, xscale=1.0, yscale=1.0):
3510 &#34;&#34;&#34;
3511 ** fctx(fluxity.FluxityContext ** context object.
3512
3513 **`text(str)`** displayed text.
3514
3515 **`cr(cairo.Context)`** frame cairo context acquired with *`FluxityContext.get_frame_cr()`*.
3516
3517 **`x(float)`** Text X position.
3518
3519 **`y(float)`** Text Y position.
3520
3521 **`rotation(float)`** Text rotation.
3522
3523 **`xscale(float)`** Text X scaling.
3524
3525 **`yscale(float)`** Text Y scaling.
3526
3527 Draws text on provided *`cairo.Context`*.
3528
3529 Calls internally *`PangoTextLayout.create_pango_layout()`* so *`PangoTextLayout.get_pixel_size()`* can be called after this.
3530 &#34;&#34;&#34;
3531 self.text = text
3532 cr.save() # Created each frame
3533
3534 self.create_pango_layout(cr, text)
3535 layout = self.pango_layout # this just artifact of dev. history, create_pango_layout() was added later then draw_layout()
3536 # to be used in typewriter plugin.
3537 # Shadow
3538 if self.shadow_on:
3539 cr.save()
3540
3541 # Get colors.
3542 r, g, b = self.shadow_color_rgb
3543 a = (self.shadow_opacity / 100.0) * self.opacity
3544
3545 # Blurred shadow need its own ImageSurface
3546 if self.shadow_blur != 0.0:
3547 w, h = fctx.get_dimensions()
3548 blurred_img = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
3549 cr_blurred = cairo.Context(blurred_img)
3550 transform_cr = cr_blurred # Set draw transform_cr to context for newly created image.
3551 else:
3552 transform_cr = cr # Set draw transform_cr to out context.
3553
3554 # Transform and set color.
3555 transform_cr.set_source_rgba(r, g, b, a)
3556 effective_shadow_xoff = self.shadow_xoff * xscale
3557 effective_shadow_yoff = self.shadow_yoff * yscale
3558 transform_cr.move_to(x + effective_shadow_xoff, y + effective_shadow_yoff)
3559 transform_cr.scale(xscale, yscale)
3560 transform_cr.rotate(rotation)
3561
3562 # If no blur for shadow, just draw layout on out context.
3563 if self.shadow_blur == 0.0:
3564 PangoCairo.update_layout(cr, layout)
3565 PangoCairo.show_layout(cr, layout)
3566 cr.restore()
3567 else:
3568 # If we have blur - draw shadow, blur it and then draw on out context.
3569 PangoCairo.update_layout(cr_blurred, layout)
3570 PangoCairo.show_layout(cr_blurred, layout)
3571
3572 img2 = Image.frombuffer(&#34;RGBA&#34;, (blurred_img.get_width(), blurred_img.get_height()), blurred_img.get_data(), &#34;raw&#34;, &#34;RGBA&#34;, 0, 1)
3573 effective_blur = xscale * self.shadow_blur # This is not going to be exact
3574 # on non-100% scales but let&#39;s try to get approximation.
3575 img2 = img2.filter(ImageFilter.GaussianBlur(radius=int(effective_blur)))
3576 imgd = img2.tobytes()
3577 a = array.array(&#39;B&#39;,imgd)
3578
3579 stride = blurred_img.get_width() * 4
3580 draw_surface = cairo.ImageSurface.create_for_data (a, cairo.FORMAT_ARGB32,
3581 blurred_img.get_width(), blurred_img.get_height(), stride)
3582 cr.restore()
3583 cr.set_source_surface(draw_surface, 0, 0)
3584 cr.paint()
3585
3586 # Text
3587 if self.fill_on:
3588 if self.gradient_color_rgba == None:
3589 cr.set_source_rgba(*self._get_opacity_rgba(self.color_rgba))
3590 else:
3591 w, h = self.pixel_size
3592 w = float(w) * xscale
3593 h = float(h) * yscale
3594 if self.gradient_direction == HORIZONTAL:
3595 grad = cairo.LinearGradient (x, 0, x + w, 0)
3596 else:
3597 grad = cairo.LinearGradient (0, y, 0, y + h)
3598
3599 r, g, b, a = self.color_rgba
3600 rg, gg, bg, ag = self.gradient_color_rgba
3601
3602 CLIP_COLOR_GRAD_1 = (0, r, g, b, 1.0)
3603 CLIP_COLOR_GRAD_2 = (1, rg, gg, bg, 1.0)
3604 grad.add_color_stop_rgba(*CLIP_COLOR_GRAD_1)
3605 grad.add_color_stop_rgba(*CLIP_COLOR_GRAD_2)
3606 cr.set_source(grad)
3607
3608 cr.move_to(x, y)
3609 cr.scale(xscale, yscale)
3610 cr.rotate(rotation)
3611
3612 PangoCairo.update_layout(cr, layout)
3613 PangoCairo.show_layout(cr, layout)
3614
3615 # Outline
3616 if self.outline_on:
3617 if self.fill_on == False: # case when user only wants outline we need to transform here
3618 cr.move_to(x, y)
3619 cr.scale(xscale, yscale)
3620 cr.rotate(rotation)
3621 PangoCairo.layout_path(cr, layout)
3622 cr.set_source_rgba(*self._get_opacity_rgba(self.outline_color_rgba))
3623 cr.set_line_width(self.outline_width)
3624 cr.stroke()
3625
3626 cr.restore()</code></pre>
3627 </details>
3628 </dd>
3629 <dt id="fluxity.PangoTextLayout.get_pango_alignment"><code class="name flex">
3630 <span>def <span class="ident">get_pango_alignment</span></span>(<span>self)</span>
3631 </code></dt>
3632 <dd>
3633 <div class="desc"><p>Returns alignment for his layout.</p>
3634 <p>To interpret enums script must do import <em><code>from gi.repository import Pango</code></em></p>
3635 <p><strong>Returns:</strong> (int) alignment enum, either <em><code>Pango.Alignment.CENTER</code></em>, <em><code>Pango.Alignment.LEFT</code></em> or <em><code>Pango.Alignment.RIGHT</code></em>.</p></div>
3636 <details class="source">
3637 <summary>
3638 <span>Expand source code</span>
3639 </summary>
3640 <pre><code class="python">def get_pango_alignment(self):
3641 &#34;&#34;&#34;
3642 Returns alignment for his layout.
3643
3644 To interpret enums script must do import *`from gi.repository import Pango`*
3645
3646 **Returns:** (int) alignment enum, either *`Pango.Alignment.CENTER`*, *`Pango.Alignment.LEFT`* or *`Pango.Alignment.RIGHT`*.
3647 &#34;&#34;&#34;
3648 return self.alignment</code></pre>
3649 </details>
3650 </dd>
3651 <dt id="fluxity.PangoTextLayout.get_pixel_size"><code class="name flex">
3652 <span>def <span class="ident">get_pixel_size</span></span>(<span>self)</span>
3653 </code></dt>
3654 <dd>
3655 <div class="desc"><p>Returns size of layout.</p>
3656 <p>Before calling this PangoCairo layout object needs to created <em><code><a title="fluxity.PangoTextLayout.create_pango_layout" href="#fluxity.PangoTextLayout.create_pango_layout">PangoTextLayout.create_pango_layout()</a></code></em> or <em><code><a title="fluxity.PangoTextLayout.draw_layout" href="#fluxity.PangoTextLayout.draw_layout">PangoTextLayout.draw_layout()</a></code>.</em></p>
3657 <p><strong>Returns:</strong> (int, int)(width, height) pixel size of layout.</p></div>
3658 <details class="source">
3659 <summary>
3660 <span>Expand source code</span>
3661 </summary>
3662 <pre><code class="python">def get_pixel_size(self):
3663 &#34;&#34;&#34;
3664 Returns size of layout.
3665
3666 Before calling this PangoCairo layout object needs to created *`PangoTextLayout.create_pango_layout()`* or *`PangoTextLayout.draw_layout()`.*
3667
3668 **Returns:** (int, int)(width, height) pixel size of layout.
3669 &#34;&#34;&#34;
3670 return self.pixel_size </code></pre>
3671 </details>
3672 </dd>
3673 <dt id="fluxity.PangoTextLayout.get_top_pad"><code class="name flex">
3674 <span>def <span class="ident">get_top_pad</span></span>(<span>self)</span>
3675 </code></dt>
3676 <dd>
3677 <div class="desc"><p>Returns pixel distance from layout top to highest possible pixel drawn for any font. </p>
3678 <p><strong>Returns:</strong> (int)(pad) Top pad size in pixels.</p></div>
3679 <details class="source">
3680 <summary>
3681 <span>Expand source code</span>
3682 </summary>
3683 <pre><code class="python">def get_top_pad(self):
3684 &#34;&#34;&#34;
3685 Returns pixel distance from layout top to highest possible pixel drawn for any font.
3686
3687 **Returns:** (int)(pad) Top pad size in pixels.
3688 &#34;&#34;&#34;
3689 return self.height - self.descent - self.ascent</code></pre>
3690 </details>
3691 </dd>
3692 <dt id="fluxity.PangoTextLayout.set_opacity"><code class="name flex">
3693 <span>def <span class="ident">set_opacity</span></span>(<span>self, opacity)</span>
3694 </code></dt>
3695 <dd>
3696 <div class="desc"><p><strong><code>opacity(float)</code></strong> Opacity in range 0.0 - 1.0.</p>
3697 <p>Sets opacity for the text to be drawn. Default value is 1.0</p></div>
3698 <details class="source">
3699 <summary>
3700 <span>Expand source code</span>
3701 </summary>
3702 <pre><code class="python">def set_opacity(self, opacity):
3703 &#34;&#34;&#34;
3704 **`opacity(float)`** Opacity in range 0.0 - 1.0.
3705
3706 Sets opacity for the text to be drawn. Default value is 1.0
3707 &#34;&#34;&#34;
3708 if opacity &lt; 0.0:
3709 opacity = 0.0
3710 if opacity &gt; 1.0:
3711 opacity = 1.0
3712
3713 self.opacity = opacity</code></pre>
3714 </details>
3715 </dd>
3716 </dl>
3717 </dd>
3718 </dl>
3719 </section>
3720 </article>
3721 <nav id="sidebar">
3722 <h1>Index</h1>
3723 <div class="toc">
3724 <ul>
3725 <li><a href="#gpl-licence-text">GPL Licence text</a></li>
3726 <li><a href="#fluxity-scripting">FLUXITY SCRIPTING</a><ul>
3727 <li><a href="#script-interface">SCRIPT INTERFACE</a></li>
3728 <li><a href="#script-lifecycle">SCRIPT LIFECYCLE</a></li>
3729 <li><a href="#example-script">EXAMPLE SCRIPT</a><ul>
3730 <li><a href="#init_script">init_script()</a></li>
3731 <li><a href="#init_render">init_render()</a></li>
3732 <li><a href="#render_frame">render_frame()</a></li>
3733 </ul>
3734 </li>
3735 <li><a href="#developing-fluxity-scripts">DEVELOPING FLUXITY SCRIPTS</a></li>
3736 </ul>
3737 </li>
3738 <li><a href="#fluxity-api_1">FLUXITY API</a></li>
3739 </ul>
3740 </div>
3741 <ul id="index">
3742 <li><h3><a href="#header-variables">Global variables</a></h3>
3743 <ul class="">
3744 <li><code><a title="fluxity.EDITOR_CHECK_BOX" href="#fluxity.EDITOR_CHECK_BOX">EDITOR_CHECK_BOX</a></code></li>
3745 <li><code><a title="fluxity.EDITOR_COLOR" href="#fluxity.EDITOR_COLOR">EDITOR_COLOR</a></code></li>
3746 <li><code><a title="fluxity.EDITOR_FILE_PATH" href="#fluxity.EDITOR_FILE_PATH">EDITOR_FILE_PATH</a></code></li>
3747 <li><code><a title="fluxity.EDITOR_FLOAT" href="#fluxity.EDITOR_FLOAT">EDITOR_FLOAT</a></code></li>
3748 <li><code><a title="fluxity.EDITOR_FLOAT_RANGE" href="#fluxity.EDITOR_FLOAT_RANGE">EDITOR_FLOAT_RANGE</a></code></li>
3749 <li><code><a title="fluxity.EDITOR_INT" href="#fluxity.EDITOR_INT">EDITOR_INT</a></code></li>
3750 <li><code><a title="fluxity.EDITOR_INT_RANGE" href="#fluxity.EDITOR_INT_RANGE">EDITOR_INT_RANGE</a></code></li>
3751 <li><code><a title="fluxity.EDITOR_OPTIONS" href="#fluxity.EDITOR_OPTIONS">EDITOR_OPTIONS</a></code></li>
3752 <li><code><a title="fluxity.EDITOR_PANGO_FONT" href="#fluxity.EDITOR_PANGO_FONT">EDITOR_PANGO_FONT</a></code></li>
3753 <li><code><a title="fluxity.EDITOR_PANGO_FONT_DEFAULT_VALUES" href="#fluxity.EDITOR_PANGO_FONT_DEFAULT_VALUES">EDITOR_PANGO_FONT_DEFAULT_VALUES</a></code></li>
3754 <li><code><a title="fluxity.EDITOR_TEXT" href="#fluxity.EDITOR_TEXT">EDITOR_TEXT</a></code></li>
3755 <li><code><a title="fluxity.EDITOR_TEXT_AREA" href="#fluxity.EDITOR_TEXT_AREA">EDITOR_TEXT_AREA</a></code></li>
3756 <li><code><a title="fluxity.KEYFRAME_DISCRETE" href="#fluxity.KEYFRAME_DISCRETE">KEYFRAME_DISCRETE</a></code></li>
3757 <li><code><a title="fluxity.KEYFRAME_LINEAR" href="#fluxity.KEYFRAME_LINEAR">KEYFRAME_LINEAR</a></code></li>
3758 <li><code><a title="fluxity.KEYFRAME_SMOOTH" href="#fluxity.KEYFRAME_SMOOTH">KEYFRAME_SMOOTH</a></code></li>
3759 <li><code><a title="fluxity.PROFILE_COLORSPACE" href="#fluxity.PROFILE_COLORSPACE">PROFILE_COLORSPACE</a></code></li>
3760 <li><code><a title="fluxity.PROFILE_DESCRIPTION" href="#fluxity.PROFILE_DESCRIPTION">PROFILE_DESCRIPTION</a></code></li>
3761 <li><code><a title="fluxity.PROFILE_DISPLAY_ASPECT_DEN" href="#fluxity.PROFILE_DISPLAY_ASPECT_DEN">PROFILE_DISPLAY_ASPECT_DEN</a></code></li>
3762 <li><code><a title="fluxity.PROFILE_DISPLAY_ASPECT_NUM" href="#fluxity.PROFILE_DISPLAY_ASPECT_NUM">PROFILE_DISPLAY_ASPECT_NUM</a></code></li>
3763 <li><code><a title="fluxity.PROFILE_FRAME_RATE_DEN" href="#fluxity.PROFILE_FRAME_RATE_DEN">PROFILE_FRAME_RATE_DEN</a></code></li>
3764 <li><code><a title="fluxity.PROFILE_FRAME_RATE_NUM" href="#fluxity.PROFILE_FRAME_RATE_NUM">PROFILE_FRAME_RATE_NUM</a></code></li>
3765 <li><code><a title="fluxity.PROFILE_HEIGHT" href="#fluxity.PROFILE_HEIGHT">PROFILE_HEIGHT</a></code></li>
3766 <li><code><a title="fluxity.PROFILE_PROGRESSIVE" href="#fluxity.PROFILE_PROGRESSIVE">PROFILE_PROGRESSIVE</a></code></li>
3767 <li><code><a title="fluxity.PROFILE_SAMPLE_ASPECT_DEN" href="#fluxity.PROFILE_SAMPLE_ASPECT_DEN">PROFILE_SAMPLE_ASPECT_DEN</a></code></li>
3768 <li><code><a title="fluxity.PROFILE_SAMPLE_ASPECT_NUM" href="#fluxity.PROFILE_SAMPLE_ASPECT_NUM">PROFILE_SAMPLE_ASPECT_NUM</a></code></li>
3769 <li><code><a title="fluxity.PROFILE_WIDTH" href="#fluxity.PROFILE_WIDTH">PROFILE_WIDTH</a></code></li>
3770 </ul>
3771 </li>
3772 <li><h3><a href="#header-functions">Functions</a></h3>
3773 <ul class="">
3774 <li><code><a title="fluxity.get_script_default_edit_data" href="#fluxity.get_script_default_edit_data">get_script_default_edit_data</a></code></li>
3775 </ul>
3776 </li>
3777 <li><h3><a href="#header-classes">Classes</a></h3>
3778 <ul>
3779 <li>
3780 <h4><code><a title="fluxity.AffineTransform" href="#fluxity.AffineTransform">AffineTransform</a></code></h4>
3781 <ul class="">
3782 <li><code><a title="fluxity.AffineTransform.apply_transform" href="#fluxity.AffineTransform.apply_transform">apply_transform</a></code></li>
3783 </ul>
3784 </li>
3785 <li>
3786 <h4><code><a title="fluxity.AnimatedValue" href="#fluxity.AnimatedValue">AnimatedValue</a></code></h4>
3787 <ul class="">
3788 <li><code><a title="fluxity.AnimatedValue.add_keyframe_at_frame" href="#fluxity.AnimatedValue.add_keyframe_at_frame">add_keyframe_at_frame</a></code></li>
3789 <li><code><a title="fluxity.AnimatedValue.get_value" href="#fluxity.AnimatedValue.get_value">get_value</a></code></li>
3790 </ul>
3791 </li>
3792 <li>
3793 <h4><code><a title="fluxity.FluxityContext" href="#fluxity.FluxityContext">FluxityContext</a></code></h4>
3794 <ul class="">
3795 <li><code><a title="fluxity.FluxityContext.add_editor" href="#fluxity.FluxityContext.add_editor">add_editor</a></code></li>
3796 <li><code><a title="fluxity.FluxityContext.create_text_layout" href="#fluxity.FluxityContext.create_text_layout">create_text_layout</a></code></li>
3797 <li><code><a title="fluxity.FluxityContext.get_data_obj" href="#fluxity.FluxityContext.get_data_obj">get_data_obj</a></code></li>
3798 <li><code><a title="fluxity.FluxityContext.get_dimensions" href="#fluxity.FluxityContext.get_dimensions">get_dimensions</a></code></li>
3799 <li><code><a title="fluxity.FluxityContext.get_editor_value" href="#fluxity.FluxityContext.get_editor_value">get_editor_value</a></code></li>
3800 <li><code><a title="fluxity.FluxityContext.get_frame_cr" href="#fluxity.FluxityContext.get_frame_cr">get_frame_cr</a></code></li>
3801 <li><code><a title="fluxity.FluxityContext.get_length" href="#fluxity.FluxityContext.get_length">get_length</a></code></li>
3802 <li><code><a title="fluxity.FluxityContext.get_profile_property" href="#fluxity.FluxityContext.get_profile_property">get_profile_property</a></code></li>
3803 <li><code><a title="fluxity.FluxityContext.get_script_data" href="#fluxity.FluxityContext.get_script_data">get_script_data</a></code></li>
3804 <li><code><a title="fluxity.FluxityContext.get_script_dir" href="#fluxity.FluxityContext.get_script_dir">get_script_dir</a></code></li>
3805 <li><code><a title="fluxity.FluxityContext.log_line" href="#fluxity.FluxityContext.log_line">log_line</a></code></li>
3806 <li><code><a title="fluxity.FluxityContext.set_author" href="#fluxity.FluxityContext.set_author">set_author</a></code></li>
3807 <li><code><a title="fluxity.FluxityContext.set_data_obj" href="#fluxity.FluxityContext.set_data_obj">set_data_obj</a></code></li>
3808 <li><code><a title="fluxity.FluxityContext.set_editors_data" href="#fluxity.FluxityContext.set_editors_data">set_editors_data</a></code></li>
3809 <li><code><a title="fluxity.FluxityContext.set_frame_name" href="#fluxity.FluxityContext.set_frame_name">set_frame_name</a></code></li>
3810 <li><code><a title="fluxity.FluxityContext.set_length" href="#fluxity.FluxityContext.set_length">set_length</a></code></li>
3811 <li><code><a title="fluxity.FluxityContext.set_name" href="#fluxity.FluxityContext.set_name">set_name</a></code></li>
3812 <li><code><a title="fluxity.FluxityContext.set_prints_to_log_file" href="#fluxity.FluxityContext.set_prints_to_log_file">set_prints_to_log_file</a></code></li>
3813 <li><code><a title="fluxity.FluxityContext.set_version" href="#fluxity.FluxityContext.set_version">set_version</a></code></li>
3814 </ul>
3815 </li>
3816 <li>
3817 <h4><code><a title="fluxity.PangoTextLayout" href="#fluxity.PangoTextLayout">PangoTextLayout</a></code></h4>
3818 <ul class="two-column">
3819 <li><code><a title="fluxity.PangoTextLayout.create_pango_layout" href="#fluxity.PangoTextLayout.create_pango_layout">create_pango_layout</a></code></li>
3820 <li><code><a title="fluxity.PangoTextLayout.draw_layout" href="#fluxity.PangoTextLayout.draw_layout">draw_layout</a></code></li>
3821 <li><code><a title="fluxity.PangoTextLayout.get_pango_alignment" href="#fluxity.PangoTextLayout.get_pango_alignment">get_pango_alignment</a></code></li>
3822 <li><code><a title="fluxity.PangoTextLayout.get_pixel_size" href="#fluxity.PangoTextLayout.get_pixel_size">get_pixel_size</a></code></li>
3823 <li><code><a title="fluxity.PangoTextLayout.get_top_pad" href="#fluxity.PangoTextLayout.get_top_pad">get_top_pad</a></code></li>
3824 <li><code><a title="fluxity.PangoTextLayout.set_opacity" href="#fluxity.PangoTextLayout.set_opacity">set_opacity</a></code></li>
3825 </ul>
3826 </li>
3827 </ul>
3828 </li>
3829 </ul>
3830 </nav>
3831 </main>
3832 <footer id="footer">
3833 <p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
3834 </footer>
3835 </body>
3836 </html>