From: John Darrington Date: Wed, 19 May 2010 12:06:36 +0000 (+0200) Subject: Added an implementation of the Chi-Square dialog box X-Git-Tag: v0.7.5~22 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb40133f880615d10473c3b7ca54f57f52fd0daf;p=pspp-builds.git Added an implementation of the Chi-Square dialog box --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 263e621b..189c3f25 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -5,6 +5,7 @@ include $(top_srcdir)/src/ui/gui/sheet/automake.mk UI_FILES = \ src/ui/gui/correlation.ui \ src/ui/gui/crosstabs.ui \ + src/ui/gui/chi-square.ui \ src/ui/gui/descriptives.ui \ src/ui/gui/examine.ui \ src/ui/gui/factor.ui \ @@ -117,6 +118,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/comments-dialog.h \ src/ui/gui/compute-dialog.c \ src/ui/gui/compute-dialog.h \ + src/ui/gui/chi-square-dialog.c \ + src/ui/gui/chi-square-dialog.h \ src/ui/gui/correlation-dialog.c \ src/ui/gui/correlation-dialog.h \ src/ui/gui/crosstabs-dialog.c \ diff --git a/src/ui/gui/chi-square-dialog.c b/src/ui/gui/chi-square-dialog.c new file mode 100644 index 00000000..6bb42e47 --- /dev/null +++ b/src/ui/gui/chi-square-dialog.c @@ -0,0 +1,254 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2010 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 "chi-square-dialog.h" + +#include + +#include "psppire-dialog.h" +#include "psppire-var-view.h" +#include "psppire-acr.h" +#include "dialog-common.h" + +#include "helper.h" +#include "executor.h" + + +#include + +struct chisquare_dialog +{ + PsppireDict *dict; + GtkWidget *var_view; + + GtkWidget *button1; + GtkWidget *button2; + + GtkWidget *range_button; + GtkWidget *value_lower; + GtkWidget *value_upper; + + GtkWidget *values_button; + + GtkListStore *expected_list; +}; + +static void +set_sensitivity (GtkToggleButton *button, GtkWidget *w) +{ + gboolean state = gtk_toggle_button_get_active (button); + gtk_widget_set_sensitive (w, state); +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + struct chisquare_dialog *csd = data; + + GtkTreeModel *vars = + gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view)); + + GtkTreeIter notused; + + if ( !gtk_tree_model_get_iter_first (vars, ¬used) ) + return FALSE; + + return TRUE; +} + + +static void +refresh (struct chisquare_dialog *csd) +{ + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view)); + + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button1), TRUE); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button2), TRUE); +} + + + +static char * +generate_syntax (const struct chisquare_dialog *scd) +{ + gchar *text; + GString *string; + + + string = g_string_new ("NPAR TEST\n\t/CHISQUARE="); + + psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->var_view), 0, string); + + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->range_button))) + { + g_string_append (string, "("); + + g_string_append (string, + gtk_entry_get_text (GTK_ENTRY (scd->value_lower))); + + g_string_append (string, ", "); + + g_string_append (string, + gtk_entry_get_text (GTK_ENTRY (scd->value_upper))); + + g_string_append (string, ")"); + } + + + + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->values_button))) + { + GtkListStore *ls = scd->expected_list; + GtkTreeIter iter; + gboolean ok; + + g_string_append (string, "\n\t"); + g_string_append (string, "/EXPECTED = "); + + + for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls), + &iter); + ok; + ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter)) + { + gdouble v; + + gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1); + + g_string_append_printf (string, " %g", v); + } + + + + } + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} + + + +/* Pops up the Chi-Square dialog box */ +void +chisquare_dialog (PsppireDataWindow *dw) +{ + gint response; + + struct chisquare_dialog csd; + + GtkBuilder *xml = builder_new ("chi-square.ui"); + PsppireVarStore *vs; + + GtkWidget *dialog = get_widget_assert (xml, "chisquare-dialog"); + + GtkWidget *range_table = get_widget_assert (xml, "range-table"); + + + + GtkWidget *values_acr = get_widget_assert (xml, "psppire-acr1"); + GtkWidget *expected_value_entry = + get_widget_assert (xml, "expected-value-entry"); + + + GtkWidget *dict_view = get_widget_assert (xml, "dict-view"); + + csd.expected_list = gtk_list_store_new (1, G_TYPE_DOUBLE); + + csd.button1 = get_widget_assert (xml, "radiobutton1"); + csd.button2 = get_widget_assert (xml, "radiobutton3"); + csd.var_view = get_widget_assert (xml, "variables-treeview"); + + csd.range_button = get_widget_assert (xml, "radiobutton4"); + csd.value_lower = get_widget_assert (xml, "entry1"); + csd.value_upper = get_widget_assert (xml, "entry2"); + + csd.values_button = get_widget_assert (xml, "radiobutton2"); + + g_object_get (dw->data_editor, "var-store", &vs, NULL); + + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw)); + + + g_object_get (vs, "dictionary", &csd.dict, NULL); + g_object_set (dict_view, + "model", csd.dict, + "predicate", var_is_numeric, + NULL); + + + g_signal_connect (csd.range_button, "toggled", G_CALLBACK (set_sensitivity), + range_table); + + + g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity), + values_acr); + + g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity), + expected_value_entry); + + + psppire_acr_set_entry (PSPPIRE_ACR (values_acr), + GTK_ENTRY (expected_value_entry)); + + psppire_acr_set_model(PSPPIRE_ACR (values_acr), csd.expected_list); + + g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &csd); + + psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), + dialog_state_valid, &csd); + + response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + + + switch (response) + { + case GTK_RESPONSE_OK: + { + gchar *syntax = generate_syntax (&csd); + + struct getl_interface *sss = create_syntax_string_source (syntax); + execute_syntax (sss); + + g_free (syntax); + } + break; + case PSPPIRE_RESPONSE_PASTE: + { + gchar *syntax = generate_syntax (&csd); + paste_syntax_to_window (syntax); + g_free (syntax); + } + break; + default: + break; + } + + g_object_unref (xml); +} diff --git a/src/ui/gui/chi-square-dialog.h b/src/ui/gui/chi-square-dialog.h new file mode 100644 index 00000000..8292ff96 --- /dev/null +++ b/src/ui/gui/chi-square-dialog.h @@ -0,0 +1,25 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2010 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 . */ + +#ifndef __CHI_SQUARE_DIALOG_H +#define __CHI_SQUARE_DIALOG_H + +#include +#include "psppire-data-window.h" + +void chisquare_dialog (PsppireDataWindow * data); + +#endif diff --git a/src/ui/gui/chi-square.ui b/src/ui/gui/chi-square.ui new file mode 100644 index 00000000..5bcc08d5 --- /dev/null +++ b/src/ui/gui/chi-square.ui @@ -0,0 +1,339 @@ + + + + + + + 100 + 1 + 10 + + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Chi-Square Test + True + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + 3 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + never + automatic + etched-in + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + False + + + + + GTK_EXPAND | GTK_SHRINK | GTK_FILL + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + vertical + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + _Test Variable List: + True + + + False + False + 0 + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + never + automatic + etched-in + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + False + + + + + 1 + + + + + 2 + 3 + GTK_EXPAND | GTK_SHRINK | GTK_FILL + + + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + dict-view + variables-treeview + + + 1 + 2 + + GTK_EXPAND + + + + + True + 0 + + + True + 12 + + + True + vertical + + + _Get from data + True + True + False + True + True + True + + + 0 + + + + + Use _specified range + True + True + False + True + True + radiobutton3 + + + 1 + + + + + True + False + 2 + 2 + 5 + + + True + _Lower: + True + True + + + + + True + _Upper: + True + + + 1 + 2 + + + + + True + True + + + + 1 + 2 + + + + + True + True + + + + 1 + 2 + 1 + 2 + + + + + 2 + + + + + + + + + True + Expected Range: + True + + + + + 1 + 2 + GTK_FILL + 5 + + + + + True + 0 + + + True + 12 + + + True + vertical + + + All categor_ies equal + True + True + False + True + True + True + + + 0 + + + + + True + + + _Values + True + True + False + True + True + radiobutton1 + + + 0 + + + + + True + False + True + + + + 1 + + + + + 1 + + + + + True + 5 + + + 2 + + + + + + + + + True + Expected Values: + True + + + + + 2 + 3 + 1 + 2 + GTK_FILL + 5 + + + + + + + + 0 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 5 + + + False + False + end + 1 + + + + + + diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index c17e6e79..9bb42897 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -28,6 +28,7 @@ #include "ui/gui/comments-dialog.h" #include "ui/gui/compute-dialog.h" #include "ui/gui/correlation-dialog.h" +#include "ui/gui/chi-square-dialog.h" #include "ui/gui/crosstabs-dialog.h" #include "ui/gui/descriptives-dialog.h" #include "ui/gui/examine-dialog.h" @@ -1117,6 +1118,8 @@ psppire_data_window_init (PsppireDataWindow *de) connect_action (de, "correlation", G_CALLBACK (correlation_dialog)); connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog)); + + connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog)); {