gtk-list digest, Vol 1 #1543 - 11 msgs



Send gtk-list mailing list submissions to
	gtk-list gnome org

To subscribe or unsubscribe via the World Wide Web, visit
	http://mail.gnome.org/mailman/listinfo/gtk-list
or, via email, send a message with subject or body 'help' to
	gtk-list-request gnome org

You can reach the person managing the list at
	gtk-list-admin gnome org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of gtk-list digest..."


Today's Topics:

   1. Deleting multiple selections from list store (Linus Walleij)
   2. Re: Working With Trees (Keith Sharp)
   3. Re: Working With Trees (Charles Tassell)
   4. install problem gtk+-2.2.0 (Erwin Panen)
   5. Re: install problem gtk+-2.2.0 (Padraig O'Briain)
   6. A question about font setting. (James Su)
   7. Re: A question about font setting. (Sven Neumann)
   8. Re: A question about font setting. (James Su)
   9. Re: Working With Trees (Owen Taylor)
  10. Re: theme-switch hack (Owen Taylor)
  11. Re: problems with GtkPaned and allocation/set_position (Owen Taylor)

--__--__--

Message: 1
Date: Thu, 22 May 2003 18:06:17 +0200 (MEST)
From: Linus Walleij <triad df lth se>
To: gtk-list gnome org
Subject: Deleting multiple selections from list store

I've been having a hard time devising a routine that deletes all the
selected rows in a view from a list store using the new GTK+-2.0 MVC
component. I sort of came up with this rather idiomatic way of doing
things, and want to know if I'm doing it right:


void remove_selected(GtkListStore *s, GtkTreeView *v)
{
  GtkTreeModel *model = GTK_TREE_MODEL(s);
  GList *selection;
  GtkTreeSelection *select = gtk_tree_view_get_selection(v);
  selection = gtk_tree_selection_get_selected_rows(select, &model);

  while (selection != NULL) {
    GList *tmp;
    GtkTreeIter iter;

    tmp = g_list_first(selection);
    /* Get the iterator for the first row and remove it */
    if (gtk_tree_model_get_iter(GTK_TREE_MODEL(get_store(listtype)),
                                &iter,
                                (GtkTreePath *) tmp->data)) {
      gtk_list_store_remove(get_store(listtype), &iter);
    }
    /*
     * We have to free this selection list and get the
     * paths again, because when we removed the line
     * all path references changed and are now invalid.
     */
    g_list_foreach (selection, (GFunc) gtk_tree_path_free, NULL);
    g_list_free(selection);
    select = gtk_tree_view_get_selection(v);
    selection = gtk_tree_selection_get_selected_rows(select, &model);
  }
}


This seems so awkward and most of all inefficient, that one intuitively
believe that there is either another way, or that you're simply not
supposed to remove multiple selections from the store, cause that's
complicated :-)

Yours,
Linus Walleij


--__--__--

Message: 2
Subject: Re: Working With Trees
From: Keith Sharp <kms passback co uk>
To: Charles Tassell <ctassell isn net>
Cc: gtk-list gnome org
Organization: Passback IT Consultancy
Date: 22 May 2003 20:26:21 +0100


--=-7ah2IT8+n+ePI4j4deNp
Content-Type: text/plain
Content-Transfer-Encoding: 7bit

