Book Annotation - Pro PHP-GTK - pg 67 - Can a Gtk::WINDOW_POPUP be a top-level window?
I have been learning PHP-GTK. I was reading Chapter 5 of the Pro PHP-GTK book by Scott Mattocks, published by Apress (published 2006) and on page 67 it says:
“The constructor for GtkWindow takes one argument, which is the window type. The window type should either be Gtk::WINDOW_TOPLEVEL or Gtk::WINDOW_POPUP.”
It is Gtk::WINDOW_TOPLEVEL by default.
So, either Gtk::WINDOW_TOPLEVEL or Gtk::WINDOW_POPUP.
So, I wondered, if we pass an argument to the constructor of GtkWindow that is NOT “Gtk::WINDOW_TOPLEVEL”, does that mean it cannot be treated like a top level window? In other words I wondered if it meant that it MUST, at some point, be a child of some other top-level window.
Well, as the code (below) shows, the answer is no.Despite the fact that it is not passed “Gtk::WINDOW_TOPLEVEL”, you CAN create a window passing Gtk::WINDOW_POPUP as the argument to the constructor, AND that window CAN stand alone. I suppose “Gtk::WINDOW_TOPLEVEL”, in this instance is refering to its appearance more than its behaviour.
In some respects, I guess Gtk::WINDOW_TOPLEVEL means “top-level and decoratable” whereas Gtk::WINDOW_POPUP seems to mean “top-level and not decoratable”.
However, it probably makes more sense to create a Top-Level window if that is what you will be using it for.
<?php
//create a window with the alternative to Gtk::WINDOW_TOPLEVEL
$window = new GtkWindow(Gtk::WINDOW_POPUP);
//commented out for experimentation
//$window = new GtkWindow(Gtk::WINDOW_TOPLEVEL);
//create button
$button = new GtkButton(’close’);
//add the widnow to the button
$window->add($button);
//connect a signal handler to close the app
$button->connect_simple(’clicked’,array(’gtk’,'main_quit’));
//just here cos i am in the habit of writing this
$window->connect_simple(’destroy’,array(’gtk’,'main_quit’));
$window->show_all();
Gtk::main();
//this creates a Gtk::WINDOW_POPUP window as a top-level window without any fuss.
