How to close FileChooserDialog immediately after selection of file?



In my program a file gets chosen and then a routine taking this file as
parameter starts which takes some time.
My problem is: the FileChooserDialog closes only _after_ the routine has
finished. 
I want the Dialog to be closed _before_ the routine starts.

I have tried it with FileChooserButton and with a separate Button which
calls a FileChooserDialog. For the last version I posted a Code Snippet. in
void on_button3_clicked() I would expect (and like to have) that
 
fcd1->hide(); //should close the dialog

works before the 

sleep(3)-statement in switch(res), 

however the hide() statement which should close the dialog comes into effect
after the sleep(3);
sleep(3); stands for the routine which takes some time.

do you have any suggestions?

With best argnu

// ------------------------------------------

Gtk::Window *win=NULL;
Gtk::Label *resultlabel=NULL;
Gtk::Toolbar *toolbar1=NULL;

std::string gladefile="/home/binder/tmp/bla/bla.glade";
Glib::RefPtr<Gnome::Glade::Xml> refXml;

void on_button3_clicked()
{
	toolbar1->freeze_child_notify();

   Gtk::FileChooserDialog *fcd1=NULL;
   refXml->get_widget("filechooserdialog1", fcd1);

   fcd1->show();	
   int res=fcd1->run();
   std::string filename = fcd1->get_filename();


   fcd1->hide();
   std::cout << "after hide "<<std::endl;

   fcd1=NULL;

  switch(res)
  {
    case(Gtk::RESPONSE_OK):
    {
     	std::cout << "Open clicked." << std::endl; 
      	std::cout << "File selected: " <<  filename << std::endl;

	std::cout << "sleeping 3"<<std::endl;

	sleep(3);

	std::cout << "FINISHED sleeping 3"<<std::endl;

      break;
    }
    case(Gtk::RESPONSE_CANCEL):
    case(Gtk::RESPONSE_DELETE_EVENT):
    {
      std::cout << "Cancel or X clicked." << std::endl;
      break;
    }
    default:
    {
      std::cout << "Unexpected button clicked." << std::endl;
      break;
    }
  }

toolbar1->thaw_child_notify();
}


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

     Gtk::Main kit(argc, argv);
     refXml = Gnome::Glade::Xml::create(gladefile);

  //toolbar1 and resultlabel is init'ed here,too, its not a leak
...


    Gtk::Button* pButton = NULL;
    refXml->get_widget("button3", pButton);

     pButton->signal_clicked().connect( sigc::ptr_fun(on_button3_clicked) );

     refXml->get_widget("window1", win);
     kit.run(*win);

}
-- 
View this message in context: http://www.nabble.com/How-to-close-FileChooserDialog-immediately-after-selection-of-file--tp20548033p20548033.html
Sent from the Gtkmm mailing list archive at Nabble.com.



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