Re: Newbie: How to program window -> serial code -> window?

On Jul 6, 2005, at 1:31 AM, Tokuyasu, Taku wrote:

I’m trying to do the following:

Open up a window (Entry) to get filenames
Close the window, and make a system call to an executable with the above filename arguments Open up a different window when the system call finishes (e.g. a dialog box with different options) I’m not sure if this is obvious or not. I tried simply duplicating a code block starting with “use Gtk2 '-init':” and ending with “Gtk2->main;”, with the system call in between, but the first window did not disappear after quit’ing the window, instead hanging around until the second window quit.
The second "use Gtk2 -init" is unnecessary; the initialization only does anything the first time.

You don't "quit a window" -- you quit an event loop (referred to as a "main loop"). In many of the small examples shown here on the list, we set up the window to kill the main loop on the window's destruction, like this:

   $window->signal_connect (destroy => sub {Gtk2->main_quit});

That says, "when the window is destroyed, stop the main loop". The destruction of the window is triggered elsewhere, such as by the default handler for the window's delete-event.

You must either ->hide or ->destroy a window to remove it from the screen. The first window stays visible because you never told it not to be.

A reasonable template would be:

   use Gtk2 -init;
   # assume create_first_dialog is a function that creates a
   # Gtk2::Dialog with the desired action buttons.
   $dialog = create_first_dialog ();
   $response = $dialog->run;
   $dialog->destroy;  # remove the dialog from the screen
   exit 0 if $response ne 'ok';

   @input = `$command`;  # program blocks here while reading input

   $dialog = create_second_dialog (@input);

Of course, if you want the ui to remain responsive during the call- out so that you can display progress or something like that, you need to take other measures. Look in the FAQ under "how do i keep my UI responsive during long file reads?"

If I lived in Teletubby Land, the homicide rate would be four.
  -- elysse

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