Trying to create a menu from file input



Does anyone have any insight into how I might read a file (which might
change from day to day) into a Gtk program and create an OptionMenu from
the list, and upon selection of the option menu, update a text entry
field?

--- snippet from the function creating the optionmenu

  clientMenu1_menu = gtk_menu_new ();
  glade_menuitem = gtk_menu_item_new_with_label (_("Clients"));
  gtk_widget_show (glade_menuitem);
  gtk_menu_append (GTK_MENU (clientMenu1_menu), glade_menuitem);
 
  if((clientList=fopen("client_list","r"))==NULL) {
     fprintf(stderr,"Could not open client list file.  Should be in same
directory as ListEditor binary.\n");
     exit(-1);
  }

  while(!feof(clientList)) {
     bzero(clientName,30);
     fscanf(clientList,"%[^,]%s%*['\n']",clientName,junk);
     glade_menuitem = gtk_menu_item_new_with_label (_(clientName));
     gtk_signal_connect_object(GTK_OBJECT(glade_menuitem),
"activate",GTK_SIGNAL_FUNC(client_select1),GTK_OBJECT(glade_menuitem));
     gtk_menu_append (GTK_MENU (clientMenu1_menu), glade_menuitem);
     gtk_widget_show (glade_menuitem);
  }

  fclose(clientList);

  gtk_option_menu_set_menu (GTK_OPTION_MENU (clientMenu1),
clientMenu1_menu);
----

--- snippet from the callbacks funtions

extern GtkWidget
*clientEntry1,*clientEntry2,*actionEntry1,*actionEntry2;

void
client_select1           (GtkObject       *selectedItem,
                                        gpointer         user_data)
{
   GtkLabel *label;
   gchar textData[80];
   /*gtk_label_get(GTK_LABEL(GTK_BIN(selectedItem)->child),&textData);*/
   label=GTK_LABEL(GTK_BIN(user_data)->child);
   gtk_label_get(label,textData);
   gtk_entry_set_text(GTK_ENTRY(clientEntry1),textData);
}

-----

Errors received:
leah% ./listedit

Gtk-WARNING **: invalid cast from (NULL) pointer to `GtkLabel'

Gtk-CRITICAL **: file gtklabel.c: line 333 (gtk_label_get): assertion
`label != NULL' failed.

---

I believe that it caused by the menu creation that I am attempting not
creating a unique menuitem object and overwriting the last one.  Not
sure how the gtk_signal_connect_object() function creates the signal...
Any help is most welcome.
Thanks,
Bob O'Connor

Attachment: roconnor.vcf
Description: Card for Bob O'Connor



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