Implemented the Binomial Test dialog box.
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 19 May 2010 15:27:51 +0000 (17:27 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 19 May 2010 15:27:51 +0000 (17:27 +0200)
src/ui/gui/automake.mk
src/ui/gui/binomial-dialog.c [new file with mode: 0644]
src/ui/gui/binomial-dialog.h [new file with mode: 0644]
src/ui/gui/binomial.ui [new file with mode: 0644]
src/ui/gui/psppire-data-window.c

index 189c3f254136968c44efcbf95643c48ad3e8daf9..4774e2ae5ec320a0ece1073c3c197b794ab5fb3e 100644 (file)
@@ -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 (file)
index 0000000..130c3dd
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+#include "binomial-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 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, &notused) )
+    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 (file)
index 0000000..8f2f9a1
--- /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 __BINOMIAL_DIALOG_H
+#define __BINOMIAL_DIALOG_H
+
+#include <gtk/gtk.h>
+#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 (file)
index 0000000..d078391
--- /dev/null
@@ -0,0 +1,253 @@
+<?xml version="1.0"?>
+<interface>
+  <!-- interface-requires gtk+ 2.12 -->
+  <requires lib="psppire" version="2053.63976"/>
+  <!-- interface-naming-policy toplevel-contextual -->
+  <object class="GtkAdjustment" id="adjustment1">
+    <property name="upper">100</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
+  </object>
+  <object class="PsppireDialog" id="binomial-dialog">
+    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+    <property name="title" translatable="yes">Binomial Test</property>
+    <property name="modal">True</property>
+    <child internal-child="hbox">
+      <object class="GtkHBox" id="dialog-hbox13">
+        <property name="visible">True</property>
+        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+        <child>
+          <object class="GtkTable" id="table1">
+            <property name="visible">True</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+            <property name="n_rows">3</property>
+            <property name="n_columns">3</property>
+            <child>
+              <object class="GtkScrolledWindow" id="scrolledwindow5">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="hscrollbar_policy">never</property>
+                <property name="vscrollbar_policy">automatic</property>
+                <property name="shadow_type">etched-in</property>
+                <child>
+                  <object class="PsppireDictView" id="dict-view">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="headers_visible">False</property>
+                    <property name="headers_clickable">False</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkVBox" id="vbox2">
+                <property name="visible">True</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="orientation">vertical</property>
+                <child>
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="xalign">0</property>
+                    <property name="label" translatable="yes">_Test Variable List:</property>
+                    <property name="use_underline">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkScrolledWindow" id="scrolledwindow1">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="hscrollbar_policy">never</property>
+                    <property name="vscrollbar_policy">automatic</property>
+                    <property name="shadow_type">etched-in</property>
+                    <child>
+                      <object class="PsppireVarView" id="variables-treeview">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="headers_visible">False</property>
+                        <property name="headers_clickable">False</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="right_attach">3</property>
+                <property name="y_options">GTK_EXPAND | GTK_SHRINK | GTK_FILL</property>
+              </packing>
+            </child>
+            <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="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="border_width">5</property>
+                <property name="source_widget">dict-view</property>
+                <property name="dest_widget">variables-treeview</property>
+              </object>
+              <packing>
+                <property name="left_attach">1</property>
+                <property name="right_attach">2</property>
+                <property name="x_options"></property>
+                <property name="y_options">GTK_EXPAND</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="GtkVBox" id="vbox4">
+                        <property name="visible">True</property>
+                        <property name="orientation">vertical</property>
+                        <child>
+                          <object class="GtkRadioButton" id="radiobutton3">
+                            <property name="label" translatable="yes">_Get from data</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="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkHBox" id="hbox1">
+                            <property name="visible">True</property>
+                            <child>
+                              <object class="GtkRadioButton" id="radiobutton4">
+                                <property name="label" translatable="yes">_Cut point:</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>
+                                <property name="group">radiobutton3</property>
+                              </object>
+                              <packing>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkEntry" id="cutpoint-entry">
+                                <property name="visible">True</property>
+                                <property name="sensitive">False</property>
+                                <property name="can_focus">True</property>
+                                <property name="invisible_char">&#x2022;</property>
+                              </object>
+                              <packing>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">1</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">Define Dichotomy</property>
+                    <property name="use_markup">True</property>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">3</property>
+                <property name="y_options">GTK_FILL</property>
+                <property name="x_padding">5</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkHBox" id="hbox2">
+                <property name="visible">True</property>
+                <property name="spacing">5</property>
+                <child>
+                  <object class="GtkLabel" id="label3">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Test _Proportion:</property>
+                    <property name="use_underline">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkEntry" id="proportion-entry">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="invisible_char">&#x2022;</property>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="left_attach">2</property>
+                <property name="right_attach">3</property>
+                <property name="top_attach">1</property>
+                <property name="bottom_attach">2</property>
+                <property name="y_options"></property>
+              </packing>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="PsppireVButtonBox" id="psppire-vbuttonbox1">
+            <property name="visible">True</property>
+            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</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 9bb42897e1ee7398ca46f684e788102cf686fcf3..ec75e086b099bdec25e9a93597aa6152917d5a4d 100644 (file)
@@ -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));
  
 
   {