Re: [gtk-list] RPC and redrawing a window (long)



On Tue, 18 May 1999 11:28:40 -1000, gtk-list@redhat.com (K. M. Hawarden-Ogata) wrote:
> I have a GUI application that is supposed to talk to another computer over a
> network, using rpcs. While the connection is being created, a message is
> supposed to be displayed in my drawing area that lets the user know that the
> program is attempting to set up a connection. This worked fine under Motif:

[snip Motif code]

> Okay, so when I rewrote these functions under GTK, my collecting_data_msg
> looks like this:
> 
> 
> void collecting_data_msg( )
> {
>     int x, y, l,
>    char_wid, char_hgt,
>    da_wid, da_hgt;
>    char *c;
> 
>    gdk_window_get_size( Status_w->window, &da_wid, &da_hgt);
> 
>    char_wid = Fixed_font_wid;
>    char_hgt = Fixed_font_hgt;
> 
>    c = " Collecting Data, Please Wait ";
>    l = strlen( c );
>    y = da_hgt - (2*char_hgt);
>    x = (da_wid - (l*char_wid))/2;
>    gdk_gc_set_foreground( Nor_gc, &CM.colors[CM_RED] );
>    gdk_draw_rectangle( Status_w->window, Nor_gc, TRUE, x, y-(char_hgt-3),
> l*char_wid, char_hgt );
>    gdk_gc_set_foreground( Nor_gc, &CM.colors[CM_YELLOW] );
>    gdk_draw_text( Status_w->window, Fixed_font, Nor_gc, x, y, c, l );
>    printf( "collecting_data_msg: %s\n", c );

Over here, add:

  while(gtk_events_pending()) gtk_main_iteration();

This is more ore less like the XFlush() in the Motif code.

> }

A couple things which got my attention: 

You have a Motif-ish GTK programming style. Forget about Motif. It's much
too complicated to get simple things done (IMHO). Do things the GTK way,
and your code will get leaner and much easier to understand. The status
message example you showed would be done in GTK like:

  GtkWidget *status_label;
  GtkStyle *style;
  GdkColor foreground, background; /* initialize them */
  int i;

  /* first create the widgets
  status_label = gtk_label_new("");
  gtk_widget_show(status_label);

  /* get its style, fill in colors, and apply it to the label */
  style = gtk_widget_get_style(GTK_WIDGET(status_label));
  for(i = 0; i < 5; i++)
    {
      style->bg[i] = background;
      style->fg[i] = foreground;
    }
  gtk_widget_set_style(GTK_WIDGET(status_label), GTK_WIDGET(style));


In collecting_data_msg() you would simply say:

  gtk_label_set(GTK_LABEL(status_label), 
                "Collecting data, please wait");
  while(gtk_events_pending()) gtk_main_iteration();


Another thing is that from a user interface design point of view, status
messages don't belong in a drawing area. Use a statusbar instead.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]