Yah that was the problem, there was no loop and therefore the app ended. I
got it working by creating the main Gtk2 loop.

I have ran into another problem. I am trying to add the client session to
the app and have been getting errors on it. I think these errors have to do
with my lack of knowledge on POE. These errors are:

syntax error at chat-client.pl line 75, near "ConnectError"
Can't use global @_ in "my" at chat-client.pl line 76, near "= @_"
syntax error at chat-client.pl line 85, near ")"

the code:


#!/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}
);

#start the UI interface (Main windowed)
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, 2, FALSE);

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

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

    #my $buffer = Gtk2::TextBuffer->new;

    $heap->{buffer} = Gtk2::TextBuffer->new;

    my $textview = Gtk2::TextView->new_with_buffer( $heap->{buffer});
    $textview->set_cursor_visible (FALSE);
    my $swindow = Gtk2::ScrolledWindow->new( undef, undef);
    $swindow->set_policy( 'automatic', 'automatic');
    $swindow->set_shadow_type( 'etched-out');

    $swindow->add( $textview);

    my $entry = Gtk2::Entry->new();

    $table->attach_defaults($label, 0, 1, 0, 1);
    $table->attach_defaults($swindow, 0, 2, 1, 2);
    $table->attach_defaults($entry, 0, 1, 2, 3);
    $table->attach_defaults($button, 1, 2, 2, 3);
    $heap->{main_window}->add($table);

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

    spawn_client();

    gtk2->main;
}

###################################################################################################

###################################################################################################

#start the client session
sub spawn_client {
    my $host   = "Deadpickle-hobo";
    my $port   = 11211;

    POE::Component::Client::TCP->new(
        RemoteAddress => $host,
        RemotePort => $port,
        Connected  => sub {
            #print "connected to $host:$port ...\n";},
            my ( $kernel, $heap) = @_[ KERNEL, HEAP];
            $heap->{buffer}->set_text("connected to $host:$port ...\n");
        }
        ConnectError => sub {
            my ( $kernel, $heap) = @_[ KERNEL, HEAP];
            #print "could not connect to $host:$port ...\n";},
            $heap->{buffer}->set_text("could not connect to $host:$port
...\n");
        }
        ServerInput => sub {
            my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP, ARG0 ];
            #print $input. "\n";
            $heap->{buffer}->set_text($input);
        }
    );
}

###################################################################################################

$poe_kernel->run();
exit 0;


On Jan 4, 2008 10:02 AM, Mike Schroeder <[EMAIL PROTECTED]> wrote:

> 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();
> > }
> >
> >
>



-- 
Jamie Ryan Lahowetz
University of Nebraska - Lincoln
Graduate Student - Geosciences
249 Hardin Hall, Section 21
402.304.0766
[EMAIL PROTECTED]

Reply via email to