From: John Darrington <john@darrington.wattle.id.au> Date: Fri, 4 Oct 2013 15:26:57 +0000 (+0200) Subject: One sample Kalmogorov-Smirnov Dialog: convert from old style to PsppireDialogAction X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9b848024070c889f4ff95a36d35081d05622f2a;p=pspp One sample Kalmogorov-Smirnov Dialog: convert from old style to PsppireDialogAction --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index d25b28ff5f..36d12bd6f6 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -161,8 +161,6 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/helper.h \ src/ui/gui/k-related-dialog.c \ src/ui/gui/k-related-dialog.h \ - src/ui/gui/ks-one-sample-dialog.c \ - src/ui/gui/ks-one-sample-dialog.h \ src/ui/gui/main.c \ src/ui/gui/missing-val-dialog.c \ src/ui/gui/missing-val-dialog.h \ @@ -189,6 +187,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-1sks.c \ + src/ui/gui/psppire-dialog-action-1sks.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 \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 99ddbfa446..4beae4807a 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -442,8 +442,9 @@ </object> </child> <child> - <object class="GtkAction" id="ks-one-sample"> + <object class="PsppireDialogAction1sks" id="ks-one-sample"> <property name="name">ks-one-sample</property> + <property name="manager">uimanager1</property> <property name="label" translatable="yes">1-Sample _K-S...</property> </object> </child> diff --git a/src/ui/gui/ks-one-sample-dialog.c b/src/ui/gui/ks-one-sample-dialog.c deleted file mode 100644 index ba27e58bf3..0000000000 --- a/src/ui/gui/ks-one-sample-dialog.c +++ /dev/null @@ -1,197 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 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 <ui/syntax-gen.h> -#include <libpspp/str.h> - -#include "ks-one-sample-dialog.h" -#include "psppire-selector.h" -#include "psppire-dictview.h" -#include "psppire-dialog.h" - -#include "psppire-data-window.h" -#include "psppire-var-view.h" - -#include "executor.h" -#include "builder-wrapper.h" -#include "helper.h" - -#include "dialog-common.h" - -#include <gtk/gtk.h> - -#include "gettext.h" -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid - - -enum - { - CB_NORMAL, - CB_POISSON, - CB_UNIFORM, - CB_EXPONENTIAL - }; - -struct ks_one_sample -{ - GtkBuilder *xml; - PsppireDict *dict; - - GtkWidget *variables; - PsppireDataWindow *de ; - - GtkWidget *cb[4]; -}; - -static char * generate_syntax (const struct ks_one_sample *rd); - - -static void -refresh (struct ks_one_sample *fd) -{ - int i; - GtkTreeModel *liststore = - gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); - gtk_list_store_clear (GTK_LIST_STORE (liststore)); - - for (i = 0; i < 4; ++i) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->cb[i]), FALSE); -} - - -static gboolean -dialog_state_valid (gpointer data) -{ - int i; - struct ks_one_sample *fd = data; - - GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); - - if (gtk_tree_model_iter_n_children (liststore, NULL) < 1) - return FALSE; - - for (i = 0; i < 4; ++i) - { - if ( TRUE == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[i]))) - break; - } - if ( i >= 4) - return FALSE; - - - return TRUE; -} - - -/* Pops up the Ks_One_Sample dialog box */ -void -ks_one_sample_dialog (PsppireDataWindow *dw) -{ - struct ks_one_sample fd; - gint response; - - GtkWidget *dialog ; - GtkWidget *source ; - - fd.xml = builder_new ("ks-one-sample.ui"); - - dialog = get_widget_assert (fd.xml, "ks-one-sample-dialog"); - source = get_widget_assert (fd.xml, "dict-view"); - - fd.cb[CB_NORMAL] = get_widget_assert (fd.xml, "checkbutton-normal"); - fd.cb[CB_POISSON] = get_widget_assert (fd.xml, "checkbutton-poisson"); - fd.cb[CB_UNIFORM] = get_widget_assert (fd.xml, "checkbutton-uniform"); - fd.cb[CB_EXPONENTIAL] = get_widget_assert (fd.xml, "checkbutton-exp"); - - fd.de = dw; - - g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd); - - - fd.variables = get_widget_assert (fd.xml, "psppire-var-view1"); - - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de)); - - g_object_get (fd.de->data_editor, "dictionary", &fd.dict, NULL); - g_object_set (source, "model", fd.dict, - "predicate", var_is_numeric, - NULL); - - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &fd); - - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); - - switch (response) - { - case GTK_RESPONSE_OK: - g_free (execute_syntax_string (dw, generate_syntax (&fd))); - break; - case PSPPIRE_RESPONSE_PASTE: - g_free (paste_syntax_to_window (generate_syntax (&fd))); - break; - default: - break; - } - - g_object_unref (fd.xml); -} - - - -static void -append_fragment (GString *string, const gchar *dist, PsppireVarView *vv) -{ - g_string_append (string, "\n\t/KOLMOGOROV-SMIRNOV"); - - g_string_append (string, " ( "); - g_string_append (string, dist); - g_string_append (string, " ) = "); - - psppire_var_view_append_names (vv, 0, string); -} - - -char * -generate_syntax (const struct ks_one_sample *rd) -{ - gchar *text; - - GString *string = g_string_new ("NPAR TEST"); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_NORMAL]))) - append_fragment (string, "NORMAL", PSPPIRE_VAR_VIEW (rd->variables)); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_UNIFORM]))) - append_fragment (string, "UNIFORM", PSPPIRE_VAR_VIEW (rd->variables)); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_POISSON]))) - append_fragment (string, "POISSON", PSPPIRE_VAR_VIEW (rd->variables)); - - if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_EXPONENTIAL]))) - append_fragment (string, "EXPONENTIAL", PSPPIRE_VAR_VIEW (rd->variables)); - - g_string_append (string, ".\n"); - - text = string->str; - - g_string_free (string, FALSE); - - return text; -} diff --git a/src/ui/gui/ks-one-sample-dialog.h b/src/ui/gui/ks-one-sample-dialog.h deleted file mode 100644 index 59f4589568..0000000000 --- a/src/ui/gui/ks-one-sample-dialog.h +++ /dev/null @@ -1,24 +0,0 @@ -/* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2011 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 __KS_ONE_SAMPLE_DIALOG_H -#define __KS_ONE_SAMPLE_DIALOG_H - -#include "psppire-data-window.h" - -void ks_one_sample_dialog (PsppireDataWindow * data); - -#endif diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 890d795543..d3b8087f62 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -43,7 +43,6 @@ #include "ui/gui/psppire-syntax-window.h" #include "ui/gui/psppire-window.h" #include "ui/gui/psppire.h" -#include "ui/gui/ks-one-sample-dialog.h" #include "ui/gui/recode-dialog.h" #include "ui/gui/select-cases-dialog.h" #include "ui/gui/split-file-dialog.h" @@ -970,7 +969,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "transform_count", G_CALLBACK (count_dialog)); 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, "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-1sks.c b/src/ui/gui/psppire-dialog-action-1sks.c new file mode 100644 index 0000000000..f71de4d88f --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-1sks.c @@ -0,0 +1,159 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 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 <http://www.gnu.org/licenses/>. */ + + +#include <config.h> + +#include "psppire-dialog-action-1sks.h" + +#include "psppire-var-view.h" + +#include "psppire-dialog.h" +#include "builder-wrapper.h" + +static void psppire_dialog_action_1sks_init (PsppireDialogAction1sks *act); +static void psppire_dialog_action_1sks_class_init (PsppireDialogAction1sksClass *class); + +G_DEFINE_TYPE (PsppireDialogAction1sks, psppire_dialog_action_1sks, PSPPIRE_TYPE_DIALOG_ACTION); + + +enum + { + CB_NORMAL, + CB_POISSON, + CB_UNIFORM, + CB_EXPONENTIAL + }; + +static void +append_fragment (GString *string, const gchar *dist, PsppireVarView *vv) +{ + g_string_append (string, "\n\t/KOLMOGOROV-SMIRNOV"); + + g_string_append (string, " ( "); + g_string_append (string, dist); + g_string_append (string, " ) = "); + + psppire_var_view_append_names (vv, 0, string); +} + + +static char * +generate_syntax (PsppireDialogAction *act) +{ + PsppireDialogAction1sks *rd = PSPPIRE_DIALOG_ACTION_1SKS (act); + gchar *text; + + GString *string = g_string_new ("NPAR TEST"); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_NORMAL]))) + append_fragment (string, "NORMAL", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_UNIFORM]))) + append_fragment (string, "UNIFORM", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_POISSON]))) + append_fragment (string, "POISSON", PSPPIRE_VAR_VIEW (rd->variables)); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->cb[CB_EXPONENTIAL]))) + append_fragment (string, "EXPONENTIAL", PSPPIRE_VAR_VIEW (rd->variables)); + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + int i; + PsppireDialogAction1sks *fd = PSPPIRE_DIALOG_ACTION_1SKS (data); + + GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); + + if (gtk_tree_model_iter_n_children (liststore, NULL) < 1) + return FALSE; + + for (i = 0; i < 4; ++i) + { + if ( TRUE == gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd->cb[i]))) + break; + } + if ( i >= 4) + return FALSE; + + return TRUE; +} + +static void +refresh (PsppireDialogAction *rd_) +{ + PsppireDialogAction1sks *fd = PSPPIRE_DIALOG_ACTION_1SKS (rd_); + int i; + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + for (i = 0; i < 4; ++i) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->cb[i]), FALSE); +} + +static void +psppire_dialog_action_1sks_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogAction1sks *act = PSPPIRE_DIALOG_ACTION_1SKS (a); + + GtkBuilder *xml = builder_new ("ks-one-sample.ui"); + pda->dialog = get_widget_assert (xml, "ks-one-sample-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); + + act->variables = get_widget_assert (xml, "psppire-var-view1"); + + act->cb[CB_NORMAL] = get_widget_assert (xml, "checkbutton-normal"); + act->cb[CB_POISSON] = get_widget_assert (xml, "checkbutton-poisson"); + act->cb[CB_UNIFORM] = get_widget_assert (xml, "checkbutton-uniform"); + act->cb[CB_EXPONENTIAL] = get_widget_assert (xml, "checkbutton-exp"); + + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, refresh); + + g_object_unref (xml); + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_1sks_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_1sks_parent_class)->activate (pda); +} + +static void +psppire_dialog_action_1sks_class_init (PsppireDialogAction1sksClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + + action_class->activate = psppire_dialog_action_1sks_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_1sks_init (PsppireDialogAction1sks *act) +{ +} + diff --git a/src/ui/gui/psppire-dialog-action-1sks.h b/src/ui/gui/psppire-dialog-action-1sks.h new file mode 100644 index 0000000000..5e201945fa --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-1sks.h @@ -0,0 +1,78 @@ +/* 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 <http://www.gnu.org/licenses/>. */ + + +#include <glib-object.h> +#include <glib.h> + +#include "psppire-dialog-action.h" + +#ifndef __PSPPIRE_DIALOG_ACTION_1SKS_H__ +#define __PSPPIRE_DIALOG_ACTION_1SKS_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_1SKS (psppire_dialog_action_1sks_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_1SKS(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_1SKS, PsppireDialogAction1sks)) + +#define PSPPIRE_DIALOG_ACTION_1SKS_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_1SKS, \ + PsppireDialogAction1sksClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_1SKS(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_1SKS)) + +#define PSPPIRE_IS_DIALOG_ACTION_1SKS_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_1SKS)) + + +#define PSPPIRE_DIALOG_ACTION_1SKS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_1SKS, \ + PsppireDialogAction1sksClass)) + +typedef struct _PsppireDialogAction1sks PsppireDialogAction1sks; +typedef struct _PsppireDialogAction1sksClass PsppireDialogAction1sksClass; + + +struct _PsppireDialogAction1sks +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + GtkWidget *variables; + + GtkWidget *cb[4]; +}; + + +struct _PsppireDialogAction1sksClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_1sks_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_1SKS_H__ */ diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 62790a2d81..d6648e10cc 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -26,6 +26,7 @@ #include "psppire-dialog-action-factor.h" #include "psppire-dialog-action-frequencies.h" #include "psppire-dialog-action-indep-samps.h" +#include "psppire-dialog-action-1sks.h" #include "psppire-dialog-action-kmeans.h" #include "psppire-dialog-action-logistic.h" #include "psppire-dialog-action-means.h" @@ -60,6 +61,7 @@ preregister_widgets (void) psppire_value_entry_get_type (); psppire_checkbox_treeview_get_type (); + psppire_dialog_action_1sks_get_type (); psppire_dialog_action_binomial_get_type (); psppire_dialog_action_chisquare_get_type (); psppire_dialog_action_correlation_get_type ();