1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * dialog-analysis-tool-wilcoxon-mann-whitney.c:
6 * Andreas J. Guelzow <aguelzow@pyrshep.ca>
8 * (C) Copyright 2010 by Andreas J. Guelzow <aguelzow@pyrshep.ca>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
24 #include <gnumeric-config.h>
25 #include <glib/gi18n-lib.h>
28 #include "analysis-wilcoxon-mann-whitney.h"
29 #include "analysis-tools.h"
32 #include <workbook-control.h>
34 #include <workbook-view.h>
36 #include <parse-util.h>
37 #include <gnm-format.h>
38 #include <dialogs/tool-dialogs.h>
39 #include <dialogs/dao-gui-utils.h>
42 #include <number-match.h>
44 #include <selection.h>
49 #include <widgets/gnm-dao.h>
50 #include <widgets/gnumeric-expr-entry.h>
55 #define WILCOXON_MANN_WHITNEY_KEY "analysistools-principal-components-dialog"
57 static char const * const grouped_by_group
[] = {
65 wilcoxon_mann_whitney_tool_update_sensitivity_cb (G_GNUC_UNUSED GtkWidget
*dummy
,
66 GnmGenericToolState
*state
)
68 GnmValue
*input_range
;
69 GnmValue
*input_range_2
;
70 gboolean input_1_ready
= FALSE
;
71 gboolean input_2_ready
= FALSE
;
73 /* Checking Input Ranges */
74 input_range
= gnm_expr_entry_parse_as_value (
75 GNM_EXPR_ENTRY (state
->input_entry
), state
->sheet
);
76 input_range_2
= gnm_expr_entry_parse_as_value
77 (GNM_EXPR_ENTRY (state
->input_entry_2
), state
->sheet
);
79 input_1_ready
= (input_range
!= NULL
);
80 input_2_ready
= ((state
->input_entry_2
== NULL
) || (input_range_2
!= NULL
));
81 value_release (input_range
);
82 value_release (input_range_2
);
85 gtk_label_set_text (GTK_LABEL (state
->warning
),
86 _("The input range for variable 1 is invalid."));
87 gtk_widget_set_sensitive (state
->ok_button
, FALSE
);
89 } else if (!input_2_ready
) {
90 gtk_label_set_text (GTK_LABEL (state
->warning
),
91 _("The input range for variable 2 is invalid."));
92 gtk_widget_set_sensitive (state
->ok_button
, FALSE
);
96 /* Checking Output Page */
97 if (!gnm_dao_is_ready (GNM_DAO (state
->gdao
))) {
98 gtk_label_set_text (GTK_LABEL (state
->warning
),
99 _("The output specification "
101 gtk_widget_set_sensitive (state
->ok_button
, FALSE
);
105 gtk_label_set_text (GTK_LABEL (state
->warning
), "");
106 gtk_widget_set_sensitive (state
->ok_button
, TRUE
);
112 * wilcoxon_mann_whitney_tool_ok_clicked_cb:
118 wilcoxon_mann_whitney_tool_ok_clicked_cb (G_GNUC_UNUSED GtkWidget
*button
,
119 GnmGenericToolState
*state
)
121 data_analysis_output_t
*dao
;
122 analysis_tools_data_generic_b_t
*data
;
126 if (state
->warning_dialog
!= NULL
)
127 gtk_widget_destroy (state
->warning_dialog
);
129 data
= g_new0 (analysis_tools_data_generic_b_t
, 1);
130 dao
= parse_output (state
, NULL
);
132 data
->wbc
= GNM_WBC (state
->wbcg
);
134 data
->range_1
= gnm_expr_entry_parse_as_value
135 (GNM_EXPR_ENTRY (state
->input_entry
), state
->sheet
);
137 data
->range_2
= gnm_expr_entry_parse_as_value
138 (GNM_EXPR_ENTRY (state
->input_entry_2
), state
->sheet
);
140 w
= go_gtk_builder_get_widget (state
->gui
, "labels_button");
141 data
->labels
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w
));
143 if (cmd_analysis_tool (GNM_WBC (state
->wbcg
), state
->sheet
,
145 analysis_tool_wilcoxon_mann_whitney_engine
, TRUE
)) {
147 text
= g_strdup_printf (
148 _("An unexpected error has occurred."));
149 error_in_entry (state
, GTK_WIDGET (state
->input_entry
), text
);
152 gtk_widget_destroy (state
->dialog
);
159 * dialog_wilcoxon_mann_whitney_tool:
163 * Show the dialog (guru).
167 dialog_wilcoxon_m_w_tool (WBCGtk
*wbcg
, Sheet
*sheet
)
169 GnmGenericToolState
*state
;
170 char const * plugins
[] = { "Gnumeric_fnstat",
175 if ((wbcg
== NULL
) ||
176 gnm_check_for_plugins_missing (plugins
, wbcg_toplevel (wbcg
)))
179 /* Only pop up one copy per workbook */
180 if (gnm_dialog_raise_if_exists (wbcg
, WILCOXON_MANN_WHITNEY_KEY
))
183 state
= g_new0 (GnmGenericToolState
, 1);
185 if (dialog_tool_init (state
, wbcg
, sheet
,
186 GNUMERIC_HELP_LINK_WILCOXON_MANN_WHITNEY
,
187 "res:ui/wilcoxon-mann-whitney.ui", "WilcoxonMannWhitney",
188 _("Could not create the Wilcoxon-Mann-Whitney Analysis Tool dialog."),
189 WILCOXON_MANN_WHITNEY_KEY
,
190 G_CALLBACK (wilcoxon_mann_whitney_tool_ok_clicked_cb
), NULL
,
191 G_CALLBACK (wilcoxon_mann_whitney_tool_update_sensitivity_cb
),
192 GNM_EE_SINGLE_RANGE
))
195 gnm_dao_set_put (GNM_DAO (state
->gdao
), TRUE
, TRUE
);
196 wilcoxon_mann_whitney_tool_update_sensitivity_cb (NULL
, state
);
197 tool_load_selection ((GnmGenericToolState
*)state
, TRUE
);