From: John Darrington Date: Fri, 4 Oct 2013 13:22:56 +0000 (+0200) Subject: Chi-square dialog: Convert from old style to psppire-dialog-action X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b246c776e802ed91e8cac6ab19dcab7e4bd9921;p=pspp Chi-square dialog: Convert from old style to psppire-dialog-action --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 9bc8995201..06825dd568 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -141,8 +141,6 @@ 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/chi-square-dialog.c \ - src/ui/gui/chi-square-dialog.h \ src/ui/gui/count-dialog.c \ src/ui/gui/count-dialog.h \ src/ui/gui/dialog-common.c \ @@ -193,6 +191,8 @@ src_ui_gui_psppire_SOURCES = \ 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-chisquare.c \ + src/ui/gui/psppire-dialog-action-chisquare.h \ src/ui/gui/psppire-dialog-action-correlation.c \ src/ui/gui/psppire-dialog-action-correlation.h \ src/ui/gui/psppire-dialog-action-crosstabs.c \ diff --git a/src/ui/gui/chi-square-dialog.c b/src/ui/gui/chi-square-dialog.c deleted file mode 100644 index df408921d1..0000000000 --- a/src/ui/gui/chi-square-dialog.c +++ /dev/null @@ -1,223 +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 "chi-square-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 chisquare_dialog -{ - PsppireDict *dict; - GtkWidget *var_view; - - GtkWidget *button1; - GtkWidget *button2; - - GtkWidget *range_button; - GtkWidget *value_lower; - GtkWidget *value_upper; - - GtkWidget *values_button; - - GtkListStore *expected_list; -}; - -static gboolean -dialog_state_valid (gpointer data) -{ - struct chisquare_dialog *csd = data; - - GtkTreeModel *vars = - gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view)); - - GtkTreeIter notused; - - if ( !gtk_tree_model_get_iter_first (vars, ¬used) ) - return FALSE; - - return TRUE; -} - - -static void -refresh (struct chisquare_dialog *csd) -{ - GtkTreeModel *liststore = - gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view)); - - gtk_list_store_clear (GTK_LIST_STORE (liststore)); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button1), TRUE); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button2), TRUE); -} - - - -static char * -generate_syntax (const struct chisquare_dialog *scd) -{ - gchar *text; - struct string dss; - - ds_init_cstr (&dss, "NPAR TEST\n\t/CHISQUARE="); - - psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (scd->var_view), 0, &dss); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->range_button))) - { - ds_put_cstr (&dss, "("); - - ds_put_cstr (&dss, - gtk_entry_get_text (GTK_ENTRY (scd->value_lower))); - - ds_put_cstr (&dss, ", "); - - ds_put_cstr (&dss, - gtk_entry_get_text (GTK_ENTRY (scd->value_upper))); - - ds_put_cstr (&dss, ")"); - } - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->values_button))) - { - GtkListStore *ls = scd->expected_list; - GtkTreeIter iter; - gboolean ok; - - ds_put_cstr (&dss, "\n\t"); - ds_put_cstr (&dss, "/EXPECTED = "); - - - for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls), - &iter); - ok; - ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter)) - { - gdouble v; - - gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1); - - ds_put_c_format (&dss, " %g", v); - } - } - - ds_put_cstr (&dss, ".\n"); - - text = ds_steal_cstr (&dss); - - ds_destroy (&dss); - - return text; -} - - - -/* Pops up the Chi-Square dialog box */ -void -chisquare_dialog (PsppireDataWindow *dw) -{ - gint response; - - struct chisquare_dialog csd; - - GtkBuilder *xml = builder_new ("chi-square.ui"); - - GtkWidget *dialog = get_widget_assert (xml, "chisquare-dialog"); - - GtkWidget *range_table = get_widget_assert (xml, "range-table"); - - - - GtkWidget *values_acr = get_widget_assert (xml, "psppire-acr1"); - GtkWidget *expected_value_entry = - get_widget_assert (xml, "expected-value-entry"); - - - GtkWidget *dict_view = get_widget_assert (xml, "dict-view"); - - csd.expected_list = gtk_list_store_new (1, G_TYPE_DOUBLE); - - csd.button1 = get_widget_assert (xml, "radiobutton1"); - csd.button2 = get_widget_assert (xml, "radiobutton3"); - csd.var_view = get_widget_assert (xml, "variables-treeview"); - - csd.range_button = get_widget_assert (xml, "radiobutton4"); - csd.value_lower = get_widget_assert (xml, "entry1"); - csd.value_upper = get_widget_assert (xml, "entry2"); - - csd.values_button = get_widget_assert (xml, "radiobutton2"); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (dw)); - - - g_object_get (dw->data_editor, "dictionary", &csd.dict, NULL); - g_object_set (dict_view, - "model", csd.dict, - "predicate", var_is_numeric, - NULL); - - - g_signal_connect (csd.range_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle), - range_table); - - - g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle), - values_acr); - - g_signal_connect (csd.values_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle), - expected_value_entry); - - - psppire_acr_set_entry (PSPPIRE_ACR (values_acr), - GTK_ENTRY (expected_value_entry)); - - psppire_acr_set_model(PSPPIRE_ACR (values_acr), csd.expected_list); - - g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &csd); - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &csd); - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); - - - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (dw, generate_syntax (&csd))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&csd))); - break; - default: - break; - } - - g_object_unref (csd.expected_list); - g_object_unref (xml); -} diff --git a/src/ui/gui/chi-square-dialog.h b/src/ui/gui/chi-square-dialog.h deleted file mode 100644 index d372b60e12..0000000000 --- a/src/ui/gui/chi-square-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 __CHI_SQUARE_DIALOG_H -#define __CHI_SQUARE_DIALOG_H - -#include "psppire-data-window.h" - -void chisquare_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 34f885da22..9fe45ecaa6 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -420,8 +420,9 @@ - + chi-square + uimanager1 _Chi-Square... diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index b4e87f0f21..69a8c6385f 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -27,7 +27,6 @@ #include "ui/gui/aggregate-dialog.h" #include "ui/gui/autorecode-dialog.h" #include "ui/gui/builder-wrapper.h" -#include "ui/gui/chi-square-dialog.h" #include "ui/gui/comments-dialog.h" #include "ui/gui/compute-dialog.h" #include "ui/gui/count-dialog.h" @@ -980,7 +979,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog)); connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); connect_action (de, "univariate", G_CALLBACK (univariate_dialog)); - connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog)); connect_action (de, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog)); connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog)); connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog)); diff --git a/src/ui/gui/psppire-dialog-action-chisquare.c b/src/ui/gui/psppire-dialog-action-chisquare.c new file mode 100644 index 0000000000..36c68c064e --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-chisquare.c @@ -0,0 +1,199 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2010, 2011, 2012, 2013 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-chisquare.h" + +#include "psppire-var-view.h" + +#include "psppire-dialog.h" +#include "builder-wrapper.h" +#include "psppire-acr.h" +#include "dialog-common.h" + +#include + +static void psppire_dialog_action_chisquare_init (PsppireDialogActionChisquare *act); +static void psppire_dialog_action_chisquare_class_init (PsppireDialogActionChisquareClass *class); + +G_DEFINE_TYPE (PsppireDialogActionChisquare, psppire_dialog_action_chisquare, PSPPIRE_TYPE_DIALOG_ACTION); + + +static char * +generate_syntax (PsppireDialogAction *act) +{ + PsppireDialogActionChisquare *scd = PSPPIRE_DIALOG_ACTION_CHISQUARE (act); + + gchar *text; + struct string dss; + + ds_init_cstr (&dss, "NPAR TEST\n\t/CHISQUARE="); + + psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (scd->var_view), 0, &dss); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->range_button))) + { + ds_put_cstr (&dss, "("); + + ds_put_cstr (&dss, + gtk_entry_get_text (GTK_ENTRY (scd->value_lower))); + + ds_put_cstr (&dss, ", "); + + ds_put_cstr (&dss, + gtk_entry_get_text (GTK_ENTRY (scd->value_upper))); + + ds_put_cstr (&dss, ")"); + } + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->values_button))) + { + GtkListStore *ls = scd->expected_list; + GtkTreeIter iter; + gboolean ok; + + ds_put_cstr (&dss, "\n\t"); + ds_put_cstr (&dss, "/EXPECTED = "); + + + for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(ls), + &iter); + ok; + ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (ls), &iter)) + { + gdouble v; + + gtk_tree_model_get (GTK_TREE_MODEL (ls), &iter, 0, &v, -1); + + ds_put_c_format (&dss, " %g", v); + } + } + + ds_put_cstr (&dss, ".\n"); + + text = ds_steal_cstr (&dss); + + ds_destroy (&dss); + + return text; +} + + +static gboolean +dialog_state_valid (gpointer a) +{ + GtkTreeIter notused; + PsppireDialogActionChisquare *act = PSPPIRE_DIALOG_ACTION_CHISQUARE (a); + + GtkTreeModel *vars = + gtk_tree_view_get_model (GTK_TREE_VIEW (act->var_view)); + + if ( !gtk_tree_model_get_iter_first (vars, ¬used) ) + return FALSE; + + return TRUE; +} + +static void +refresh (PsppireDialogAction *rd_) +{ + PsppireDialogActionChisquare *csd = PSPPIRE_DIALOG_ACTION_CHISQUARE (rd_); + + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (csd->var_view)); + + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button1), TRUE); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (csd->button2), TRUE); + gtk_entry_set_text (GTK_ENTRY (csd->value_lower), ""); + gtk_entry_set_text (GTK_ENTRY (csd->value_upper), ""); +} + +static void +psppire_dialog_action_chisquare_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogActionChisquare *act = PSPPIRE_DIALOG_ACTION_CHISQUARE (a); + + GtkBuilder *xml = builder_new ("chi-square.ui"); + + GtkWidget *range_table = get_widget_assert (xml, "range-table"); + GtkWidget *values_acr = get_widget_assert (xml, "psppire-acr1"); + GtkWidget *expected_value_entry = + get_widget_assert (xml, "expected-value-entry"); + + pda->dialog = get_widget_assert (xml, "chisquare-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); + + act->expected_list = gtk_list_store_new (1, G_TYPE_DOUBLE); + + act->button1 = get_widget_assert (xml, "radiobutton1"); + act->button2 = get_widget_assert (xml, "radiobutton3"); + act->var_view = get_widget_assert (xml, "variables-treeview"); + + act->range_button = get_widget_assert (xml, "radiobutton4"); + act->value_lower = get_widget_assert (xml, "entry1"); + act->value_upper = get_widget_assert (xml, "entry2"); + + act->values_button = get_widget_assert (xml, "radiobutton2"); + + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, refresh); + + g_object_unref (xml); + + g_signal_connect (act->range_button, "toggled", + G_CALLBACK (set_sensitivity_from_toggle), + range_table); + + + g_signal_connect (act->values_button, "toggled", + G_CALLBACK (set_sensitivity_from_toggle), + values_acr); + + g_signal_connect (act->values_button, "toggled", + G_CALLBACK (set_sensitivity_from_toggle), + expected_value_entry); + + psppire_acr_set_entry (PSPPIRE_ACR (values_acr), + GTK_ENTRY (expected_value_entry)); + + psppire_acr_set_model(PSPPIRE_ACR (values_acr), act->expected_list); + + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_chisquare_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_chisquare_parent_class)->activate (pda); +} + +static void +psppire_dialog_action_chisquare_class_init (PsppireDialogActionChisquareClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + + action_class->activate = psppire_dialog_action_chisquare_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_chisquare_init (PsppireDialogActionChisquare *act) +{ +} + diff --git a/src/ui/gui/psppire-dialog-action-chisquare.h b/src/ui/gui/psppire-dialog-action-chisquare.h new file mode 100644 index 0000000000..9ce0421cdd --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-chisquare.h @@ -0,0 +1,88 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2013 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_CHISQUARE_H__ +#define __PSPPIRE_DIALOG_ACTION_CHISQUARE_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_CHISQUARE (psppire_dialog_action_chisquare_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_CHISQUARE(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_CHISQUARE, PsppireDialogActionChisquare)) + +#define PSPPIRE_DIALOG_ACTION_CHISQUARE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_CHISQUARE, \ + PsppireDialogActionChisquareClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_CHISQUARE(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_CHISQUARE)) + +#define PSPPIRE_IS_DIALOG_ACTION_CHISQUARE_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_CHISQUARE)) + + +#define PSPPIRE_DIALOG_ACTION_CHISQUARE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_CHISQUARE, \ + PsppireDialogActionChisquareClass)) + +typedef struct _PsppireDialogActionChisquare PsppireDialogActionChisquare; +typedef struct _PsppireDialogActionChisquareClass PsppireDialogActionChisquareClass; + + +struct _PsppireDialogActionChisquare +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *var_view; + + GtkWidget *button1; + GtkWidget *button2; + + GtkWidget *range_button; + GtkWidget *value_lower; + GtkWidget *value_upper; + + GtkWidget *values_button; + + GtkListStore *expected_list; +}; + + +struct _PsppireDialogActionChisquareClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_chisquare_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_CHISQUARE_H__ */ diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 6d07bdfec7..00942a4a67 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -17,6 +17,7 @@ #include "psppire-checkbox-treeview.h" #include "psppire-dialog-action-binomial.h" +#include "psppire-dialog-action-chisquare.h" #include "psppire-dialog-action-correlation.h" #include "psppire-dialog-action-crosstabs.h" #include "psppire-dialog-action-descriptives.h" @@ -59,6 +60,7 @@ preregister_widgets (void) psppire_checkbox_treeview_get_type (); psppire_dialog_action_binomial_get_type (); + psppire_dialog_action_chisquare_get_type (); psppire_dialog_action_correlation_get_type (); psppire_dialog_action_crosstabs_get_type (); psppire_dialog_action_descriptives_get_type ();