1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2012 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "psppire-dialog-action-binomial.h"
21 #include "psppire-value-entry.h"
23 #include "dialog-common.h"
25 #include <ui/syntax-gen.h>
26 #include "psppire-var-view.h"
28 #include "psppire-dialog.h"
29 #include "builder-wrapper.h"
30 #include "checkbox-treeview.h"
31 #include "psppire-dict.h"
32 #include "libpspp/str.h"
35 #define _(msgid) gettext (msgid)
36 #define N_(msgid) msgid
40 psppire_dialog_action_binomial_class_init (PsppireDialogActionBinomialClass *class);
42 G_DEFINE_TYPE (PsppireDialogActionBinomial, psppire_dialog_action_binomial, PSPPIRE_TYPE_DIALOG_ACTION);
46 get_proportion (PsppireDialogActionBinomial *act, double *prop)
48 const gchar *text = gtk_entry_get_text (GTK_ENTRY (act->prop_entry));
50 *prop = g_strtod (text, &endptr);
59 dialog_state_valid (gpointer data)
61 PsppireDialogActionBinomial *act = PSPPIRE_DIALOG_ACTION_BINOMIAL (data);
65 gtk_tree_view_get_model (GTK_TREE_VIEW (act->var_view));
69 if ( !gtk_tree_model_get_iter_first (vars, ¬used) )
72 if ( ! get_proportion (act, &prop))
75 if (prop < 0 || prop > 1.0)
82 refresh (PsppireDialogAction *da)
84 PsppireDialogActionBinomial *act = PSPPIRE_DIALOG_ACTION_BINOMIAL (da);
85 GtkTreeModel *liststore =
86 gtk_tree_view_get_model (GTK_TREE_VIEW (act->var_view));
88 gtk_list_store_clear (GTK_LIST_STORE (liststore));
90 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (act->button1), TRUE);
92 gtk_entry_set_text (GTK_ENTRY (act->prop_entry), "0.5");
94 gtk_entry_set_text (GTK_ENTRY (act->cutpoint_entry), "");
99 psppire_dialog_action_binomial_activate (GtkAction *a)
101 PsppireDialogActionBinomial *act = PSPPIRE_DIALOG_ACTION_BINOMIAL (a);
102 PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
104 GtkBuilder *xml = builder_new ("binomial.ui");
106 pda->dialog = get_widget_assert (xml, "binomial-dialog");
107 pda->source = get_widget_assert (xml, "dict-view");
109 act->var_view = get_widget_assert (xml, "variables-treeview");
110 act->button1 = get_widget_assert (xml, "radiobutton3");
111 act->prop_entry = get_widget_assert (xml, "proportion-entry");
113 act->cutpoint_entry = get_widget_assert (xml, "cutpoint-entry");
114 act->cutpoint_button = get_widget_assert (xml, "radiobutton4");
116 g_object_unref (xml);
119 g_signal_connect (act->cutpoint_button, "toggled", G_CALLBACK (set_sensitivity_from_toggle),
120 act->cutpoint_entry);
122 psppire_dialog_action_set_refresh (pda, refresh);
124 psppire_dialog_action_set_valid_predicate (pda,
127 if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_binomial_parent_class)->activate)
128 PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_binomial_parent_class)->activate (pda);
134 generate_syntax (PsppireDialogAction *a)
136 PsppireDialogActionBinomial *scd = PSPPIRE_DIALOG_ACTION_BINOMIAL (a);
142 ds_init_cstr (&str, "NPAR TEST\n\t/BINOMIAL");
144 if ( get_proportion (scd, &prop))
145 ds_put_c_format (&str, "(%g)", prop);
147 ds_put_cstr (&str, " =");
149 psppire_var_view_append_names_str (PSPPIRE_VAR_VIEW (scd->var_view), 0, &str);
151 if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (scd->cutpoint_button)))
153 const gchar *cutpoint = gtk_entry_get_text (GTK_ENTRY (scd->cutpoint_entry));
154 ds_put_c_format (&str, "(%s)", cutpoint);
157 ds_put_cstr (&str, ".\n");
159 text = ds_steal_cstr (&str);
167 psppire_dialog_action_binomial_class_init (PsppireDialogActionBinomialClass *class)
169 GtkActionClass *action_class = GTK_ACTION_CLASS (class);
171 action_class->activate = psppire_dialog_action_binomial_activate;
173 PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax;
178 psppire_dialog_action_binomial_init (PsppireDialogActionBinomial *act)