On Thu, 2003-05-22 at 00:30, Charles Tassell wrote:
> Doesn't make any difference, I've tried the code below, and it seems to
> do the same thing.  Am I wrong here, or is the GtkTreeStore type not
> compatible with GtkTreeModel?  From the docs, I think I should be able
> to use a GtkTreeStore pointer with any function that takes a
> GtkTreeModel, but maybe I'm misreading something.
>
> int SetFolders(void)
> {
>   GtkTreeStore    *tstoreFolders;
>   GtkTreeIter     iterStore, iterTest;
>   char            *Test, *readTest;
>
>   /* Create test strings */
>   Test = malloc(100);
>   memset(Test, 0, 100);
>   strcpy(Test, "This is a test");
>
>   readTest = malloc(100);
>   memset(readTest, 0, 100);

How about replacing the above two lines with:

gchar *readTest;

>   /* Create the storage area */
>   tstoreFolders = gtk_tree_store_new(NUM_COLUMNS, G_TYPE_STRING);
>
>   /* Add the test entry */
>   gtk_tree_store_append(GTK_TREE_MODEL(tstoreFolders), &iterStore,
> NULL);
>   gtk_tree_store_set(GTK_TREE_MODEL(tstoreFolders), &iterStore,
> FOLDER_NAME, Test, -1);
>
>
>   /* Read the value we just wrote back */
>   if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tstoreFolders),
> &iterTest)) {
>     printf("Couldn't get first iterator\n");
>   }
>   gtk_tree_model_get(GTK_TREE_MODEL(tstoreFolders), &iterTest,
> FOLDER_NAME, readTest, -1);
>   printf("Test is %s\n", readTest);

and adding:

g_free (readTest);

>   return 0;
> }

I've also attached a C file that show how to create a GtkTreeStore,
populate it, and retrieve the data.  It also does some other stuff like
setting editable cells.  Tested on Red Hat 9.  Might be of some help...

Keith.

--=-7ah2IT8+n+ePI4j4deNp
Content-Disposition: attachment; filename=example.c
Content-Type: text/x-c; name=example.c; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

/*
  Example Code for GtkTreeStore and GtkTreeView Tutorial Part 2
  =============================================================

  This example shows how to create a tree model, add
  some data to the model, and then extract some data
  from the model, all while displaying on the screen.

  To compile this:

  gcc -o example `pkg-config --libs gtk+-2.0 --cflags gtk+-2.0` example.c

*/

#include <gtk/gtk.h>

enum {
  FIRSTNAME = 0,
  LASTNAME,
  EDITABLE
};

/* Standard callback to halt the application correctly
   when closed using the Window Manager */
gint delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data) {
  gtk_main_quit ();
  return FALSE;
}

/* This function creates a GTK_TREE_STORE object and populates
   it with some data */
GtkTreeModel *create_and_populate_model () {

  GtkTreeStore *treestore;
  GtkTreeIter parent, child;

  /* Create the new Tree Store object, the arguments to the function
     are the number of columns and the then the type of each column.
     In this example we have two columns, both of type string */
treestore = gtk_tree_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);

  /* Next we need to create some new rows, and then populate them
     with data, the structure we create is:

           TOP LEVEL
           - Jane Doe
	         - Susan Clark
		- Babs Jensen
	   - John Smith
  */

  /* The first row at the top level */
  gtk_tree_store_append (treestore, &parent, NULL);
gtk_tree_store_set (treestore, &parent, FIRSTNAME, "Jane", LASTNAME, "Doe", EDITABLE, TRUE, -1);

  /* The first child row of the first row at the top level */
  gtk_tree_store_append (treestore, &child, &parent);
gtk_tree_store_set (treestore, &child, FIRSTNAME, "Susan", LASTNAME, "Clark", EDITABLE, TRUE, -1);

  /* The second child row of the first row at the top level */
  gtk_tree_store_append (treestore, &child, &parent);
gtk_tree_store_set (treestore, &child, FIRSTNAME, "Babs", LASTNAME, "Jensen", EDITABLE, TRUE, -1);

  /* The second row at the top level */
  gtk_tree_store_append (treestore, &parent, NULL);
gtk_tree_store_set (treestore, &parent, FIRSTNAME, "John", LASTNAME, "Smith", EDITABLE, TRUE, -1);

  /* And finally return our model */
  return GTK_TREE_MODEL(treestore);
}

/* This function is called recursively to extract all the data from
   the GtkTreeModel */
