GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 17, 2014 6:44 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [Solved]Problem with Gtktable
PostPosted: Mon Apr 09, 2007 2:17 pm 
Offline
Familiar Face

Joined: Mon Apr 09, 2007 2:09 pm
Posts: 10
during the execution i have a problem :
Gtk-CRITICAL **: gtk_table_attach: assertion `GTK_IS_TABLE (table)' failed
I suppose that he tell that my table is not a real table however i init this with
gtk_table_new
Thanks for the assistance brought .

Code:
/* maogtk.c
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 59
* Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#include <stdlib.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include "importimage.h"



struct Data_s
{
  int sort;
  char **ptr;
  GtkWidget *images[11];
  GtkWidget *buttons[11];
  GtkWidget *table;
};
typedef struct Data_s Data;


static void
cb_menu (GtkWidget * widget, Data * data)
{

}

static void
quit (GtkWidget * w)
{
  gtk_main_quit ();
}

int
main (int argc, char *argv[])
{
  int i;
  int j;
  GtkWidget *window;
  GtkWidget *sort_p;
  GtkWidget *sort_d;
  GtkWidget *vbox;
  GtkWidget *hbox;
  GtkWidget *b_previously;
  GtkWidget *b_quit;
  GtkWidget *opt;
  GtkWidget *separator;
  GtkWidget *b_next;
  char filename[17];
  GtkWidget *menu1;

  Data *data = NULL;


  gtk_init (&argc, &argv);




  data = malloc (sizeof (*data));
  VER_NULL (data);
  data->ptr = NULL;
  data->sort = SORT_POPULARITY;
  vbox = gtk_vbox_new (FALSE, 0);
  VER_NULL (vbox);
  menu1 = gtk_menu_new ();
  VER_NULL (menu1);
  separator = gtk_hseparator_new ();
  VER_NULL (separator);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  VER_NULL (window);
  opt = gtk_option_menu_new ();
  VER_NULL (opt);
  b_quit = gtk_button_new_with_label ("Quit");
  VER_NULL (b_quit);
  hbox = gtk_hbox_new (TRUE, 0);
  VER_NULL (hbox);
  data->table = gtk_table_new (3, 4, TRUE);
  VER_NULL (data->table);
  b_next = gtk_button_new_with_label ("Next");
  VER_NULL (b_next);
  b_previously = gtk_button_new_with_label ("Previously");
  VER_NULL (b_previously);
  sort_d = gtk_menu_item_new_with_label ("Date");
  VER_NULL (sort_d);
  sort_p = gtk_menu_item_new_with_label ("Popularity");
  VER_NULL (sort_p);


  for (i = 0; i < 12; i++)
    {
      data->buttons[i] = gtk_button_new ();
      VER_NULL (data->buttons[i]);
    }

  for (i = 0; i < 12; i++)
    {
      sprintf (filename, "/tmp/image%d.png", i);
      data->images[i] = gtk_image_new_from_file (filename);
      VER_NULL (data->images[i]);

    }


  for (i = 0; i < 4; i++)
    {
      for (j = 0; j < 3; j++)
    {
      gtk_table_attach_defaults (GTK_TABLE (data->table),
                     data->buttons[3 * i + j], j, j + 1, i,
                     i + 1);
    }
    }

  for (i = 0; i < 12; i++)
    {
      gtk_container_add (GTK_CONTAINER (data->buttons[i]), data->images[i]);
    }

  gtk_menu_shell_append (GTK_MENU_SHELL (menu1), sort_d);
  gtk_menu_shell_append (GTK_MENU_SHELL (menu1), sort_p);
  gtk_option_menu_set_menu (GTK_OPTION_MENU (opt), menu1);



  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER_ALWAYS);
  gtk_window_set_title (GTK_WINDOW (window), "ImportImage");
  gtk_container_add (GTK_CONTAINER (window), vbox);

  gtk_box_pack_start (GTK_BOX (vbox), data->table, TRUE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), separator, TRUE, FALSE, 20);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, FALSE, 0);



  gtk_box_pack_start (GTK_BOX (hbox), b_quit, TRUE, TRUE, 10);
  gtk_box_pack_start (GTK_BOX (hbox), opt, TRUE, FALSE, 10);
  gtk_box_pack_start (GTK_BOX (hbox), b_previously, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (hbox), b_next, TRUE, TRUE, 0);



  g_signal_connect (G_OBJECT (b_quit), "clicked", G_CALLBACK (quit), NULL);
  g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (quit), NULL);
  g_signal_connect (G_OBJECT (sort_d), "activate", G_CALLBACK (cb_menu),
            (gpointer) data);


  gtk_widget_show_all (window);
  gtk_main ();
  return 0;

}


Last edited by scriptoff on Mon Apr 09, 2007 7:09 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 09, 2007 5:23 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
When declaring your images and button arrays you're only declaring 11 elements so when you loop through the buttons you're exceeding the bounds of the array into the table variable which results in a call to gtk_button_new() on the table data member.

Do this:

Code:
struct Data_s
{
  int sort;
  char **ptr;
  GtkWidget *images[12];  // 12 total elements, 0-11
  GtkWidget *buttons[12]; // 12 total elements, 0-11
  GtkWidget *table;
};
typedef struct Data_s Data;

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 09, 2007 7:08 pm 
Offline
Familiar Face

Joined: Mon Apr 09, 2007 2:09 pm
Posts: 10
Thanks , That's not possible i'm really stupid


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group