<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <link rel="stylesheet" href="style.css" type="text/css"> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type"> <link rel="Start" href="index.html"> <link rel="previous" href="Lwt_lib.html"> <link rel="next" href="Lwt_preemptive.html"> <link rel="Up" href="index.html"> <link title="Index of types" rel=Appendix href="index_types.html"> <link title="Index of exceptions" rel=Appendix href="index_exceptions.html"> <link title="Index of values" rel=Appendix href="index_values.html"> <link title="Index of class attributes" rel=Appendix href="index_attributes.html"> <link title="Index of class methods" rel=Appendix href="index_methods.html"> <link title="Index of classes" rel=Appendix href="index_classes.html"> <link title="Index of class types" rel=Appendix href="index_class_types.html"> <link title="Index of modules" rel=Appendix href="index_modules.html"> <link title="Index of module types" rel=Appendix href="index_module_types.html"> <link title="Lwt_condition" rel="Chapter" href="Lwt_condition.html"> <link title="Lwt_list" rel="Chapter" href="Lwt_list.html"> <link title="Lwt" rel="Chapter" href="Lwt.html"> <link title="Lwt_mutex" rel="Chapter" href="Lwt_mutex.html"> <link title="Lwt_mvar" rel="Chapter" href="Lwt_mvar.html"> <link title="Lwt_pool" rel="Chapter" href="Lwt_pool.html"> <link title="Lwt_sequence" rel="Chapter" href="Lwt_sequence.html"> <link title="Lwt_stream" rel="Chapter" href="Lwt_stream.html"> <link title="Lwt_switch" rel="Chapter" href="Lwt_switch.html"> <link title="Lwt_util" rel="Chapter" href="Lwt_util.html"> <link title="Lwt_pqueue" rel="Chapter" href="Lwt_pqueue.html"> <link title="Lwt_lib" rel="Chapter" href="Lwt_lib.html"> <link title="Lwt_glib" rel="Chapter" href="Lwt_glib.html"> <link title="Lwt_preemptive" rel="Chapter" href="Lwt_preemptive.html"> <link title="Lwt_event" rel="Chapter" href="Lwt_event.html"> <link title="Lwt_signal" rel="Chapter" href="Lwt_signal.html"> <link title="Lwt_react" rel="Chapter" href="Lwt_react.html"> <link title="Lwt_ssl" rel="Chapter" href="Lwt_ssl.html"> <link title="Lwt_text" rel="Chapter" href="Lwt_text.html"> <link title="Lwt_term" rel="Chapter" href="Lwt_term.html"> <link title="Lwt_read_line" rel="Chapter" href="Lwt_read_line.html"> <link title="Lwt_top" rel="Chapter" href="Lwt_top.html"> <link title="Lwt_chan" rel="Chapter" href="Lwt_chan.html"> <link title="Lwt_daemon" rel="Chapter" href="Lwt_daemon.html"> <link title="Lwt_gc" rel="Chapter" href="Lwt_gc.html"> <link title="Lwt_io" rel="Chapter" href="Lwt_io.html"> <link title="Lwt_log" rel="Chapter" href="Lwt_log.html"> <link title="Lwt_main" rel="Chapter" href="Lwt_main.html"> <link title="Lwt_process" rel="Chapter" href="Lwt_process.html"> <link title="Lwt_throttle" rel="Chapter" href="Lwt_throttle.html"> <link title="Lwt_timeout" rel="Chapter" href="Lwt_timeout.html"> <link title="Lwt_unix" rel="Chapter" href="Lwt_unix.html"> <link title="Lwt_sys" rel="Chapter" href="Lwt_sys.html"> <link title="Lwt_engine" rel="Chapter" href="Lwt_engine.html"> <link title="Lwt_bytes" rel="Chapter" href="Lwt_bytes.html"> <link title="Pa_lwt" rel="Chapter" href="Pa_lwt.html"> <link title="Pa_lwt_log" rel="Chapter" href="Pa_lwt_log.html"><title>Lwt_glib</title> </head> <body> <div class="navbar"><a class="pre" href="Lwt_lib.html" title="Lwt_lib">Previous</a> <a class="up" href="index.html" title="Index">Up</a> <a class="post" href="Lwt_preemptive.html" title="Lwt_preemptive">Next</a> </div> <h1>Module <a href="type_Lwt_glib.html">Lwt_glib</a></h1> <pre><span class="keyword">module</span> Lwt_glib: <code class="code"><span class="keyword">sig</span></code> <a href="Lwt_glib.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info"> Glib integration<br> </div> <hr width="100%"> <br> This module allow to use Lwt in GTK applications. <p> Here is what you have to do to make Lwt and GTK work together:<ul> <li>call <a href="Lwt_glib.html#VALinstall"><code class="code"><span class="constructor">Lwt_glib</span>.install</code></a> at the beginning of your program (before or after GMain.init, it does not matter)</li> <li>do not call GMain.main, write your application as a normal Lwt application instead.</li> </ul> For example: <p> <pre class="codepre"><code class="code"> <span class="keyword">let</span> () = <span class="constructor">Lwt_main</span>.run (<br> <span class="comment">(* Initializes GTK. *)</span><br> ignore (<span class="constructor">GMain</span>.init ());<br> <br> <span class="comment">(* Install Lwt<->Glib integration. *)</span><br> <span class="constructor">Lwt_glib</span>.install ();<br> <br> <span class="comment">(* Thread which is wakeup when the main window is closed. *)</span><br> <span class="keyword">let</span> waiter, wakener = <span class="constructor">Lwt</span>.wait () <span class="keyword">in</span><br> <br> <span class="comment">(* Create a window. *)</span><br> <span class="keyword">let</span> window = <span class="constructor">GWindow</span>.window () <span class="keyword">in</span><br> <br> <span class="comment">(* Display something inside the window. *)</span><br> ignore (<span class="constructor">GMisc</span>.label ~text:<span class="string">"Hello, world!"</span> ~packing:window<span class="keywordsign">#</span>add ());<br> <br> <span class="comment">(* Quit when the window is closed. *)</span><br> ignore (window<span class="keywordsign">#</span>connect<span class="keywordsign">#</span>destroy (<span class="constructor">Lwt</span>.wakeup wakener));<br> <br> <span class="comment">(* Show the window. *)</span><br> window<span class="keywordsign">#</span>show ();<br> <br> <span class="comment">(* Wait for it to be closed. *)</span><br> waiter<br> )<br> </code></pre><br> <pre><span id="VALinstall"><span class="keyword">val</span> install</span> : <code class="type">?mode:[ `glib_into_lwt | `lwt_into_glib ] -> unit -> unit</code></pre><div class="info"> Install the Glib<->Lwt integration. <p> If <code class="code">mode</code> is <code class="code"><span class="keywordsign">`</span>glib_into_lwt</code> then glib will use the Lwt main loop, and if <code class="code">mode</code> is <code class="code"><span class="keywordsign">`</span>lwt_into_glib</code> then Lwt will use the Glib main loop. <p> <code class="code">mode</code> defaults to <code class="code"><span class="keywordsign">`</span>lwt_into_glib</code> because it is more portable. <code class="code"><span class="keywordsign">`</span>glib_into_lwt</code> does not work under Windows and MacOS. <p> If the integration is already active, this function does nothing.<br> </div> <pre><span id="VALremove"><span class="keyword">val</span> remove</span> : <code class="type">unit -> unit</code></pre><div class="info"> Remove the Glib<->Lwt integration.<br> </div> <pre><span id="VALiter"><span class="keyword">val</span> iter</span> : <code class="type">bool -> unit</code></pre><div class="info"> This function is not related to Lwt. <code class="code">iter may_block</code> does the same as <code class="code"><span class="constructor">Glib</span>.<span class="constructor">Main</span>.iteration may_block</code> but can safely be called in a multi-threaded program, it will not block the whole program. <p> For example: <p> <pre class="codepre"><code class="code"> <span class="keyword">let</span> main () =<br> <span class="keyword">while</span> <span class="keyword">true</span> <span class="keyword">do</span><br> <span class="constructor">Lwt_glib</span>.iter <span class="keyword">true</span><br> <span class="keyword">done</span><br> <br> <span class="keyword">let</span> thread = <span class="constructor">Thread</span>.create main ()<br> </code></pre> <p> Note: you can call this function only from one thread at a time, otherwise it will raise <code class="code"><span class="constructor">Failure</span></code>.<br> </div> <pre><span id="VALwakeup"><span class="keyword">val</span> wakeup</span> : <code class="type">unit -> unit</code></pre><div class="info"> If one thread is blocking on <a href="Lwt_glib.html#VALiter"><code class="code"><span class="constructor">Lwt_glib</span>.iter</code></a>, then <code class="code">wakeup ()</code> make <a href="Lwt_glib.html#VALiter"><code class="code"><span class="constructor">Lwt_glib</span>.iter</code></a> to return immediatly.<br> </div> </body></html>