void dump_tree_data (GtkTreeModel *model, GtkTreeIter iter) {

  GtkTreeIter child;
  gchar *first, *last;

  /* Dump data from this node */
  gtk_tree_model_get (model, &iter, 0, &first, -1);
  gtk_tree_model_get (model, &iter, 1, &last, -1);
  g_print ("Firstname: %s, Lastname: %s\n", first, last);
  g_free (first);
  g_free (last);

  /* Check if this node has a child and if so recursively call
     this function again for that child */
  if(gtk_tree_model_iter_children (model, &child, &iter)) {
    dump_tree_data (model, child);
  }
  /* Next, check if this node has a sibling and if so recursively
     call this function again for that sibling */
  if (gtk_tree_model_iter_next (model, &iter)) {
    dump_tree_data (model, iter);
  }
  return;
}

/* The callback for the editing of text in our GtkTreeView */
void lastname_edited (GtkCellRendererText *cell, gchar *path_string,
		      gchar *new_text, gpointer data) {

  GtkTreeModel *treemodel = (GtkTreeModel *)data;
  GtkTreeIter iter;

  /* Convert the string path to the row that has changed to a GtkIter */
gtk_tree_model_get_iter (treemodel, &iter, gtk_tree_path_new_from_string (path_string));

  /* Update the GtkTreeModel with the new value */
gtk_tree_store_set (GTK_TREE_STORE(treemodel), &iter, LASTNAME, new_text, -1);

  /* Dump the model out to STDOUT to show the changes */
  gtk_tree_model_get_iter_first (GTK_TREE_MODEL(treemodel), &iter);
  dump_tree_data (GTK_TREE_MODEL(treemodel), iter);

  return;
}

/* The main function of our example application */
int main (int argc, char *argv[]) {

  GtkWidget *window;

  GtkTreeModel *treemodel;
  GtkCellRenderer *render;
  GtkWidget *treeview;
  GtkTreeIter iter;

  gtk_init (&argc, &argv);

  /* Create the application window, and connect the delete event
     callback to the delete event signal */
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  g_signal_connect (G_OBJECT(window), "delete_event",
                    G_CALLBACK(delete_event_cb), NULL);

  /* This calls a function which creates the new model and
     then populates it with some data.  This function is
     defined above */
  treemodel = create_and_populate_model ();

  /* Create the tree view widget which shows the data in the GUI*/
  treeview = gtk_tree_view_new ();

  /* Attach this widget to the model we have already created */
gtk_tree_view_set_model (GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(treemodel));

  /* For each column we want to display in our view we need to
     create a renderer and attach it to the view */
  render = gtk_cell_renderer_text_new ();
g_signal_connect (G_OBJECT(render), "edited", G_CALLBACK(lastname_edited), treemodel);
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(treeview),
                                               -1, "Last name", render,
                                               "text", LASTNAME,
					       "editable", EDITABLE, NULL);
  render = gtk_cell_renderer_text_new ();
  gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW(treeview),
                                               -1, "First name", render,
                                               "text", FIRSTNAME, NULL);

  /* Add the view widget to the window */
  gtk_container_add (GTK_CONTAINER (window), treeview);

  /* Get a GtkTreeIter for the first node in the model */
  gtk_tree_model_get_iter_first (GTK_TREE_MODEL(treemodel), &iter);

  /* Call our recursive function to print the data in the model
     to STDOUT */
  dump_tree_data (GTK_TREE_MODEL(treemodel), iter);

  /* Show all of the widgets, and then enter the gtk_main loop */
  gtk_widget_show_all  (window);
  gtk_main ();

  return 0;
}

--=-7ah2IT8+n+ePI4j4deNp--


--__--__--

Message: 3
Subject: Re: Working With Trees
From: Charles Tassell <ctassell isn net>
To: Keith Sharp <kms passback co uk>
Cc: gtk-list gnome org
Organization:
Date: 21 May 2003 20:30:46 -0300

Doesn't make any difference, I've tried the code below, and it seems to
do the same thing.  Am I wrong here, or is the GtkTreeStore type not
compatible with GtkTreeModel?  From the docs, I think I should be able
to use a GtkTreeStore pointer with any function that takes a
GtkTreeModel, but maybe I'm misreading something.

int SetFolders(void)
{
  GtkTreeStore    *tstoreFolders;
  GtkTreeIter     iterStore, iterTest;
  char            *Test, *readTest;

  /* Create test strings */
  Test = malloc(100);
  memset(Test, 0, 100);
  strcpy(Test, "This is a test");

  readTest = malloc(100);
  memset(readTest, 0, 100);

  /* Create the storage area */
  tstoreFolders = gtk_tree_store_new(NUM_COLUMNS, G_TYPE_STRING);

  /* Add the test entry */
  gtk_tree_store_append(GTK_TREE_MODEL(tstoreFolders), &iterStore,
NULL);
  gtk_tree_store_set(GTK_TREE_MODEL(tstoreFolders), &iterStore,
FOLDER_NAME, Test, -1);


  /* Read the value we just wrote back */
  if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(tstoreFolders),
&iterTest)) {
    printf("Couldn't get first iterator\n");
  }
  gtk_tree_model_get(GTK_TREE_MODEL(tstoreFolders), &iterTest,
FOLDER_NAME, readTest, -1);
  printf("Test is %s\n", readTest);

  return 0;
}


On Wed, 2003-05-21 at 04:50, Keith Sharp wrote:
[snip]

> What happens if you take the g_free(gTest) out?
>
> Keith.
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>


--__--__--

Message: 4
From: Erwin Panen <erwinpanen imapmail org>
Reply-To: erwin panen skynet be
Organization: TFT
To: gtk-list gnome org
Subject: install problem gtk+-2.2.0
Date: Thu, 22 May 2003 15:43:27 +0200
Cc: lists gtklist erwinpanen imapmail org

Hello all,

I would like to get Abiword-1.9.1 running.
I'm using mandrake 9.1 with kde 3.1
Abiword requires among others gtk+-.
After downloading the install readme says I will need
	GLib
	Pango
	Atk
After downloading those and installing them, I retry gtk+-2.2 but I get errors
saying that Atk is not installed.

I should check the path.....

Can anyone give me a clue what is happening? How to go about?
When I do a search with Kpackage, it  only finds libatk1.0_0.
Is this what the libraries of atk should be?

Any help much appreciated,

Regards,

Erwin Panen

P.S. I can mail the config.log

--__--__--

Message: 5
Date: Fri, 23 May 2003 08:31:59 +0100 (BST)
From: "Padraig O'Briain" <Padraig Obriain Sun COM>
Reply-To: "Padraig O'Briain" <Padraig Obriain Sun COM>
Subject: Re: install problem gtk+-2.2.0
To: gtk-list gnome org, erwin panen skynet be
Cc: lists gtklist erwinpanen imapmail org

Erwin,

Please send me the config log.

Padraig

>
>
> I would like to get Abiword-1.9.1 running.
> I'm using mandrake 9.1 with kde 3.1
> Abiword requires among others gtk+-.
> After downloading the install readme says I will need
> 	GLib
> 	Pango
> 	Atk
> After downloading those and installing them, I retry gtk+-2.2 but I get errors
> saying that Atk is not installed.
>
> I should check the path.....
>
> Can anyone give me a clue what is happening? How to go about?
> When I do a search with Kpackage, it  only finds libatk1.0_0.
> Is this what the libraries of atk should be?
>
> Any help much appreciated,
>
> Regards,
>
> Erwin Panen
>
> P.S. I can mail the config.log
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list


--__--__--

Message: 6
Date: Fri, 23 May 2003 18:04:10 +0800
From: James Su <suzhe turbolinux com cn>
To: gtk-list gnome org
Subject: A question about font setting.

Hi,
If I set a default font in /etc/gtk-2.0/gtkrc like this:

style "gtk-default-font-style" {
font_name = "Sans 11"
}
class "GtkWidget" style "gtk-default-font-style"

I cannot change the gtk font on the fly by gnome-font-properties any
longer. It seems that gtkrc has higher priority than gtk-font-name
event. Can I change this behavior to give gtk-font-name higher priority?
In other word, I want to let the font setting in gtkrc a default one and
can only be used when there is no gtk-font-name properties, like in KDE
environment. How can I do that?

Regards
James Su


--__--__--

Message: 7
To: James Su <suzhe turbolinux com cn>
Cc: gtk-list gnome org
Subject: Re: A question about font setting.
From: Sven Neumann <sven gimp org>
Date: 23 May 2003 12:23:36 +0200

James Su <suzhe turbolinux com cn> writes:

> If I set a default font in /etc/gtk-2.0/gtkrc like this:
>
> style "gtk-default-font-style" {
> font_name = "Sans 11"
> }
> class "GtkWidget" style "gtk-default-font-style"
>
> I cannot change the gtk font on the fly by gnome-font-properties any
> longer. It seems that gtkrc has higher priority than gtk-font-name
> event. Can I change this behavior to give gtk-font-name higher priority?
> In other word, I want to let the font setting in gtkrc a default one and
> can only be used when there is no gtk-font-name properties, like in KDE
> environment. How can I do that?

You are using the wrong setting in your gtkrc. Try this simple line
instead:

 gtk-font-name = "Sans 11"


Sven

--__--__--

Message: 8
Date: Fri, 23 May 2003 18:30:12 +0800
From: James Su <suzhe turbolinux com cn>
To: Sven Neumann <sven gimp org>
Cc: gtk-list gnome org
Subject: Re: A question about font setting.

Thank you very much!

Sven Neumann wrote:

>James Su <suzhe turbolinux com cn> writes:
>
>
>
>>If I set a default font in /etc/gtk-2.0/gtkrc like this:
>>
>>style "gtk-default-font-style" {
>>font_name = "Sans 11"
>>}
>>class "GtkWidget" style "gtk-default-font-style"
>>
>>I cannot change the gtk font on the fly by gnome-font-properties any
>>longer. It seems that gtkrc has higher priority than gtk-font-name
>>event. Can I change this behavior to give gtk-font-name higher priority?
>>In other word, I want to let the font setting in gtkrc a default one and
>>can only be used when there is no gtk-font-name properties, like in KDE
>>environment. How can I do that?
>>
>>
>
>You are using the wrong setting in your gtkrc. Try this simple line
>instead:
>
> gtk-font-name = "Sans 11"
>
>
>Sven
>
>
>




--__--__--

Message: 9
Subject: Re: Working With Trees
From: Owen Taylor <otaylor redhat com>
To: Charles Tassell <ctassell isn net>
Cc: gtk-list gnome org
Organization:
Date: 23 May 2003 11:26:15 -0400

On Mon, 2003-05-19 at 04:27, Charles Tassell wrote:
> I'm using Glade 2.0 and GTK 2.something to try and write a very simple
> file manager, and I can't get the GtkTreeView object to work at all.
> I've looked around, and there doesn't seem to be any docs in regards to
> this widget, other than the API, and the examples in the API are garbage
> (my apologies to their authors): most of them are referencing variables
> that they don't even define.
>
> What I am trying to do at the moment is add an item to the GtkTreeStore,
> but it doesn't seem to want to go.  I'm not getting any warnings on the
> console about bad types or non-existant objects, or anything else for
> that matter, but gtk_tree_model_get just returns garbage.  The code is
> below.

For gtk_tree_model_get() returning garbage-you need to use it
as shown in the example in:

http://developer.gnome.org/doc/API/2.0/gtk/GtkTreeModel.html

      gchar *str_data;
      gint   int_data;

      /* Make sure you terminate calls to gtk_tree_model_get()
       * with a '-1' value
       */
      gtk_tree_model_get (list_store, &iter,
                          STRING_COLUMN, &str_data,
                          INT_COLUMN, &int_data,
                          -1);

      /* Do something with the data */
      g_print ("Row %d: (%s,%d)\n", row_count, str_data, int_data);
      g_free (str_data);


What you have with char Test[100] just isn't the same thing at
all; its the difference between a malloc()'ed string and an array.

Why your GtkTreeView isn't working ... hard to say. It's often useful
to make examples posted here complete and standalone (sort of like
what you were complaining about in the API docs :-) ... from
gtk_init() on. Often the problem can be something that you aren't
thinking about and didn't quote.

