Open a URL with the default browser from an HtmlWindow?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Open a URL with the default browser from an HtmlWindow?

Peter Buschman-2

I'm not sure if I'm using the wrong control here, but I have a dialog that
contains some simple
formatted HTML using an HtmlWindow and want to include a hyperlink that,
when clicked, opens
the URL in the user's default web browser.

Is this possible with an HtmlWindow?  So far, the only effect I am able to
produce is that of the URL
being loaded within the HtmlWindow itself...

--PLB



Reply | Threaded
Open this post in threaded view
|

Re: Open a URL with the default browser from an HtmlWindow?

Will McGugan-4
Peter L. Buschman wrote:

>
> I'm not sure if I'm using the wrong control here, but I have a dialog
> that contains some simple
> formatted HTML using an HtmlWindow and want to include a hyperlink
> that, when clicked, opens
> the URL in the user's default web browser.
>
> Is this possible with an HtmlWindow?  So far, the only effect I am
> able to produce is that of the URL
> being loaded within the HtmlWindow itself...


You need to catch the click then get the link. Derive from an htmlwindow
and define OnLinkClicked.

eg.

     def OnLinkClicked(self, link):

          href = link.GetHref()
          App.OnLink(href)

Here's what I use to launch the browser..

        if href.startswith("http") or href.startswith("mailto:"):
            wx.BeginBusyCursor()
            import webbrowser
            webbrowser.open(href)
            wx.EndBusyCursor()

You can do whatever you want with the link, its an excellent way to
create dynamic interfaces..


Will McGugan
--
http://www.kelpiesoft.com


Reply | Threaded
Open this post in threaded view
|

Re: Open a URL with the default browser from an HtmlWindow?

Peter Buschman-2

Will:

That did the trick!  Thanks for the pointer :)  I thought I was going to
have to do something much more complicated
involving wx.lib.hyperlink and was already headed down that path....

Cheers!

--Peter

At 05:00 PM 9/8/2005, you wrote:

>Peter L. Buschman wrote:
>
>>
>>I'm not sure if I'm using the wrong control here, but I have a dialog
>>that contains some simple
>>formatted HTML using an HtmlWindow and want to include a hyperlink that,
>>when clicked, opens
>>the URL in the user's default web browser.
>>
>>Is this possible with an HtmlWindow?  So far, the only effect I am able
>>to produce is that of the URL
>>being loaded within the HtmlWindow itself...
>
>
>You need to catch the click then get the link. Derive from an htmlwindow
>and define OnLinkClicked.
>
>eg.
>
>     def OnLinkClicked(self, link):
>
>          href = link.GetHref()
>          App.OnLink(href)
>
>Here's what I use to launch the browser..
>
>        if href.startswith("http") or href.startswith("mailto:"):
>            wx.BeginBusyCursor()
>            import webbrowser
>            webbrowser.open(href)
>            wx.EndBusyCursor()
>
>You can do whatever you want with the link, its an excellent way to create
>dynamic interfaces..
>
>
>Will McGugan
>--
>http://www.kelpiesoft.com
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>