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/>.
19 #include <glade/glade.h>
21 #include "t-test-independent-samples-dialog.h"
22 #include "psppire-dict.h"
23 #include "psppire-var-store.h"
25 #include <gtksheet/gtksheet.h>
26 #include "data-editor.h"
27 #include "psppire-dialog.h"
28 #include "dialog-common.h"
29 #include "dict-display.h"
30 #include "widget-io.h"
32 #include <language/syntax-string-source.h>
33 #include "syntax-editor.h"
36 #define _(msgid) gettext (msgid)
37 #define N_(msgid) msgid
40 struct tt_indep_samples_dialog
42 GladeXML *xml; /* The xml that generated the widgets */
45 gboolean groups_defined;
46 gboolean non_default_options;
47 gdouble confidence_interval;
52 generate_syntax (const struct tt_indep_samples_dialog *d)
56 get_widget_assert (d->xml, "indep-samples-t-test-entry");
59 get_widget_assert (d->xml, "indep-samples-t-test-treeview2");
61 GString *str = g_string_new ("T-TEST /VARIABLES=");
63 append_variable_names (str, d->dict, GTK_TREE_VIEW (tv));
65 g_string_append (str, "\n\t/GROUPS=");
67 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry)));
69 if ( d->groups_defined )
71 GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
72 GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
74 g_string_append (str, "(");
75 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry1)));
76 g_string_append (str, ",");
77 g_string_append (str, gtk_entry_get_text (GTK_ENTRY (entry2)));
78 g_string_append (str, ")");
81 if ( d->non_default_options )
83 GtkToggleButton *analysis =
84 GTK_TOGGLE_BUTTON (get_widget_assert (d->xml, "radiobutton1"));
86 g_string_append (str, "\n\t");
87 g_string_append_printf (str, "/CRITERIA=CIN(%g)",
88 d->confidence_interval/100.0);
91 g_string_append (str, "\n\t");
92 g_string_append_printf (str, "/MISSING=%s",
93 gtk_toggle_button_get_active (analysis) ?
94 "ANALYSIS" : "LISTWISE");
97 g_string_append (str, ".\n");
101 g_string_free (str, FALSE);
109 refresh (GladeXML *xml)
112 get_widget_assert (xml, "indep-samples-t-test-entry");
115 get_widget_assert (xml, "indep-samples-t-test-treeview2");
117 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tv));
119 gtk_entry_set_text (GTK_ENTRY (entry), "");
121 gtk_list_store_clear (GTK_LIST_STORE (model));
126 define_groups_state_valid (gpointer data)
128 struct tt_indep_samples_dialog *d = data;
130 GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
131 GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
133 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry1))))
136 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry2))))
143 run_define_groups (struct tt_indep_samples_dialog *ttd)
147 get_widget_assert (ttd->xml, "define-groups-dialog");
150 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
151 define_groups_state_valid, ttd);
153 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (ttd->dialog));
155 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
157 ttd->groups_defined = (response == PSPPIRE_RESPONSE_CONTINUE);
162 run_options (struct tt_indep_samples_dialog *ttd)
166 get_widget_assert (ttd->xml, "options-dialog");
169 get_widget_assert (ttd->xml, "vbox1");
171 GtkSpinButton *conf_percent = NULL;
173 GtkWidget *confidence =
174 widget_scanf (_("Confidence Interval: %2d %%"),
177 gtk_spin_button_set_value (conf_percent, ttd->confidence_interval);
179 gtk_widget_show (confidence);
181 gtk_box_pack_start_defaults (GTK_BOX (box), confidence);
183 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (ttd->dialog));
185 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
187 if ( response == PSPPIRE_RESPONSE_CONTINUE)
189 ttd->non_default_options = TRUE;
190 ttd->confidence_interval = gtk_spin_button_get_value (conf_percent);
193 gtk_container_remove (GTK_CONTAINER (box), confidence);
200 dialog_state_valid (gpointer data)
202 struct tt_indep_samples_dialog *tt_d = data;
205 get_widget_assert (tt_d->xml, "indep-samples-t-test-entry");
208 get_widget_assert (tt_d->xml, "indep-samples-t-test-treeview2");
210 GtkTreeModel *vars = gtk_tree_view_get_model (GTK_TREE_VIEW (tv_vars));
214 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))))
218 if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used))
225 /* Pops up the dialog box */
227 t_test_independent_samples_dialog (GObject *o, gpointer data)
229 struct tt_indep_samples_dialog tt_d;
231 struct data_editor *de = data;
235 GladeXML *xml = XML_NEW ("t-test.glade");
237 tt_d.dialog = get_widget_assert (xml,
238 "t-test-independent-samples-dialog");
240 GtkSheet *var_sheet =
241 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
243 GtkWidget *dict_view =
244 get_widget_assert (xml, "indep-samples-t-test-treeview1");
246 GtkWidget *test_variables_treeview =
247 get_widget_assert (xml, "indep-samples-t-test-treeview2");
249 GtkWidget *selector2 =
250 get_widget_assert (xml, "indep-samples-t-test-selector2");
252 GtkWidget *selector1 =
253 get_widget_assert (xml, "indep-samples-t-test-selector1");
257 get_widget_assert (xml, "indep-samples-t-test-entry");
259 GtkWidget *define_groups_button =
260 get_widget_assert (xml, "define-groups-button");
262 GtkWidget *options_button =
263 get_widget_assert (xml, "options-button");
265 vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
268 tt_d.dict = vs->dict;
269 tt_d.groups_defined = FALSE;
270 tt_d.non_default_options = FALSE;
271 tt_d.confidence_interval = 95.0;
273 gtk_window_set_transient_for (GTK_WINDOW (tt_d.dialog), de->parent.window);
275 attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view),
277 GTK_SELECTION_MULTIPLE, NULL);
279 set_dest_model (GTK_TREE_VIEW (test_variables_treeview), vs->dict);
282 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector1),
283 dict_view, test_variables_treeview,
284 insert_source_row_into_tree_view,
288 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector2),
290 insert_source_row_into_entry,
291 is_currently_in_entry);
293 g_signal_connect_swapped (define_groups_button, "clicked",
294 G_CALLBACK (run_define_groups), &tt_d);
297 g_signal_connect_swapped (options_button, "clicked",
298 G_CALLBACK (run_options), &tt_d);
301 g_signal_connect_swapped (tt_d.dialog, "refresh", G_CALLBACK (refresh), xml);
304 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (tt_d.dialog),
305 dialog_state_valid, &tt_d);
307 response = psppire_dialog_run (PSPPIRE_DIALOG (tt_d.dialog));
311 case GTK_RESPONSE_OK:
313 gchar *syntax = generate_syntax (&tt_d);
314 struct getl_interface *sss = create_syntax_string_source (syntax);
315 execute_syntax (sss);
320 case PSPPIRE_RESPONSE_PASTE:
322 gchar *syntax = generate_syntax (&tt_d);
324 struct syntax_editor *se =
325 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
327 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
337 g_object_unref (xml);