[gtk-server] Re: Formatting floats (Was: gtk-server Digest V5 #3)

  • From: Peter van Eerten <administrator@xxxxxxxxxxxxxx>
  • To: gtk-server@xxxxxxxxxxxxx
  • Date: Mon, 08 Sep 2008 15:53:33 +0200

Hi Erik,

The way to show different values on different lines is explained in the same tutorial: retrieve the float from the treemodel, and turn it into a string where the float has only two digits after the colon/comma, and render that with the text cell renderer.

So, the clue is: store your actual values into the treemodel, and in some callback function render them with the cell renderers.

One approach which pops up to my mind, is setting up an async signal with 'gtk_server_timeout', setting the timeout value to, for example, 100msecs. Each time the timeout expires, your mainloop receives an event, then jump to some function where you update the cells, by going through the treemodel line by line (you can use the calls 'gtk_tree_model_get_iter_first' and 'gtk_tree_model_iter_next' to walk through the tree) and set the "text" property of each renderer accordingly, the way as it is demonstrated in my previous post.

Another similar approach would be to connect the "row-changed" signal to the treemodel, and only at this signal update the renderers in the list (maybe better, less CPU).

Another approach would be to use the good old "CList" instead, which is a deprecated widget, but maybe sufficient for your needs. See also: http://library.gnome.org/devel/gtk/stable/GtkCList.html

Nobody says GTK is easy ;-) In fact, the list widget is one of the most complicated of all widgets.

Regards
Peter

Quoting Erik Winkels <euqirea@xxxxxxxxx>:

Hi Peter,

First of all thanks for you patience :-)  Although I've been programming for
the better part of my life this is actually the first time I'm seriously
using a GUI library.

Things are finally starting to sink in and your last post and example have
explained a lot, but one thing is still causing me problems which isn't
explained by your example either:

Date: Sat, 06 Sep 2008 10:36:28 +0200
From: Peter van Eerten <administrator@xxxxxxxxxxxxxx>
Subject: [gtk-server] Re: Formatting floats (Was: gtk-server Digest V5

So, make sure the iter has the correct line in the table, and create a
separate cellrenderer for the column where you store the float values.
Then format your value with 'g_snprintf' and set the value with
g_object_set. Don't forget to redefine some of the GTK/GLib calls
correctly!

I don't know how I can make sure the iter is on the correct line when the
view is getting drawn.  I do know on which line the iter is when I'm filling
the model but setting the cell renderer text property is of little use then,
because when the view is shown each line of the column will show the value
the text property was last set to during the initialisation of the model.

Or, more concrete: in your example if you do not want to display 1.23 but
a different value on each line... how would you do that?

Would I need to make an event for each time the cell is going to get drawn
and set the text property then?  This solution would bring a whole lot of
extra code and complexity with it since my list store has got nine columns,
each of which can be sorted, of which two need to display monetary values.

(I don't even known whether it's possible to set an event for this since
I really do not want to go into this direction :-) )


Erik



--
http://www.gtk-server.org


Other related posts: