1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2007, 2010, 2011 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/>.
21 #include "t-test-one-sample.h"
22 #include "psppire-dict.h"
23 #include "psppire-var-store.h"
24 #include "psppire-var-view.h"
26 #include "psppire-data-window.h"
27 #include "psppire-dialog.h"
28 #include "dialog-common.h"
29 #include "dict-display.h"
30 #include "widget-io.h"
33 #include "t-test-options.h"
36 #define _(msgid) gettext (msgid)
37 #define N_(msgid) msgid
40 struct tt_one_sample_dialog
43 GtkWidget *vars_treeview;
44 GtkWidget *test_value_entry;
45 struct tt_options_dialog *opt;
50 generate_syntax (const struct tt_one_sample_dialog *d)
54 GString *str = g_string_new ("T-TEST ");
56 g_string_append_printf (str, "/TESTVAL=%s",
57 gtk_entry_get_text (GTK_ENTRY (d->test_value_entry)));
59 g_string_append (str, "\n\t/VARIABLES=");
61 psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->vars_treeview), 0, str);
63 tt_options_dialog_append_syntax (d->opt, str);
65 g_string_append (str, ".\n");
69 g_string_free (str, FALSE);
77 refresh (const struct tt_one_sample_dialog *d)
80 gtk_tree_view_get_model (GTK_TREE_VIEW (d->vars_treeview));
82 gtk_entry_set_text (GTK_ENTRY (d->test_value_entry), "");
84 gtk_list_store_clear (GTK_LIST_STORE (model));
90 dialog_state_valid (gpointer data)
94 struct tt_one_sample_dialog *tt_d = data;
97 gtk_tree_view_get_model (GTK_TREE_VIEW (tt_d->vars_treeview));
101 text = gtk_entry_get_text (GTK_ENTRY (tt_d->test_value_entry));
103 if ( 0 == strcmp ("", text))
106 /* Check to see if the entry is numeric */
109 if (s - text != strlen (text))
113 if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used))
120 /* Pops up the dialog box */
122 t_test_one_sample_dialog (PsppireDataWindow *de)
124 struct tt_one_sample_dialog tt_d;
127 PsppireVarStore *vs = NULL;
129 GtkBuilder *xml = builder_new ("t-test.ui");
131 GtkWidget *dict_view =
132 get_widget_assert (xml, "one-sample-t-test-treeview2");
134 GtkWidget *options_button =
135 get_widget_assert (xml, "button1");
137 GtkWidget *dialog = get_widget_assert (xml, "t-test-one-sample-dialog");
139 g_object_get (de->data_editor, "var-store", &vs, NULL);
141 g_object_get (vs, "dictionary", &tt_d.dict, NULL);
142 tt_d.vars_treeview = get_widget_assert (xml, "one-sample-t-test-treeview1");
143 tt_d.test_value_entry = get_widget_assert (xml, "test-value-entry");
144 tt_d.opt = tt_options_dialog_create (GTK_WINDOW (de));
146 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
148 g_object_set (dict_view, "model",
151 var_is_numeric, NULL);
153 g_signal_connect_swapped (dialog, "refresh",
154 G_CALLBACK (refresh), &tt_d);
157 g_signal_connect_swapped (options_button, "clicked",
158 G_CALLBACK (tt_options_dialog_run), tt_d.opt);
160 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
161 dialog_state_valid, &tt_d);
163 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
167 case GTK_RESPONSE_OK:
168 g_free (execute_syntax_string (de, generate_syntax (&tt_d)));
170 case PSPPIRE_RESPONSE_PASTE:
171 g_free (paste_syntax_to_window (generate_syntax (&tt_d)));
178 g_object_unref (xml);
179 tt_options_dialog_destroy (tt_d.opt);