/usr/share/gtk-doc/html/libgwymodule/gwymodule-tutorial-beyond.html is in libgwyddion20-doc 2.34-3ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Gwyddion Module Library Reference Manual: Beyond the Minimal Module</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="Gwyddion Module Library Reference Manual">
<link rel="up" href="ModuleTutorial.html" title="Gwyddion Module Tutorial">
<link rel="prev" href="gwymodule-tutorial-minimal.html" title="Minimal Module">
<link rel="next" href="gwymodule-tutorial-process.html" title="Data Processing Modules">
<meta name="generator" content="GTK-Doc V1.19 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="10"><tr valign="middle">
<td width="100%" align="left"></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td>
<td><a accesskey="u" href="ModuleTutorial.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td>
<td><a accesskey="p" href="gwymodule-tutorial-minimal.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td>
<td><a accesskey="n" href="gwymodule-tutorial-process.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td>
</tr></table>
<div class="refentry">
<a name="gwymodule-tutorial-beyond"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle">Beyond the Minimal Module</span></h2>
<p>Beyond the Minimal Module —
Common module idioms
</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsect1">
<a name="id-1.3.4.3"></a><h2>Multiple Modules, Multiple Function, Multifunctions</h2>
<p>
Often one wants to implement a group of closely related functions that
could share quite a bit of code. There are several posibilities how
to do it.
</p>
<p>
The naive approach would be to put the code of all the modules to
a one file and share what is shareable. But alas! there can be only one
<a class="link" href="libgwymodule-gwymoduleloader.html#GWY-MODULE-QUERY:CAPS" title="GWY_MODULE_QUERY()"><code class="literal">GWY_MODULE_QUERY</code></a> per file, thus a one file can register only a one
module and this approach would not work.
</p>
<p>
The prefered solution is to register more than function for the module.
This is as simple as it sounds. One just has to call
<a class="link" href="libgwymodule-gwymodule-process.html#gwy-process-func-register" title="gwy_process_func_register ()"><code class="function">gwy_process_func_register()</code></a> (or other feature registration method)
several times with different functions. It is even possible to register
functions of different kind in a one module, but usually there is no
reason to do this.
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gboolean">gboolean</a></span>
<span class="function">module_register</span><span class="symbol">(</span><span class="type">void</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal"> </span><span class="function"><a href="libgwymodule-gwymodule-process.html#gwy-process-func-register">gwy_process_func_register</a></span><span class="symbol">(</span><span class="string">"sobel_horizontal"</span><span class="symbol">,</span>
<span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="libgwymodule-gwymodule-process.html#GwyProcessFunc">GwyProcessFunc</a></span><span class="symbol">)&</span><span class="normal">gradient_sobel_horizontal</span><span class="symbol">,</span>
<span class="normal"> </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"/_Presentation/_Gradient/_Sobel (horizontal)"</span><span class="symbol">),</span>
<span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span>
<span class="normal"> GRADIENT_RUN_MODES</span><span class="symbol">,</span>
<span class="normal"> <a href="../libgwyapp/libgwyapp-menu.html#GWY-MENU-FLAG-DATA:CAPS">GWY_MENU_FLAG_DATA</a></span><span class="symbol">,</span>
<span class="normal"> </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"Horizontal Sobel gradient presentation"</span><span class="symbol">));</span>
<span class="normal"> </span><span class="function"><a href="libgwymodule-gwymodule-process.html#gwy-process-func-register">gwy_process_func_register</a></span><span class="symbol">(</span><span class="string">"sobel_vertical"</span><span class="symbol">,</span>
<span class="normal"> </span><span class="symbol">(</span><span class="normal"><a href="libgwymodule-gwymodule-process.html#GwyProcessFunc">GwyProcessFunc</a></span><span class="symbol">)&</span><span class="normal">gradient_sobel_vertical</span><span class="symbol">,</span>
<span class="normal"> </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"/_Presentation/_Gradient/_Sobel (vertical)"</span><span class="symbol">),</span>
<span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span>
<span class="normal"> GRADIENT_RUN_MODES</span><span class="symbol">,</span>
<span class="normal"> <a href="../libgwyapp/libgwyapp-menu.html#GWY-MENU-FLAG-DATA:CAPS">GWY_MENU_FLAG_DATA</a></span><span class="symbol">,</span>
<span class="normal"> </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#N-:CAPS">N_</a></span><span class="symbol">(</span><span class="string">"Vertical Sobel gradient presentation"</span><span class="symbol">));</span>
<span class="normal"> </span><span class="keyword">return</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#TRUE:CAPS">TRUE</a></span><span class="symbol">;</span>
<span class="cbracket">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
The other posibility is to call <a class="link" href="libgwymodule-gwymodule-process.html#gwy-process-func-register" title="gwy_process_func_register ()"><code class="function">gwy_process_func_register()</code></a> several times
with the same <em class="parameter"><code>func</code></em> argument. The function can then
determine from its last argument (<em class="parameter"><code>name</code></em>) what
function the caller thinks it is calling. This approach can be used
when the differences between the functions are very small. Incidentally,
this is also exactly how the plugin-proxy module works.
</p>
</div>
<div class="refsect1">
<a name="id-1.3.4.4"></a><h2>Settings</h2>
<p>
The nice thing about <span class="application">Gwyddion</span> module dialog
boxes is that they show the same parameter values as when you last opened
them, and they remember the settings even across sessions. And you of
course want this feature in your modules too.
</p>
<p>
Saving and restoring settings usually has sense only for modules with
a GUI, simple noninteractive modules like value inversion have no
settings to remember. We will get to GUI later.
</p>
<p>
There is a one <a href="../libgwyddion/GwyContainer.html"><span class="type">GwyContainer</span></a> in <span class="application">Gwyddion</span>
containing settings for all modules (and other creatures). The function
<a href="../libgwyapp/libgwyapp-settings.html#gwy-app-settings-get"><code class="function">gwy_app_settings_get()</code></a> will bring it to you. It is loaded on startup and
saved on exit and you don not need to take care about this. So the only
thing you have to care about is to read the settings from it when your
module starts and store them there on exit. OK, there are in fact two
things you have to care about. There are no limitations on who can
access what in the settings, so to avoid surprises you should use only
keys startings with
<code class="literal">"/module/<em class="parameter"><code>my-module-name</code></em>/"</code>.
</p>
<p>
Loading settings could look (remember they may not always exist, for
instance when the function is run the first time):
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="usertype">GwyContainer</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">settings</span><span class="symbol">;</span>
<span class="normal">settings </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="../libgwyapp/libgwyapp-settings.html#gwy-app-settings-get">gwy_app_settings_get</a></span><span class="symbol">();</span>
<span class="normal">ratio </span><span class="symbol">=</span><span class="normal"> </span><span class="number">1.61803</span><span class="symbol">;</span>
<span class="function"><a href="../libgwyddion/GwyContainer.html#gwy-container-gis-double-by-name">gwy_container_gis_double_by_name</a></span><span class="symbol">(</span><span class="normal">settings</span><span class="symbol">,</span>
<span class="normal"> </span><span class="string">"/module/my_module/ratio"</span><span class="symbol">,</span>
<span class="normal"> </span><span class="symbol">&</span><span class="normal">ratio</span><span class="symbol">);</span>
<span class="normal">ratio </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#CLAMP:CAPS">CLAMP</a></span><span class="symbol">(</span><span class="normal">ratio</span><span class="symbol">,</span><span class="normal"> </span><span class="number">1.0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">2.0</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
Function <a href="../libgwyddion/GwyContainer.html#gwy-container-gis-double-by-name"><code class="function">gwy_container_gis_double_by_name()</code></a> function updates its last
argument only when there is a corresponding value in the container.
The use of <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#CLAMP:CAPS"><code class="function">CLAMP()</code></a> is a recommended defensive measure against corrupted
settings (for example manually (mis)edited by the user) that could cause
troubles later.
</p>
<p>
Saving settings is equally easy:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="usertype">GwyContainer</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">settings</span><span class="symbol">;</span>
<span class="normal">settings </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="../libgwyapp/libgwyapp-settings.html#gwy-app-settings-get">gwy_app_settings_get</a></span><span class="symbol">();</span>
<span class="function"><a href="../libgwyddion/GwyContainer.html#gwy-container-set-double-by-name">gwy_container_set_double_by_name</a></span><span class="symbol">(</span><span class="normal">settings</span><span class="symbol">,</span>
<span class="normal"> </span><span class="string">"/module/my_module/ratio"</span><span class="symbol">,</span>
<span class="normal"> ratio</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
Modules customarily define a function <span class="symbol"><code class="function">load_settings()</code></span>
that fills its internal parameter representation on the start of
execution and santitizes them. Likewise function
<span class="symbol"><code class="function">save_settings()</code></span> stores them to back to the global
settings upon exit. Note to achieve the typical state preservation of
<span class="application">Gwyddion</span> modules parameters have to be saved
both after successful execution and cancellation.
</p>
</div>
<div class="refsect1">
<a name="id-1.3.4.5"></a><h2>Creating New Files, Data Fields and Graphs</h2>
<p>
Not always one wants to modify the original data instead one prefers to
create a new window for the result, or the output is perhaps of diffrent
kind than the source: a graph is created from two-dimensional data.
</p>
<p>
Modules usually do not create new files, if they create new objects, they
put them to the same container as the source data. A notable exception
are file modules, they however just return the newly created container.
New data containers, if one wishes to create them, are put under the
control of the data browser with <a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-data-browser-add"><code class="function">gwy_app_data_browser_add()</code></a>. If they
contain no visible data, they would be inaccessible by the user and
present a memory leak. Therefore some data must be added and made
visible later (or beforehand).
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="usertype">GwyContainer</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">container</span><span class="symbol">;</span>
<span class="normal">container </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="../libgwyddion/GwyContainer.html#gwy-container-new">gwy_container_new</a></span><span class="symbol">();</span>
<span class="comment">/* Fill data with something meaningful */</span>
<span class="symbol">...</span>
<span class="function"><a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-data-browser-add">gwy_app_data_browser_add</a></span><span class="symbol">(</span><span class="normal">container</span><span class="symbol">);</span>
<span class="function"><a href="http://developer.gnome.org/doc/API/2.0/gobject/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span><span class="symbol">(</span><span class="normal">container</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
New data fields can be created from scratch with <a href="../libgwyprocess/GwyDataField.html#gwy-data-field-new"><code class="function">gwy_data_field_new()</code></a>,
in most cases the new data field is strongly related to an existing one
and then <a href="../libgwyprocess/GwyDataField.html#gwy-data-field-new-alike"><code class="function">gwy_data_field_new_alike()</code></a> or <a href="../libgwyprocess/GwyDataField.html#gwy-data-field-duplicate"><code class="function">gwy_data_field_duplicate()</code></a> come
handy. The former copies all properties <span class="emphasis"><em>except</em></span> the
data itself, the latter duplicates a data field completely.
</p>
<p>
When we created the new object and we have to add it to the current file.
We <span class="emphasis"><em>could</em></span> just use one of <a href="../libgwyddion/GwyContainer.html"><span class="type">GwyContainer</span></a> functions
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="function"><a href="../libgwyddion/GwyContainer.html#gwy-container-set-object-by-name">gwy_container_set_object_by_name</a></span><span class="symbol">(</span><span class="normal">container</span><span class="symbol">,</span><span class="normal"> </span><span class="string">"/12345/data"</span><span class="symbol">,</span><span class="normal"> data_field</span><span class="symbol">);</span>
<span class="function"><a href="http://developer.gnome.org/doc/API/2.0/gobject/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span><span class="symbol">(</span><span class="normal">data_field</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
The data browser would notice it and add the data field, but this method
is generally very inconvenient – for start, how we came to
<code class="literal">"/12345/data"</code>?. Therefore we use the high-level
interface and obtain the new channel number for free:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="normal">new_id </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-data-browser-add-data-field">gwy_app_data_browser_add_data_field</a></span><span class="symbol">(</span><span class="normal">container</span><span class="symbol">,</span><span class="normal"> data_field</span><span class="symbol">);</span>
<span class="function"><a href="http://developer.gnome.org/doc/API/2.0/gobject/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span><span class="symbol">(</span><span class="normal">data_field</span><span class="symbol">);</span>
<span class="function"><a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-set-data-field-title">gwy_app_set_data_field_title</a></span><span class="symbol">(</span><span class="normal">container</span><span class="symbol">,</span><span class="normal"> new_id</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#gettext-macro">_</a></span><span class="symbol">(</span><span class="string">"Bogosity"</span><span class="symbol">));</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
Often the new data field should inherit more properties from the original
one than just the dimensions, e.g., the color gradient. This can be
easily achieved with <a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-sync-data-items"><code class="function">gwy_app_sync_data_items()</code></a>
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="function"><a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-sync-data-items">gwy_app_sync_data_items</a></span><span class="symbol">(</span><span class="normal">container</span><span class="symbol">,</span><span class="normal"> container</span><span class="symbol">,</span>
<span class="normal"> old_id</span><span class="symbol">,</span><span class="normal"> new_id</span><span class="symbol">,</span>
<span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">,</span>
<span class="normal"> <a href="../libgwyapp/libgwyapp-data-browser.html#GWY-DATA-ITEM-GRADIENT:CAPS">GWY_DATA_ITEM_GRADIENT</a></span><span class="symbol">,</span>
<span class="normal"> <a href="../libgwyapp/libgwyapp-data-browser.html#GWY-DATA-ITEM-MASK-COLOR:CAPS">GWY_DATA_ITEM_MASK_COLOR</a></span><span class="symbol">,</span>
<span class="normal"> </span><span class="number">0</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
The id number of the source data field (<span class="symbol">old_id</span>)
was obtained with <a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-data-browser-get-current"><code class="function">gwy_app_data_browser_get_current()</code></a>
(normally together with the data field itself, its key and/or other
current objects)
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="function"><a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-data-browser-get-current">gwy_app_data_browser_get_current</a></span><span class="symbol">(</span><span class="normal"><a href="../libgwyapp/libgwyapp-data-browser.html#GWY-APP-DATA-FIELD-ID:CAPS">GWY_APP_DATA_FIELD_ID</a></span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">&</span><span class="normal">old_id</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
Creation and addition of graphs is very similar. We create a new graph
model with <a href="../libgwydgets/GwyGraphModel.html#gwy-graph-model-new"><code class="function">gwy_graph_model_new()</code></a> or a similar function, create
individual curves with <a href="../libgwydgets/GwyGraphCurveModel.html#gwy-graph-curve-model-new"><code class="function">gwy_graph_curve_model_new()</code></a> and fill the curves
with data. Then we add it to the data browser
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="normal">new_id </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="../libgwyapp/libgwyapp-data-browser.html#gwy-app-data-browser-add-graph-model">gwy_app_data_browser_add_graph_model</a></span><span class="symbol">(</span><span class="normal">container</span><span class="symbol">,</span><span class="normal"> graph_model</span><span class="symbol">);</span>
<span class="function"><a href="http://developer.gnome.org/doc/API/2.0/gobject/gobject-The-Base-Object-Type.html#g-object-unref">g_object_unref</a></span><span class="symbol">(</span><span class="normal">graph_model</span><span class="symbol">);</span></pre></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="refsect1">
<a name="id-1.3.4.6"></a><h2>Graphical User Interface (GUI)</h2>
<p>
You are encouraged to use the <a class="ulink" href="http://gtk.org/" target="_top">Gtk+</a>
graphical toolkit for your module GUI. It has following advantages:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
It is used by <span class="application">Gwyddion</span> itself.
Mixing multiple graphical toolkits in one application often leads
to intricate and hard to resolve bugs, not speaking about
inconsistent look and feel.
</li>
<li class="listitem">
It is used by <span class="application">Gwyddion</span> itself.
Any specialized <span class="application">Gwyddion</span> widgets
you could make use of are Gtk+ widgets.
</li>
<li class="listitem">
It is available for a variety of platforms, allowing to easily
create portable modules.
</li>
<li class="listitem">
It is licensed under GNU LGPL (for all the platforms), this meaning
namely it is free, with complete source code available and imposing
few restrictions on programs using it.
</li>
</ul></div>
<p>
There is an extensive
<a class="ulink" href="http://gtk.org/tutorial/" target="_top">Gtk+ Tutorial</a>
and <a class="ulink" href="http://gtk.org/api/" target="_top">API Reference</a> available
on the Gtk+ Web site. You can use existing modules as templates
for your module.
</p>
<p>
A very simple graphical user interface asking for a one value
(unimaginatively called Amount) can be implemented in Gtk+ as follows:
</p>
<div class="informalexample">
<table class="listing_frame" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="listing_lines" align="right"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42</pre></td>
<td class="listing_code"><pre class="programlisting"><span class="keyword">static</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Basic-Types.html#gboolean">gboolean</a></span>
<span class="function">slope_dialog</span><span class="symbol">(</span><span class="usertype">gdouble</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">amount</span><span class="symbol">)</span>
<span class="cbracket">{</span>
<span class="normal"> </span><span class="usertype">GtkWidget</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">dialog</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">table</span><span class="symbol">,</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">spin</span><span class="symbol">;</span>
<span class="normal"> </span><span class="usertype">GtkObject</span><span class="normal"> </span><span class="symbol">*</span><span class="normal">adjust</span><span class="symbol">;</span>
<span class="normal"> </span><span class="usertype">gint</span><span class="normal"> response</span><span class="symbol">;</span>
<span class="normal"> </span><span class="comment">/* Create the dialog */</span>
<span class="normal"> dialog </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="http://developer.gnome.org/doc/API/2.0/gtk/GtkDialog.html#gtk-dialog-new-with-buttons">gtk_dialog_new_with_buttons</a></span><span class="symbol">(</span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#gettext-macro">_</a></span><span class="symbol">(</span><span class="string">"Frobnicate"</span><span class="symbol">),</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">,</span>
<span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/gtk/gtk3-Stock-Items.html#GTK-STOCK-CANCEL:CAPS">GTK_STOCK_CANCEL</a></span><span class="symbol">,</span><span class="normal"> <a href="http://developer.gnome.org/doc/API/2.0/gtk/GtkDialog.html#GTK-RESPONSE-CANCEL:CAPS">GTK_RESPONSE_CANCEL</a></span><span class="symbol">,</span>
<span class="normal"> <a href="/usr/share/gtk-doc/html/gtk3/gtk3-Stock-Items.html#GTK-STOCK-OK:CAPS">GTK_STOCK_OK</a></span><span class="symbol">,</span><span class="normal"> <a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#GTK-RESPONSE-OK:CAPS">GTK_RESPONSE_OK</a></span><span class="symbol">,</span>
<span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#NULL:CAPS">NULL</a></span><span class="symbol">);</span>
<span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk2/GtkDialog.html#gtk-dialog-set-has-separator">gtk_dialog_set_has_separator</a></span><span class="symbol">(</span><span class="function">GTK_DIALOG</span><span class="symbol">(</span><span class="normal">dialog</span><span class="symbol">),</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">);</span>
<span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#gtk-dialog-set-default-response">gtk_dialog_set_default_response</a></span><span class="symbol">(</span><span class="function">GTK_DIALOG</span><span class="symbol">(</span><span class="normal">dialog</span><span class="symbol">),</span><span class="normal"> <a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#GTK-RESPONSE-OK:CAPS">GTK_RESPONSE_OK</a></span><span class="symbol">);</span>
<span class="normal"> </span><span class="comment">/* Create the parameter controls */</span>
<span class="normal"> table </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkTable.html#gtk-table-new">gtk_table_new</a></span><span class="symbol">(</span><span class="number">1</span><span class="symbol">,</span><span class="normal"> </span><span class="number">3</span><span class="symbol">,</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">);</span>
<span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkBox.html#gtk-box-pack-start">gtk_box_pack_start</a></span><span class="symbol">(</span><span class="function">GTK_BOX</span><span class="symbol">(</span><span class="function">GTK_DIALOG</span><span class="symbol">(</span><span class="normal">dialog</span><span class="symbol">)-></span><span class="normal">vbox</span><span class="symbol">),</span><span class="normal"> table</span><span class="symbol">,</span>
<span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">,</span><span class="normal"> <a href="/usr/share/gtk-doc/html/glib/glib-Standard-Macros.html#FALSE:CAPS">FALSE</a></span><span class="symbol">,</span><span class="normal"> </span><span class="number">4</span><span class="symbol">);</span>
<span class="normal"> adjust </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkAdjustment.html#gtk-adjustment-new">gtk_adjustment_new</a></span><span class="symbol">(*</span><span class="normal">amount</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> </span><span class="number">100</span><span class="symbol">,</span><span class="normal"> </span><span class="number">1</span><span class="symbol">,</span><span class="normal"> </span><span class="number">10</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">);</span>
<span class="normal"> spin </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="../libgwydgets/libgwydgets-gwydgetutils.html#gwy-table-attach-hscale">gwy_table_attach_hscale</a></span><span class="symbol">(</span><span class="normal">table</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">,</span><span class="normal"> </span><span class="function"><a href="../libgwyddion/libgwyddion-gwymacros.html#gettext-macro">_</a></span><span class="symbol">(</span><span class="string">"Amount:"</span><span class="symbol">),</span><span class="normal"> </span><span class="string">"percent"</span><span class="symbol">,</span>
<span class="normal"> adjust</span><span class="symbol">,</span><span class="normal"> </span><span class="number">0</span><span class="symbol">);</span>
<span class="normal"> </span><span class="comment">/* Run the dialog and respond to user actions */</span>
<span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkWidget.html#gtk-widget-show-all">gtk_widget_show_all</a></span><span class="symbol">(</span><span class="normal">dialog</span><span class="symbol">);</span>
<span class="normal"> response </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#gtk-dialog-run">gtk_dialog_run</a></span><span class="symbol">(</span><span class="function">GTK_DIALOG</span><span class="symbol">(</span><span class="normal">dialog</span><span class="symbol">));</span>
<span class="normal"> </span><span class="keyword">switch</span><span class="normal"> </span><span class="symbol">(</span><span class="normal">response</span><span class="symbol">)</span><span class="normal"> </span><span class="cbracket">{</span>
<span class="normal"> </span><span class="keyword">case</span><span class="normal"> <a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#GTK-RESPONSE-CANCEL:CAPS">GTK_RESPONSE_CANCEL</a></span><span class="symbol">:</span>
<span class="normal"> </span><span class="keyword">case</span><span class="normal"> <a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#GTK-RESPONSE-DELETE-EVENT:CAPS">GTK_RESPONSE_DELETE_EVENT</a></span><span class="symbol">:</span>
<span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkWidget.html#gtk-widget-destroy">gtk_widget_destroy</a></span><span class="symbol">(</span><span class="normal">dialog</span><span class="symbol">);</span>
<span class="normal"> </span><span class="keyword">case</span><span class="normal"> <a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#GTK-RESPONSE-NONE:CAPS">GTK_RESPONSE_NONE</a></span><span class="symbol">:</span>
<span class="normal"> </span><span class="keyword">break</span><span class="symbol">;</span>
<span class="normal"> </span><span class="keyword">case</span><span class="normal"> <a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#GTK-RESPONSE-OK:CAPS">GTK_RESPONSE_OK</a></span><span class="symbol">:</span>
<span class="normal"> </span><span class="symbol">*</span><span class="normal">amount </span><span class="symbol">=</span><span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkAdjustment.html#gtk-adjustment-get-value">gtk_adjustment_get_value</a></span><span class="symbol">(</span><span class="function">GTK_ADJUSTMENT</span><span class="symbol">(</span><span class="normal">adjust</span><span class="symbol">));</span>
<span class="normal"> </span><span class="function"><a href="/usr/share/gtk-doc/html/gtk3/GtkWidget.html#gtk-widget-destroy">gtk_widget_destroy</a></span><span class="symbol">(</span><span class="normal">dialog</span><span class="symbol">);</span>
<span class="normal"> </span><span class="keyword">break</span><span class="symbol">;</span>
<span class="normal"> </span><span class="cbracket">}</span>
<span class="normal"> </span><span class="keyword">return</span><span class="normal"> response </span><span class="symbol">==</span><span class="normal"> <a href="/usr/share/gtk-doc/html/gtk3/GtkDialog.html#GTK-RESPONSE-OK:CAPS">GTK_RESPONSE_OK</a></span><span class="symbol">;</span>
<span class="cbracket">}</span></pre></td>
</tr>
</tbody>
</table>
</div>
<p>
There is no rocket science in here: the dialog is created with some
standard buttons and settings. Then a table with a value entry with
a description is placed there and the range of allowed values is
specified. Then the dialog is run and depending on user's action the
value of <code class="varname">amount</code> is possibly updated, and
<code class="literal">TRUE</code> or <code class="literal">FALSE</code> is returned to
the caller to indicate user's action (we take everything as
cancellation, except pressing <span class="guibutton">OK</span>).
</p>
</div>
</div>
<div class="footer">
<hr>
Generated by GTK-Doc V1.19</div>
</body>
</html>
|