[vtkusers] VTK + GTK

Zampini Samuele samuele.zampini at epfl.ch
Tue Aug 4 10:08:59 EDT 2009


Hi all,

I am trying to create a button in glade in order to open a VTK window in my GUI.

Actually, I am finding it very difficult. The button seems to work but the window doesn't appear.

==========================================================================================
This is my function:

extern "C" void on_aprire_vmtk_clicked(GtkToggleButton *togglebutton,gpointer user_data)
{
printf("The button works\n");

//This is a sentence I write in my Terminal to check that my button works.


add_vtk_widget_to_container("vbox2",1,1,0);

}
==========================================================================================

==========================================================================================
Where add_vtk_widget_to_container("vbox2",1,1,0) is the following function:

void add_vtk_widget_to_container(const gchar *container_name,gboolean expand,gboolean fill,guint padding)
{
   //Create the gtk vtk interactor. This also creates the gtk widget.
   vtkGtkRenderWindowInteractor *iren = vtkGtkRenderWindowInteractor::New();

   // Connect the renderer to the gtk vtk rendering window
   vtkRenderer *scene = create_scene();
   iren->GetRenderWindow()->AddRenderer(scene);

   GtkWidget *vbox = lookup_widget (container_name);

   gtk_box_pack_start (GTK_BOX (vbox),iren->get_drawing_area(),expand,fill,padding);

}
==========================================================================================

==========================================================================================
On the contraty, if I call the function in the main script, the windows appear but, of course, it appears immediately and
not when I want it to appera (clicking the button).
I am posting the main too.
Now the line wth 

add_vtk_widget_to_container("vbox2",1,1,0);

is commented, since I want to open my  windows throught the button.
Any idea???


int GUI_N_OBJECTS=0;
typedef struct {char *name;GtkWidget *pointer;} gui_object;
gui_object *GUI_LOOKUP_TABLE;


int main (int argc, char *argv[])
{
   GtkBuilder *builder;
   GtkWidget *window;

   gtk_init (&argc, &argv);
   gtk_gl_init(&argc, &argv);

   builder = gtk_builder_new();
   gtk_builder_add_from_file (builder, argv[1], NULL);
   build_lookup_table(builder);
   window = GTK_WIDGET (gtk_builder_get_object (builder, "main_win"));
   gtk_builder_connect_signals (builder, NULL);
   gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, TRUE);
//   add_vtk_widget_to_container("vbox2",1,1,0);
//   g_object_unref (G_OBJECT (builder));
        
   gtk_widget_show_all (window);
   gtk_main ();

   return 0;
}


Thanks a lot for your great help,
Samuele






More information about the vtkusers mailing list