From: John Darrington Date: Wed, 19 May 2010 15:27:51 +0000 (+0200) Subject: Implemented the Binomial Test dialog box. X-Git-Tag: v0.7.5~20 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=006e4c8eef534aa82d28869a34c49a382076371d Implemented the Binomial Test dialog box. --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 189c3f25..4774e2ae 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -3,6 +3,7 @@ include $(top_srcdir)/src/ui/gui/sheet/automake.mk UI_FILES = \ + src/ui/gui/binomial.ui \ src/ui/gui/correlation.ui \ src/ui/gui/crosstabs.ui \ src/ui/gui/chi-square.ui \ @@ -112,6 +113,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-hbuttonbox.c \ src/ui/gui/psppire-vbuttonbox.c \ src/ui/gui/psppire-acr.c \ + src/ui/gui/binomial-dialog.c \ + src/ui/gui/binomial-dialog.h \ src/ui/gui/checkbox-treeview.c \ src/ui/gui/checkbox-treeview.h \ src/ui/gui/comments-dialog.c \ diff --git a/src/ui/gui/binomial-dialog.c b/src/ui/gui/binomial-dialog.c new file mode 100644 index 00000000..130c3dd6 --- /dev/null +++ b/src/ui/gui/binomial-dialog.c @@ -0,0 +1,211 @@ +/* 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 "binomial-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 binomial_dialog +{ + PsppireDict *dict; + GtkWidget *var_view; + + GtkWidget *button1; + + GtkWidget *prop_entry; + + GtkWidget *cutpoint_button; + GtkWidget *cutpoint_entry; +}; + +static void +set_sensitivity (GtkToggleButton *button, GtkWidget *w) +{ + gboolean state = gtk_toggle_button_get_active (button); + gtk_widget_set_sensitive (w, state); +} + + +static gboolean +get_proportion (const struct binomial_dialog *bin_d, double *prop) +{ + const gchar *text = gtk_entry_get_text (GTK_ENTRY (bin_d->prop_entry)); + gchar *endptr = NULL; + *prop = g_strtod (text, &endptr); + + if (endptr == text) + return FALSE; + + return TRUE; +} + +static gboolean +dialog_state_valid (gpointer data) +{ + double prop; + struct binomial_dialog *bin_d = data; + + GtkTreeModel *vars = + gtk_tree_view_get_model (GTK_TREE_VIEW (bin_d->var_view)); + + GtkTreeIter notused; + + if ( !gtk_tree_model_get_iter_first (vars, ¬used) ) + return FALSE; + + if ( ! get_proportion (bin_d, &prop)) + return FALSE; + + if (prop < 0 || prop > 1.0) + return FALSE; + + return TRUE; +} + + +static void +refresh (struct binomial_dialog *bin_d) +{ + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (bin_d->var_view)); + + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (bin_d->button1), TRUE); + + gtk_entry_set_text (GTK_ENTRY (bin_d->prop_entry), "0.5"); + + gtk_entry_set_text (GTK_ENTRY (bin_d->cutpoint_entry), ""); +} + + + +static char * +generate_syntax (const struct binomial_dialog *scd) +{ + gchar *text; + double prop; + GString *string; + + string = g_string_new ("NPAR TEST\n\t/BINOMIAL"); + + if ( get_proportion (scd, &prop)) + g_string_append_printf (string, "(%g)", prop); + + g_string_append (string, " ="); + + psppire_var_view_append_names (PSPPIRE_VAR_VIEW (scd->var_view), 0, string); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->cutpoint_button))) + { + const gchar *cutpoint = gtk_entry_get_text (GTK_ENTRY (scd->cutpoint_entry)); + g_string_append_printf (string, "(%s)", cutpoint); + } + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} + + + +/* Pops up the Chi-Square dialog box */ +void +binomial_dialog (PsppireDataWindow *dw) +{ + gint response; + + struct binomial_dialog bin_d; + + GtkBuilder *xml = builder_new ("binomial.ui"); + PsppireVarStore *vs; + + GtkWidget *dialog = get_widget_assert (xml, "binomial-dialog"); + + + + GtkWidget *dict_view = get_widget_assert (xml, "dict-view"); + + g_object_get (dw->data_editor, "var-store", &vs, NULL); + + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw)); + + bin_d.var_view = get_widget_assert (xml, "variables-treeview"); + bin_d.button1 = get_widget_assert (xml, "radiobutton3"); + bin_d.prop_entry = get_widget_assert (xml, "proportion-entry"); + + bin_d.cutpoint_entry = get_widget_assert (xml, "cutpoint-entry"); + bin_d.cutpoint_button = get_widget_assert (xml, "radiobutton4"); + + g_object_get (vs, "dictionary", &bin_d.dict, NULL); + g_object_set (dict_view, + "model", bin_d.dict, + "predicate", var_is_numeric, + NULL); + + g_signal_connect (bin_d.cutpoint_button, "toggled", G_CALLBACK (set_sensitivity), + bin_d.cutpoint_entry); + + g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &bin_d); + + psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), + dialog_state_valid, &bin_d); + + response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + + + switch (response) + { + case GTK_RESPONSE_OK: + { + gchar *syntax = generate_syntax (&bin_d); + + struct getl_interface *sss = create_syntax_string_source (syntax); + execute_syntax (sss); + + g_free (syntax); + } + break; + case PSPPIRE_RESPONSE_PASTE: + { + gchar *syntax = generate_syntax (&bin_d); + paste_syntax_to_window (syntax); + g_free (syntax); + } + break; + default: + break; + } + + g_object_unref (xml); +} diff --git a/src/ui/gui/binomial-dialog.h b/src/ui/gui/binomial-dialog.h new file mode 100644 index 00000000..8f2f9a18 --- /dev/null +++ b/src/ui/gui/binomial-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 __BINOMIAL_DIALOG_H +#define __BINOMIAL_DIALOG_H + +#include +#include "psppire-data-window.h" + +void binomial_dialog (PsppireDataWindow * data); + +#endif diff --git a/src/ui/gui/binomial.ui b/src/ui/gui/binomial.ui new file mode 100644 index 00000000..d0783918 --- /dev/null +++ b/src/ui/gui/binomial.ui @@ -0,0 +1,253 @@ + + + + + + + 100 + 1 + 10 + + + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + Binomial 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 + 3 + 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 + + + + + True + + + _Cut point: + True + True + False + True + True + radiobutton3 + + + 0 + + + + + True + False + True + + + + 1 + + + + + 1 + + + + + + + + + True + Define Dichotomy + True + + + + + 1 + 3 + GTK_FILL + 5 + + + + + True + 5 + + + True + Test _Proportion: + True + + + 0 + + + + + True + True + + + + 1 + + + + + 2 + 3 + 1 + 2 + + + + + + + + + + + + + + + 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 9bb42897..ec75e086 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -25,6 +25,7 @@ #include "language/syntax-string-source.h" #include "libpspp/message.h" #include "ui/gui/help-menu.h" +#include "ui/gui/binomial-dialog.h" #include "ui/gui/comments-dialog.h" #include "ui/gui/compute-dialog.h" #include "ui/gui/correlation-dialog.h" @@ -1120,6 +1121,8 @@ psppire_data_window_init (PsppireDataWindow *de) connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog)); connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog)); + + connect_action (de, "binomial", G_CALLBACK (binomial_dialog)); {