2 * dialog-analysis-tool-normality.c:
5 * Andreas J. Guelzow <aguelzow@taliesin.ca>
7 * (C) Copyright 2009 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
23 #include <gnumeric-config.h>
24 #include <glib/gi18n-lib.h>
26 #include <dialogs/dialogs.h>
27 #include <tools/analysis-normality.h>
28 #include <tools/analysis-tools.h>
31 #include <workbook-control.h>
33 #include <workbook-view.h>
35 #include <parse-util.h>
36 #include <gnm-format.h>
37 #include <dialogs/tool-dialogs.h>
38 #include <dialogs/dao-gui-utils.h>
41 #include <number-match.h>
43 #include <selection.h>
46 #include <dialogs/help.h>
48 #include <widgets/gnm-dao.h>
49 #include <widgets/gnm-expr-entry.h>
53 #define NORMALITY_KEY "analysistools-normality-dialog"
56 GnmGenericToolState base
;
57 GtkWidget
*alpha_entry
;
58 } NormalityTestsToolState
;
61 static char const * const grouped_by_group
[] = {
68 static char const * const test_group
[] = {
77 * normality_tool_update_sensitivity_cb:
81 * Update the dialog widgets sensitivity
84 normality_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget
*dummy
,
85 NormalityTestsToolState
*state
)
90 input_range
= gnm_expr_entry_parse_as_list (
91 GNM_EXPR_ENTRY (state
->base
.input_entry
),
93 if (input_range
== NULL
) {
94 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
95 _("The input range is invalid."));
96 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
99 range_list_destroy (input_range
);
102 alpha
= gtk_spin_button_get_value
103 (GTK_SPIN_BUTTON (state
->alpha_entry
));
104 if (!(alpha
> 0 && alpha
< 1)) {
105 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
106 _("The alpha value should "
107 "be a number between 0 and 1."));
108 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
112 /* Checking Output Page */
113 if (!gnm_dao_is_ready (GNM_DAO (state
->base
.gdao
))) {
114 gtk_label_set_text (GTK_LABEL (state
->base
.warning
),
115 _("The output specification "
117 gtk_widget_set_sensitive (state
->base
.ok_button
, FALSE
);
121 gtk_label_set_text (GTK_LABEL (state
->base
.warning
), "");
122 gtk_widget_set_sensitive (state
->base
.ok_button
, TRUE
);
128 * normality_tool_ok_clicked_cb:
132 * Retrieve the information from the dialog and call the normality_tool.
133 * Note that we assume that the ok_button is only active if the entry fields
134 * contain sensible data.
137 normality_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget
*button
,
138 NormalityTestsToolState
*state
)
140 data_analysis_output_t
*dao
;
142 analysis_tools_data_normality_t
*data
;
144 data
= g_new0 (analysis_tools_data_normality_t
, 1);
145 dao
= parse_output ((GnmGenericToolState
*)state
, NULL
);
147 data
->base
.input
= gnm_expr_entry_parse_as_list (
148 GNM_EXPR_ENTRY (state
->base
.input_entry
), state
->base
.sheet
);
149 data
->base
.group_by
= gnm_gui_group_value (state
->base
.gui
, grouped_by_group
);
151 w
= go_gtk_builder_get_widget (state
->base
.gui
, "labels_button");
152 data
->base
.labels
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w
));
153 data
->alpha
= gtk_spin_button_get_value
154 (GTK_SPIN_BUTTON (state
->alpha_entry
));
156 data
->type
= gnm_gui_group_value (state
->base
.gui
, test_group
);
158 w
= go_gtk_builder_get_widget (state
->base
.gui
, "normalprobabilityplot");
159 data
->graph
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w
));
161 if (!cmd_analysis_tool (GNM_WBC (state
->base
.wbcg
),
163 dao
, data
, analysis_tool_normality_engine
,
165 gtk_widget_destroy (state
->base
.dialog
);
171 * dialog_normality_tool:
175 * Show the dialog (guru).
179 dialog_normality_tool (WBCGtk
*wbcg
, Sheet
*sheet
)
181 NormalityTestsToolState
*state
;
182 char const * plugins
[] = { "Gnumeric_fnstat",
183 "Gnumeric_fnlogical",
186 if ((wbcg
== NULL
) ||
187 gnm_check_for_plugins_missing (plugins
, wbcg_toplevel (wbcg
)))
190 /* Only pop up one copy per workbook */
191 if (gnm_dialog_raise_if_exists (wbcg
, NORMALITY_KEY
))
194 state
= g_new0 (NormalityTestsToolState
, 1);
196 if (dialog_tool_init (&state
->base
, wbcg
, sheet
,
197 GNUMERIC_HELP_LINK_NORMALITY
,
198 "res:ui/normality-tests.ui", "Normality-Tests",
199 _("Could not create the Normality Test Tool dialog."),
201 G_CALLBACK (normality_tool_ok_clicked_cb
), NULL
,
202 G_CALLBACK (normality_tool_update_sensitivity_cb
),
210 state
->alpha_entry
= tool_setup_update
211 (&state
->base
, "alpha-entry",
212 G_CALLBACK (normality_tool_update_sensitivity_cb
),
215 float_to_entry (GTK_ENTRY (state
->alpha_entry
), 0.05);
217 gnm_dao_set_put (GNM_DAO (state
->base
.gdao
), TRUE
, TRUE
);
218 normality_tool_update_sensitivity_cb (NULL
, state
);
219 tool_load_selection ((GnmGenericToolState
*)state
, TRUE
);