CUFP
marioroy
<p>Respected Monks,</p>
<p>Starting with [https://metacpan.org/release/MCE|MCE 1.828] and [https://metacpan.org/release/MCE-Shared|MCE::Shared 1.825], running MCE with [https://metacpan.org/pod/Prima|Prima] is possible. The following is based on the [id://1188651|Tk + MCE::Hobo demonstration] (2nd example in the post). I tested Prima + MCE on Linux using CentOS 7.x and Windows with Strawberry Perl 5.22.x.</p>
<code>
use strict;
use warnings;
use MCE::Hobo;
use MCE::Shared;
use Prima qw( Application Buttons Label );
my $que = MCE::Shared->queue();
my $msg = MCE::Shared->scalar("Start");
my $hobo = MCE::Hobo->create("bg_task");
my $wm = Prima::MainWindow->new(
size => [ 250, 200 ], text => 'Hello world!', onDestroy => \&quit
);
my $lbl1 = Prima::Label->create(
owner => $wm, size => [ 220, 50 ], text => 'Prima + MCE Demo',
alignment => ta::Center, valignment => ta::Middle,
pack => {}
);
my $btn1 = Prima::Button->new(
owner => $wm, size => [ 120, 50 ], text => $msg->get,
onClick => \&fun,
pack => {}
);
my $btn2 = Prima::Button->new(
owner => $wm, size => [ 120, 50 ], text => 'Quit',
onClick => sub { $::application->close },
pack => {}
);
my $timer = Prima::Timer->create(
timeout => 100, onTick => sub {
my $new_text = $msg->get;
if ($new_text ne $btn1->text) {
$btn1->set( text => $msg->get );
}
}
);
$timer->start;
run Prima;
sub fun {
$que->enqueue("some event");
return;
}
sub quit {
$timer->stop;
$hobo->exit->join;
$::application->close;
}
sub bg_task {
while ( my $event = $que->dequeue ) {
$msg->set("Step One");
sleep 1;
$msg->set("Step Two");
sleep 1;
$msg->set("Step Three");
}
}
</code>
<p>So that the quit function isn't called twice, I'm only calling $::application->close inside the Quit handler. That closes the window which then triggers the MainWindow's onDestroy handler.</p>
<p>Regards, Mario</p>
<p><b>Update:</b> Updated the timer handler. Thanks [id://1189162|zentara].</p>
<p><b>Update:</b> On the Mac, mouse clicks between windows is greatly improved by setting an option in XQuartz -> Preferences -> Windows -> Click-through Inactive Windows. <i>When enabled, clicking on an inactive window will cause that mouse click to pass through to that window in addition to activating it.</i></p>
<p><b>Update:</b> To improve performance on the Mac, set XQuartz -> Preferences -> Output -> Colors to Thousands. Then relaunch XQuartz for the option to take effect. Prima for the most part runs very well. Thank you, [dk|Dmitry].</p>