Regards,
                                     Owen



--__--__--

Message: 10
Subject: Re: theme-switch hack
From: Owen Taylor <otaylor redhat com>
To: suk <suk artax karlin mff cuni cz>
Cc: gtk-list gnome org
Organization:
Date: 23 May 2003 11:29:12 -0400

On Tue, 2003-05-20 at 19:33, suk wrote:
> Hi again,
> I was looking at theme-switch from muhri. He allows to preview themes
> before he switch them. And he does this with:
>
> 1) locate theme
> 2) fork another process
>         inside the child he does
>
>         gchar *default_files[2] = { located_theme , NULL };
>         gtk_rc_set_default_files( default_files );
>         gtk_init( &argc, &argv );
>
>         create preview_window with plenty widgets
>
> This is because he needs really fresh gtk. Tweaking default_files
> after gtk_init is too late. When I first do gtk_init and then change
> gtk_rc_set_default_files, or call reparse_all or anything, I will always
> get some strange merge of several themes.
>         As I don't understand gtkrc exactly, I think that the problem
> might be in static variable global_rc_files in gtkrc.c. Every new theme
> is added there, but never removed. Is my intention correct ?
>
> I'd like to write theme-switch in similar way as gnomecc. No need to
> fork. Have some widgets in container and say them to change theme.
> But I don't understand gnomecc code. I was completely lost, when even
> browsing through it.
> Can someone gimme a hint please ?

Every GTK+ program effectively has only a single theme. That's why
a fork is necessary if you want to both standard and "preview"
widgets.

You can override the default really easily with GTK+-2.2 for the
current application.

 GtkSettings *settings = gtk_settings_get_default ();
 g_object_set (settings, "gtk-theme-name", "MyTheme", NULL);

Regards,
                                           Owen



--__--__--

Message: 11
Subject: Re: problems with GtkPaned and allocation/set_position
From: Owen Taylor <otaylor redhat com>
To: Paul Davis <paul linuxaudiosystems com>
Cc: gtk-list gnome org
Organization:
Date: 23 May 2003 11:38:18 -0400

On Wed, 2003-05-21 at 22:42, Paul Davis wrote:
> [ major caveat: working with gtk+ 1.2 ]
>
> i don't know if this has gotten any better with gtk+2, but in the 1.2
> series, attempts to use gtk_paned_set_position() before the paned has
> been allocated its final size result in failure. the position is
> clamped to the initial allocation size, and thus when later
> allocations occur that expand the size, the original position is never
> used.
>
> to fix this, i have had to use a connect_after signal handler for the
> allocation signal, and within that signal check to see if the
> allocation is large enough for the desired position, then set it, and
> then disconnect (or make sure the set_position() is not called again,
> since this causes an endless cycle of set_position() -> queue_resize()
> -> size_allocate() signals).
>
> this all seems very messy. has it been improved in gtk+2, and if not,
> is it likely to be?

I'm not sure what you mean by "allocated a final size". Most programs
allocate each widget only once when a window is initially shown,
and I'm pretty sure GtkPaned handles set_position() before
size_allocate() fine.

I've never seen a problem with setting the paned position, from, say,
a Glade file, even for 1.2.

If widgets are getting allocated to a tiny size before they get their
final size, then you are probably doing something funny in your app.

It might be possible to treat the set position as "virtual" and
never clamp it, I might even take a patch to do that, though I'd be
worried that it would look bizarre to the user if the paned was
clamped to the right edge, they resized the window bigger, and the
paned stayed clamped to the right edge.

But I don't think it should be necessary in most cases, and I'd like to
see an test case of where things don't work first.

Regards,
                                         Owen

(Certainly both the size allocation and the paned positioning code
have been extensively rewritten and improved in various ways in the last
4+ years, so the 2.x may well behave better for your case. Nothing
has changed in particular in respect to paned clamping, as far as I
know.)



--__--__--

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list


End of gtk-list Digest




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