Slow table of GtkEntry's




Why would a moderately sized table of GtkEntry widgets take so long to render?

I've attached a simple program that illustrates the problem. It consists essentially of a table of 512 rows and 16 columns. At each cell of the table is a GtkEntry widget. Ignore for a moment that this program is totally unusable - the purpose of this program is just to illustrate the rendering problem.

Here are the details about my system:

Athlon 64 3500+
FC 3
$ pkg-config --modversion gtk+-2.0
2.4.13

FYI, what I'm attempting to do is to create a matrix of editable cells. This is used in my simulator for editing the memory of a microprocessor. I currently use the gtksheet widget that is part of gtk+extra, but since gtk+extra is dying I'd like to remove any dependence on it. I have experimented with a GtkTreeView's and have found that they render very efficiently. Unfortunately, there's no way to select a cell without selecting a whole row (from what I've read in the archives, this is hard coded deep inside GTK).

Thanks,
Scott
/*
  gcc -c slowtable.c -Wall -g -O2 `pkg-config --cflags gtk+-2.0`
  gcc -o slowtable slowtable.o `pkg-config --libs gtk+-2.0`

  A simple program to illustrate how long it takes for gtk to render
  a table of entry widgets. 
*/

#include <gtk/gtk.h>

#include <stdio.h>


int main(int argc, char **argv)
{

  GtkWidget *table;
  GtkWidget *window;

  int nRows, nCols;
  char buf[32];
  int row,col;

  int cell_width = 2;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size(GTK_WINDOW(window), 800,600);
  g_signal_connect (window, "delete_event", gtk_main_quit, NULL);


  nCols = 16;
  nRows = 512;

  table = gtk_table_new (nRows,nCols,FALSE);
  gtk_table_set_row_spacings (GTK_TABLE(table),0);

  for(row=0; row<nRows; row++) {
    for(col=0; col<nCols;col++) {
      GtkWidget *rc;
      snprintf(buf,sizeof(buf),"%02X",(row*16+col) & 0xff);
      rc = gtk_entry_new ();
      gtk_entry_set_width_chars(GTK_ENTRY (rc), cell_width);

      gtk_entry_set_text (GTK_ENTRY (rc), buf);

      gtk_table_attach_defaults (GTK_TABLE(table),rc,
				 col+0, col+1, row+0, row+1);
    }
  }
  gtk_container_add (GTK_CONTAINER (window), table);

  gtk_widget_show_all (window);

  gtk_main ();

  return 0;

}


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