Gtk tree view filter
- From: "IGNASIDP terra es" <IGNASIDP terra es>
- To: "gnome-cl-list gnome org" <gnome-cl-list gnome org>
- Subject: Gtk tree view filter
- Date: Sat, 15 Mar 2008 11:31:45 +0100 (MET)
Hola,
estoy intentando hacer mi primer programa en Gtk. Es muy sencillo: la idea es presentar una lista en la ventana izquierda y un tree-view en la derecha, de tal manera que al seleccionar un elemento en la lista se muestre en el tree-view las filas que cumplen la condición establecida.
Mi problema es cómo conectar las dos ventanas. Por más que lo intento me da errores del tipo: Gtk-CRITICAL **; gtk_tree_model_filter_refilter: assertion 'GTK_IS_MODEL_FILTER(filter)' failed
¿Me podéis ayudar? Os dejo parte del código.
Muchas gracias
Mount
static gboolean
Filter_func (GtkTreeModel *model,
GtkTreeIter *iter,
gpointer data)
{
gchar *grp;
gboolean ret = FALSE;
gtk_tree_model_get (model, iter, COL_GROUP, &grp, -1);
if (strcmp (grp, selname) == 0)
{
ret = TRUE;
}
g_free (grp);
return ret;
}
static void
group_selected (GtkTreeSelection *selection,
gpointer data)
{
GtkTreeModel *treeview;
GtkTreeIter iter;
GtkTreeModel *model;
gchar *name;
GtkWidget *widget = lookup_widget (GTK_WIDGET (window), "treeview");
treeview = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
gtk_tree_model_get (model, &iter, COL_NAME, &name, -1);
selname = name;
g_print ("You selected: %s\tselname: %s\n", name, selname);
g_free (name);
}
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (treeview));
}
static void
add_col_groups (GtkTreeView *treeview,
GtkTreeModel *groups_model)
{
GtkCellRenderer *renderer;
GtkTreeSelection *select;
renderer = gtk_cell_renderer_text_new ();
g_object_set (renderer,
"editable", FALSE,
NULL);
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COL_NAME));
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
-1, "Name", renderer,
"text", COL_NAME,
NULL);
select = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
gtk_tree_selection_set_mode (select, GTK_SELECTION_SINGLE);
g_signal_connect (G_OBJECT (select), "changed",
G_CALLBACK (group_selected),
NULL);
}
GtkWidget *
do_editable_cells (GtkWidget *do_widget)
{
GtkWidget *sw1;
GtkWidget *sw2;
GtkWidget *treeview;
GtkWidget *groupsview;
GtkTreeModel *items_model;
GtkTreeModel *groups_model;
GtkTreeModel *treeviewfilter;
sw1 = gtk_scrolled_window_new (NULL, NULL);
sw2 = gtk_scrolled_window_new (NULL, NULL);
/* crea los modelos */
items_model = create_items_model ();
groups_model = create_groups_model ();
/* crea el tree view */
treeviewfilter = gtk_tree_model_filter_new (items_model, NULL);
treeview = gtk_tree_view_new_with_model (treeviewfilter);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
GTK_SELECTION_SINGLE);
add_columns (GTK_TREE_VIEW (treeview), items_model);
/* crea el groups view */
groupsview = gtk_tree_view_new_with_model (groups_model);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (groupsview), TRUE);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (groupsview)),
GTK_SELECTION_SINGLE);
add_col_groups (GTK_TREE_VIEW (groupsview), groups_model);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (treeviewfilter),
Filter_func, NULL, NULL);
gtk_container_add (GTK_CONTAINER (sw1), groupsview);
gtk_container_add (GTK_CONTAINER (sw2), treeview);
.....
return window;
}
int
main (int argc, char **argv)
{
gtk_init (&argc, &argv);
do_editable_cells (window);
gtk_main ();
return 0;
}
Ahora también puedes acceder a tu correo Terra desde el móvil.
Infórmate pinchando aquí.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]