From: John Darrington Date: Mon, 25 Jul 2011 19:40:27 +0000 (+0200) Subject: Added dialog for the NPAR RUNS subcommand X-Git-Tag: v0.7.9~207 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b0a85a90ec68578d775a8cf5161c8e3ad9d35241;p=pspp-builds.git Added dialog for the NPAR RUNS subcommand --- diff --git a/doc/statistics.texi b/doc/statistics.texi index 36727c44..0b2fdaf5 100644 --- a/doc/statistics.texi +++ b/doc/statistics.texi @@ -895,7 +895,7 @@ not be run. @cindex runs test @display - [ /RUNS (@{MEAN, MEDIAN, MODE, value@}) varlist ] + [ /RUNS (@{MEAN, MEDIAN, MODE, value@}) = varlist ] @end display The /RUNS subcommand tests whether a data sequence is randomly ordered. diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index f21cbe70..bdb695df 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -24,6 +24,7 @@ UI_FILES = \ src/ui/gui/paired-samples.ui \ src/ui/gui/psppire.ui \ src/ui/gui/rank.ui \ + src/ui/gui/runs.ui \ src/ui/gui/sort.ui \ src/ui/gui/split-file.ui \ src/ui/gui/recode.ui \ @@ -233,6 +234,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/reliability-dialog.h \ src/ui/gui/roc-dialog.c \ src/ui/gui/roc-dialog.h \ + src/ui/gui/runs-dialog.c \ + src/ui/gui/runs-dialog.h \ src/ui/gui/select-cases-dialog.c \ src/ui/gui/select-cases-dialog.h \ src/ui/gui/sort-cases-dialog.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 5feccaa2..c7faa8a9 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -445,6 +445,12 @@ _Binomial... + + + runs + R_uns... + + "two-related-samples"> @@ -591,6 +597,7 @@ + diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index b009ff90..e695310e 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -52,6 +52,7 @@ #include "ui/gui/psppire-window.h" #include "ui/gui/psppire.h" #include "ui/gui/rank-dialog.h" +#include "ui/gui/runs-dialog.h" #include "ui/gui/recode-dialog.h" #include "ui/gui/regression-dialog.h" #include "ui/gui/reliability-dialog.h" @@ -1120,9 +1121,8 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "k-means", G_CALLBACK (k_means_dialog)); connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog)); - connect_action (de, "binomial", G_CALLBACK (binomial_dialog)); - + connect_action (de, "runs", G_CALLBACK (runs_dialog)); connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog)); connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog)); diff --git a/src/ui/gui/runs-dialog.c b/src/ui/gui/runs-dialog.c new file mode 100644 index 00000000..64f50ace --- /dev/null +++ b/src/ui/gui/runs-dialog.c @@ -0,0 +1,223 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2011 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 "dialog-common.h" +#include +#include + +#include "runs-dialog.h" +#include "psppire-selector.h" +#include "psppire-dictview.h" +#include "psppire-dialog.h" + +#include "psppire-data-window.h" +#include "psppire-var-view.h" + +#include "executor.h" +#include "helper.h" + +#include + +#include "gettext.h" +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + + +enum + { + CB_MEDIAN, + CB_MEAN, + CB_MODE, + CB_CUSTOM + }; + +struct runs +{ + GtkBuilder *xml; + PsppireDict *dict; + + GtkWidget *variables; + PsppireDataWindow *de ; + + GtkWidget *entry; + GtkWidget *cb[4]; +}; + +static char * generate_syntax (const struct runs *rd); + +/* Makes widget W's sensitivity follow the active state of TOGGLE */ +static void +sensitive_if_active (GtkToggleButton *toggle, GtkWidget *w) +{ + gboolean active = gtk_toggle_button_get_active (toggle); + + gtk_widget_set_sensitive (w, active); +} + +static void +refresh (struct runs *fd) +{ + int i; + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + gtk_entry_set_text (GTK_ENTRY (fd->entry), ""); + + for (i = 0; i < 4; ++i) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->cb[i]), FALSE); +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + int i; + struct runs *fd = data; + + GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); + + if (gtk_tree_model_iter_n_children (liststore, NULL) < 1) + return FALSE; + + for (i = 0; i < 4; ++i) + { + if ( TRUE == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[i]))) + break; + } + if ( i >= 4) + return FALSE; + + + if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[CB_CUSTOM]))) + { + if (0 == strcmp ("", gtk_entry_get_text (GTK_ENTRY (fd->entry)))) + return FALSE; + } + + return TRUE; +} + + +/* Pops up the Runs dialog box */ +void +runs_dialog (PsppireDataWindow *dw) +{ + struct runs fd; + gint response; + + PsppireVarStore *vs; + + GtkWidget *dialog ; + GtkWidget *source ; + + fd.xml = builder_new ("runs.ui"); + + dialog = get_widget_assert (fd.xml, "runs-dialog"); + source = get_widget_assert (fd.xml, "dict-view"); + + fd.entry = get_widget_assert (fd.xml, "entry1"); + fd.cb[CB_MEDIAN] = get_widget_assert (fd.xml, "checkbutton1"); + fd.cb[CB_MEAN] = get_widget_assert (fd.xml, "checkbutton2"); + fd.cb[CB_MODE] = get_widget_assert (fd.xml, "checkbutton4"); + fd.cb[CB_CUSTOM] = get_widget_assert (fd.xml, "checkbutton3"); + + fd.de = dw; + + g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd); + + + fd.variables = get_widget_assert (fd.xml, "psppire-var-view1"); + + g_object_get (fd.de->data_editor, "var-store", &vs, NULL); + + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de)); + + g_object_get (vs, "dictionary", &fd.dict, NULL); + g_object_set (source, "model", fd.dict, + "predicate", var_is_numeric, + NULL); + + g_signal_connect (fd.cb[CB_CUSTOM], "toggled", + G_CALLBACK (sensitive_if_active), fd.entry); + + psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), + dialog_state_valid, &fd); + + response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + + switch (response) + { + case GTK_RESPONSE_OK: + g_free (execute_syntax_string (dw, generate_syntax (&fd))); + break; + case PSPPIRE_RESPONSE_PASTE: + g_free (paste_syntax_to_window (generate_syntax (&fd))); + break; + default: + break; + } + + g_object_unref (fd.xml); +} + + + +static void +append_fragment (GString *string, const gchar *cut, PsppireVarView *vv) +{ + g_string_append (string, "\n\t/RUNS"); + + g_string_append (string, " ( "); + g_string_append (string, cut); + g_string_append (string, " ) = "); + + psppire_var_view_append_names (vv, 0, string); +} + + +char * +generate_syntax (const struct runs *rd) +{ + gchar *text; + + GString *string = g_string_new ("NPAR TEST"); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEAN]))) + append_fragment (string, "MEAN", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MEDIAN]))) + append_fragment (string, "MEDIAN", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_MODE]))) + append_fragment (string, "MODE", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_CUSTOM]))) + { + char *text = gtk_entry_get_text (GTK_ENTRY (rd->entry)); + append_fragment (string, text, PSPPIRE_VAR_VIEW (rd->variables)); + } + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} diff --git a/src/ui/gui/runs-dialog.h b/src/ui/gui/runs-dialog.h new file mode 100644 index 00000000..f34b48d1 --- /dev/null +++ b/src/ui/gui/runs-dialog.h @@ -0,0 +1,24 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2011 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 __RUNS_DIALOG_H +#define __RUNS_DIALOG_H + +#include "psppire-data-window.h" + +void runs_dialog (PsppireDataWindow * data); + +#endif diff --git a/src/ui/gui/runs.ui b/src/ui/gui/runs.ui new file mode 100644 index 00000000..96c894a7 --- /dev/null +++ b/src/ui/gui/runs.ui @@ -0,0 +1,227 @@ + + + + + + + Runs Test + True + Vertical + + + True + vertical + 2 + + + True + 5 + 5 + 5 + + + True + vertical + 5 + + + True + + + True + True + never + automatic + in + + + True + True + 5 + False + False + + + + + 0 + + + + + True + 0 + 0 + + + True + True + True + 5 + dict-view + psppire-var-view1 + + + + + False + False + 1 + + + + + True + True + never + automatic + in + + + True + True + 5 + False + False + + + + + 2 + + + + + 0 + + + + + True + 0 + + + True + 12 + + + True + 2 + 2 + + + _Median + True + True + False + True + True + + + + + M_ean + True + True + False + True + True + + + 1 + 2 + + + + + Mo_de + True + True + False + True + True + + + 1 + 2 + + + + + True + + + _Custom: + True + True + False + True + True + + + False + False + 0 + + + + + True + True + + 0 + + + 1 + + + + + 1 + 2 + 1 + 2 + + + + + + + + + True + Cut Point + True + + + + + False + False + 1 + + + + + + + 0 + + + + + True + 5 + PSPPIRE_BUTTON_GOTO_MASK + + + False + False + end + 1 + + + + + +