From: John Darrington Date: Sat, 12 Dec 2009 15:48:02 +0000 (+0100) Subject: Implemented a dialog box for the ROC command X-Git-Tag: sid-i386-build122~12 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp-builds.git;a=commitdiff_plain;h=bb025f49673d66a2e490a781d7d59b2f32da0087 Implemented a dialog box for the ROC command --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index f2f0b813..22e2350b 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -67,6 +67,7 @@ UI_FILES = \ src/ui/gui/recode.ui \ src/ui/gui/regression.ui \ src/ui/gui/reliability.ui \ + src/ui/gui/roc.ui \ src/ui/gui/t-test.ui \ src/ui/gui/text-data-import.ui \ src/ui/gui/var-sheet-dialogs.ui \ @@ -187,6 +188,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/regression-dialog.h \ src/ui/gui/reliability-dialog.c \ src/ui/gui/reliability-dialog.h \ + src/ui/gui/roc-dialog.c \ + src/ui/gui/roc-dialog.h \ src/ui/gui/select-cases-dialog.c \ src/ui/gui/select-cases-dialog.h \ src/ui/gui/sort-cases-dialog.c \ diff --git a/src/ui/gui/data-editor.glade b/src/ui/gui/data-editor.glade index 06776248..ca7efc90 100644 --- a/src/ui/gui/data-editor.glade +++ b/src/ui/gui/data-editor.glade @@ -1,7 +1,7 @@ - - - + + + True @@ -13,8 +13,8 @@ - True gtk-new + True True True @@ -39,8 +39,8 @@ - True gtk-open + True True True @@ -78,16 +78,16 @@ - True gtk-save + True True True - True gtk-save-as + True True True @@ -150,8 +150,8 @@ - True gtk-quit + True True True @@ -185,10 +185,11 @@ + Go To Case True False - Go To Case True + True @@ -199,27 +200,27 @@ + gtk-cut True False - gtk-cut True True + gtk-copy True False - gtk-copy True True + gtk-paste True False - gtk-paste True True @@ -247,9 +248,9 @@ + gtk-find True False - gtk-find True True @@ -332,15 +333,10 @@ + _Sort Cases True - _Sort Cases True - - - True - gtk-sort-ascending - - + True @@ -439,7 +435,7 @@ False _Run Pending Transforms True - + @@ -592,6 +588,13 @@ + + + True + ROC Cur_ve... + True + + @@ -661,28 +664,18 @@ + _Reference Manual True - _Reference Manual True - - - True - gtk-help - - + True + _About True - _About True - - - True - gtk-about - - + True @@ -692,7 +685,6 @@ True - GTK_SHADOW_OUT True @@ -704,6 +696,7 @@ False + True @@ -714,6 +707,7 @@ False + True @@ -724,6 +718,7 @@ False + True @@ -734,14 +729,13 @@ False + True - - + False - False @@ -752,6 +746,7 @@ False + True @@ -762,6 +757,7 @@ False + True @@ -770,7 +766,6 @@ False - False @@ -782,6 +777,7 @@ False + True @@ -793,6 +789,7 @@ False + True @@ -801,7 +798,6 @@ False - False @@ -813,6 +809,7 @@ False + True @@ -821,7 +818,6 @@ False - False @@ -834,6 +830,7 @@ False + True @@ -846,6 +843,7 @@ False + True @@ -854,7 +852,6 @@ False - False @@ -866,6 +863,7 @@ False + True @@ -877,6 +875,7 @@ False + True @@ -889,6 +888,7 @@ False + True @@ -897,7 +897,6 @@ False - False @@ -909,6 +908,7 @@ False + True @@ -919,6 +919,7 @@ False + True @@ -931,7 +932,7 @@ True 0 - GTK_SHADOW_IN + in True @@ -945,12 +946,15 @@ + + 0 + True 0 - GTK_SHADOW_IN + in True @@ -975,7 +979,7 @@ True 0 - GTK_SHADOW_IN + in True @@ -1000,7 +1004,7 @@ True 0 - GTK_SHADOW_IN + in True @@ -1008,7 +1012,7 @@ True - PANGO_ELLIPSIZE_START + start 10 True @@ -1026,7 +1030,7 @@ True 0 - GTK_SHADOW_IN + in True @@ -1034,7 +1038,7 @@ True - PANGO_ELLIPSIZE_START + start 15 True @@ -1052,7 +1056,7 @@ True 0 - GTK_SHADOW_IN + in True @@ -1060,7 +1064,7 @@ True - PANGO_ELLIPSIZE_START + start 15 True diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 2707498c..e42d2bd0 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -56,6 +56,7 @@ #include "examine-dialog.h" #include "regression-dialog.h" #include "reliability-dialog.h" +#include "roc-dialog.h" #include "oneway-anova-dialog.h" #include "t-test-independent-samples-dialog.h" #include "t-test-one-sample.h" @@ -1692,6 +1693,20 @@ psppire_data_window_init (PsppireDataWindow *de) G_CALLBACK (reliability_dialog), de); } + { + GtkAction *invoke_roc_dialog = + resolve_action (de->builder, "roc-curve", NULL); + + g_object_set (invoke_roc_dialog, + "tooltip", _("ROC Curve"), + "stock-id", "pspp-roc", + NULL + ); + + g_signal_connect (invoke_roc_dialog, "activate", + G_CALLBACK (roc_dialog), de); + } + { GtkUIManager *uim = GTK_UI_MANAGER (get_object_assert (de->builder, "uimanager1", GTK_TYPE_UI_MANAGER)); diff --git a/src/ui/gui/roc-dialog.c b/src/ui/gui/roc-dialog.c new file mode 100644 index 00000000..6896ef7b --- /dev/null +++ b/src/ui/gui/roc-dialog.c @@ -0,0 +1,239 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2009 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 "dialog-common.h" +#include +#include +#include + +#include "roc-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 "helper.h" + +#include + +#include "gettext.h" +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + + +struct roc +{ + PsppireDict *dict; + + GtkWidget *test_variables; + GtkWidget *state_variable; + GtkWidget *state_value; + + GtkWidget *curve; + GtkWidget *reference; + GtkWidget *standard_error; + GtkWidget *coordinates; +}; + + +static char * generate_syntax (const struct roc *rd); + + +static void +refresh (struct roc *rd) +{ + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables)); + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + gtk_entry_set_text (GTK_ENTRY (rd->state_variable), ""); + gtk_entry_set_text (GTK_ENTRY (rd->state_value), ""); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->curve), TRUE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->reference), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->standard_error), FALSE); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (rd->coordinates), FALSE); +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + struct roc *rd = data; + const gchar *text; + + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (rd->test_variables)); + + if (gtk_tree_model_iter_n_children (liststore, NULL) < 1) + return FALSE; + + + text = gtk_entry_get_text (GTK_ENTRY (rd->state_variable)); + if ( 0 == strcmp ("", text)) + return FALSE; + + + text = gtk_entry_get_text (GTK_ENTRY (rd->state_value)); + if ( 0 == strcmp ("", text)) + return FALSE; + + + return TRUE; +} + + +/* Pops up the Roc dialog box */ +void +roc_dialog (GObject *o, gpointer data) +{ + struct roc rd; + gint response; + + GtkBuilder *xml = builder_new ("roc.ui"); + PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data); + PsppireVarStore *vs; + + GtkWidget *dialog = get_widget_assert (xml, "roc-dialog"); + GtkWidget *source = get_widget_assert (xml, "dict-view"); + + rd.test_variables = get_widget_assert (xml, "psppire-var-view1"); + rd.state_variable = get_widget_assert (xml, "entry1"); + rd.state_value = get_widget_assert (xml, "entry2"); + + rd.curve = get_widget_assert (xml, "curve"); + rd.reference = get_widget_assert (xml, "reference-line"); + rd.standard_error = get_widget_assert (xml, "standard-error"); + rd.coordinates = get_widget_assert (xml, "co-ordinates"); + + + g_object_get (de->data_editor, "var-store", &vs, NULL); + + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); + + g_object_get (vs, "dictionary", &rd.dict, NULL); + g_object_set (source, "model", rd.dict, NULL); + + g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &rd); + + psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), + dialog_state_valid, &rd); + + response = psppire_dialog_run (PSPPIRE_DIALOG (dialog)); + + switch (response) + { + case GTK_RESPONSE_OK: + { + gchar *syntax = generate_syntax (&rd); + + struct getl_interface *sss = create_syntax_string_source (syntax); + execute_syntax (sss); + + g_free (syntax); + } + break; + case PSPPIRE_RESPONSE_PASTE: + { + gchar *syntax = generate_syntax (&rd); + paste_syntax_in_new_window (syntax); + + g_free (syntax); + } + break; + default: + break; + } + + g_object_unref (xml); +} + + + + +static char * +generate_syntax (const struct roc *rd) +{ + gchar *text; + const gchar *var_name = gtk_entry_get_text (GTK_ENTRY (rd->state_variable)); + GString *string = g_string_new ("ROC"); + + psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->test_variables), 0, string); + + g_string_append (string, " BY "); + + g_string_append (string, var_name); + + g_string_append (string, " ("); + { + const gchar *value = gtk_entry_get_text (GTK_ENTRY (rd->state_value)); + + const struct variable *var = psppire_dict_lookup_var (rd->dict, var_name); + + g_return_val_if_fail (var, NULL); + + if ( var_is_alpha (var)) + { + struct string xx; + ds_init_empty (&xx); + syntax_gen_string (&xx, ss_cstr (value)); + g_string_append (string, ds_cstr (&xx)); + ds_destroy (&xx); + } + else + g_string_append (string, value); + } + g_string_append (string, ")"); + + + /* The /PLOT subcommand */ + g_string_append (string, "\n\t/PLOT "); + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->curve))) + { + g_string_append (string, "CURVE"); + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->reference))) + g_string_append (string, " (REFERENCE)"); + } + else + g_string_append (string, "NONE"); + + + /* The /PRINT subcommand */ + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error)) || + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates)) ) + { + g_string_append (string, "\n\t/PRINT"); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->standard_error))) + g_string_append (string, " SE"); + + if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->coordinates))) + g_string_append (string, " COORDINATES"); + } + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} diff --git a/src/ui/gui/roc-dialog.h b/src/ui/gui/roc-dialog.h new file mode 100644 index 00000000..02449802 --- /dev/null +++ b/src/ui/gui/roc-dialog.h @@ -0,0 +1,25 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2009 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 __ROC_DIALOG_H +#define __ROC_DIALOG_H + + +#include + +void roc_dialog (GObject *o, gpointer data); + +#endif diff --git a/src/ui/gui/roc.ui b/src/ui/gui/roc.ui new file mode 100644 index 00000000..8bb82cc8 --- /dev/null +++ b/src/ui/gui/roc.ui @@ -0,0 +1,317 @@ + + + + + + + ROC Curve + True + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 3 + 3 + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + 5 + dict-view + psppire-var-view1 + + + 1 + 2 + + + + + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + 5 + dict-view + entry1 + + + 1 + 2 + 1 + 2 + + + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + never + automatic + etched-in + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + + + + + 3 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + none + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 12 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + never + automatic + etched-in + + + True + True + 5 + False + False + + + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Test Variable: + True + True + + + + + 2 + 3 + + + + + True + 0 + none + + + True + 12 + + + True + True + + + + + + + + True + _State Variable: + True + True + + + + + 2 + 3 + 1 + 2 + GTK_FILL + + + + + True + vertical + + + True + + + True + 1 + _Value of state variable: + True + entry2 + + + 0 + + + + + True + True + + + + 1 + + + + + 0 + + + + + True + 0 + + + True + 12 + + + True + vertical + + + ROC C_urve + True + True + False + True + True + + + False + False + 0 + + + + + _With diagonal reference line + True + True + False + True + 0 + True + + + False + False + 12 + 1 + + + + + Standard _Error and Confidence Interval + True + True + False + True + True + + + False + False + 2 + + + + + _Coordinate points of the ROC Curve + True + True + False + True + True + + + False + False + 3 + + + + + + + + + True + Display + True + + + + + 1 + + + + + 1 + 3 + 2 + 3 + GTK_FILL + 5 + 2 + + + + + 0 + + + + + True + 5 + vertical + + + False + False + end + 1 + + + + + +