Is the window disappearing or is the script exiting? I know with POE::Loop::Wx you sometimes need to add a keep alive loop in POE...

On 03/01/08 06:04 PM, Jamie Lahowetz wrote:
I would like to create a Gtk2 based Chat client that can be used with the
chat server on the POE cookbook. To do this I have to sort of reteach myself
on using Gtk2 in the POE loop. Currently I am trying to get the program to
create a simple window. I'm having trouble with this, the window seems to
just disappear with no warnings. Any ideas?

#!/usr/bin/perl
use warnings;
use strict;

use Gtk2 -init;
use Glib qw/TRUE FALSE/;
use POE::Kernel { loop => "Glib" };
use POE::Session;

# Create the session that will drive the user interface.

POE::Session->create(
    inline_states => {
        _start   => \&ui_start,
        #ev_count => \&ui_count,
        #ev_clear => \&ui_clear,
      }
);

# Run the program until it is exited.

$poe_kernel->run();
exit 0;

sub ui_start {
    my ( $kernel, $session, $heap ) = @_[ KERNEL, SESSION, HEAP ];

    $heap->{main_window} = Gtk2::Window->new("toplevel");
    $kernel->signal_ui_destroy( $heap->{main_window} );

    my $table = Gtk2::Table->new(3, 1, FALSE);

    my $label = Gtk2::Label->new("Chat Client Test");

    $table->attach_defaults($label, 0, 1, 0, 1);

    my $buffer = Gtk2::TextBuffer->new;
    my $textview = Gtk2::TextView->new_with_buffer( $buffer);

    $table->attach_defaults($textview, 0, 1, 1, 2);

    my $button = Gtk2::Button->new("Connect");

    $table->attach_defaults($button, 0, 1, 2, 3);

    $heap->{main_window}->add($table);

    $heap->{main_window}->show_all();
}

Reply via email to