On 8/29/22 13:03, ToddAndMargo via perl6-users wrote:
On 8/28/22 15:58, ToddAndMargo via perl6-users wrote:
Hi All,

I am thinking of using

    BEGIN {}

to fire up a splash screen (libnotify).

Question: is what happens between the brackets
isolated from the rest of the code?   If I set
variable values or declare variables, are they
wiped out, etc.?

Many thanks,
-T

Follow up:

Thank you all for the help!

My splash screen pops up whilst the
rest of the program compiles.

Here is my BEGIN code.   If you are
wondering why all the variables when
I could just write it in the run line,
it is becasue the names of the variables
and the comments next to them tell me what
the parameters of notify-send are and
how to use them.  Much easier to maintain.



#!/usr/bin/env perl6

use RunNoShellLib :RunNoShell, :RunNoShellCode, :RunNoShellErr;

BEGIN {
    # Splash Screen

  ( my $ProgramName   = $?FILE ) ~~ s|.*"/"||;
    my Str $NotifyStr = "\nStarting $ProgramName\n";
    my Str $Icon      = "/home/linuxutil/Images/Info.png";
    my Str $Title     = "$ProgramName Splash Screen";
    my Str $Timeout   = "8000";  # milliseconds

   RunNoShell( "notify-send -u normal -t \"$Timeout\" -i \"$Icon\" \"$Title\" \"$NotifyStr\"" );
}



:-)

Love Raku!

-T


I changed my BEGIN a bit. Send-notify open on the right under the last notification.

Zenity allow me to open up right in the middle to the
screen.

And I had to switch from run to shell to get zenity
to detach.  Otherwise the compiler stops until
zenity returns


BEGIN {
   # Splash Screen

 ( my $ProgramName   = $?FILE ) ~~ s|.*"/"||;
   my Str $NotifyStr = "\nStarting $ProgramName\n";
   my Str $Icon      = "/home/linuxutil/Images/Info.png";
   my Str $Title     = "$ProgramName Splash Screen";
   # my Str $Timeout   = "8000";  # notify-send = milliseconds
   my Str $Timeout   = "8";       # zenity = seconds

   # Note: zenity seems to not detach when run without a shell
# RunNoShell( "zenity --info --title \"$Title\" --text \"$NotifyStr\" --width=220 --timeout=$Timeout" ); shell "zenity --info --title \"$Title\" --text \"$NotifyStr\" --width=220 --timeout=$Timeout &";
}


--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Computers are like air conditioners.
They malfunction when you open windows
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to