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-one-sample.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 "t-test-options.h"
34 #include <language/syntax-string-source.h>
35 #include "syntax-editor.h"
38 #define _(msgid) gettext (msgid)
39 #define N_(msgid) msgid
42 struct tt_one_sample_dialog
45 GtkWidget *vars_treeview;
46 GtkWidget *test_value_entry;
47 struct tt_options_dialog *opt;
52 generate_syntax (const struct tt_one_sample_dialog *d)
56 GString *str = g_string_new ("T-TEST ");
58 g_string_append_printf (str, "/TESTVAL=%s",
59 gtk_entry_get_text (GTK_ENTRY (d->test_value_entry)));
61 g_string_append (str, "\n\t/VARIABLES=");
63 append_variable_names (str, d->dict, GTK_TREE_VIEW (d->vars_treeview), 0);
65 tt_options_dialog_append_syntax (d->opt, str);
67 g_string_append (str, ".\n");
71 g_string_free (str, FALSE);
79 refresh (const struct tt_one_sample_dialog *d)
82 gtk_tree_view_get_model (GTK_TREE_VIEW (d->vars_treeview));
84 gtk_entry_set_text (GTK_ENTRY (d->test_value_entry), "");
86 gtk_list_store_clear (GTK_LIST_STORE (model));
92 dialog_state_valid (gpointer data)
96 struct tt_one_sample_dialog *tt_d = data;
99 gtk_tree_view_get_model (GTK_TREE_VIEW (tt_d->vars_treeview));
103 text = gtk_entry_get_text (GTK_ENTRY (tt_d->test_value_entry));
105 if ( 0 == strcmp ("", text))
108 /* Check to see if the entry is numeric */
111 if (s - text != strlen (text))
115 if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used))
122 /* Pops up the dialog box */
124 t_test_one_sample_dialog (GObject *o, gpointer data)
126 struct tt_one_sample_dialog tt_d;
128 struct data_editor *de = data;
132 GladeXML *xml = XML_NEW ("t-test.glade");
134 GtkSheet *var_sheet =
135 GTK_SHEET (get_widget_assert (de->xml, "variable_sheet"));
137 GtkWidget *dict_view =
138 get_widget_assert (xml, "one-sample-t-test-treeview2");
140 GtkWidget *options_button =
141 get_widget_assert (xml, "button1");
143 GtkWidget *selector = get_widget_assert (xml, "psppire-selector1");
145 GtkWidget *dialog = get_widget_assert (xml, "t-test-one-sample-dialog");
147 vs = PSPPIRE_VAR_STORE (gtk_sheet_get_model (var_sheet));
149 tt_d.dict = vs->dict;
150 tt_d.vars_treeview = get_widget_assert (xml, "one-sample-t-test-treeview1");
151 tt_d.test_value_entry = get_widget_assert (xml, "test-value-entry");
152 tt_d.opt = tt_options_dialog_create (xml, de->parent.window);
154 gtk_window_set_transient_for (GTK_WINDOW (dialog), de->parent.window);
156 attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view),
158 GTK_SELECTION_MULTIPLE,
161 set_dest_model (GTK_TREE_VIEW (tt_d.vars_treeview), vs->dict);
164 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
165 dict_view, tt_d.vars_treeview,
166 insert_source_row_into_tree_view,
171 g_signal_connect_swapped (dialog, "refresh",
172 G_CALLBACK (refresh), &tt_d);
175 g_signal_connect_swapped (options_button, "clicked",
176 G_CALLBACK (tt_options_dialog_run), tt_d.opt);
178 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
179 dialog_state_valid, &tt_d);
181 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
185 case GTK_RESPONSE_OK:
187 gchar *syntax = generate_syntax (&tt_d);
188 struct getl_interface *sss = create_syntax_string_source (syntax);
189 execute_syntax (sss);
194 case PSPPIRE_RESPONSE_PASTE:
196 gchar *syntax = generate_syntax (&tt_d);
198 struct syntax_editor *se =
199 (struct syntax_editor *) window_create (WINDOW_SYNTAX, NULL);
201 gtk_text_buffer_insert_at_cursor (se->buffer, syntax, -1);
211 g_object_unref (xml);
212 tt_options_dialog_destroy (tt_d.opt);