Added a dialog box for the CORRELATION command
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 13 Dec 2009 19:37:13 +0000 (20:37 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 13 Dec 2009 19:37:13 +0000 (20:37 +0100)
src/ui/gui/automake.mk
src/ui/gui/correlation-dialog.c [new file with mode: 0644]
src/ui/gui/correlation-dialog.h [new file with mode: 0644]
src/ui/gui/correlation.ui [new file with mode: 0644]
src/ui/gui/data-editor.glade
src/ui/gui/psppire-data-window.c

index 22e2350b5156cfd02d2e198abdde130dd5d9175a..f69cad5b93a61edba147d2e8ff2c937a1f27182f 100644 (file)
@@ -54,6 +54,7 @@ UNINSTALL_DATA_HOOKS += uninstall-icons
 
 
 UI_FILES = \
+       src/ui/gui/correlation.ui \
        src/ui/gui/crosstabs.ui \
        src/ui/gui/descriptives.ui \
        src/ui/gui/examine.ui \
@@ -114,6 +115,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/correlation-dialog.c \
+       src/ui/gui/correlation-dialog.h \
        src/ui/gui/crosstabs-dialog.c \
        src/ui/gui/crosstabs-dialog.h \
        src/ui/gui/customentry.c \
diff --git a/src/ui/gui/correlation-dialog.c b/src/ui/gui/correlation-dialog.c
new file mode 100644 (file)
index 0000000..19bb7a7
--- /dev/null
@@ -0,0 +1,177 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2009  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 <language/syntax-string-source.h>
+#include <ui/syntax-gen.h>
+#include <libpspp/str.h>
+
+#include "correlation-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
+
+
+struct correlation
+{
+  PsppireDict *dict;
+
+  GtkWidget *variables ;
+
+  GtkWidget *significant;
+  GtkWidget *two_tailed;
+};
+
+
+static char * generate_syntax (const struct correlation *rd);
+
+
+static void
+refresh (struct correlation *rd)
+{
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->significant), FALSE);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->two_tailed), TRUE);
+}
+
+
+static gboolean
+dialog_state_valid (gpointer data)
+{
+  struct correlation *corr = data;
+
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (corr->variables));
+
+  if  (gtk_tree_model_iter_n_children (liststore, NULL) >= 1)
+    return TRUE;
+
+  return FALSE;
+}
+
+
+/* Pops up the Correlation dialog box */
+void
+correlation_dialog (GObject *o, gpointer data)
+{
+  struct correlation rd;
+  gint response;
+
+  GtkBuilder *xml = builder_new ("correlation.ui");
+  PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
+  PsppireVarStore *vs;
+
+  GtkWidget *dialog = get_widget_assert   (xml, "correlation-dialog");
+  GtkWidget *source = get_widget_assert   (xml, "dict-view");
+
+  g_object_get (de->data_editor, "var-store", &vs, NULL);
+
+  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
+
+  g_object_get (vs, "dictionary", &rd.dict, NULL);
+  g_object_set (source, "model", rd.dict, NULL);
+
+  rd.variables = get_widget_assert (xml, "psppire-var-view1");
+  rd.significant = get_widget_assert (xml, "button-flag-significants");
+  rd.two_tailed = get_widget_assert (xml, "button-two-tailed");
+
+  g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh),  &rd);
+
+  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
+                                     dialog_state_valid, &rd);
+
+  response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
+
+  switch (response)
+    {
+    case GTK_RESPONSE_OK:
+      {
+       gchar *syntax = generate_syntax (&rd);
+
+       struct getl_interface *sss = create_syntax_string_source (syntax);
+       execute_syntax (sss);
+
+       g_free (syntax);
+      }
+      break;
+    case PSPPIRE_RESPONSE_PASTE:
+      {
+       gchar *syntax = generate_syntax (&rd);
+        paste_syntax_in_new_window (syntax);
+
+       g_free (syntax);
+      }
+      break;
+    default:
+      break;
+    }
+
+  g_object_unref (xml);
+}
+
+
+\f
+
+static char *
+generate_syntax (const struct correlation *rd)
+{
+  gchar *text;
+  GString *string = g_string_new ("CORRELATION");
+  g_string_append (string, "\n\t/VARIABLES = ");
+
+  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->variables), 0, string);
+
+
+  g_string_append (string, "\n\t/PRINT =");
+
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->two_tailed)))
+    g_string_append (string, " TWOTAIL");
+  else
+    g_string_append (string, " ONETAIL");
+
+
+  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->significant)))
+    g_string_append (string, " NOSIG");
+  else
+    g_string_append (string, " SIG");
+
+
+  g_string_append (string, ".\n");
+
+  text = string->str;
+
+  g_string_free (string, FALSE);
+
+  return text;
+}
diff --git a/src/ui/gui/correlation-dialog.h b/src/ui/gui/correlation-dialog.h
new file mode 100644 (file)
index 0000000..532970f
--- /dev/null
@@ -0,0 +1,24 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2009  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 __CORRELATION_DIALOG_H
+#define __CORRELATION_DIALOG_H
+
+#include <gtk/gtk.h>
+
+void correlation_dialog (GObject *o, gpointer data);
+
+#endif
diff --git a/src/ui/gui/correlation.ui b/src/ui/gui/correlation.ui
new file mode 100644 (file)
index 0000000..1fad344
--- /dev/null
@@ -0,0 +1,265 @@
+<?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="correlation-dialog">
+    <property name="title" translatable="yes">Bivariate Correlations</property>
+    <property name="modal">True</property>
+    <child internal-child="hbox">
+      <object class="GtkHBox" id="dialog-hbox1">
+        <property name="visible">True</property>
+        <property name="spacing">2</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">automatic</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="GtkVBox" id="vbox2">
+                    <property name="visible">True</property>
+                    <property name="orientation">vertical</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>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="padding">5</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">automatic</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="frame2">
+                <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="GtkHButtonBox" id="hbuttonbox2">
+                        <property name="visible">True</property>
+                        <property name="layout_style">start</property>
+                        <child>
+                          <object class="GtkCheckButton" id="button-pearson">
+                            <property name="label" translatable="yes">Pearso_n</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="GtkCheckButton" id="button-kendall">
+                            <property name="label" translatable="yes">_Kendall's tau-b</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">1</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkCheckButton" id="button-spearman">
+                            <property name="label" translatable="yes">_Spearman</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">2</property>
+                          </packing>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label2">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Correlation Coefficients</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="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>
+                        <property name="layout_style">start</property>
+                        <child>
+                          <object class="GtkRadioButton" id="button-two-tailed">
+                            <property name="label" translatable="yes">_Two-tailed</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="active">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="GtkRadioButton" id="button-one-tailed">
+                            <property name="label" translatable="yes">One-tai_led</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="active">True</property>
+                            <property name="draw_indicator">True</property>
+                            <property name="group">button-two-tailed</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</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">Test of Significance</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkCheckButton" id="button-flag-significants">
+                <property name="label" translatable="yes">_Flag significant correlations</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="position">3</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="padding">2</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="PsppireVButtonBox" id="psppire-vbuttonbox1">
+            <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">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
index ca7efc90aff231c0f970f1f71a37352e2b1b1386..9431002b82a0fdd7173615064042b08fd613e9be 100644 (file)
                 </child>
               </widget>
             </child>
