Added a dialog box for the k-related-sample non-parametric tests.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 30 Oct 2010 12:06:51 +0000 (14:06 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 30 Oct 2010 12:06:51 +0000 (14:06 +0200)
src/ui/gui/automake.mk
src/ui/gui/data-editor.ui
src/ui/gui/k-related-dialog.c [new file with mode: 0644]
src/ui/gui/k-related-dialog.h [new file with mode: 0644]
src/ui/gui/k-related.ui [new file with mode: 0644]
src/ui/gui/psppire-data-window.c

index 989677f865a1dd11f961fdf4bf9d820f7f4261d0..1595fdd00e356bca8d6504e271087c9fe3ad559c 100644 (file)
@@ -15,6 +15,7 @@ UI_FILES = \
        src/ui/gui/factor.ui \
        src/ui/gui/find.ui \
        src/ui/gui/frequencies.ui \
+       src/ui/gui/k-related.ui \
        src/ui/gui/oneway.ui \
        src/ui/gui/psppire.ui \
        src/ui/gui/rank.ui \
@@ -158,6 +159,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/help-menu.c \
        src/ui/gui/help-menu.h \
        src/ui/gui/helper.h \
+       src/ui/gui/k-related-dialog.c \
+       src/ui/gui/k-related-dialog.h \
        src/ui/gui/main.c \
        src/ui/gui/missing-val-dialog.c \
        src/ui/gui/missing-val-dialog.h \
index 69f2b413901f43aa4e67e5f6cb5c01bce72ef468..d87596cf16a17b23601a66c0943dce30ee0b05aa 100644 (file)
             <property name="label" translatable="yes">_Binomial</property>
           </object>
         </child>
+        <child>
+          <object class="GtkAction" id="k-related-samples">
+            <property name="name">"k-related-samples"></property>
+            <property name="label" translatable="yes">K Related _Samples</property>
+          </object>
+        </child>
         <child>
           <object class="GtkAction" id="roc-curve">
             <property name="name">roc-curve</property>
           <menu action="non-parametrics">
             <menuitem action="chi-square"/>
             <menuitem action="binomial"/>
+            <menuitem action="k-related-samples"/>
           </menu>
           <menuitem action="roc-curve"/>
         </menu>
diff --git a/src/ui/gui/k-related-dialog.c b/src/ui/gui/k-related-dialog.c
new file mode 100644 (file)
index 0000000..fb0a785
--- /dev/null
@@ -0,0 +1,186 @@
+/* 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 <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "k-related-dialog.h"
+
+#include <language/syntax-string-source.h>
+
+#include "psppire-dialog.h"
+#include "psppire-var-view.h"
+#include "psppire-acr.h"
+#include "dialog-common.h"
+
+#include "helper.h"
+#include "executor.h"
+
+
+#include <gtk/gtk.h>
+
+struct k_related_dialog
+{
+  PsppireDict *dict;
+  GtkWidget *var_view;
+
+  GtkWidget *friedman;
+  GtkWidget *kendal;
+  GtkWidget *cochran;
+};
+
+static gboolean
+dialog_state_valid (gpointer data)
+{
+  struct k_related_dialog *krd = data;
+
+  GtkTreeModel *vars =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (krd->var_view));
+
+  /* Tests using less than 3 variables are not useful */
+  if (gtk_tree_model_iter_n_children (vars, NULL) < 3)
+    return FALSE;
+
+  /* At least one checkbutton must be active */
+  if ( 
+      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->friedman))
+      && 
+      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->kendal))
+      && 
+      ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->cochran))
+       )
+    return FALSE;
+
+  return TRUE;
+}
+
+
+static void
+refresh (struct k_related_dialog *krd)
+{
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (krd->var_view));
+
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->friedman), TRUE);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->kendal), FALSE);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (krd->cochran), FALSE);
+}
+
+
+static char *
+generate_syntax (const struct k_related_dialog *krd)
+{
+  gchar *text;
+  GString *string;
+
+  string = g_string_new ("NPAR TEST");
+
+  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->friedman)))
+    {
+      g_string_append (string, "\n\t/FRIEDMAN = ");
+      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
+    }
+
+  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->kendal)))
+    {
+      g_string_append (string, "\n\t/KENDAL = ");
+      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
+    }
+
+  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (krd->cochran)))
+    {
+      g_string_append (string, "\n\t/COCHRAN = ");
+      psppire_var_view_append_names (PSPPIRE_VAR_VIEW (krd->var_view), 0, string);
+    }
+
+  g_string_append (string, ".\n");
+
+  text = string->str;
+
+  g_string_free (string, FALSE);
+
+  return text;
+}
+
+
+
+/* Pops up the K-Related dialog box */
+void
+k_related_dialog (PsppireDataWindow *dw)
+{
+  gint response;
+
+  struct k_related_dialog krd;
+
+  GtkBuilder *xml = builder_new ("k-related.ui");
+  PsppireVarStore *vs;
+
+  GtkWidget *dialog = get_widget_assert   (xml, "k-related-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));
+
+  krd.var_view  = get_widget_assert (xml, "variables-treeview");
+
+  krd.friedman =  get_widget_assert (xml, "friedman-checkbutton");
+  krd.kendal =  get_widget_assert (xml, "kendal-checkbutton");
+  krd.cochran =  get_widget_assert (xml, "cochran-checkbutton");
+
+  g_object_get (vs, "dictionary", &krd.dict, NULL);
+  g_object_set (dict_view,
+               "model", krd.dict, 
+               "predicate", var_is_numeric,
+               NULL);
+
+
+  g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh),  &krd);
+
+  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
+                                     dialog_state_valid, &krd);
+
+  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
+
+
+  switch (response)
+    {
+    case GTK_RESPONSE_OK:
+      {
+       gchar *syntax = generate_syntax (&krd);
+
+       struct getl_interface *sss = create_syntax_string_source (syntax);
+       execute_syntax (sss);
+
+       g_free (syntax);
+      }
+      break;
+    case PSPPIRE_RESPONSE_PASTE:
+      {
+       gchar *syntax = generate_syntax (&krd);
+       paste_syntax_to_window (syntax);
+       g_free (syntax);
+      }
+      break;
+    default:
+      break;
+    }
+
+  g_object_unref (xml);
+}
diff --git a/src/ui/gui/k-related-dialog.h b/src/ui/gui/k-related-dialog.h
new file mode 100644 (file)
index 0000000..73288b6
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. */
+
+#ifndef K_RELATED_DIALOG
+#define K_RELATED_DIALOG 1
+
+#include "psppire-data-window.h"
+
+void k_related_dialog (PsppireDataWindow *dw);
+
+
+#endif
diff --git a/src/ui/gui/k-related.ui b/src/ui/gui/k-related.ui
new file mode 100644 (file)
index 0000000..a499a1f
--- /dev/null
@@ -0,0 +1,194 @@
+<?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="k-related-dialog">
+    <property name="title" translatable="yes">Tests for Several Related Samples</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="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">automatic</property>
+                <property name="vscrollbar_policy">never</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="GtkAspectFrame" id="aspectframe1">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="label_yalign">0</property>
+                <property name="shadow_type">none</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">variables-treeview</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="GtkFrame" id="frame2">
+                <property name="visible">True</property>
+                <property name="label_xalign">0</property>
+                <property name="shadow_type">none</property>
+                <child>
+                  <object class="GtkAlignment" id="alignment2">
+                    <property name="visible">True</property>
+                    <property name="left_padding">12</property>
+                    <child>
+                      <object class="GtkScrolledWindow" id="scrolledwindow2">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="hscrollbar_policy">automatic</property>
+                        <property name="vscrollbar_policy">automatic</property>
+                        <property name="shadow_type">in</property>
+                        <child>
+                          <object class="PsppireVarView" id="variables-treeview">
+                            <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>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">_Test Variables:</property>
+                    <property name="use_markup">True</property>
+                    <property name="use_underline">True</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="alignment1">
+                <property name="visible">True</property>
+                <property name="left_padding">12</property>
+                <child>
+                  <object class="GtkHButtonBox" id="hbuttonbox1">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkCheckButton" id="friedman-checkbutton">
+                        <property name="label" translatable="yes">_Friedman</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</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="GtkCheckButton" id="kendal-checkbutton">
+                        <property name="label" translatable="yes">_Kendall's W</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkCheckButton" id="cochran-checkbutton">
+                        <property name="label" translatable="yes">_Cochran's Q</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">False</property>
+                        <property name="draw_indicator">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child type="label">
+              <object class="GtkLabel" id="frame">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Test Type</property>
+                <property name="use_markup">True</property>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="PsppireHButtonBox" id="psppire-hbuttonbox1">
+            <property name="visible">True</property>
+            <property name="border_width">5</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
index 63ad9fe1bdc0457644ff5c9865a7c9c7f3acab1e..e024fb94d3c366caa2b87b299eae172b5f086d1c 100644 (file)
@@ -37,6 +37,7 @@
 #include "ui/gui/factor-dialog.h"
 #include "ui/gui/find-dialog.h"
 #include "ui/gui/frequencies-dialog.h"
+#include "ui/gui/k-related-dialog.h"
 #include "ui/gui/goto-case-dialog.h"
 #include "ui/gui/helper.h"
 #include "ui/gui/oneway-anova-dialog.h"
@@ -1132,6 +1133,8 @@ psppire_data_window_init (PsppireDataWindow *de)
   connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
 
   connect_action (de, "binomial", G_CALLBACK (binomial_dialog));
+
+  connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog));
  
 
   {