Pausing durring widget creation...



I am working on an application that has the option of either a
horizontally paned section, or the main window + another additional
window. I switch modes by clicking on a button, and generally,
everything works just fine.

<Code Snippet>
void do_switcheroo(GtkWidget *widget, gpointer data)
{
   if(GTK_IS_WIDGET(list_window))
   {
      switch_back(widget, data);
   }
   else
   {
      gtk_widget_set_sensitive(switch_button, FALSE);
      gtk_widget_hide(cur_project->hbox);
      gtk_label_set_text(GTK_LABEL(switch_label), ">");
      gtk_widget_ref(clist_window);
      gtk_widget_ref(edit_box);
      gtk_container_remove(GTK_CONTAINER(paned), clist_window);
      gtk_container_remove(GTK_CONTAINER(paned), edit_box);
      gtk_box_pack_start(GTK_BOX(main_window_box), edit_box, TRUE, TRUE,
0);
      gtk_widget_hide(paned);
      gtk_widget_unref(edit_box);

      list_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_container_set_border_width(GTK_CONTAINER(list_window), 5);
      gtk_signal_connect(GTK_OBJECT(list_window), "delete_event",
GTK_SIGNAL_FUNC(switch_back), NULL);
      gtk_container_add(GTK_CONTAINER(list_window), clist_window);
      gtk_widget_unref(clist_window);
      gtk_widget_show(list_window);
      gtk_widget_show(cur_project->hbox);
      gtk_widget_set_sensitive(switch_button, TRUE);
   }
}


void switch_back(GtkWidget *widget, gpointer data)
{
   gtk_widget_set_sensitive(switch_button, FALSE);
   gtk_widget_hide(cur_project->hbox);
   gtk_label_set_text(GTK_LABEL(switch_label), "<");
   gtk_widget_ref(clist_window);
   gtk_widget_ref(edit_box);
   gtk_container_remove(GTK_CONTAINER(list_window), clist_window);
   gtk_paned_add1(GTK_PANED(paned), clist_window);
   gtk_container_remove(GTK_CONTAINER(main_window_box), edit_box);
   gtk_paned_add2(GTK_PANED(paned), edit_box);
   gtk_paned_set_position(GTK_PANED(paned), 100);
   gtk_widget_show(paned);
   gtk_widget_unref(clist_window);
   gtk_widget_unref(edit_box);
   gtk_widget_destroy(list_window);
   gtk_widget_show(cur_project->hbox);
   gtk_widget_set_sensitive(switch_button, TRUE);
}
</Code Snippet>

Like I said, most of the time, everything works just fine. Unfotunatly,
if i get to clicking the button that causes the switch very quickly, I
start getting errors, and eventually a crash. Im guessing that I need to
just slow down the end of the two functions, of to add a condition that
a particular widget had to be in a particular state. My problem is, i
dont know what that state is... I have tried GTK_WIDGET_MAPPED() and
VISIBLE and others, but it always ends up crashing...I know this isnt
really a big deal, as no one should ever be clicking my button 5 times a
seccond, but i want this app to be bulletproof, so im taking all
neccessary precautions.

Thanks for any help,
Chicane



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