gui interface with gtk




Hi, i'm trying to make a simple interface to display images from a frameGrabber(FG). In one window i
displays images and another window displays buttons, bars, etc.  i obtain the images calling a
method that read from the FG, so a while loop call this method, to display images continously. The
problem is when i lanch the program i can't see the buttons, bars, etc from the other window, while
the loop is running, when i replace the while loop to a for loop, with 20 rounds, i can't see
nothing else images before the for loop is complete, when the loop is complete the buttons appear. I
have also try making two thread one for the window(images) and other for window two, but the problem
is the same,  nothing
 else images, when the loop is running.  i'll appreciate any help. thanks.

The code i'm using is:.


* For gettimeofday */
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <pthread.h>


#include "FrameGrabber_Imaging_PC_COMP.hh"
#include "gtk.h"


FrameGrabber_Imaging_PC_COMP *pGrabber;
void  *image_mmaped;
int nImSize;

pthread_t thread1,thread2;

guchar bufIm[384*288*20];
guchar *pImColor;

GtkWidget *window;
GtkWidget *window2;
GtkWidget *vbox;
GtkWidget *vbox2;
GtkWidget *button;
GtkWidget *button2;
GtkWidget *drawing_area;
GtkWidget *drawing_area2;
GtkWidget *aspect_frame;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *box;
GtkWidget *vpaned;

GtkWidget *main_vbox;

GtkWidget *hbox;
GtkWidget *frame_horz;
GtkWidget *frame_vert;


int SiguienteFrame();
void *WindowOne(void *);
void *WindowTwo(void *);


gint delete_event(GtkWidget *widget,GdkEvent *event,gpointer data){
  gtk_main_quit();
  return false;
}


static void quit_func (GtkWidget *widget, gpointer dummy)
{
  gtk_main_quit ();
  pthread_exit(&thread1);
  pthread_exit(&thread2);

}

#define WIDTH 384
#define HEIGHT 288

gdouble get_time (void)
{
  struct timeval tv;
  struct timezone tz;

  gettimeofday (&tv, &tz);

  return tv.tv_sec + 1e-6 * tv.tv_usec;
}

#define NUM_ITERS 100



void testrgb_rgb_test (GtkWidget *drawing_area){


  printf("pImColor=%d\n",pImColor);
  printf("bufIm=%d\n",bufIm);

  while(true){     /*  for(int i=0;i<20;i++){*/
    SiguienteFrame();    /*read images from the FG*/

      gdk_draw_gray_image (drawing_area->window,
         drawing_area->style->white_gc,
         0, 0, WIDTH+10, HEIGHT+10, GDK_RGB_DITHER_NONE,
   bufIm, WIDTH);}


}
void *WindowTwo(void *){

window2 = gtk_widget_new (gtk_window_get_type (),
      "GtkObject::user_data", NULL,
      "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
      "GtkWindow::title", "ventana dos",
      "GtkWindow::allow_shrink", FALSE,
      NULL);

 gtk_signal_connect (GTK_OBJECT (window2), "destroy",
        (GtkSignalFunc) quit_func, NULL);

 vbox2 = gtk_vbox_new (FALSE, 0);
 drawing_area2 = gtk_drawing_area_new ();
 gtk_widget_set_usize (drawing_area2, 400, 300);
 gtk_box_pack_start (GTK_BOX (vbox2), drawing_area2, FALSE, FALSE, 0);

 button2 = gtk_button_new_with_label ("Quit 2");

 gtk_widget_show (drawing_area2);
 gtk_box_pack_start (GTK_BOX (vbox2), button2, FALSE, FALSE, 0);

 gtk_signal_connect_object (GTK_OBJECT (button2), "clicked",
        (GtkSignalFunc) gtk_widget_destroy,
        GTK_OBJECT (window2));


 gtk_widget_show (button2);
 gtk_container_add (GTK_CONTAINER (window2), vbox2);
 gtk_widget_show (vbox2);
 gtk_widget_show (window2);

 return 0;

}


void *WindowOne (void *){

  window = gtk_widget_new (gtk_window_get_type (),
      "GtkObject::user_data", NULL,
      "GtkWindow::type", GTK_WINDOW_TOPLEVEL,
      "GtkWindow::title", "ventana uno",
      "GtkWindow::allow_shrink", FALSE, NULL);

  gtk_signal_connect (GTK_OBJECT (window), "destroy",
        (GtkSignalFunc) quit_func, NULL);


  vbox = gtk_vbox_new (FALSE, 0);
  drawing_area = gtk_drawing_area_new ();

  gtk_widget_set_usize (drawing_area, 400, 300);
  gtk_box_pack_start (GTK_BOX (vbox), drawing_area, FALSE, FALSE, 0);
  gtk_widget_show (drawing_area);

  button = gtk_button_new_with_label ("Quit");

  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

  gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
        (GtkSignalFunc) gtk_widget_destroy,
        GTK_OBJECT (window));

  gtk_widget_show (button);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show (vbox);
  gtk_widget_show (window);

  testrgb_rgb_test (drawing_area);

 return 0;

}
int SiguienteFrame(){

  pGrabber->LeeImagen(pImColor);

return 0;
}



int main (int argc, char **argv){

  pGrabber=new FrameGrabber_Imaging_PC_COMP();
  pGrabber->GrabacionContinua();

  gtk_init (&argc, &argv);

  gdk_rgb_set_verbose (TRUE);
  pImColor=bufIm;
  gdk_rgb_init ();

  gtk_widget_set_default_colormap (gdk_rgb_get_cmap ());
  gtk_widget_set_default_visual (gdk_rgb_get_visual ());

  pthread_create(&thread1,NULL,WindowOne,NULL);  /*threaded version*/
  pthread_create(&thread2,NULL,WindowTwo,NULL);

  //WindowOne();
  //WindowTwo();      /* original*/

  pthread_join(thread1,NULL);
  pthread_join(thread2,NULL);

gtk_main ();

  return 0;


}



Luis Mejias
lmejias hotmail com
__________________________
Computer Vision Group
http://www.disam.upm.es/vision
DISAM
ETS Ingenieros Industriales
Jose Gutierrez Abascal, 2
28006 MADRID (SPAIN)
phone: +34 91 7454660
           +34 91 3363061
fax:      +34 91 3363010
___________________________




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