Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: A question on using Tk::ItemStyle in Tk::Tree

by Anonymous Monk
on Nov 01, 2014 at 05:13 UTC ( #1105776=note: print w/replies, xml ) Need Help??

in reply to Re: A question on using Tk::ItemStyle in Tk::Tree
in thread A question on using Tk::ItemStyle in Tk::Tree

Hi Ken,

Thank you for your response to my query. As I'm new to perl, can you please explain me little bit about what the following construct you added does ?

$mw->after( 'idle', [ configure => $styleref_select_parent, -background => 'cyan', ]);
    I referred to Mastering Perl/Tk book(Oreilly Press), but I could not find anything being talked about this method named: after.
  1. under what circumstances is this construct useful?
  2. Also, Tk::Widget doesn't have any such method at all. So how this method gets inherited by Tk::Widget class?
  3. The anonymous array passed as second parameter suprisingly has no hyphen prefixing the configure option either.
  4. I was wondering if you have any answers for me to Question: 3 in the original post. (about the size of the font applied to + - indicators as well)

    Please let me know.
    Thanks again,

Replies are listed 'Best First'.
Re^3: A question on using Tk::ItemStyle in Tk::Tree
by choroba (Cardinal) on Nov 01, 2014 at 08:07 UTC
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thanks for pointing me to this Tk::after. However, I must honestly admit that I'm having difficulty in understanding the docs.

      Firstly, the after method has only two forms.
      1. after(*ms)
      2. after(*ms,*callback)
          In both forms the first parameter is time delay and this should be specified in milliseconds. But Khen1950fx's construct specifies a string 'idle'

          Secondly, the second parameter is the callback whose execution has to be delayed. But in Khen1950fx's construct the method after is called on an instance of MainWindow and does not specify any name of the callback method whose execution is to be delayed.

      But fundamentally speaking though, how does delaying the execution of a callback get helpful?

      I'm unable to find any other docs on this. So please let me know. Thanks in advance

        choroba will likely come along with some more details for you, but maybe this will suffice for now, given:

        $mw->after( 'idle', [ configure => $styleref_select_parent, -background => 'cyan' ], );

        Even though it could be made more clear, we do see in the Internal Details documentation:

        $time is the string 'idle', representing an idle queue timer, or a integer millisecond value.

        If you never wanted to use that idle string anomaly, there is an ->afterIdle method. The equivalent of the above could be coded:

        $mw->afterIdle([ configure => $styleref_select_parent, -background => +'cyan' ]);

        The See Also links to Tk::callbacks where it shows the valid ways to specify a callback, one of which is:

        [ 'methodname', args... ], ...

        So going back to the sample from Khen1950fx, we see that he passes 'configure', as the method name, and $styleref_select_parent as the object reference that will be passed as the first argument to Tk::ItemStyle::configure, along with the with arguments to change the background color. Incidentally, the fact that after() method is attached to the "$mw" object means that the timer will be cancelled if the MainWindow is destroyed before it fires.

        Here's one last example, that shows the square brackets turn out to be optional in this case, as well. After two seconds, set the entire background color:

        $mw->after( 2000 => configure => $tree, -background => 'green' );

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1105776]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2022-12-09 22:30 GMT
Find Nodes?
    Voting Booth?

    No recent polls found