| 1 |
<html><head><meta name="robots" content="index,follow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 2 |
<title>Scripting 9. Turning a script into a stand-alone program</title> |
| 3 |
<style> |
| 4 |
td { padding-left: 5pt; padding-right: 5pt; } |
| 5 |
th { padding-left: 5pt; padding-right: 5pt; } |
| 6 |
code { white-space: pre-wrap; } |
| 7 |
dd { white-space: pre-wrap; } |
| 8 |
</style> |
| 9 |
</head><body bgcolor="#FFFFFF"> |
| 10 |
|
| 11 |
<table border=0 cellpadding=0 cellspacing=0><tr><td bgcolor="#CCCC00"><table border=4 cellpadding=9><tr><td align=middle bgcolor="#000000"><font face="Palatino,Times" size=6 color="#999900"><b> |
| 12 |
Scripting 9. Turning a script into a stand-alone program |
| 13 |
</b></font></table></table> |
| 14 |
<p>You can turn your script into a double-clickable stand-alone program by including it into Praat's <b>main</b> procedure. If you want to try this, you should already know how to compile and link the Praat program on your computer.</p> |
| 15 |
<p>These stand-alone programs do not show the Objects window and the Picture window; therefore, you will usually want to use <a href="Demo_window.html">Demo window</a> commands in your script. Here is an example:</p> |
| 16 |
<code> #include "praat.h"<br></code> |
| 17 |
<code> <br></code> |
| 18 |
<code> const char32 myScript [ ] = U""<br></code> |
| 19 |
<code> "demo Text: 0.5, \"centre\", 0.5, \"half\", \"Hello world\"\n"<br></code> |
| 20 |
<code> "demoWaitForInput ( )\n"<br></code> |
| 21 |
<code> ;<br></code> |
| 22 |
<code> <br></code> |
| 23 |
<code> int main (int argc, char *argv [ ]) {<br></code> |
| 24 |
<code> praat_setStandAloneScriptText (myScript);<br></code> |
| 25 |
<code> praat_init (U"Hello", argc, argv);<br></code> |
| 26 |
<code> INCLUDE_LIBRARY (praat_uvafon_init)<br></code> |
| 27 |
<code> praat_run ();<br></code> |
| 28 |
<code> return 0; // obligatory<br></code> |
| 29 |
<code> }<br></code> |
| 30 |
<p>The script in this example raises the Demo window, writes “Hello world” in the middle of the window, waits until the user clicks the mouse or presses a key, and then closes.</p> |
| 31 |
<p>Note that Praat is distributed under the General Public License (GPL). This means that if you distribute a Praat-based stand-alone program, you have to make it open source under the GPL as well (version 3.0 or later).</p> |
| 32 |
<p>See also <a href="Programming_with_Praat.html">Programming with Praat</a>.</p> |
| 33 |
<h2>Details</h2> |
| 34 |
<p>Your program can save its preferences in a folder of its choice, e.g. in <b><code><font size=+1>preferencesDirectory$ + “/../GuineaPigAnalyzer”</font></code></b> if your program is called GuineaPigAnalyzer. If you want to be less conspicuous and like to use the Praat preferences folder instead, please use the <b><code><font size=+1>apps</font></code></b> subfolder, in this way:</p> |
| 35 |
<code> <a href="_createFolder_.html">createFolder</a>: preferencesDirectory$ + “/apps”<br></code> |
| 36 |
<code> <a href="_createFolder_.html">createFolder</a>: preferencesDirectory$ + “/apps/GuineaPigAnalyzer”<br></code> |
| 37 |
<h3>Links to this page</h3> |
| 38 |
<ul> |
| 39 |
<li><a href="Scripting.html">Scripting</a> |
| 40 |
<li><a href="What_was_new_in_5_2_.html">What was new in 5.2?</a> |
| 41 |
</ul> |
| 42 |
<hr> |
| 43 |
<address> |
| 44 |
<p>© ppgb 20201229</p> |
| 45 |
</address> |
| 46 |
</body> |
| 47 |
</html> |