Respected Monks,
Starting with MCE 1.828 and MCE::Shared 1.825, running MCE with Prima is possible. The following is based on the 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.
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");
}
}
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.
Regards, Mario
Update: Updated the timer handler. Thanks zentara.
Update: On the Mac, mouse clicks between windows is greatly improved by setting an option in XQuartz -> Preferences -> Windows -> Click-through Inactive Windows. When enabled, clicking on an inactive window will cause that mouse click to pass through to that window in addition to activating it.
Update: 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, Dmitry.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.