From b0fd056eedc6872d45541c1ee0eb43e909bbc8b1 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 24 Nov 2012 08:46:15 +0100 Subject: [PATCH] Binomial test dialog: Convert to new style of action objects. --- src/ui/gui/automake.mk | 4 +- src/ui/gui/binomial-dialog.c | 190 -------------------- src/ui/gui/binomial-dialog.h | 24 --- src/ui/gui/data-editor.ui | 3 +- src/ui/gui/psppire-data-window.c | 2 - src/ui/gui/psppire-dialog-action-binomial.c | 179 ++++++++++++++++++ src/ui/gui/psppire-dialog-action-binomial.h | 83 +++++++++ src/ui/gui/widgets.c | 2 + 8 files changed, 268 insertions(+), 219 deletions(-) delete mode 100644 src/ui/gui/binomial-dialog.c delete mode 100644 src/ui/gui/binomial-dialog.h create mode 100644 src/ui/gui/psppire-dialog-action-binomial.c create mode 100644 src/ui/gui/psppire-dialog-action-binomial.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 115837343a..2c6427a255 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -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 index 8f1df37f49..0000000000 --- a/src/ui/gui/binomial-dialog.c +++ /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 . */ - -#include - -#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 - -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, ¬used) ) - 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 index b50e444cf4..0000000000 --- a/src/ui/gui/binomial-dialog.h +++ /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 . */ - -#ifndef __BINOMIAL_DIALOG_H -#define __BINOMIAL_DIALOG_H - -#include "psppire-data-window.h" - -void binomial_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 07910dd217..3408036357 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -477,8 +477,9 @@ - + binomial + uimanager1 _Binomial... diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index f6bd2efbd9..ea3ec43d1f 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -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 index 0000000000..97a5f3cfcc --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-binomial.c @@ -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 . */ + + +#include + +#include "psppire-dialog-action-binomial.h" +#include "psppire-value-entry.h" + +#include "dialog-common.h" +#include "helper.h" +#include +#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, ¬used) ) + 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 index 0000000000..0541a402dd --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-binomial.h @@ -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 . */ + + +#include +#include + +#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__ */ diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index a7c52c6d45..1230d5d6c3 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -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 (); -- 2.30.2