Re: gtk_tree_view/store, best way to select all nodes of a branch

2012-09-26 Thread Arne Pagel

I played around with the gtk_tree_selection_select_range functions, but as far 
as I have seen this is not working for collapsed elements.
Also I found the handling very difficult for my purpose, and the operation can 
be distorted by other mouse movements.

I implemented this now by using the gtk_tree_model_foreach function, probably 
not the most efficient method, but at least a working one:

gtk_tree_model_foreach_hierarchy (GtkTreeModel *model,
  GtkTreeModelForeachFunc func,
  GtkTreePath * path,
  gpointer user_data)

The gtk_tree_model_foreach_hierarchy executes the GtkTreeModelForeachFunc func 
in a parent-child hierarchy for the parent and each child.
The parameter treepath has to point to one element in the desired hierarchy.


-- code --

typedef struct
{
  GtkTreeModelForeachFunc func;
  int index;
  gpointer user_data;
}t_gtmfh;

gboolean foreach_indices (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter 
*iter, gpointer user_data)
{
  int ret = 0;
  t_gtmfh * gtmfh;
  int * ind;

  gtmfh = user_data;
  ind = gtk_tree_path_get_indices (path);

  if (*ind == gtmfh->index)
  {
gtmfh->func(model, path, iter, gtmfh->user_data);
  }
  else if (*ind > gtmfh->index)
  {
ret = 1;
  }

  return ret;
}


void gtk_tree_model_foreach_hierarchy (GtkTreeModel *model, 
GtkTreeModelForeachFunc func,GtkTreePath * path,gpointer user_data)
{
  t_gtmfh gtmfh;
  int *ind;

  ind = gtk_tree_path_get_indices (path);

  gtmfh.func = func;
  gtmfh.index = *ind;
  gtmfh.user_data = user_data;

  gtk_tree_model_foreach (model,foreach_indices,>mfh);
}




Am 12.09.2012 10:54, schrieb David Nečas:

On Wed, Sep 12, 2012 at 10:40:11AM +0200, Arne Pagel wrote:

My current simple solution is as follows:
I use the gtk_tree_model_foreach() function and pass some user data with the 
current major number of the tree-path.
Inside the foreach-function I use gtk_tree_path_to_string, where I check if the 
first number is identical to the user data.

This works, but I have to use a lot of string functions.
Is there a smarter way to do that with less overhead?


Use gtk_tree_selection_select_range().

You already have the start path, so, how to get the end path?  Use
gtk_tree_model_iter_n_children() and gtk_tree_model_iter_nth_child()
recursively to always move to the last child in the branch.  If your
tree is only two-level (as it seems to be) you do not even need to
recurse.

Regards,

Yeti




___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Gtk_Tree_View, drawing speed

2012-09-26 Thread Arne Pagel

Thank you for this hint,

I tried it and indeed I notice a speedup, but just factor ~1,3.
There must be something more.

I removed all columns expect the "Value" column, and now I notice a speedup 
factor of ~3, if I remove just one column, is see a speedup factor of ~2.
Now I am sure that there is some processing on cells where the corresponding 
data in the treestore are not touched.
If I remove columns on the first treeview which is using the same tree-store I 
see no effect.

What is interesting that I now notice also a speedup of my single elements 
objects, there now I can achieve an update rate of 570 requests per second.

- -

I just noticed that I can't compare the single element objects and structured 
objects in that way I did before,
but anyway, with the column removing I see some potential for speeding up 
everything.

Of course the given value of 570 requests per second is not the design goal of 
the program.
But later I want to have many structured objects in the treeview with an 
acceptable update rate and not 100% CPU load.

regards
  Arne

Am 26.09.2012 10:51, schrieb jcup...@gmail.com:

On 26 September 2012 07:09, Arne Pagel  wrote:

Do you see any other option?


Have you tried setting the fixed-height hint on the treeview?

By default treeview supports variable-height rows. This is great, of
course, but there is a performance penalty: whenever the model
changes, the view has to rescan the model and recalculate all the
heights. If all your rows are the same height, and they might be from
looking at your screenshot, you can set the fixed-height hint and get
treeview to just sample a single row.

