// Simple image viewing program. Loads all images on the command line

// Number of windows, and the destroy handler. When all windows are
// gone, exit the program.
int window;
void window_gone() {  if(!--window) exit(0); }

// The function that loads the image and displays it in a window.
void load_image( string i )
{
  if( mapping image = GTK.Util.load_image( i ) )
    GTK.Window( GTK.WindowToplevel )->set_policy( 0,0,1 )
      ->add( GTK.Pixmap( image->img ) )->show_all()->set_title( "PV: "+i)
      ->signal_connect( "destroy", window_gone );
  else
    GTK.Alert("Failed to load the image '"+i+"'")
	->signal_connect( "destroy", window_gone );
}

int main(int argc, array argv)
{
  argv = GTK.setup_gtk( argv );
  window = sizeof(argv)-1;
  foreach(argv[1..], string i)
    load_image( i );
  return -1; // Let the backend take over. From now on it's all event driven
}
