Exemple #1
0
static void
on_expression_toggle (GtkToggleButton *button, gpointer data)
{
  struct compute_dialog *cd = data;

  GtkWidget *entry =
    get_widget_assert (cd->xml, "type-and-label-label-entry");

  if ( gtk_toggle_button_get_active (button))
    {
      gtk_entry_set_text (GTK_ENTRY (entry), "");
      gtk_widget_set_sensitive (entry, FALSE);
    }
  else
    {
      const char *label;
      struct variable *target_var;
      const gchar *target_name = gtk_entry_get_text
	(GTK_ENTRY (get_widget_assert (cd->xml, "compute-entry1")));

      target_var = psppire_dict_lookup_var (cd->dict, target_name);
      if ( target_var )
	{
	  label = var_get_label (target_var);

	  if ( label )
	    gtk_entry_set_text (GTK_ENTRY (entry), label);
	}
      else
	gtk_entry_set_text (GTK_ENTRY (entry), "");

      gtk_widget_set_sensitive (entry, TRUE);
    }
}
static void
set_define_groups_sensitivity (GtkEntry *entry,
			       struct tt_indep_samples_dialog *tt_d)
{
  const gchar *text = gtk_entry_get_text (entry);

  const struct variable *v = psppire_dict_lookup_var (tt_d->dict, text);

