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"
32 #include "t-test-options.h"
33 #include <libpspp/syntax-gen.h>
35 #include <language/syntax-string-source.h>
36 #include "syntax-editor.h"
39 #define _(msgid) gettext (msgid)
40 #define N_(msgid) msgid
43 struct tt_indep_samples_dialog
45 GladeXML *xml; /* The xml that generated the widgets */
48 gboolean groups_defined;
50 struct tt_options_dialog *opts;
55 generate_syntax (const struct tt_indep_samples_dialog *d)
57 struct variable *group_variable;
60 get_widget_assert (d->xml, "indep-samples-t-test-entry");
63 get_widget_assert (d->xml, "indep-samples-t-test-treeview2");
65 GString *str = g_string_new ("T-TEST /VARIABLES=");
67 append_variable_names (str, d->dict, GTK_TREE_VIEW (tv));
69 g_string_append (str, "\n\t/GROUPS=");
72 psppire_dict_lookup_var (d->dict, gtk_entry_get_text (GTK_ENTRY (entry)));
74 g_string_append (str, var_get_name (group_variable));
76 if ( d->groups_defined )
78 GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
79 GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
81 const gchar *val1 = gtk_entry_get_text (GTK_ENTRY (entry1));
82 const gchar *val2 = gtk_entry_get_text (GTK_ENTRY (entry2));
84 g_string_append (str, "(");
85 if ( var_is_alpha (group_variable))
88 ds_init_cstr (&s, val1);
89 gen_quoted_string (&s);
90 g_string_append (str, ds_cstr (&s));
95 g_string_append (str, val1);
97 g_string_append (str, ",");
98 if ( var_is_alpha (group_variable))
101 ds_init_cstr (&s, val2);
102 gen_quoted_string (&s);
103 g_string_append (str, ds_cstr (&s));
108 g_string_append (str, val2);
110 g_string_append (str, ")");
114 tt_options_dialog_append_syntax (d->opts, str);
116 g_string_append (str, ".\n");
120 g_string_free (str, FALSE);
128 refresh (GladeXML *xml)
131 get_widget_assert (xml, "indep-samples-t-test-entry");
134 get_widget_assert (xml, "indep-samples-t-test-treeview2");
136 GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tv));
138 gtk_entry_set_text (GTK_ENTRY (entry), "");
140 gtk_list_store_clear (GTK_LIST_STORE (model));
145 define_groups_state_valid (gpointer data)
147 struct tt_indep_samples_dialog *d = data;
149 GtkWidget *entry1 = get_widget_assert (d->xml, "group1-entry");
150 GtkWidget *entry2 = get_widget_assert (d->xml, "group2-entry");
152 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry1))))
155 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry2))))
162 run_define_groups (struct tt_indep_samples_dialog *ttd)
166 get_widget_assert (ttd->xml, "define-groups-dialog");
169 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
170 define_groups_state_valid, ttd);
172 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (ttd->dialog));
174 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
176 ttd->groups_defined = (response == PSPPIRE_RESPONSE_CONTINUE);
182 dialog_state_valid (gpointer data)
184 struct tt_indep_samples_dialog *tt_d = data;
187 get_widget_assert (tt_d->xml, "indep-samples-t-test-entry");
190 get_widget_assert (tt_d->xml, "indep-samples-t-test-treeview2");
192 GtkTreeModel *vars = gtk_tree_view_get_model (GTK_TREE_VIEW (tv_vars));
196 if ( 0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (entry))))
200 if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used))
207 /* Pops up the dialog box */
209 t_test_independent_samples_dialog (GObject *o, gpointer data)
211 struct tt_indep_samples_dialog tt_d;
213 struct data_editor *de = data;
217 GladeXML *xml = XML_NEW ("t-test.glade");
219 GtkSheet *var_sheet =
220 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
222 GtkWidget *dict_view =
223 get_widget_assert (xml, "indep-samples-t-test-treeview1");
225 GtkWidget *test_variables_treeview =
226 get_widget_assert (xml, "indep-samples-t-test-treeview2");
228 GtkWidget *selector2 =
229 get_widget_assert (xml, "indep-samples-t-test-selector2");
231 GtkWidget *selector1 =
232 get_widget_assert (xml, "indep-samples-t-test-selector1");
235 get_widget_assert (xml, "indep-samples-t-test-entry");
237 GtkWidget *define_groups_button =
238 get_widget_assert (xml, "define-groups-button");
240 GtkWidget *options_button =
241 get_widget_assert (xml, "options-button");
243 vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
245 tt_d.dialog = get_widget_assert (xml, "t-test-independent-samples-dialog");
247 tt_d.dict = vs->dict;
248 tt_d.groups_defined = FALSE;
249 tt_d.opts = tt_options_dialog_create (xml, de->parent.window);
251 gtk_window_set_transient_for (GTK_WINDOW (tt_d.dialog), de->parent.window);
253 attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view),
255 GTK_SELECTION_MULTIPLE, NULL);
257 set_dest_model (GTK_TREE_VIEW (test_variables_treeview), vs->dict);
260 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector1),
261 dict_view, test_variables_treeview,
262 insert_source_row_into_tree_view,
266 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector2),
268 insert_source_row_into_entry,
269 is_currently_in_entry);
271 g_signal_connect_swapped (define_groups_button, "clicked",
272 G_CALLBACK (run_define_groups), &tt_d);
275 g_signal_connect_swapped (options_button, "clicked",
276 G_CALLBACK (tt_options_dialog_run), tt_d.opts);
279 g_signal_connect_swapped (tt_d.dialog, "refresh", G_CALLBACK (refresh), xml);
282 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (tt_d.dialog),
283 dialog_state_valid, &tt_d);
285 response = psppire_dialog_run (PSPPIRE_DIALOG (tt_d.dialog));
289 case GTK_RESPONSE_OK:
291 gchar *syntax = generate_syntax (&tt_d);
292 struct getl_interface *sss = create_syntax_string_source (syntax);
293 execute_syntax (sss);
298 case PSPPIRE_RESPONSE_PASTE:
300 gchar *syntax = generate_syntax (&tt_d);
302 struct syntax_editor *se =
303 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
305 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
314 tt_options_dialog_destroy (tt_d.opts);
315 g_object_unref (xml);