one optionmenu affecting the contents of another?
- From: Emil Malmberg <emil iconmedialab dk>
- To: gtk-list redhat com
- Subject: one optionmenu affecting the contents of another?
- Date: Tue, 19 Oct 1999 10:01:12 +0200 (CEST)
Hi!
I'm having some problems with a couple of optionmenues. I want the first
one to switch the contents of the other one. I've tried to do this by
creating a list of menues, and attaching a function to the first
optionmenu that replaces the menu in the second optionmenu by an
associated menu. (phew...)
It works ok when I select items from the first optionmenu with increasing
indices, but if I try to go "back" then I receive this error message:
Gtk-CRITICAL **: file gtkoptionmenu.c: line 191
(gtk_option_menu_set_menu): assertion `GTK_IS_MENU (menu)' failed.
This is (part of) my code, the part that I guess is relevant. I have
deliberately removed things like include files, main window definitions
etc.
struct proj_def {
char *name;
GQuark quark;
GList *activities;
GtkWidget *drop_down_activities;
};
struct act_def {
char *name;
GQuark quark;
};
GtkWidget *drop_down_projects;
GtkWidget *drop_down_projects_box, *drop_down_activities_box;
int main(int argc,char *argv[]) {
gtk_init(&argc, &argv);
parseRC(rc);
// create and pack the drop down boxes:
drop_down_projects_box = gtk_option_menu_new();
drop_down_activities_box = gtk_option_menu_new();
gtk_table_attach_defaults(GTK_TABLE (mainbox), drop_down_projects_box, 1, 2, 0, 1);
gtk_table_attach_defaults(GTK_TABLE (mainbox), drop_down_activities_box, 1, 2, 1, 2);
gtk_option_menu_set_menu(GTK_OPTION_MENU (drop_down_projects_box),drop_down_projects);
gtk_option_menu_set_menu(GTK_OPTION_MENU (drop_down_activities_box), ((struct proj_def *) g_list_nth_data(project_list, 0))->drop_down_activities);
gtk_widget_show(drop_down_projects_box);
gtk_widget_show(drop_down_activities_box);
gtk_main();
return(0);
}
void switchActivities(GtkWidget *widget, gpointer data) {
printf("Switching activities (%d)\n", (int) data);
// This is where I get the error. I've checked to see that (int) data returns the correct value.
gtk_option_menu_set_menu(GTK_OPTION_MENU (drop_down_activities_box), ((struct proj_def *) g_list_nth_data(project_list, (int) data))->drop_down_activities);
printf("...done\n");
}
int parseRC(FILE *rc) {
struct proj_def *new_project;
struct act_def *new_activity;
GtkWidget *item;
char *line;
project_list = NULL;
drop_down_projects = gtk_menu_new();
// parsing a startup file, line by line, identifying project
// definitions and activity definitions as we go along.
EITHER THIS:
// we've got a syntactically correct, non-empty activity declaration.
if ((new_activity = (struct act_def *) calloc(1, sizeof(struct act_def))) == NULL) {
perror("Memory allocation error");
exit(1);
}
if ((new_activity->name = (char *) calloc(strlen(line) - 1, sizeof(char))) == NULL) {
perror("Memory allocation error");
exit(1);
}
strncpy(new_activity->name, line, strcspn(line, ";"));
new_activity->quark = g_quark_from_string(new_activity->name);
((struct proj_def *) g_list_nth_data(project_list, index))->activities = g_list_append(((struct
proj_def *) g_list_nth_data(project_list, index))->activities, (gpointer) new_activity);
item = gtk_menu_item_new_with_label(new_activity->name);
gtk_widget_show(item);
gtk_menu_append(GTK_MENU (((struct proj_def *) g_list_nth_data(project_list, index))->drop_down_activities),
item);
OR THIS HAPPENS:
// we've encountered a syntactically correct, non-empty project declaration.
if ((new_project = (struct proj_def *) calloc(1, sizeof(struct proj_def))) == NULL) {
perror("Memory allocation error");
exit(1);
}
if ((new_project->name = (char *) calloc(strlen(line) - 1, sizeof(char))) == NULL) {
perror("Memory allocation error");
exit(1);
}
strncpy(new_project->name, line, strcspn(line, "{"));
new_project->quark = g_quark_from_string(new_project->name);
new_project->activities = NULL;
new_project->drop_down_activities = gtk_menu_new();
project_list = g_list_append(project_list, (gpointer) new_project);
item = gtk_menu_item_new_with_label(new_project->name);
// I'm guessing my problem lies somewhere around here...
// index is a variable that starts out at zero and increases by one every time a new froject definition is found.
gtk_signal_connect(GTK_OBJECT (item), "activate",
GTK_SIGNAL_FUNC(switchActivities), (gpointer) index);
gtk_widget_show(item);
gtk_menu_append(GTK_MENU (drop_down_projects), item);
OK one last remark. I'm a GTK newbie (started out last week), so it is
utterly possible that my problem is a very simple / common one. However, I
have searched the FAQ, Tutorial and references without finding the answer.
Thank you very much for your time.
regards, Emil
-----
Emil Malmberg
Programmer
Icon Medialab Denmark
+45 3338 1458
emil@iconmedialab.dk
www.iconmedialab.dk
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]