http://qs321.pair.com?node_id=1050558


in reply to Perl Gtk2 AboutDialog's "set_url_hook()" is Not Working as Expected.

When you say this:

$about_window->set_url_hook(open_browser($url));

You're calling set_url_hook with as parameter the result of open_browser($url). I'm not familiar with Gtk2, but you probably want something like

$about_window->set_url_hook("open_browser",$url);

i.e. you tell set_url_hook the name of the function to call; it's possible that you have to pass the argument to open_browser in a different way; you'll have to experiment or read the docs to find out.

Replies are listed 'Best First'.
Re^2: Perl Gtk2 AboutDialog's "set_url_hook()" is Not Working as Expected.
by mmartin (Monk) on Aug 22, 2013 at 21:31 UTC
    Hey Crackers, thanks for the reply

    Humm, just tried what you showed and this time nothing happened when I opened the About window, which is good.

    But this time something actually did happen when I clicked on the link. I got an error from the open_browser() function but still good news because its actually now executing what's in there when I click the link... Thanks!

    I was about to walk out the door before you replied so I'll mess with it a bit tomorrow when I get back in.


    Thanks AGAIN for the reply, much appreciated!


    Thanks Again,
    Matt


Re^2: Perl Gtk2 AboutDialog's "set_url_hook()" is Not Working as Expected.
by mmartin (Monk) on Aug 23, 2013 at 14:40 UTC
    Ok... Got it working!

    So this is what I've found out this morning testing the set_url_hook() function. Seems that whatever is set in "$about_window->set_website($url);" for the $url variable will get passed to the "open_url()" sub which is an argument to the "$about_window->set_url_hook("open_url");" function, which is a subroutine.

    So with these 2 commands I can now successfully open the URL in a browser when I click on the link:
    ### 1st we need to define HOOK before we set the website: # *open_url() is a Subroutine: $about_window->set_url_hook("open_url"); ### Now we call the set_website() function: # *The $website var will be passed as an ARG to open_url(): $about_window->set_website($website); # This receives 2 Args: # ARG[0] --> AboutDialog Widget # ARG[1] --> $website sub open_url() { my ($widget, $url) = @_; print " url == $url\n"; print "Widget == $widget\n\n"; open_browser($url); }
    So now it seems everything is working as expected...! Thanks again Crackers, if you hadn't posted your example of the set_url_hook("open_broswer", $url) it probably would have taken me much longer to find that's how the syntax should be for that set_url_hook() Function's Arguments...!


    So thanks again for the reply, much appreciated!


    Thanks Again,
    Matt