Sample Code 404: How to open one window from another window - Part 1 - using GtkDialog? |
|
Written by kksou
|
|
Wednesday, 09 January 2008 |
|
Problem Suppose you have set up an application that first displays a menu (let's call this app A). When the user selects an option, the corresponding application (let's call this B) will be launched as shown below:

Solution
- In this Part 1, we make use of GtkDialog instead of GtkWindow.
- With GtkDialog, you do not need to worry about how to pass the GTK main loop back and forth between app A and app B.
- The use of GtkDialog::run() and GtkDialog::destroy() simplify things a lot.
Sample Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| <?php setup_appA(); // note 1
function setup_appA() { $dialog = new GtkDialog(); $dialog->set_size_request(400, 200); $vbox = $dialog->vbox;
// display title
$title = new GtkLabel("Opening app B from app A\n". " Part 1 - using GtkDialog"); $title->modify_font(new PangoFontDescription("Times New Roman Italic 10")); $title->modify_fg(Gtk::STATE_NORMAL, GdkColor::parse("#0000ff")); $title->set_size_request(-1, 40); $vbox->pack_start($title, 0, 0);
$vbox->pack_start(new GtkLabel('This is app A'));
$vbox->pack_start($hbox = new GtkHBox(), 0); $hbox->pack_start(new GtkLabel()); $hbox->pack_start($button = new GtkButton('Launch app B'), 0); $hbox->pack_start(new GtkLabel()); $vbox->pack_start(new GtkLabel()); $button->connect('clicked', 'on_click', $dialog, 'A');
$dialog->set_has_separator(false); $dialog->show_all(); $dialog->run(); $dialog->destroy(); }
function on_click($button, $dialog, $id) { echo "on_click: $id!\n"; $dialog->destroy(); // note 2
if ($id=='A') { setup_appB(); // note 3
} elseif ($id='B') { setup_appA(); // note 4
} }
function setup_appB() {
|
- Note that this is only 70% of the sample code. You have to be a registered member to see the entire sample code. Please login or register.
- Registration is free and immediate.
- Have some doubt about the registration? Please read this forum article.
Explanation
- Set up and display app A.
- To launch app B, we first destroy dialog A.
- Then set up and display app B.
- From app B back to app A, we first destroy dialog B, then set up and display app A.
Related Links
User reviews There are no user reviews yet. Note: You have to be a registered member to leave a comment. Free registration here. |