Problem with Gtk2 and POE

K

Krisztian VASAS

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
 
R

Rocco Caputo

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__
 
K

Krisztian VASAS

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
 
K

Krisztian VASAS

Rocco Caputo wrote this on 2004-06-28 19:48:
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
 
R

Rocco Caputo

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top