Binomial test dialog: Convert to new style of action objects.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 24 Nov 2012 07:46:15 +0000 (08:46 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 24 Nov 2012 07:46:15 +0000 (08:46 +0100)
src/ui/gui/automake.mk
src/ui/gui/binomial-dialog.c [deleted file]
src/ui/gui/binomial-dialog.h [deleted file]
src/ui/gui/data-editor.ui
src/ui/gui/psppire-data-window.c
src/ui/gui/psppire-dialog-action-binomial.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-binomial.h [new file with mode: 0644]
src/ui/gui/widgets.c

index 115837343af8676dc7d9d0a882c0c84dca4400eb..2c6427a255e868b08b194e8a0888d31d9449bc2a 100644 (file)
@@ -164,8 +164,6 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/autorecode-dialog.h \
        src/ui/gui/aggregate-dialog.c \
        src/ui/gui/aggregate-dialog.h \
-       src/ui/gui/binomial-dialog.c \
-       src/ui/gui/binomial-dialog.h \
        src/ui/gui/builder-wrapper.c \
        src/ui/gui/builder-wrapper.h \
        src/ui/gui/checkbox-treeview.c \
@@ -226,6 +224,8 @@ src_ui_gui_psppire_SOURCES = \
        src/ui/gui/psppire-dialog.h \
        src/ui/gui/psppire-dialog-action.c \
        src/ui/gui/psppire-dialog-action.h \
+       src/ui/gui/psppire-dialog-action-binomial.c \
+       src/ui/gui/psppire-dialog-action-binomial.h \
        src/ui/gui/psppire-dialog-action-correlation.c \
        src/ui/gui/psppire-dialog-action-correlation.h \
        src/ui/gui/psppire-dialog-action-descriptives.c \
diff --git a/src/ui/gui/binomial-dialog.c b/src/ui/gui/binomial-dialog.c
deleted file mode 100644 (file)
index 8f1df37..0000000
+++ /dev/null
@@ -1,190 +0,0 @@
-/* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2010, 2011, 2012  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 "psppire-dialog.h"
-#include "psppire-var-view.h"
-#include "psppire-acr.h"
-#include "dialog-common.h"
-
-#include "builder-wrapper.h"
-#include "executor.h"
-#include "helper.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 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_from_toggle),
-                   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:
-      g_free (execute_syntax_string (dw, generate_syntax (&bin_d)));
-      break;
-    case PSPPIRE_RESPONSE_PASTE:
-      g_free (paste_syntax_to_window (generate_syntax (&bin_d)));
-      break;
-    default:
-      break;
-    }
-
-  g_object_unref (xml);
-}
diff --git a/src/ui/gui/binomial-dialog.h b/src/ui/gui/binomial-dialog.h
deleted file mode 100644 (file)
index b50e444..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/* 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 "psppire-data-window.h"
-
-void binomial_dialog (PsppireDataWindow * data);
-
-#endif
index 07910dd217397b3b2b935aa2211c78052bcea33a..3408036357cd4087bb5e1024e934c25be618bb97 100644 (file)
           </object>
         </child>
         <child>
-          <object class="GtkAction" id="binomial">
+          <object class="PsppireDialogActionBinomial" id="binomial">
             <property name="name">binomial</property>
+            <property name="manager">uimanager1</property>
             <property name="label" translatable="yes">_Binomial...</property>
           </object>
         </child>
index f6bd2efbd979b1063f745bc709129c4b1c3b674c..ea3ec43d1fb7000a9724b64aab40a487159cc8d2 100644 (file)
@@ -26,7 +26,6 @@
 #include "libpspp/str.h"
 #include "ui/gui/aggregate-dialog.h"
 #include "ui/gui/autorecode-dialog.h"
-#include "ui/gui/binomial-dialog.h"
 #include "ui/gui/builder-wrapper.h"
 #include "ui/gui/chi-square-dialog.h"
 #include "ui/gui/comments-dialog.h"
@@ -1076,7 +1075,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_action (de, "crosstabs", G_CALLBACK (crosstabs_dialog));
   connect_action (de, "univariate", G_CALLBACK (univariate_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, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog));
   connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog));
diff --git a/src/ui/gui/psppire-dialog-action-binomial.c b/src/ui/gui/psppire-dialog-action-binomial.c
new file mode 100644 (file)
index 0000000..97a5f3c
--- /dev/null
@@ -0,0 +1,179 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2012  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 "psppire-dialog-action-binomial.h"
+#include "psppire-value-entry.h"
+
+#include "dialog-common.h"
+#include "helper.h"
+#include <ui/syntax-gen.h>
+#include "psppire-var-view.h"
+
+#include "psppire-dialog.h"
+#include "builder-wrapper.h"
+#include "checkbox-treeview.h"
+#include "psppire-dict.h"
+#include "libpspp/str.h"
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+#define N_(msgid) msgid
+
+
+static void
+psppire_dialog_action_binomial_class_init (PsppireDialogActionBinomialClass *class);
+
+G_DEFINE_TYPE (PsppireDialogActionBinomial, psppire_dialog_action_binomial, PSPPIRE_TYPE_DIALOG_ACTION);
+
+
+static gboolean
+get_proportion (PsppireDialogActionBinomial *act, double *prop)
+{
+    const gchar *text = gtk_entry_get_text (GTK_ENTRY (act->prop_entry));
+    gchar *endptr = NULL;
+     *prop = g_strtod (text, &endptr);
+
+    if (endptr == text)
+      return FALSE;
+
+    return TRUE; 
+}
+
+static gboolean
+dialog_state_valid (gpointer data)
+{
+  PsppireDialogActionBinomial *act = PSPPIRE_DIALOG_ACTION_BINOMIAL (data);
+  double prop;
+
+  GtkTreeModel *vars =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (act->var_view));
+
+  GtkTreeIter notused;
+
+  if ( !gtk_tree_model_get_iter_first (vars, &notused) )
+    return FALSE;
+
+  if ( ! get_proportion (act, &prop))
+    return FALSE;
+
+  if (prop < 0 || prop > 1.0)
+    return FALSE;
+
+  return TRUE;
+}
+
+static void
+refresh (PsppireDialogAction *da)
+{
+  PsppireDialogActionBinomial *act = PSPPIRE_DIALOG_ACTION_BINOMIAL (da);
+  GtkTreeModel *liststore =
+    gtk_tree_view_get_model (GTK_TREE_VIEW (act->var_view));
+
+  gtk_list_store_clear (GTK_LIST_STORE (liststore));
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (act->button1), TRUE);
+
+  gtk_entry_set_text (GTK_ENTRY (act->prop_entry), "0.5");
+
+  gtk_entry_set_text (GTK_ENTRY (act->cutpoint_entry), "");
+}
+
+
+static void
+psppire_dialog_action_binomial_activate (GtkAction *a)
+{
+  PsppireDialogActionBinomial *act = PSPPIRE_DIALOG_ACTION_BINOMIAL (a);
+  PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
+
+  GtkBuilder *xml = builder_new ("binomial.ui");
+
+  pda->dialog = get_widget_assert   (xml, "binomial-dialog");
+  pda->source = get_widget_assert   (xml, "dict-view");
+
+  act->var_view   = get_widget_assert (xml, "variables-treeview");
+  act->button1   = get_widget_assert (xml, "radiobutton3");
+  act->prop_entry = get_widget_assert (xml, "proportion-entry");
+
+  act->cutpoint_entry =     get_widget_assert   (xml, "cutpoint-entry");
+  act->cutpoint_button =    get_widget_assert   (xml, "radiobutton4");
+
+  g_object_unref (xml);
+
+
+  g_signal_connect (act->cutpoint_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle),
+                   act->cutpoint_entry);
+
+  psppire_dialog_action_set_refresh (pda, refresh);
+
+  psppire_dialog_action_set_valid_predicate (pda,
+                                       dialog_state_valid);
+
+  if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_binomial_parent_class)->activate)
+    PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_binomial_parent_class)->activate (pda);
+}
+
+
+
+static char *
+generate_syntax (PsppireDialogAction *a)
+{
+  PsppireDialogActionBinomial *scd = PSPPIRE_DIALOG_ACTION_BINOMIAL (a);
+  gchar *text = NULL;
+
+  double prop;
+  GString *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;
+}
+
+static void
+psppire_dialog_action_binomial_class_init (PsppireDialogActionBinomialClass *class)
+{
+  GtkActionClass *action_class = GTK_ACTION_CLASS (class);
+
+  action_class->activate = psppire_dialog_action_binomial_activate;
+
+  PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
+}
+
+
+static void
+psppire_dialog_action_binomial_init (PsppireDialogActionBinomial *act)
+{
+}
+
diff --git a/src/ui/gui/psppire-dialog-action-binomial.h b/src/ui/gui/psppire-dialog-action-binomial.h
new file mode 100644 (file)
index 0000000..0541a40
--- /dev/null
@@ -0,0 +1,83 @@
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2012  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 <glib-object.h>
+#include <glib.h>
+
+#include "psppire-dialog-action.h"
+
+#ifndef __PSPPIRE_DIALOG_ACTION_BINOMIAL_H__
+#define __PSPPIRE_DIALOG_ACTION_BINOMIAL_H__
+
+G_BEGIN_DECLS
+
+
+#define PSPPIRE_TYPE_DIALOG_ACTION_BINOMIAL (psppire_dialog_action_binomial_get_type ())
+
+#define PSPPIRE_DIALOG_ACTION_BINOMIAL(obj)    \
+                     (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+                                                 PSPPIRE_TYPE_DIALOG_ACTION_BINOMIAL, PsppireDialogActionBinomial))
+
+#define PSPPIRE_DIALOG_ACTION_BINOMIAL_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_CAST ((klass), \
+                                PSPPIRE_TYPE_DIALOG_ACTION_BINOMIAL, \
+                                 PsppireDialogActionBinomialClass))
+
+
+#define PSPPIRE_IS_DIALOG_ACTION_BINOMIAL(obj) \
+                    (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_BINOMIAL))
+
+#define PSPPIRE_IS_DIALOG_ACTION_BINOMIAL_CLASS(klass) \
+                     (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_BINOMIAL))
+
+
+#define PSPPIRE_DIALOG_ACTION_BINOMIAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+                                  PSPPIRE_TYPE_DIALOG_ACTION_BINOMIAL, \
+                                  PsppireDialogActionBinomialClass))
+
+typedef struct _PsppireDialogActionBinomial       PsppireDialogActionBinomial;
+typedef struct _PsppireDialogActionBinomialClass  PsppireDialogActionBinomialClass;
+
+
+struct _PsppireDialogActionBinomial
+{
+  PsppireDialogAction parent;
+
+  /*< private >*/
+  gboolean dispose_has_run ;
+
+
+  GtkWidget *var_view;
+  GtkWidget *button1;
+  GtkWidget *prop_entry;
+
+  GtkWidget *cutpoint_entry;
+  GtkWidget *cutpoint_button;
+};
+
+
+struct _PsppireDialogActionBinomialClass
+{
+  PsppireDialogActionClass parent_class;
+};
+
+
+GType psppire_dialog_action_binomial_get_type (void) ;
+
+G_END_DECLS
+
+#endif /* __PSPPIRE_DIALOG_ACTION_BINOMIAL_H__ */
index a7c52c6d4566c33f008db289161c806fa30e7509..1230d5d6c36c38e94a288a61dc7b96079968bb7e 100644 (file)
@@ -15,6 +15,7 @@
 #include "psppire-var-view.h"
 #include "psppire-val-chooser.h"
 
+#include "psppire-dialog-action-binomial.h"
 #include "psppire-dialog-action-correlation.h"
 #include "psppire-dialog-action-descriptives.h"
 #include "psppire-dialog-action-examine.h"
@@ -51,6 +52,7 @@ preregister_widgets (void)
   psppire_var_view_get_type ();
   psppire_value_entry_get_type ();
 
+  psppire_dialog_action_binomial_get_type ();
   psppire_dialog_action_correlation_get_type ();
   psppire_dialog_action_descriptives_get_type ();
   psppire_dialog_action_examine_get_type ();