+            <child>
+              <widget class="GtkMenuItem" id="correlation">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Bivariate _Correlation...</property>
+                <property name="use_underline">True</property>
+              </widget>
+            </child>
             <child>
               <widget class="GtkMenuItem" id="reliability">
                 <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
index e42d2bd08875f7d296ab5067ffe62703b16624ce..e9a89465b4cf1c17cda74bd5356e9547cf5b296d 100644 (file)
@@ -57,6 +57,7 @@
 #include "regression-dialog.h"
 #include "reliability-dialog.h"
 #include "roc-dialog.h"
+#include "correlation-dialog.h"
 #include "oneway-anova-dialog.h"
 #include "t-test-independent-samples-dialog.h"
 #include "t-test-one-sample.h"
@@ -1707,6 +1708,20 @@ psppire_data_window_init (PsppireDataWindow *de)
                      G_CALLBACK (roc_dialog), de);
   }
 
+  {
+    GtkAction *invoke_correlation_dialog =
+      resolve_action (de->builder, "correlation", NULL);
+
+    g_object_set (invoke_correlation_dialog,
+                 "tooltip", _("Bivariate Correlation"),
+                 "stock-id", "pspp-correlation",
+                 NULL
+                 );
+
+    g_signal_connect (invoke_correlation_dialog, "activate",
+                     G_CALLBACK (correlation_dialog), de);
+  }
+
 
   {
     GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER));