Re: XForms: displaying results

Steve Lamont (spl@szechuan.ucsd.edu)
Sat, 10 Apr 99 07:39:10 PDT

# To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> However, I fiddle and try and whatever... I just can't get my result
> number displayed in the (text) widget. Printf puts it nicely on my
> xterm; so it exists.
> I have a callback there for the text widget (retrieve_mass_compd) and no
> argument (properties in fdesign window).

The Text object (please, it's not a Widget -- Widgets are the
misbegotten spawn of the X Toolkit and XForms is not X Toolkit based)
does not invoke a callback since it is a more or less inert object.

Presumably you have something going on in your application which
generates this number. The easiest way for you to update the Text
object is to do

[...]
char text_buffer[50]; /* Buffer size is overkill */

[... compute your value here ...]

sprintf( text_buffer, "%g", your_value );
fl_set_object_label( fd_whatever->text_object, text_buffer );
fl_check_forms(); /* Do this to force an update */

You may not need to do the fl_check_forms() call if you are
immediately returning control to the XForms main loop, for instance,
if this computation takes place in a callback and you exit the
callback more or less immediately after setting the object label.

You can, of course, put anything you want in the label as long as you
have buffer space in the text buffer and space allocated in the Text
object (that is, the Text object is big enough to contain the
characters):

sprintf( text_buffer, "The number is: %g", your_value );
fl_set_object_label( fd_whatever->text_object, text_buffer );

Since I'm lazy and don't like to write that code every place in my
programs where I want to update a readout, I've written a little
function:

#include <stdarg.h>

void readout( FL_OBJECT *obj, char *fmt, ... )

{

va_list list;
char buffer[80];

va_start( list, fmt );

vsprintf( buffer, fmt, list );

va_end( list );

fl_set_object_label( obj, buffer );

}

This function works more or less like the functions in the printf()
family, you'd call it like

readout( fd_whatever->text_object, "Data is %g", your_value );

Like printf(), the arguments following the format string may be
arbitrary data types -- floats, doubles, chars, or anything else that
makes sense in a printf().

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuhs.mil or see
http://bob.usuhs.mil/mailserv/xforms.html
XForms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuhs.mil/mailserv/list-archives/