From f0d3b9e75a250c98c48c982aa0b5377868b5bfad Mon Sep 17 00:00:00 2001 From: John Darrington Date: Mon, 25 Jul 2011 14:38:42 +0200 Subject: [PATCH] Added dialog box for quick cluster command --- src/ui/gui/automake.mk | 3 + src/ui/gui/data-editor.ui | 7 ++ src/ui/gui/k-means-dialog.c | 163 +++++++++++++++++++++++++++++++ src/ui/gui/k-means-dialog.h | 24 +++++ src/ui/gui/k-means.ui | 143 +++++++++++++++++++++++++++ src/ui/gui/psppire-data-window.c | 3 + 6 files changed, 343 insertions(+) create mode 100644 src/ui/gui/k-means-dialog.c create mode 100644 src/ui/gui/k-means-dialog.h create mode 100644 src/ui/gui/k-means.ui diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 9f34620016..f21cbe7042 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -18,6 +18,7 @@ UI_FILES = \ src/ui/gui/factor.ui \ src/ui/gui/find.ui \ src/ui/gui/frequencies.ui \ + src/ui/gui/k-means.ui \ src/ui/gui/k-related.ui \ src/ui/gui/oneway.ui \ src/ui/gui/paired-samples.ui \ @@ -170,6 +171,8 @@ 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/k-means-dialog.c \ + src/ui/gui/k-means-dialog.h \ src/ui/gui/main.c \ src/ui/gui/missing-val-dialog.c \ src/ui/gui/missing-val-dialog.h \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 52a34131d3..5feccaa24e 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -403,6 +403,12 @@ Bivariate _Correlation... + + + k-means + _K-Means Cluster... + + factor-analysis @@ -578,6 +584,7 @@ + diff --git a/src/ui/gui/k-means-dialog.c b/src/ui/gui/k-means-dialog.c new file mode 100644 index 0000000000..1de9b74c2b --- /dev/null +++ b/src/ui/gui/k-means-dialog.c @@ -0,0 +1,163 @@ +/* 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 . */ + +#include + +#include "dialog-common.h" +#include +#include + +#include "k-means-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 k_means +{ + GtkBuilder *xml; + PsppireDict *dict; + + GtkWidget *variables; + PsppireDataWindow *de ; + + GtkWidget *entry; +}; + +static char * generate_syntax (const struct k_means *rd); + + +static void +refresh (struct k_means *fd) +{ + GtkTreeModel *liststore = + gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + gtk_entry_set_text (GTK_ENTRY (fd->entry), ""); +} + + +static gboolean +dialog_state_valid (gpointer data) +{ + struct k_means *fd = data; + + GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (fd->variables)); + + if (gtk_tree_model_iter_n_children (liststore, NULL) < 2) + return FALSE; + + if (atoi (gtk_entry_get_text (GTK_ENTRY (fd->entry))) < 2) + return FALSE; + + return TRUE; +} + + +/* Pops up the K_Means dialog box */ +void +k_means_dialog (PsppireDataWindow *dw) +{ + struct k_means fd; + gint response; + + PsppireVarStore *vs; + + GtkWidget *dialog ; + GtkWidget *source ; + + fd.xml = builder_new ("k-means.ui"); + + dialog = get_widget_assert (fd.xml, "k-means-dialog"); + source = get_widget_assert (fd.xml, "dict-view"); + + fd.entry = get_widget_assert (fd.xml, "entry1"); + + fd.de = dw; + + g_signal_connect_swapped (dialog, "refresh", G_CALLBACK (refresh), &fd); + + + fd.variables = get_widget_assert (fd.xml, "psppire-var-view1"); + + g_object_get (fd.de->data_editor, "var-store", &vs, NULL); + + gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (fd.de)); + + g_object_get (vs, "dictionary", &fd.dict, NULL); + g_object_set (source, "model", fd.dict, NULL); + + psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog), + dialog_state_valid, &fd); + + psppire_selector_set_allow (PSPPIRE_SELECTOR (get_widget_assert (fd.xml, "psppire-selector1")), + numeric_only); + + 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 char * +generate_syntax (const struct k_means *km) +{ + gchar *text; + + GString *string = g_string_new ("QUICK CLUSTER "); + + psppire_var_view_append_names (PSPPIRE_VAR_VIEW (km->variables), 0, string); + + g_string_append_printf (string, "\n\t/CRITERIA=CLUSTERS(%d)", + atoi (gtk_entry_get_text (GTK_ENTRY (km->entry)))); + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} diff --git a/src/ui/gui/k-means-dialog.h b/src/ui/gui/k-means-dialog.h new file mode 100644 index 0000000000..522acbc897 --- /dev/null +++ b/src/ui/gui/k-means-dialog.h @@ -0,0 +1,24 @@ +/* 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 __K_MEANS_DIALOG_H +#define __K_MEANS_DIALOG_H + +#include "psppire-data-window.h" + +void k_means_dialog (PsppireDataWindow * data); + +#endif diff --git a/src/ui/gui/k-means.ui b/src/ui/gui/k-means.ui new file mode 100644 index 0000000000..53ff4892d9 --- /dev/null +++ b/src/ui/gui/k-means.ui @@ -0,0 +1,143 @@ + + + + + + + K-Means Cluster Analysis + True + Vertical + + + True + vertical + 2 + + + True + 2 + 3 + + + True + True + True + 5 + dict-view + psppire-var-view1 + + + 1 + 2 + + + + + + + True + True + never + automatic + in + + + True + True + True + 5 + False + False + + + + + 2 + + + + + True + True + automatic + automatic + in + + + True + True + 5 + False + False + + + + + 2 + 3 + GTK_EXPAND | GTK_SHRINK | GTK_FILL + + + + + True + + + True + 1 + N_umber of Clusters: + True + entry1 + + + False + False + 0 + + + + + True + True + + 0 + + + 1 + + + + + 2 + 3 + 1 + 2 + GTK_EXPAND | GTK_SHRINK | GTK_FILL + + + + + + + + + 0 + + + + + True + 5 + PSPPIRE_BUTTON_GOTO_MASK + + + False + False + end + 1 + + + + + + diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 0ed974e0b3..b009ff90f3 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -43,6 +43,7 @@ #include "ui/gui/goto-case-dialog.h" #include "ui/gui/help-menu.h" #include "ui/gui/helper.h" +#include "ui/gui/k-means-dialog.h" #include "ui/gui/k-related-dialog.h" #include "ui/gui/npar-two-sample-related.h" #include "ui/gui/oneway-anova-dialog.h" @@ -1116,6 +1117,8 @@ psppire_data_window_finish_init (PsppireDataWindow *de, connect_action (de, "factor-analysis", G_CALLBACK (factor_dialog)); + connect_action (de, "k-means", G_CALLBACK (k_means_dialog)); + connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog)); connect_action (de, "binomial", G_CALLBACK (binomial_dialog)); -- 2.30.2