1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <glade/glade.h>
22 #include "t-test-independent-samples-dialog.h"
23 #include "psppire-dict.h"
24 #include "psppire-var-store.h"
26 #include <gtksheet/gtksheet.h>
27 #include "data-editor.h"
28 #include "psppire-dialog.h"
29 #include "dialog-common.h"
30 #include "dict-display.h"
31 #include "widget-io.h"
33 #include <language/syntax-string-source.h>
34 #include "syntax-editor.h"
37 #define _(msgid) gettext (msgid)
38 #define N_(msgid) msgid
41 struct tt_indep_samples_dialog
43 GladeXML *xml; /* The xml that generated the widgets */
46 gboolean groups_defined;
47 gboolean non_default_options;
48 gdouble confidence_interval;
53 generate_syntax (const struct tt_indep_samples_dialog *d)
57 get_widget_assert (d->xml, "indep-samples-t-test-entry");
60 get_widget_assert (d->xml, "indep-samples-t-test-treeview2");
62 GString *str = g_string_new ("T-TEST /VARIABLES=");
64 append_variable_names (str, d->dict, GTK_TREE_VIEW (tv));
66 g_string_append (str, "\n\t/GROUPS=");
68 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry)));
70 if ( d->groups_defined )
72 GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
73 GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
75 g_string_append (str, "(");
76 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry1)));
77 g_string_append (str, ",");
78 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry2)));
79 g_string_append (str, ")");
82 if ( d->non_default_options )
84 GtkToggleButton *analysis =
85 GTK_TOGGLE_BUTTON (get_widget_assert (d->xml, "radiobutton1"));
87 g_string_append (str, "\n\t");
88 g_string_append_printf (str, "/CRITERIA=CIN(%g)",
89 d->confidence_interval/100.0);
92 g_string_append (str, "\n\t");
93 g_string_append_printf (str, "/MISSING=%s",
94 gtk_toggle_button_get_active (analysis) ?
95 "ANALYSIS" : "LISTWISE");
98 g_string_append (str, ".\n");
102 g_string_free (str, FALSE);
110 refresh (GladeXML *xml)
113 get_widget_assert (xml, "indep-samples-t-test-entry");
116 get_widget_assert (xml, "indep-samples-t-test-treeview2");
118 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tv));
120 gtk_entry_set_text (GTK_ENTRY (entry), "");
122 gtk_list_store_clear (GTK_LIST_STORE (model));
127 define_groups_state_valid (gpointer data)
129 struct tt_indep_samples_dialog *d = data;
131 GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
132 GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
134 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry1))))
137 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry2))))
144 run_define_groups (struct tt_indep_samples_dialog *ttd)
148 get_widget_assert (ttd->xml, "define-groups-dialog");
151 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
152 define_groups_state_valid, ttd);
154 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (ttd->dialog));
156 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
158 ttd->groups_defined = (response == PSPPIRE_RESPONSE_CONTINUE);
163 run_options (struct tt_indep_samples_dialog *ttd)
167 get_widget_assert (ttd->xml, "options-dialog");
170 get_widget_assert (ttd->xml, "vbox1");
172 GtkSpinButton *conf_percent = NULL;
174 GtkWidget *confidence =
175 widget_scanf (_("Confidence Interval: %2d %%"),
178 gtk_spin_button_set_value (conf_percent, ttd->confidence_interval);
180 gtk_widget_show (confidence);
182 gtk_box_pack_start_defaults (GTK_BOX (box), confidence);
184 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (ttd->dialog));
186 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
188 if ( response == PSPPIRE_RESPONSE_CONTINUE)
190 ttd->non_default_options = TRUE;
191 ttd->confidence_interval = gtk_spin_button_get_value (conf_percent);
194 gtk_container_remove (GTK_CONTAINER (box), confidence);
201 dialog_state_valid (gpointer data)
203 struct tt_indep_samples_dialog *tt_d = data;
206 get_widget_assert (tt_d->xml, "indep-samples-t-test-entry");
209 get_widget_assert (tt_d->xml, "indep-samples-t-test-treeview2");
211 GtkTreeModel *vars = gtk_tree_view_get_model (GTK_TREE_VIEW (tv_vars));
215 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))))
219 if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used))
226 /* Pops up the dialog box */
228 t_test_independent_samples_dialog (GObject *o, gpointer data)
230 struct tt_indep_samples_dialog tt_d;
232 struct data_editor *de = data;
236 GladeXML *xml = XML_NEW ("t-test.glade");
238 GtkSheet *var_sheet =
239 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
241 GtkWidget *dict_view =
242 get_widget_assert (xml, "indep-samples-t-test-treeview1");
244 GtkWidget *test_variables_treeview =
245 get_widget_assert (xml, "indep-samples-t-test-treeview2");
247 GtkWidget *selector2 =
248 get_widget_assert (xml, "indep-samples-t-test-selector2");
250 GtkWidget *selector1 =
251 get_widget_assert (xml, "indep-samples-t-test-selector1");
255 get_widget_assert (xml, "indep-samples-t-test-entry");
257 GtkWidget *define_groups_button =
258 get_widget_assert (xml, "define-groups-button");
260 GtkWidget *options_button =
261 get_widget_assert (xml, "options-button");
263 vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
265 tt_d.dialog = get_widget_assert (xml, "t-test-independent-samples-dialog");
267 tt_d.dict = vs->dict;
268 tt_d.groups_defined = FALSE;
269 tt_d.non_default_options = FALSE;
270 tt_d.confidence_interval = 95.0;
272 gtk_window_set_transient_for (GTK_WINDOW (tt_d.dialog), de->parent.window);
274 attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view),
276 GTK_SELECTION_MULTIPLE, NULL);
278 set_dest_model (GTK_TREE_VIEW (test_variables_treeview), vs->dict);
281 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector1),
282 dict_view, test_variables_treeview,
283 insert_source_row_into_tree_view,
287 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector2),
289 insert_source_row_into_entry,
290 is_currently_in_entry);
292 g_signal_connect_swapped (define_groups_button, "clicked",
293 G_CALLBACK (run_define_groups), &tt_d);
296 g_signal_connect_swapped (options_button, "clicked",
297 G_CALLBACK (run_options), &tt_d);
300 g_signal_connect_swapped (tt_d.dialog, "refresh", G_CALLBACK (refresh), xml);
303 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (tt_d.dialog),
304 dialog_state_valid, &tt_d);
306 response = psppire_dialog_run (PSPPIRE_DIALOG (tt_d.dialog));
310 case GTK_RESPONSE_OK:
312 gchar *syntax = generate_syntax (&tt_d);
313 struct getl_interface *sss = create_syntax_string_source (syntax);
314 execute_syntax (sss);
319 case PSPPIRE_RESPONSE_PASTE:
321 gchar *syntax = generate_syntax (&tt_d);
323 struct syntax_editor *se =
324 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
326 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
336 g_object_unref (xml);