Todd
I'm answering this question in the main list to explain some shortcuts.
Just to make sure it all works (if Windows will accept GTK), copy the
program from the Readme to a script file and run it with raku.
Playing around with it should make things clear.
On 07/06/2020 07:16, ToddAndMargo via perl6-users wrote:
On 2020-06-04 04:35, Richard Hainsworth wrote:
Todd,
I wrote you one a very long time ago, after a question from you.
The module is called "Inform". Its on the modules site.
Since it was a long time ago, there may be some bit-rot. Let me know
if there is .
The module should show how to use GTK, and there is a time-out function.
Richard, aka finanalyst
On 04/06/2020 02:55, ToddAndMargo via perl6-users wrote:
Hi All,
Okay, now I know I am pushing it. Can anyone point me to
an example of a GTK information pop up with a time out
feature? Or similar?
Many thanks,
-T
Hi Richard,
Some follow questions:
1) where are the directions?
I don't understand this question. Which directions? I tried to make the
example as full of explanation as possible.
where are the
variable definitions?
I don't understand this. The variables are all defined.
in the following:
# my first attempt:
first you will need a 'my'. In the example, I put:
my $popup = inform .... etc
As I said, but I expanded in the comments, 'inform' is a subroutine that
returns and 'Informing' object.
Actually, this is also a pointer in answer to something you asked
elsewhere. This is a way of creating something to which methods are
attached.
$popup = inform( 'Something cleaver here',
# :buttons(Dismiss => 'Dismiss Test',
:Response('Dismissed'))
# :buttons(Dismiss => 'Dismiss Test'),
# :buttons( OK=>'OK',b2=>'Not on your life',
'Cancel'=> "I don't want to")
:buttons( OK=>'OK Maybe', b2=>'Not on your life' ),
:timer(5),
:title("5 second Countdown test"),
:show-countdown );
print( "popup = <$popup>\n" );
print( "data.response = <$data.response>\n" );
The first print should give you something about the Informing object
Note that in the second print, you have invoked the `.response` method
on the object. This is used to extract the information from the dialog
box. However, you have used '<' which is used inside a "" string for
other things. Better to use
print "data response is = < { $popup.response } >";
Also note that you have not defined $data.
2) why do I have to have more than one button?
`:buttons( OK=>'OK Maybe' )` errors with
Type check failed in binding to parameter
'@buttons'; expected Positional but got Pair
(:OK("OK Maybe"))
More than one button, possible!
But look at the error message. You have specified `OK => 'string'` which
is the definition of a Pair, as the error message says.
But what is wanted is a Positional, as the error message says. An
example of a Positional is an Array. So try this
`:buttons( [ :OK("OK Maybe") ] )
The [ ] creates an Array, which is a Positional.
In my example, I gave three Pairs separated by commas. That is
interpreted by raku as a Sequence, which is also a Positional.
You could have written
:buttons(:OK("OK Maybe) , ) # note the trailing comma, which is
essential here.
There is no reason why an Array can only have one item. But in order to
make things generic, there needs to be a way to have more than one.
3) what is the difference between "buttons" and "response"?
Both of these give two buttons:
:buttons(Dismiss => 'Dismiss Test', :Response('Dismissed'))
This is simply raku. There are two ways to define a pair (a) String =>
SomeObject, (b) :String(SomeObject)
When you use => the key is autoquoted to make it a string.
4) why am I getting a weird response:
popup = <Informative::Informing<86939520>>
Not at all weird, but highly informative :) . This is telling you that
popup is an Informing Object instance from the Informative Module.
If you look at the text (which you can find in github - my p6/raku
repositories are public), you will see how Informative is defined.
data.response = <Informative::Informing<86939696>.response>
5) What is popup suppose to show?
Say what?
6) why is it not dismissing after 5 seconds?
I don't understand this. I am not prescient - I cannot see what is
happening on your screen with your setup. It works fine on my computer.
7) why is there no "show-countdown"?
There is! `:show-countdown` is named parameter to the method 'show', and
an example is shown.
By default `:show-countdown` is True, so there is no need to set it if
you want a countdown. If you dont want a count-down shown, then you need
to set `:!show-countdown` , which in itself is a shortcut for
`show-countdown(True)` . This was one of the examples.
Those shortcuts are becoming fairly common raku idioms. I didn't think
it would be necessary to document them.
Many thanks,
-T
Hope the Module could be of some use.