[Glade-users] problems with treeview (Atmadarshini devi dasi)
- From: neubuffalo at 163.com (郑伟)
- Subject: [Glade-users] problems with treeview (Atmadarshini devi dasi)
- Date: Wed, 19 Mar 2008 09:24:24 +0800 (CST)
the tree view is not a toplevel widget ,so you have to pack it into a container to show it.In the callback of
the button ,you create a new window ,and tree view,while you do not pack the tree view into the windows.
if you want the callback function of button to manipulate the treeview in the main window which the button is
pack into,you can use the lookup_widget()function or g_object_set()and g_object_get() function,to obtain the
pointer of the tree view in the main windows.
Generally there are 4 steps to use the treeview widget.
1.add data to Gtkliststore or Gtktreestore.
2.pack the GtktreeviewColumn into GTKtreeview
3.pack the Gtkcellrenderer into a GtktreeviewColumn
3.bind the data in Gtklist(tree)store with Gtkcellrenderer.
??2008-03-18??glade-users-request at lists.ximian.com ??????
Send Glade-users mailing list submissions to
glade-users at lists.ximian.com
To subscribe or unsubscribe via the World Wide Web, visit
http://lists.ximian.com/mailman/listinfo/glade-users
or, via email, send a message with subject or body 'help' to
glade-users-request at lists.ximian.com
You can reach the person managing the list at
glade-users-owner at lists.ximian.com
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Glade-users digest..."
Today's Topics:
1. Re: problems with treeview (Tristan Van Berkom)
2. Re: problems with treeview (Alexey Kurochkin)
3. How to create a popup menu using glade (praveenya kumar)
4. Re: problems with treeview (Atmadarshini devi dasi)
----------------------------------------------------------------------
Message: 1
Date: Mon, 17 Mar 2008 14:21:33 -0300
From: "Tristan Van Berkom" <tvb at gnome.org>
Subject: Re: [Glade-users] problems with treeview
To: "Atmadarshini devi dasi" <atmadarshini_dd at yahoo.com>
Cc: glade users <glade-users at lists.ximian.com>
Message-ID:
<560259cb0803171021r1c47cfcj309572f3fe881d8e at mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Hi, what version of glade are you using ? can you send
us the glade file ?
-Tristan
On Mon, Mar 17, 2008 at 1:39 PM, Atmadarshini devi dasi
<atmadarshini_dd at yahoo.com> wrote:
hi there
I am trying to use treeview in order to view an addressbook that i am trying
to create. now i was trying out a working example that is suppose to work to
see how things work before implementing my own function.
but for some reason all that it does is shows me an empty treeview screen
with no data or headings in it. on the glade side of things, all i have done
is put in the treeview into the window. I have not attched any signals or
changed anything. Is that correct?
I have posted the code below that I have used.
enum
{
COL_FIRST_NAME = 0,
COL_LAST_NAME,
COL_YEAR_BORN,
NUM_COLS
} ;
static GtkTreeModel *
create_and_fill_model (void)
{
GtkTreeStore *treestore;
GtkTreeIter toplevel, child;
treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_UINT); /* NUM_COLS = 3 */
/* Append a top level row and leave it empty */
gtk_tree_store_append(treestore, &toplevel, NULL);
gtk_tree_store_set(treestore, &toplevel,
COL_FIRST_NAME, "Maria",
COL_LAST_NAME, "Incognito",
-1);
/* Append a second top level row, and fill it with some data */
gtk_tree_store_append(treestore, &toplevel, NULL);
gtk_tree_store_set(treestore, &toplevel,
COL_FIRST_NAME, "Jane",
COL_LAST_NAME, "Average",
COL_YEAR_BORN, (guint) 1962,
-1);
/* Append a child to the second top level row, and fill in some data */
gtk_tree_store_append(treestore, &child, &toplevel);
gtk_tree_store_set(treestore, &child,
COL_FIRST_NAME, "Janinita",
COL_LAST_NAME, "Average",
COL_YEAR_BORN, (guint) 1985,
-1);
return GTK_TREE_MODEL(treestore);
}
void
age_cell_data_func (GtkTreeViewColumn *col,
GtkCellRenderer *renderer,
GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data)
{
guint year_born;
guint year_now = 2003; /* to save code not relevant for the example */
gchar buf[64];
gtk_tree_model_get(model, iter, COL_YEAR_BORN, &year_born, -1);
if (year_born <= year_now && year_born > 0)
{
guint age = year_now - year_born;
g_snprintf(buf, sizeof(buf), "%u years old", age);
g_object_set(renderer, "foreground-set", FALSE, NULL); /* print this
normal */
}
else
{
g_snprintf(buf, sizeof(buf), "age unknown");
g_object_set(renderer, "foreground", "Red", "foreground-set", TRUE,
NULL); /* make red */
}
g_object_set(renderer, "text", buf, NULL);
}
static GtkWidget *
create_view_and_model (void)
{
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
GtkWidget *view;
GtkTreeModel *model;
view = gtk_tree_view_new();
/* --- Column #1 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "First Name");
/* pack tree view column into tree view */
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
/* pack cell renderer into tree view column */
gtk_tree_view_column_pack_start(col, renderer, TRUE);
/* connect 'text' property of the cell renderer to model column that
contains the first name */
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_FIRST_NAME);
/* --- Column #2 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Last Name");
/* pack tree view column into tree view */
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
/* pack cell renderer into tree view column */
gtk_tree_view_column_pack_start(col, renderer, TRUE);
/* connect 'text' property of the cell renderer to model column that
contains the last name */
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_LAST_NAME);
/* set 'weight' property of the cell renderer to bold print (we want all
last names in bold) */
g_object_set(renderer, "weight", PANGO_WEIGHT_BOLD, "weight-set", TRUE,
NULL);
/* --- Column #3 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Age");
/* pack tree view column into tree view */
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
/* pack cell renderer into tree view column */
gtk_tree_view_column_pack_start(col, renderer, TRUE);
/* connect a cell data function */
gtk_tree_view_column_set_cell_data_func(col, renderer, age_cell_data_func,
NULL, NULL);
model = create_and_fill_model();
gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
g_object_unref(model); /* destroy model automatically with view */
gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
GTK_SELECTION_NONE);
return view;
}
void
on_view_button_clicked (GtkButton *button,
gpointer user_data)
{
GtkWidget *treeview;
view_address_window = create_view_address_window();
treeview = create_view_and_model();
gtk_widget_show (view_address_window);
}
the view button is a button that i use in order to see the window with the
treeview . i get no errors but dont see anything in my treeview.
Please help.
thanks
Aakanksha
________________________________
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
_______________________________________________
Glade-users maillist - Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
------------------------------
Message: 2
Date: Mon, 17 Mar 2008 15:16:48 -0500
From: Alexey Kurochkin <alexey.kurochkin at pathfinderlwd.com>
Subject: Re: [Glade-users] problems with treeview
To: glade-users at lists.ximian.com
Message-ID: <1205785008.2858.10.camel at localhost.localdomain>
Content-Type: text/plain
On Mon, 2008-03-17 at 09:39 -0700, Atmadarshini devi dasi wrote:
void
on_view_button_clicked (GtkButton *button,
gpointer user_data)
{
GtkWidget *treeview;
view_address_window = create_view_address_window();
treeview = create_view_and_model();
gtk_widget_show (view_address_window);
}
Based on what I see above, you create brand new treeview, and then never
pack it to any window, and never even show it. I guess what you actually
see on screen is an empty tree from a glade file. You have two
treeviews, one empty and one hidden! So you either have to go all the
way and create window which would hold the treeview in your code, or do
not call gtk_treeview_new at all and get the widget from the glade file
instead.
the view button is a button that i use in order to see the window with
the treeview . i get no errors but dont see anything in my treeview.
Please help.
thanks
Aakanksha
------------------------------
Message: 3
Date: Tue, 18 Mar 2008 17:19:01 +0530
From: "praveenya kumar" <praveenya.g at gmail.com>
Subject: [Glade-users] How to create a popup menu using glade
To: glade-users at lists.ximian.com
Message-ID:
<c442fe290803180449k299d6a9fgf3455ac3fd6b20ba at mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hai!
I am bit new to glade. I am facing problem in creating a popup menu.
I want a simple gtk application that displays a popup or context menu with 3
entries when started.
There is a widget popup menu in gtk+ applications i added this widget but I
could not see any gui related to that. How to add and make it visibe.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/glade-users/attachments/20080318/ef1266b8/attachment-0001.html
------------------------------
Message: 4
Date: Tue, 18 Mar 2008 05:04:02 -0700 (PDT)
From: Atmadarshini devi dasi <atmadarshini_dd at yahoo.com>
Subject: Re: [Glade-users] problems with treeview
To: Tristan Van Berkom <tvb at gnome.org>
Cc: glade users <glade-users at lists.ximian.com>
Message-ID: <618093.16204.qm at web56409.mail.re3.yahoo.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi I am using glade version 2. When u say that I should send u the glade file, which file exactly do u mean
and where do i find it?
thanks
Tristan Van Berkom <tvb at gnome.org> wrote: Hi, what version of glade are you using ? can you send
us the glade file ?
-Tristan
On Mon, Mar 17, 2008 at 1:39 PM, Atmadarshini devi dasi
wrote:
hi there
I am trying to use treeview in order to view an addressbook that i am trying
to create. now i was trying out a working example that is suppose to work to
see how things work before implementing my own function.
but for some reason all that it does is shows me an empty treeview screen
with no data or headings in it. on the glade side of things, all i have done
is put in the treeview into the window. I have not attched any signals or
changed anything. Is that correct?
I have posted the code below that I have used.
enum
{
COL_FIRST_NAME = 0,
COL_LAST_NAME,
COL_YEAR_BORN,
NUM_COLS
} ;
static GtkTreeModel *
create_and_fill_model (void)
{
GtkTreeStore *treestore;
GtkTreeIter toplevel, child;
treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_UINT); /* NUM_COLS = 3 */
/* Append a top level row and leave it empty */
gtk_tree_store_append(treestore, &toplevel, NULL);
gtk_tree_store_set(treestore, &toplevel,
COL_FIRST_NAME, "Maria",
COL_LAST_NAME, "Incognito",
-1);
/* Append a second top level row, and fill it with some data */
gtk_tree_store_append(treestore, &toplevel, NULL);
gtk_tree_store_set(treestore, &toplevel,
COL_FIRST_NAME, "Jane",
COL_LAST_NAME, "Average",
COL_YEAR_BORN, (guint) 1962,
-1);
/* Append a child to the second top level row, and fill in some data */
gtk_tree_store_append(treestore, &child, &toplevel);
gtk_tree_store_set(treestore, &child,
COL_FIRST_NAME, "Janinita",
COL_LAST_NAME, "Average",
COL_YEAR_BORN, (guint) 1985,
-1);
return GTK_TREE_MODEL(treestore);
}
void
age_cell_data_func (GtkTreeViewColumn *col,
GtkCellRenderer *renderer,
GtkTreeModel *model,
GtkTreeIter *iter,
gpointer user_data)
{
guint year_born;
guint year_now = 2003; /* to save code not relevant for the example */
gchar buf[64];
gtk_tree_model_get(model, iter, COL_YEAR_BORN, &year_born, -1);
if (year_born <= year_now && year_born > 0)
{
guint age = year_now - year_born;
g_snprintf(buf, sizeof(buf), "%u years old", age);
g_object_set(renderer, "foreground-set", FALSE, NULL); /* print this
normal */
}
else
{
g_snprintf(buf, sizeof(buf), "age unknown");
g_object_set(renderer, "foreground", "Red", "foreground-set", TRUE,
NULL); /* make red */
}
g_object_set(renderer, "text", buf, NULL);
}
static GtkWidget *
create_view_and_model (void)
{
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
GtkWidget *view;
GtkTreeModel *model;
view = gtk_tree_view_new();
/* --- Column #1 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "First Name");
/* pack tree view column into tree view */
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
/* pack cell renderer into tree view column */
gtk_tree_view_column_pack_start(col, renderer, TRUE);
/* connect 'text' property of the cell renderer to model column that
contains the first name */
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_FIRST_NAME);
/* --- Column #2 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Last Name");
/* pack tree view column into tree view */
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
/* pack cell renderer into tree view column */
gtk_tree_view_column_pack_start(col, renderer, TRUE);
/* connect 'text' property of the cell renderer to model column that
contains the last name */
gtk_tree_view_column_add_attribute(col, renderer, "text", COL_LAST_NAME);
/* set 'weight' property of the cell renderer to bold print (we want all
last names in bold) */
g_object_set(renderer, "weight", PANGO_WEIGHT_BOLD, "weight-set", TRUE,
NULL);
/* --- Column #3 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Age");
/* pack tree view column into tree view */
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
/* pack cell renderer into tree view column */
gtk_tree_view_column_pack_start(col, renderer, TRUE);
/* connect a cell data function */
gtk_tree_view_column_set_cell_data_func(col, renderer, age_cell_data_func,
NULL, NULL);
model = create_and_fill_model();
gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);
g_object_unref(model); /* destroy model automatically with view */
gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(view)),
GTK_SELECTION_NONE);
return view;
}
void
on_view_button_clicked (GtkButton *button,
gpointer user_data)
{
GtkWidget *treeview;
view_address_window = create_view_address_window();
treeview = create_view_and_model();
gtk_widget_show (view_address_window);
}
the view button is a button that i use in order to see the window with the
treeview . i get no errors but dont see anything in my treeview.
Please help.
thanks
Aakanksha
________________________________
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
_______________________________________________
Glade-users maillist - Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
---------------------------------
Never miss a thing. Make Yahoo your homepage.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/glade-users/attachments/20080318/eda90b6d/attachment.html
------------------------------
_______________________________________________
Glade-users mailing list
Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
End of Glade-users Digest, Vol 35, Issue 5
******************************************
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/glade-users/attachments/20080319/91eb0506/attachment-0001.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]