  gtk_widget_set_sensitive (tt_d->define_groups_button, v != NULL);
}
/* Called whenever the group variable entry widget's contents change */
static void
on_grp_var_change (GtkEntry *entry, PsppireDialogActionIndepSamps *act)
{
  PsppireDialogAction *da = PSPPIRE_DIALOG_ACTION (act);
  const gchar *text = gtk_entry_get_text (entry);

  const struct variable *v = psppire_dict_lookup_var (da->dict, text);

  gtk_widget_set_sensitive (act->define_groups_button, v != NULL);

  if (act->grp_var)
    {
      int width = var_get_width (act->grp_var);
      value_destroy (&act->cut_point, width);
      value_destroy (&act->grp_val[0], width);
      value_destroy (&act->grp_val[1], width);
    }

  if (v)
    {
      const int width = var_get_width (v);
      value_init (&act->cut_point, width);
      value_init (&act->grp_val[0], width);
      value_init (&act->grp_val[1], width);

      if (width == 0)
        {
          act->cut_point.f  = SYSMIS;
          act->grp_val[0].f = SYSMIS;
          act->grp_val[1].f = SYSMIS;
        }
      else
        {
          act->cut_point.short_string[0] = '\0';
          act->grp_val[0].short_string[0] = '\0';
          act->grp_val[1].short_string[0] = '\0';
        }
    }

  act->grp_var = v;
}
Exemple #4
0
static void
reset_type_label_dialog (struct compute_dialog *cd)
{
  const gchar *target_name;
  struct variable *target_var;

  GtkWidget *width_entry =
    get_widget_assert (cd->xml, "type-and-label-width");

  GtkWidget *label_entry =
    get_widget_assert (cd->xml, "type-and-label-label-entry");

  GtkWidget *numeric_target =
    get_widget_assert (cd->xml, "radio-button-numeric");

  GtkWidget *string_target =
    get_widget_assert (cd->xml, "radio-button-string");


  target_name = gtk_entry_get_text
    (GTK_ENTRY (get_widget_assert (cd->xml, "compute-entry1")));


  if ( (target_var = psppire_dict_lookup_var (cd->dict, target_name)) )
    {
      /* Existing Variable */
      const gchar *label ;
      GtkWidget *user_label =
	get_widget_assert (cd->xml, "radio-button-user-label");

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (user_label), TRUE);

      label = var_get_label (target_var);

      if ( label )
	{
	  gtk_entry_set_text (GTK_ENTRY (label_entry), label);
	}

      gtk_widget_set_sensitive (width_entry, FALSE);

      if ( var_is_numeric (target_var))
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (numeric_target),
				      TRUE);
      else
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (string_target),
				      TRUE);

      gtk_widget_set_sensitive (numeric_target, FALSE);
      gtk_widget_set_sensitive (string_target, FALSE);
    }
  else
    {
      GtkWidget *expression =
	get_widget_assert (cd->xml, "radio-button-expression-label");

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (expression), TRUE);

      gtk_widget_set_sensitive (width_entry, TRUE);
      gtk_widget_set_sensitive (numeric_target, TRUE);
      gtk_widget_set_sensitive (string_target, TRUE);

      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (numeric_target),
				    TRUE);
    }

}
Exemple #5
0
static char *
generate_syntax (const struct compute_dialog *cd)
{
  gchar *text;
  GString *string ;
  const gchar *target_name ;
  gchar *expression;
  const gchar *label;
  GtkTextIter start, end;
  GtkWidget *target = get_widget_assert   (cd->xml, "compute-entry1");
  GtkWidget *syntax_area = get_widget_assert (cd->xml, "compute-textview1");
  GtkWidget *string_toggle = get_widget_assert (cd->xml, "radio-button-string");
  GtkWidget *user_label_toggle =
    get_widget_assert (cd->xml, "radio-button-user-label");
  GtkWidget *width_entry = get_widget_assert (cd->xml, "type-and-label-width");
  GtkWidget *label_entry = get_widget_assert (cd->xml,
					      "type-and-label-label-entry");


  GtkTextBuffer *buffer =
    gtk_text_view_get_buffer (GTK_TEXT_VIEW (syntax_area));

  gtk_text_buffer_get_start_iter (buffer, &start);
  gtk_text_buffer_get_end_iter (buffer, &end);

  target_name = gtk_entry_get_text (GTK_ENTRY (target));

  expression = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);

  string = g_string_sized_new (64);

  if ( cd-> use_type &&
       NULL == psppire_dict_lookup_var (cd->dict, target_name ))
    {
      if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (string_toggle)))
	{
	  const char *w = gtk_entry_get_text (GTK_ENTRY(width_entry));
	  g_string_append_printf (string,
				  "STRING %s (a%s).\n", target_name, w);
	}
      else
	g_string_append_printf (string, "NUMERIC %s.\n", target_name);
    }

  if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (user_label_toggle)))
    label = gtk_entry_get_text (GTK_ENTRY (label_entry));
  else
    label = expression;

  if ( strlen (label) > 0 )
    g_string_append_printf (string, "VARIABLE LABEL %s '%s'.\n",
			    target_name,
			    label);

  g_string_append_printf (string, "COMPUTE %s = %s.\n",
			  target_name,
			  expression
			  );

  g_string_append (string, "EXECUTE.\n");


  g_free (expression);

  text = string->str;

  g_string_free (string, FALSE);

  return text;
}
static void
run_define_groups (struct tt_indep_samples_dialog *ttd)
{
  struct tt_groups_dialog *grps = ttd->grps;

  gint response;

  GtkWidget *box = get_widget_assert (ttd->xml, "dialog-hbox2");

  const gchar *text = gtk_entry_get_text (GTK_ENTRY (ttd->groups_entry));

  const struct variable *v = psppire_dict_lookup_var (ttd->dict, text);

  if ( grps->table2->parent)
    gtk_container_remove (GTK_CONTAINER (grps->table2->parent), grps->table2);

  if ( grps->table1->parent)
    gtk_container_remove (GTK_CONTAINER (grps->table1->parent), grps->table1);


  if ( var_is_numeric (v))
    {
      gtk_table_attach_defaults (GTK_TABLE (grps->table1), grps->table2,
				 1, 2, 1, 2);

      gtk_container_add (GTK_CONTAINER (box), grps->table1);
    }
  else
    {
      gtk_container_add (GTK_CONTAINER (box), grps->table2);
      grps->group_defn = GROUPS_VALUES;
    }


  psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (grps->dialog),
				      define_groups_state_valid, grps);

  if ( grps->group_defn != GROUPS_CUT_POINT )
    {
      gtk_toggle_button_set_active
	(GTK_TOGGLE_BUTTON (grps->cut_point_toggle_button), TRUE);

      gtk_toggle_button_set_active
	(GTK_TOGGLE_BUTTON (grps->values_toggle_button), TRUE);

      gtk_entry_set_text (GTK_ENTRY (grps->grp_entry[0]), grps->val[0]);
      gtk_entry_set_text (GTK_ENTRY (grps->grp_entry[1]), grps->val[1]);

      gtk_entry_set_text (GTK_ENTRY (grps->cut_point_entry), "");
    }
  else
    {
      gtk_toggle_button_set_active
	(GTK_TOGGLE_BUTTON (grps->values_toggle_button), TRUE);

      gtk_toggle_button_set_active
	(GTK_TOGGLE_BUTTON (grps->cut_point_toggle_button), TRUE);

      gtk_entry_set_text (GTK_ENTRY (grps->grp_entry[0]), "");
      gtk_entry_set_text (GTK_ENTRY (grps->grp_entry[1]), "");

      gtk_entry_set_text (GTK_ENTRY (grps->cut_point_entry), grps->val[0]);
    }

  g_signal_emit_by_name (grps->grp_entry[0], "changed");
  g_signal_emit_by_name (grps->grp_entry[1], "changed");
  g_signal_emit_by_name (grps->cut_point_entry, "changed");

  response = psppire_dialog_run (PSPPIRE_DIALOG (grps->dialog));

  if (response == PSPPIRE_RESPONSE_CONTINUE)
    {
      g_free (grps->val[0]);
      g_free (grps->val[1]);

      if (gtk_toggle_button_get_active
	  (GTK_TOGGLE_BUTTON (grps->values_toggle_button)))
	{
	  grps->group_defn = GROUPS_VALUES;

	  grps->val[0] =
	    xstrdup (gtk_entry_get_text (GTK_ENTRY (grps->grp_entry[0])));

	  grps->val[1] =
	    xstrdup (gtk_entry_get_text (GTK_ENTRY (grps->grp_entry[1])));
	}
      else
	{
	  grps->group_defn = GROUPS_CUT_POINT;

	  grps->val[1] = NULL;

	  grps->val[0] =
	    xstrdup (gtk_entry_get_text (GTK_ENTRY (grps->cut_point_entry)));
	}

      psppire_dialog_notify_change (PSPPIRE_DIALOG (ttd->dialog));
    }
}
static gchar *
generate_syntax (const struct tt_indep_samples_dialog *d)
{
  struct variable *group_variable;
  gchar *text;

  GtkWidget *tv =
    get_widget_assert (d->xml, "indep-samples-t-test-treeview2");

  GString *str = g_string_new ("T-TEST /VARIABLES=");

  psppire_var_view_append_names (PSPPIRE_VAR_VIEW (tv), 0, str);

  g_string_append (str, "\n\t/GROUPS=");

  group_variable =
    psppire_dict_lookup_var (d->dict,
			     gtk_entry_get_text (GTK_ENTRY (d->groups_entry)));

  g_string_append (str, var_get_name (group_variable));

  if (d->grps->group_defn != GROUPS_UNDEF)
    {
      g_string_append (str, "(");

      if ( var_is_alpha (group_variable))
	{
	  struct string s = DS_EMPTY_INITIALIZER;
	  syntax_gen_string (&s, ss_cstr (d->grps->val[0]));
	  g_string_append (str, ds_cstr (&s));
	  ds_destroy (&s);
	}
      else
	{
	  g_string_append (str, d->grps->val[0]);
	}

      if ( d->grps->group_defn == GROUPS_VALUES )
	{
	  g_string_append (str, ",");

	  if ( var_is_alpha (group_variable))
	    {
	      struct string s = DS_EMPTY_INITIALIZER;
	      syntax_gen_string (&s, ss_cstr (d->grps->val[1]));
	      g_string_append (str, ds_cstr (&s));
	      ds_destroy (&s);
	    }
	  else
	    {
	      g_string_append (str, d->grps->val[1]);
	    }
	}

      g_string_append (str, ")");
    }

  tt_options_dialog_append_syntax (d->opts, str);

  g_string_append (str, ".\n");

  text = str->str;

  g_string_free (str, FALSE);

  return text;
}