From: John Darrington Date: Fri, 4 Oct 2013 20:44:22 +0000 (+0200) Subject: T-Test One Sample Dialog: Convert to PsppireDialogAction X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e05092538d9cd5f7dd5091a4357f7536e90f6798;p=pspp T-Test One Sample Dialog: Convert to PsppireDialogAction --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 36d12bd6f6..5d10360e8b 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -227,6 +227,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-runs.h \ src/ui/gui/psppire-dialog-action-sort.c \ src/ui/gui/psppire-dialog-action-sort.h \ + src/ui/gui/psppire-dialog-action-tt1s.c \ + src/ui/gui/psppire-dialog-action-tt1s.h \ src/ui/gui/psppire-dialog-action-univariate.c \ src/ui/gui/psppire-dialog-action-univariate.h \ src/ui/gui/psppire-dialog-action-var-info.c \ @@ -293,8 +295,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/page-sheet-spec.h \ src/ui/gui/text-data-import-dialog.c \ src/ui/gui/text-data-import-dialog.h \ - src/ui/gui/t-test-one-sample.c \ - src/ui/gui/t-test-one-sample.h \ src/ui/gui/t-test-options.c \ src/ui/gui/t-test-options.h \ src/ui/gui/t-test-paired-samples.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 4beae4807a..dd7ddb6901 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -328,8 +328,9 @@ - + one-sample-t-test + uimanager1 _One Sample T Test... diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index d3b8087f62..069a3e8413 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -46,7 +46,6 @@ #include "ui/gui/recode-dialog.h" #include "ui/gui/select-cases-dialog.h" #include "ui/gui/split-file-dialog.h" -#include "ui/gui/t-test-one-sample.h" #include "ui/gui/t-test-paired-samples.h" #include "ui/gui/text-data-import-dialog.h" #include "ui/gui/weight-cases-dialog.h" @@ -964,7 +963,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog)); connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog)); connect_action (de, "paired-t-test", G_CALLBACK (t_test_paired_samples_dialog)); - connect_action (de, "one-sample-t-test", G_CALLBACK (t_test_one_sample_dialog)); connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog)); connect_action (de, "transform_count", G_CALLBACK (count_dialog)); connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog)); diff --git a/src/ui/gui/psppire-dialog-action-tt1s.c b/src/ui/gui/psppire-dialog-action-tt1s.c new file mode 100644 index 0000000000..70dbfabd31 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-tt1s.c @@ -0,0 +1,165 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012, 2013 Free Software Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#include + +#include "psppire-dialog-action-tt1s.h" + +#include "psppire-var-view.h" +#include "t-test-options.h" + +#include "psppire-dialog.h" +#include "builder-wrapper.h" + +static void psppire_dialog_action_tt1s_init (PsppireDialogActionTt1s *act); +static void psppire_dialog_action_tt1s_class_init (PsppireDialogActionTt1sClass *class); + +G_DEFINE_TYPE (PsppireDialogActionTt1s, psppire_dialog_action_tt1s, PSPPIRE_TYPE_DIALOG_ACTION); + + +static char * +generate_syntax (PsppireDialogAction *act) +{ + PsppireDialogActionTt1s *d = PSPPIRE_DIALOG_ACTION_TT1S (act); + gchar *text; + + GString *str = g_string_new ("T-TEST "); + + g_string_append_printf (str, "/TESTVAL=%s", + gtk_entry_get_text (GTK_ENTRY (d->test_value_entry))); + + g_string_append (str, "\n\t/VARIABLES="); + + psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->vars_treeview), 0, str); + + tt_options_dialog_append_syntax (d->opt, str); + + g_string_append (str, ".\n"); + + text = str->str; + + g_string_free (str, FALSE); + + return text; +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + PsppireDialogActionTt1s *tt_d = PSPPIRE_DIALOG_ACTION_TT1S (data); + gchar *s = NULL; + const gchar *text; + + + GtkTreeModel *vars = + gtk_tree_view_get_model (GTK_TREE_VIEW (tt_d->vars_treeview)); + + GtkTreeIter notused; + + text = gtk_entry_get_text (GTK_ENTRY (tt_d->test_value_entry)); + + if ( 0 == strcmp ("", text)) + return FALSE; + + /* Check to see if the entry is numeric */ + g_strtod (text, &s); + + if (s - text != strlen (text)) + return FALSE; + + + if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used)) + return FALSE; + + return TRUE; +} + +static void +refresh (PsppireDialogAction *rd_) +{ + PsppireDialogActionTt1s *d = PSPPIRE_DIALOG_ACTION_TT1S (rd_); + + GtkTreeModel *model = + gtk_tree_view_get_model (GTK_TREE_VIEW (d->vars_treeview)); + + gtk_entry_set_text (GTK_ENTRY (d->test_value_entry), ""); + + gtk_list_store_clear (GTK_LIST_STORE (model)); +} + +static void +psppire_dialog_action_tt1s_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogActionTt1s *act = PSPPIRE_DIALOG_ACTION_TT1S (a); + + GtkBuilder *xml = builder_new ("t-test.ui"); + GtkWidget *options_button = get_widget_assert (xml, "button1"); + + pda->dialog = get_widget_assert (xml, "t-test-one-sample-dialog"); + pda->source = get_widget_assert (xml, "one-sample-t-test-treeview2"); + + g_object_set (pda->source, + "predicate", var_is_numeric, NULL); + + act->vars_treeview = get_widget_assert (xml, "one-sample-t-test-treeview1"); + act->test_value_entry = get_widget_assert (xml, "test-value-entry"); + + act->opt = tt_options_dialog_create (GTK_WINDOW (pda->toplevel)); + + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, refresh); + + g_signal_connect_swapped (options_button, "clicked", + G_CALLBACK (tt_options_dialog_run), act->opt); + + + g_object_unref (xml); + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_tt1s_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_tt1s_parent_class)->activate (pda); +} + +static void +psppire_dialog_action_tt1s_finalize (GObject *a) +{ + PsppireDialogActionTt1s *act = PSPPIRE_DIALOG_ACTION_TT1S (a); + tt_options_dialog_destroy (act->opt); +} + +static void +psppire_dialog_action_tt1s_class_init (PsppireDialogActionTt1sClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->finalize = psppire_dialog_action_tt1s_finalize; + action_class->activate = psppire_dialog_action_tt1s_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_tt1s_init (PsppireDialogActionTt1s *act) +{ +} + + + + + diff --git a/src/ui/gui/psppire-dialog-action-tt1s.h b/src/ui/gui/psppire-dialog-action-tt1s.h new file mode 100644 index 0000000000..f09461fc39 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-tt1s.h @@ -0,0 +1,79 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2013 Free Software Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#include +#include + +#include "psppire-dialog-action.h" + +#ifndef __PSPPIRE_DIALOG_ACTION_TT1S_H__ +#define __PSPPIRE_DIALOG_ACTION_TT1S_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_TT1S (psppire_dialog_action_tt1s_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_TT1S(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_TT1S, PsppireDialogActionTt1s)) + +#define PSPPIRE_DIALOG_ACTION_TT1S_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_TT1S, \ + PsppireDialogActionTt1sClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_TT1S(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_TT1S)) + +#define PSPPIRE_IS_DIALOG_ACTION_TT1S_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_TT1S)) + + +#define PSPPIRE_DIALOG_ACTION_TT1S_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_TT1S, \ + PsppireDialogActionTt1sClass)) + +typedef struct _PsppireDialogActionTt1s PsppireDialogActionTt1s; +typedef struct _PsppireDialogActionTt1sClass PsppireDialogActionTt1sClass; + + +struct tt_options_dialog; + +struct _PsppireDialogActionTt1s +{ + PsppireDialogAction parent; + + /*< private >*/ + GtkWidget *vars_treeview; + GtkWidget *test_value_entry; + struct tt_options_dialog *opt; +}; + + +struct _PsppireDialogActionTt1sClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_tt1s_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_TT1S_H__ */ diff --git a/src/ui/gui/t-test-one-sample.c b/src/ui/gui/t-test-one-sample.c deleted file mode 100644 index d2bc126383..0000000000 --- a/src/ui/gui/t-test-one-sample.c +++ /dev/null @@ -1,178 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2007, 2010, 2011, 2012 Free Software Foundation - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - - -#include -#include -#include "t-test-one-sample.h" -#include "psppire-dict.h" -#include "psppire-var-view.h" -#include "builder-wrapper.h" -#include "psppire-data-window.h" -#include "psppire-dialog.h" -#include "dialog-common.h" -#include "dict-display.h" -#include "widget-io.h" -#include "executor.h" - -#include "t-test-options.h" -#include "helper.h" - -#include -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid - - -struct tt_one_sample_dialog -{ - PsppireDict *dict; - GtkWidget *vars_treeview; - GtkWidget *test_value_entry; - struct tt_options_dialog *opt; -}; - - -static gchar * -generate_syntax (const struct tt_one_sample_dialog *d) -{ - gchar *text; - - GString *str = g_string_new ("T-TEST "); - - g_string_append_printf (str, "/TESTVAL=%s", - gtk_entry_get_text (GTK_ENTRY (d->test_value_entry))); - - g_string_append (str, "\n\t/VARIABLES="); - - psppire_var_view_append_names (PSPPIRE_VAR_VIEW (d->vars_treeview), 0, str); - - tt_options_dialog_append_syntax (d->opt, str); - - g_string_append (str, ".\n"); - - text = str->str; - - g_string_free (str, FALSE); - - return text; -} - - - -static void -refresh (const struct tt_one_sample_dialog *d) -{ - GtkTreeModel *model = - gtk_tree_view_get_model (GTK_TREE_VIEW (d->vars_treeview)); - - gtk_entry_set_text (GTK_ENTRY (d->test_value_entry), ""); - - gtk_list_store_clear (GTK_LIST_STORE (model)); -} - - - -static gboolean -dialog_state_valid (gpointer data) -{ - gchar *s = NULL; - const gchar *text; - struct tt_one_sample_dialog *tt_d = data; - - GtkTreeModel *vars = - gtk_tree_view_get_model (GTK_TREE_VIEW (tt_d->vars_treeview)); - - GtkTreeIter notused; - - text = gtk_entry_get_text (GTK_ENTRY (tt_d->test_value_entry)); - - if ( 0 == strcmp ("", text)) - return FALSE; - - /* Check to see if the entry is numeric */ - g_strtod (text, &s); - - if (s - text != strlen (text)) - return FALSE; - - - if ( 0 == gtk_tree_model_get_iter_first (vars, ¬used)) - return FALSE; - - return TRUE; -} - - -/* Pops up the dialog box */ -void -t_test_one_sample_dialog (PsppireDataWindow *de) -{ - struct tt_one_sample_dialog tt_d; - gint response; - - GtkBuilder *xml = builder_new ("t-test.ui"); - - GtkWidget *dict_view = - get_widget_assert (xml, "one-sample-t-test-treeview2"); - - GtkWidget *options_button = - get_widget_assert (xml, "button1"); - - GtkWidget *dialog = get_widget_assert (xml, "t-test-one-sample-dialog"); - - g_object_get (de->data_editor, "dictionary", &tt_d.dict, NULL); - tt_d.vars_treeview = get_widget_assert (xml, "one-sample-t-test-treeview1"); - tt_d.test_value_entry = get_widget_assert (xml, "test-value-entry"); - tt_d.opt = tt_options_dialog_create (GTK_WINDOW (de)); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - - g_object_set (dict_view, "model", - tt_d.dict, - "predicate", - var_is_numeric, NULL); - - g_signal_connect_swapped (dialog, "refresh", - G_CALLBACK (refresh), &tt_d); - - - g_signal_connect_swapped (options_button, "clicked", - G_CALLBACK (tt_options_dialog_run), tt_d.opt); - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &tt_d); - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); - - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (de, generate_syntax (&tt_d))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&tt_d))); - break; - default: - break; - } - - - g_object_unref (xml); - tt_options_dialog_destroy (tt_d.opt); -} - - diff --git a/src/ui/gui/t-test-one-sample.h b/src/ui/gui/t-test-one-sample.h deleted file mode 100644 index 3c8e144070..0000000000 --- a/src/ui/gui/t-test-one-sample.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef T_TEST_ONE_SAMPLE_DIALOG -#define T_TEST_ONE_SAMPLE_DIALOG - -#include "psppire-data-window.h" - -void t_test_one_sample_dialog (PsppireDataWindow *) ; - -#endif diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index d6648e10cc..b61f13247a 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -37,6 +37,7 @@ #include "psppire-dialog-action-roc.h" #include "psppire-dialog-action-runs.h" #include "psppire-dialog-action-sort.h" +#include "psppire-dialog-action-tt1s.h" #include "psppire-dialog-action-univariate.h" #include "psppire-dialog-action-var-info.h" #include "psppire-value-entry.h" @@ -83,6 +84,7 @@ preregister_widgets (void) psppire_dialog_action_roc_get_type (); psppire_dialog_action_runs_get_type (); psppire_dialog_action_sort_get_type (); + psppire_dialog_action_tt1s_get_type (); psppire_dialog_action_univariate_get_type (); /* This seems to be necessary on Cygwin.