http://developer.gnome.org/gtk3/stable/GtkTreeView.html#gtk-tree-view-set-fixed-height-mode

John



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Gtk_Tree_View, drawing speed

2012-09-26 Thread jcupitt
On 26 September 2012 07:09, Arne Pagel  wrote:
> Do you see any other option?

Have you tried setting the fixed-height hint on the treeview?

By default treeview supports variable-height rows. This is great, of
course, but there is a performance penalty: whenever the model
changes, the view has to rescan the model and recalculate all the
heights. If all your rows are the same height, and they might be from
looking at your screenshot, you can set the fixed-height hint and get
treeview to just sample a single row.

http://developer.gnome.org/gtk3/stable/GtkTreeView.html#gtk-tree-view-set-fixed-height-mode

John
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


improvements in gtktreeview

2012-09-26 Thread Rudra Banerjee
Dear friends, 
below  I have copied the way I am creating a treeview. Maybe, you may
find some part is not necessary, but still I put them to show you how I
am doing the things. 

I need help in few things:
1) for my typical testing file, which has ~150 entry(to be parsed by
parse.sh, create file "fauth.dat" and then read by fauth) It takes
around 5 second! I am afraid what will happen for a bigger file. I tried
to create a parser in C that will directly store the entries of
fauth.dat in array, but failed(Any help in this will be hugely
welcome). 
Is there anyway to sppedup the process ?
2) Entries in "COL_BIB_NAME" can be arbitraryly long(I have set up max
length to 500). Problem is in my present settings, the full line is
written in a single line. Can I set the width of each sell fixed? So,
that when the entry is more then the width, they will break up in
several line? In other word, currently, my cells have fixed hight,
variable width. can I change it to variable hight, fixed width?
3) These two is my matter of concern. But being a novice, I  am looking
for any other advice as well. 

static GtkTreeModel *
create_and_fill_model(void) {

treestore = gtk_tree_store_new(NUM_COLS,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_STRING);
return GTK_TREE_MODEL(treestore);
}

static GtkWidget *
create_view_and_model(void) {
GtkTreeViewColumn *col;
GtkCellRenderer *renderer;
GtkWidget *view;
GtkTreeModel *model;

view = gtk_tree_view_new();

/* --- Column #0 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Type");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "text",
COL_BIB_TYPE);

/* --- Column #1 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Name");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "text",
COL_BIB_NAME);


/* --- Column #2 --- */
col = gtk_tree_view_column_new();
gtk_tree_view_column_set_title(col, "Year");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "text",
COL_BIB_YEAR);
/*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, "Journal");
gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(col, renderer, TRUE);
gtk_tree_view_column_add_attribute(col, renderer, "text",
COL_BIB_PUB);
/* 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;
}

static void open_file(GtkWidget *widget, gpointer data) {
GtkWidget *dialog; //, *entry;
GtkFileFilter *filter;
dialog = gtk_file_chooser_dialog_new("Open File", NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
NULL);

filter = gtk_file_filter_new();
gtk_file_filter_set_name(filter, "All files (*.*)");
gtk_file_filter_add_pattern(filter, "*");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);

filter = gtk_file_filter_new();
gtk_file_filter_set_name(filter, "Bibtex file (*.bib)");
gtk_file_filter_add_pattern(filter, "*.bib");
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);

if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
filename =
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
char pcomm[1028];
sprintf(pcomm, "bash parse.sh %s", filename);
g_print("%s", pcomm);
system((char *) pcomm);
}
int i=0;//,j=0,k=0;
int num_line=0, ch;
FILE *fauth, *fyear, *ftitle;
   FILE* tfauth=fopen("fauth.dat","r");
do{
  ch=fgetc(tfauth);
  if(ch == '\n')
   num_line++;
  }while (ch != EOF);
/*   if(ch != '\n' && num_line != 0) 
num_line++;*/
fclose(tfauth);
  printf("%d\n",num_line);

char
aau