Hi zentara,

Some time ago (about a year), I tried running your demonstration with background workers. Then forgotten about it until recently and thought lost. Notice the 1 ms repeat interval for no other reason than to see Gtk, Tk, and STDOUT go :) Well, am no longer worried about losing these two demonstrations for running background workers with Gtk2 and Tk.

Gtk2 + Tk + MCE::Hobo + MCE::Shared

#!/usr/bin/perl # Re: AnyEvent + Wx, Gtk2/3 or Tk ? # https://www.perlmonks.org/?node_id=1008085 use strict; use warnings; use Gtk2; use Tk; use MCE::Hobo; use MCE::Shared; use Time::HiRes 'time'; $| = 1; my $que = MCE::Shared->queue( fast => 1 ); my $count = MCE::Shared->scalar( 0 ); my $count_tk = 0; MCE::Hobo->create( sub { while (defined (my $c = $que->dequeue)) { print "$c\n"; } }) for (1..3); my $start = time; # setup Tk loop my $mw = MainWindow->new(-title=>'Tk Window'); my $labtk = $mw->Label(-textvariable => \$count_tk)->pack; # setup Gtk2 loop Gtk2->init; my $window = Gtk2::Window->new('toplevel'); $window->set_title('Gtk2 Window'); my $glabel = Gtk2::Label->new("This is a Gtk2 Label 0"); $window->add($glabel); $window->show_all; # make Tk loop the master, but you could make Gtk2 master if desired # the lower the repeat rate, i.e. 1 ms, # will give more cpu time to the gtk2 loop # this is sometimes called manually pumping the event loop my $tktimer = $mw->repeat( 1, sub { my $c = $count->incr; $count_tk = $c; $glabel->set_text("This is a Gtk2 Label $c"); Gtk2->main_iteration while Gtk2->events_pending; quit() if ($c >= 2000); $que->enqueue(($c) x 3); }); $mw->Button( -text => ' Tk control Quit ', -command => \&quit )->pack; $mw->protocol( WM_DELETE_WINDOW => \&quit ); MainLoop; sub quit { $tktimer->cancel(), $que->clear(), $que->end(); $_->kill('QUIT') for MCE::Hobo->list(); kill('TERM', -$$); exit; } END { printf "duration: %0.03f seconds\n", time - $start; }

Regards, Mario


In reply to Re^2: AnyEvent + Wx, Gtk2/3 or Tk ? by marioroy
in thread [Solved] AnyEvent + Wx, Gtk2/3 or Tk ? by mascip

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.