From f9b848024070c889f4ff95a36d35081d05622f2a Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 4 Oct 2013 17:26:57 +0200 Subject: [PATCH] One sample Kalmogorov-Smirnov Dialog: convert from old style to PsppireDialogAction --- src/ui/gui/automake.mk | 4 +- src/ui/gui/data-editor.ui | 3 +- src/ui/gui/ks-one-sample-dialog.h | 24 --- src/ui/gui/psppire-data-window.c | 2 - ...-dialog.c => psppire-dialog-action-1sks.c} | 190 +++++++----------- src/ui/gui/psppire-dialog-action-1sks.h | 78 +++++++ src/ui/gui/widgets.c | 2 + 7 files changed, 160 insertions(+), 143 deletions(-) delete mode 100644 src/ui/gui/ks-one-sample-dialog.h rename src/ui/gui/{ks-one-sample-dialog.c => psppire-dialog-action-1sks.c} (54%) create mode 100644 src/ui/gui/psppire-dialog-action-1sks.h 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 @@ - + ks-one-sample + uimanager1 1-Sample _K-S... 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 . */ - -#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/ks-one-sample-dialog.c b/src/ui/gui/psppire-dialog-action-1sks.c similarity index 54% rename from src/ui/gui/ks-one-sample-dialog.c rename to src/ui/gui/psppire-dialog-action-1sks.c index ba27e58bf3..f71de4d88f 100644 --- a/src/ui/gui/ks-one-sample-dialog.c +++ b/src/ui/gui/psppire-dialog-action-1sks.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2011, 2012 Free Software Foundation + 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 @@ -14,30 +14,20 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include -#include -#include +#include -#include "ks-one-sample-dialog.h" -#include "psppire-selector.h" -#include "psppire-dictview.h" -#include "psppire-dialog.h" +#include "psppire-dialog-action-1sks.h" -#include "psppire-data-window.h" #include "psppire-var-view.h" -#include "executor.h" +#include "psppire-dialog.h" #include "builder-wrapper.h" -#include "helper.h" - -#include "dialog-common.h" -#include +static void psppire_dialog_action_1sks_init (PsppireDialogAction1sks *act); +static void psppire_dialog_action_1sks_class_init (PsppireDialogAction1sksClass *class); -#include "gettext.h" -#define _(msgid) gettext (msgid) -#define N_(msgid) msgid +G_DEFINE_TYPE (PsppireDialogAction1sks, psppire_dialog_action_1sks, PSPPIRE_TYPE_DIALOG_ACTION); enum @@ -48,30 +38,46 @@ enum CB_EXPONENTIAL }; -struct ks_one_sample +static void +append_fragment (GString *string, const gchar *dist, PsppireVarView *vv) { - GtkBuilder *xml; - PsppireDict *dict; - - GtkWidget *variables; - PsppireDataWindow *de ; + g_string_append (string, "\n\t/KOLMOGOROV-SMIRNOV"); - GtkWidget *cb[4]; -}; + g_string_append (string, " ( "); + g_string_append (string, dist); + g_string_append (string, " ) = "); -static char * generate_syntax (const struct ks_one_sample *rd); + psppire_var_view_append_names (vv, 0, string); +} -static void -refresh (struct ks_one_sample *fd) +static char * +generate_syntax (PsppireDialogAction *act) { - int i; - GtkTreeModel *liststore = - gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); - gtk_list_store_clear (GTK_LIST_STORE (liststore)); + PsppireDialogAction1sks *rd = PSPPIRE_DIALOG_ACTION_1SKS (act); + gchar *text; - for (i = 0; i < 4; ++i) - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd->cb[i]), FALSE); + 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; } @@ -79,7 +85,7 @@ static gboolean dialog_state_valid (gpointer data) { int i; - struct ks_one_sample *fd = data; + PsppireDialogAction1sks *fd = PSPPIRE_DIALOG_ACTION_1SKS (data); GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); @@ -94,104 +100,60 @@ dialog_state_valid (gpointer data) if ( i >= 4) return FALSE; - return TRUE; } - -/* Pops up the Ks_One_Sample dialog box */ -void -ks_one_sample_dialog (PsppireDataWindow *dw) +static void +refresh (PsppireDialogAction *rd_) { - 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); + 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); +} - fd.variables = get_widget_assert (fd.xml, "psppire-var-view1"); +static void +psppire_dialog_action_1sks_activate (GtkAction *a) +{ + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + PsppireDialogAction1sks *act = PSPPIRE_DIALOG_ACTION_1SKS (a); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de)); + 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"); - g_object_get (fd.de->data_editor, "dictionary", &fd.dict, NULL); - g_object_set (source, "model", fd.dict, - "predicate", var_is_numeric, - NULL); + act->variables = get_widget_assert (xml, "psppire-var-view1"); - psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), - dialog_state_valid, &fd); + 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"); - response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid); + psppire_dialog_action_set_refresh (pda, refresh); - 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 (xml); - g_object_unref (fd.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 -append_fragment (GString *string, const gchar *dist, PsppireVarView *vv) +psppire_dialog_action_1sks_class_init (PsppireDialogAction1sksClass *class) { - g_string_append (string, "\n\t/KOLMOGOROV-SMIRNOV"); + GtkActionClass *action_class = GTK_ACTION_CLASS (class); - g_string_append (string, " ( "); - g_string_append (string, dist); - g_string_append (string, " ) = "); - - psppire_var_view_append_names (vv, 0, string); + action_class->activate = psppire_dialog_action_1sks_activate; + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; } -char * -generate_syntax (const struct ks_one_sample *rd) +static void +psppire_dialog_action_1sks_init (PsppireDialogAction1sks *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; } + 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 . */ + + +#include +#include + +#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 (); -- 2.30.2