Beyond the Minimal Module

Beyond the Minimal Module — Common module idioms

Multiple Modules, Multiple Function, Multifunctions

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.

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 %GWY_MODULE_QUERY per file, thus a one file can register only a one module and this approach would not work.

The prefered solution is to register more than function for the module. This is as simple as it sounds. One just has to call gwy_process_func_register() (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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
static gboolean
module_register(void)
{
    gwy_process_func_register("sobel_horizontal",
                              (GwyProcessFunc)&gradient_sobel_horizontal,
                              N_("/_Presentation/_Gradient/_Sobel (horizontal)"),
                              NULL,
                              GRADIENT_RUN_MODES,
                              GWY_MENU_FLAG_DATA,
                              N_("Horizontal Sobel gradient presentation"));
    gwy_process_func_register("sobel_vertical",
                              (GwyProcessFunc)&gradient_sobel_vertical,
                              N_("/_Presentation/_Gradient/_Sobel (vertical)"),
                              NULL,
                              GRADIENT_RUN_MODES,
                              GWY_MENU_FLAG_DATA,
                              N_("Vertical Sobel gradient presentation"));

    return TRUE;
}

The other posibility is to call gwy_process_func_register() several times with the same func argument. The function can then determine from its last argument (name) 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.

Settings

The nice thing about Gwyddion 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.

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.

There is a one GwyContainer in Gwyddion containing settings for all modules (and other creatures). The function gwy_app_settings_get() 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 "/module/my-module-name/".

Loading settings could look (remember they may not always exist, for instance when the function is run the first time):

1
2
3
4
5
6
7
8
GwyContainer *settings;

settings = gwy_app_settings_get();
ratio = 1.61803;
gwy_container_gis_double_by_name(settings,
                                 "/module/my_module/ratio",
                                 &ratio);
ratio = CLAMP(ratio, 1.0, 2.0);

Function gwy_container_gis_double_by_name() function updates its last argument only when there is a corresponding value in the container. The use of CLAMP() is a recommended defensive measure against corrupted settings (for example manually (mis)edited by the user) that could cause troubles later.

Saving settings is equally easy:

1
2
3
4
5
6
GwyContainer *settings;

settings = gwy_app_settings_get();
gwy_container_set_double_by_name(settings,
                                 "/module/my_module/ratio",
                                 ratio);

Modules customarily define a function load_settings() that fills its internal parameter representation on the start of execution and santitizes them. Likewise function save_settings() stores them to back to the global settings upon exit. Note to achieve the typical state preservation of Gwyddion modules parameters have to be saved both after successful execution and cancellation.

Creating New Files, Data Fields and Graphs

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.

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 howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception are file modules, they howeverss="no. A notable exception