Problem with Gtk2 and POE

Discussion in 'Perl Misc' started by Krisztian VASAS, Jun 28, 2004.

  1. Hello all...


    I have a big problem with Gtk2 and POE (or I'm too stupid to the POE)...

    Between the POE examples, there is a Gtk Interface (small counter)...
    I've tried to rewrite it in Gtk2, but didn't want to work.

    Neither the $kernel->yield("state_name"), nor the
    $session->postback("state_name") works...

    The Gtk2 interface starts, but if I press the button, nothing happens.
    If I close the window, perl writes this:
    "POE::Kernel's run() method was never called."

    I can't understand this, because the first part of the script hasn't
    changed:

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

    But when I press the button, the signal_connect doesn't want to run the
    $session->postback("ev_clear") command...

    Can anyone tell me, why?


    IroNiQ
    --
    Web: http://ironiq.hu
    Email:
    LinuxCounter: #331532
     
    Krisztian VASAS, Jun 28, 2004
    #1
    1. Advertising

  2. Krisztian VASAS

    Rocco Caputo Guest

    On Mon, 28 Jun 2004 19:12:12 +0200, Krisztian VASAS wrote:
    >
    > Hello all...
    >
    >
    > I have a big problem with Gtk2 and POE (or I'm too stupid to the POE)...
    >
    > Between the POE examples, there is a Gtk Interface (small counter)...
    > I've tried to rewrite it in Gtk2, but didn't want to work.
    >
    > Neither the $kernel->yield("state_name"), nor the
    > $session->postback("state_name") works...


    Works here. The program I tested with is nearly the same as the one on
    POE's wiki. I just changed all the "Gtk"s to "Gtk2". Here's a copy:

    #!/usr/bin/perl

    use warnings;
    use strict;

    use Gtk2;
    use POE;

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

    $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 $box = Gtk2::VBox->new( 0, 0 );
    $heap->{main_window}->add($box);
    $box->show();

    my $label = Gtk2::Label->new("Counter");
    $box->pack_start( $label, 1, 1, 0 );
    $label->show();

    $heap->{counter} = 0;
    $heap->{counter_label} = Gtk2::Label->new( $heap->{counter} );
    $box->pack_start( $heap->{counter_label}, 1, 1, 0 );
    $heap->{counter_label}->show();

    my $button = Gtk2::Button->new("Clear");
    $button->signal_connect( "clicked", $session->postback("ev_clear") );
    $box->pack_start( $button, 1, 1, 0 );
    $button->show();

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

    $kernel->yield("ev_count");
    }

    sub ui_count {
    my ( $kernel, $heap ) = @_[ KERNEL, HEAP ];
    $heap->{counter_label}->set_text( ++$_[HEAP]->{counter} );
    $kernel->yield("ev_count");
    }

    sub ui_clear {
    $_[HEAP]->{counter} = 0;
    }

    __END__

    --
    Rocco Caputo - http://poe.perl.org/
     
    Rocco Caputo, Jun 28, 2004
    #2
    1. Advertising

  3. Rocco Caputo wrote this on 2004-06-28 19:48:
    > Works here. The program I tested with is nearly the same as the one on
    > POE's wiki. I just changed all the "Gtk"s to "Gtk2". Here's a copy:


    Problem solved...

    Wasn't installed the POE::Loop::Gtk2...


    IroNiQ
    --
    Web: http://ironiq.hu
    Email:
    LinuxCounter: #331532
     
    Krisztian VASAS, Jun 28, 2004
    #3
  4. > Rocco Caputo wrote this on 2004-06-28 19:48:
    >
    >> Works here. The program I tested with is nearly the same as the one on
    >> POE's wiki. I just changed all the "Gtk"s to "Gtk2". Here's a copy:

    >
    >
    > Problem solved...
    >
    > Wasn't installed the POE::Loop::Gtk2...


    Well, now works quiet well, but I have another problem and I can't
    decide what's the problem...

    I write a small chat client... I use POE to handle the net connection
    and the Gtk2 UI... The POE::Session starts the main window... If the
    main window is ready, calls the login window...
    If I miss calling the login window and connect to the server, the
    program works good...
    If I call the login window, the program gets a stop signal
    (POE::Session->create( inline_states => _stop)...

    I've tried to reduce the program to the smallest amount code that still
    triggers the problem and looks like this is Gtk2's (?) fault.

    Here's the code: http://www.nomorepasting.com/paste.php?pasteID=15366

    Thanks...


    IroNiQ
    --
    Web: http://ironiq.hu
    Email:
    LinuxCounter: #331532
     
    Krisztian VASAS, Jun 29, 2004
    #4
  5. Krisztian VASAS

    Rocco Caputo Guest

    On Tue, 29 Jun 2004 22:15:17 +0200, Krisztian VASAS wrote:
    >
    > Well, now works quiet well, but I have another problem and I can't
    > decide what's the problem...


    [...]

    > I've tried to reduce the program to the smallest amount code that still
    > triggers the problem and looks like this is Gtk2's (?) fault.
    >
    > Here's the code: http://www.nomorepasting.com/paste.php?pasteID=15366


    When I run that code, I get:

    2) poerbook:~/projects/support% perl gtk2-client.perl
    Bareword "menuitem_quit" not allowed while "strict subs" in use \
    at gtk2-client.perl line 73.
    BEGIN not safe after errors--compilation aborted \
    at gtk2-client.perl line 243.

    After I changed line 73 to be

    $window->signal_connect("destroy", \&menuitem_quit );

    I started getting these errors:

    Gtk-WARNING **: gtk_item_factory_create_item(): Can't specify a \
    callback on a branch: "/_File" at gtk2-client.perl line 85.
    Gtk-WARNING **: gtk_item_factory_create_item(): Can't specify a \
    callback on a branch: "/_Settings" at gtk2-client.perl line 85.
    Gtk-WARNING **: gtk_item_factory_create_item(): Can't specify a \
    callback on a branch: "/_Help" at gtk2-client.perl line 85.
    Fontconfig error: Cannot load default config file
    2 -> login (from gtk2-client.perl at 132)
    2 -> _stop (from \
    /Users/troc/projects/poe/poe/lib/POE/Resource/Sessions.pm at 492)

    The Gtk-WARNING lines say you're not setting up @menu_items correctly.
    Sure enough, they go away when I replace the 0 callbacks with undef.

    The \&loginablak callback for "<control>N" should probably be
    $session->postback("login") instead. The program doesn't immediately
    exit when I change it here, but it also doesn't connect to a server when
    I try that.

    Line 203 reads

    $session->postback("ar_conn")

    You probably should add this to gui_start()

    $kernel->alias_set("gui");

    and then replace line 203 with

    $poe_kernel->post("gui", "ar_conn");

    .... and that makes the [Ok] button connect to the server.

    I have placed an updated version of your script at
    http://www.nomorepasting.com/paste.php?pasteID=15396

    Have fun!

    --
    Rocco Caputo - http://poe.perl.org/
     
    Rocco Caputo, Jun 30, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fmp Fmpf
    Replies:
    0
    Views:
    94
    Fmp Fmpf
    May 27, 2008
  2. Krisztian VASAS

    problem between perl-gtk2 and POE::Session

    Krisztian VASAS, Jun 21, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    106
    Rocco Caputo
    Jun 24, 2004
  3. Theo James

    POE and Port Redirection

    Theo James, Sep 18, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    152
    news.hinet.net
    Sep 20, 2004
  4. Kurt M. Weber

    POE::Component::IRC::State and nick changes

    Kurt M. Weber, Nov 9, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    98
    Kurt M. Weber
    Nov 9, 2007
  5. Mpapec

    POE and SOAP

    Mpapec, Mar 14, 2008, in forum: Perl Misc
    Replies:
    0
    Views:
    140
    Mpapec
    Mar 14, 2008
Loading...

Share This Page