Added dialog for the NPAR RUNS subcommand
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 25 Jul 2011 19:40:27 +0000 (21:40 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 25 Jul 2011 19:40:27 +0000 (21:40 +0200)
doc/statistics.texi
src/ui/gui/automake.mk
src/ui/gui/data-editor.ui
src/ui/gui/psppire-data-window.c
src/ui/gui/runs-dialog.c [new file with mode: 0644]
src/ui/gui/runs-dialog.h [new file with mode: 0644]
src/ui/gui/runs.ui [new file with mode: 0644]

index 36727c44c5f75dfa7620e900029875d4c2dd874b..0b2fdaf5c01b1d41181dfcc8a6d2a11fcb2730f7 100644 (file)
@@ -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.
index f21cbe7042cf1fec0a2471ac7d8873f4a2f3573e..bdb695df1a8955e37bc29572d151889e753a424d 100644 (file)
@@ -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 \
index 5feccaa24e7effc0a68191530ce949dfd9308188..c7faa8a93698b94122468d388dc9e23c09f2061a 100644 (file)
             <property name="label" translatable="yes">_Binomial...</property>
           </object>
         </child>
+        <child>
+          <object class="GtkAction" id="runs">
+            <property name="name">runs</property>
+            <property name="label" translatable="yes">R_uns...</property>
+          </object>
+        </child>
         <child>
           <object class="GtkAction" id="two-related-samples">
             <property name="name">"two-related-samples"></property>
           <menu action="non-parametrics">
             <menuitem action="chi-square"/>
             <menuitem action="binomial"/>
+            <menuitem action="runs"/>
             <menuitem action="two-related-samples"/>
             <menuitem action="k-related-samples"/>
           </menu>
index b009ff90f37de8d744fe576d9521876c28181bb8..e695310e0e17cfe2e6086035108deab43c5779ff 100644 (file)
@@ -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 (file)
index 0000000..64f50ac
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "dialog-common.h"
+#include <ui/syntax-gen.h>
+#include <libpspp/str.h>
+
+#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 <gtk/gtk.h>
+
+#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);
+}
+
+
+\f
+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 (file)
index 0000000..f34b48d
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. */
+
+#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 (file)
index 0000000..96c894a
--- /dev/null
@@ -0,0 +1,227 @@
+<?xml version="1.0"?>
+<interface>
+  <!-- interface-requires psppire 0.0 -->
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="PsppireDialog" id="runs-dialog">
+    <property name="title" translatable="yes">Runs Test</property>
+    <property name="modal">True</property>
+    <property name="orientation">Vertical</property>
+    <child internal-child="hbox">
+      <object class="GtkVBox" id="dialog-hbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkAlignment" id="alignment1">
+            <property name="visible">True</property>
+            <property name="top_padding">5</property>
+            <property name="left_padding">5</property>
+            <property name="right_padding">5</property>
+            <child>
+              <object class="GtkVBox" id="vbox1">
+                <property name="visible">True</property>
+                <property name="orientation">vertical</property>
+                <property name="spacing">5</property>
+                <child>
+                  <object class="GtkHBox" id="hbox1">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkScrolledWindow" id="scrolledwindow1">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hscrollbar_policy">never</property>
+                        <property name="vscrollbar_policy">automatic</property>
+                        <property name="shadow_type">in</property>
+                        <child>
+                          <object class="PsppireDictView" id="dict-view">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="border_width">5</property>
+                            <property name="headers_visible">False</property>
+                            <property name="headers_clickable">False</property>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkAlignment" id="alignment3">
+                        <property name="visible">True</property>
+                        <property name="xscale">0</property>
+                        <property name="yscale">0</property>
+                        <child>
+                          <object class="PsppireSelector" id="psppire-selector1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="receives_default">True</property>
+                            <property name="border_width">5</property>
+                            <property name="source_widget">dict-view</property>
+                            <property name="dest_widget">psppire-var-view1</property>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkScrolledWindow" id="scrolledwindow2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hscrollbar_policy">never</property>
+                        <property name="vscrollbar_policy">automatic</property>
+                        <property name="shadow_type">in</property>
+                        <child>
+                          <object class="PsppireVarView" id="psppire-var-view1">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="border_width">5</property>
+                            <property name="headers_visible">False</property>
+                            <property name="headers_clickable">False</property>
+                          </object>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkFrame" id="frame1">
+                    <property name="visible">True</property>
+                    <property name="label_xalign">0</property>
+                    <child>
+                      <object class="GtkAlignment" id="alignment2">
+                        <property name="visible">True</property>
+                        <property name="left_padding">12</property>
+                        <child>
+                          <object class="GtkTable" id="table1">
+                            <property name="visible">True</property>
+                            <property name="n_rows">2</property>
+                            <property name="n_columns">2</property>
+                            <child>
+                              <object class="GtkCheckButton" id="checkbutton1">
+                                <property name="label" translatable="yes">_Median</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="GtkCheckButton" id="checkbutton2">
+                                <property name="label" translatable="yes">M_ean</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkCheckButton" id="checkbutton4">
+                                <property name="label" translatable="yes">Mo_de</property>
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="draw_indicator">True</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkHBox" id="hbox2">
+                                <property name="visible">True</property>
+                                <child>
+                                  <object class="GtkCheckButton" id="checkbutton3">
+                                    <property name="label" translatable="yes">_Custom:</property>
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="receives_default">False</property>
+                                    <property name="use_underline">True</property>
+                                    <property name="draw_indicator">True</property>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkEntry" id="entry1">
+                                    <property name="visible">True</property>
+                                    <property name="can_focus">True</property>
+                                    <property name="invisible_char">&#x25CF;</property>
+                                    <property name="width_chars">0</property>
+                                  </object>
+                                  <packing>
+                                    <property name="position">1</property>
+                                  </packing>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="right_attach">2</property>
+                                <property name="top_attach">1</property>
+                                <property name="bottom_attach">2</property>
+                              </packing>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel" id="label1">
+                        <property name="visible">True</property>
+                        <property name="label" translatable="yes">Cut Point</property>
+                        <property name="use_markup">True</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="PsppireHButtonBox" id="psppire-hbuttonbox1">
+            <property name="visible">True</property>
+            <property name="border_width">5</property>
+            <property name="default">PSPPIRE_BUTTON_GOTO_MASK</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>