Clickable URLs in panels

I want to put a clickable URL in my "About" panel:
  http://foobar.com/

I'm guessing that wx.StaticText(), an EVT_LEFT_DOWN, and Python's
webbrowser will do the trick, but I wanted to see if anyone on the list
had already done this?

···

--
Chuck
http://ChuckEsterbrook.com

Chuck Esterbrook wrote:

I want to put a clickable URL in my "About" panel:
http://foobar.com/

I'm guessing that wx.StaticText(), an EVT_LEFT_DOWN, and Python's webbrowser will do the trick, but I wanted to see if anyone on the list had already done this?

Hi Chuck,

I do this using a flattened button (so it looks just like a static text or bitmap). The attached probably has a few outside dependencies that I'm forgetting to include, but should give the general idea.

-tim

# In my application.

    def ShowAbout(self, event=None):
        title = "About " + self.name
        modules = '\n '.join(["%s [%s]" % (x.name, x.version) for x in self.modules])
        message = "About " + self.name
        message += "\nInstalled Modules:\n " + modules
        libs = ((tools.LoadBitmap("python"), "http://www.python.org"),
                (tools.LoadBitmap("wxPython"), "http://www.wxpython.org"),
                (tools.LoadBitmap("wxWindows"), "http://www.wxwindows.org"))
        licensedir = "Licenses"
        tools.ShowAbout(title, message, libs, licensedir)

# In tools

*def LoadBitmap(name, mask=(255,0,255)): # Pink is default mask color
    path = os.path.join(utilities.findHomeDirectory(), "images", name)
    if sys.platform == "win32":
        bmp = wx.wxBitmap(path + ".bmp", wx.wxBITMAP_TYPE_BMP)
    else:
        bmp = wx.wxBitmap(path + ".xpm", wx.wxBITMAP_TYPE_XPM)
    img = wx.wxImageFromBitmap(bmp)
    img.SetMaskColour(*mask)
    return img.ConvertToBitmap()*

def ShowAbout(title, message, libs, licensedir, target=wx.NULL):
    dlg = wx.wxDialog(target, -1, title, style=wx.wxDEFAULT_DIALOG_STYLE|wx.wxSUNKEN_BORDER) button = wx.wxButton(dlg, -1, "Ok")
    wx.EVT_BUTTON(dlg, button.GetId(), lambda e, d=dlg: d.EndModal(0))
    vert = wx.wxBoxSizer(wx.wxVERTICAL)
    txt = wx.wxStaticText(dlg, -1, message + "\n\nPowered by:")
    vert.Add(txt, 0, wx.wxTOP | wx.wxLEFT | wx.wxRIGHT, 10)
    horz = wx.wxBoxSizer(wx.wxHORIZONTAL)
    for bitmap, url in libs:
        bbutton = wx.wxBitmapButton(dlg, -1, bitmap, style=wx.wxNO_3D)
        wx.EVT_BUTTON(dlg, bbutton.GetId(), lambda e, url=url, wb=webbrowser: wb.open(url))
        horz.Add(bbutton, 0, wx.wxALIGN_CENTRE)
    vert.Add(horz, 0, wx.wxALIGN_CENTER | wx.wxALL, 10)
    licensepath = "file://" + os.path.join(utilities.findHomeDirectory(),licensedir, "index.html")
    horz = wx.wxBoxSizer(wx.wxHORIZONTAL)
    for text, url in [("See directory ", None),
                      ('<font color="blue" weight="bold">%s</font>' % licensedir, licensepath),
                      (' for full text of licenses', None)]:
        bmp = wxFancyText.renderToBitmap(text,
                  background=wx.wxTheBrushList.FindOrCreateBrush(dlg.GetBackgroundColour(),wx.wxSOLID))
        bbutton = wx.wxBitmapButton(dlg, -1, bmp, style=wx.wxNO_3D)
        if url is not None:
            wx.EVT_BUTTON(dlg, bbutton.GetId(), lambda e, url=url, wb=webbrowser: wb.open(url))
        horz.Add(bbutton, 0, wx.wxALIGN_LEFT)
    vert.Add(horz, 0, wx.wxALIGN_CENTER|wx.wxBOTTOM|wx.wxLEFT|wx.wxRIGHT, 10)
    vert.Add(button, 0, wx.wxALIGN_CENTRE|wx.wxBOTTOM, 10)
    dlg.SetAutoLayout(wx.true)
    dlg.SetSizer(vert)
    vert.Fit(dlg)
    vert.SetSizeHints(dlg)
    dlg.ShowModal()
    dlg.Destroy()

Thanks for all the code, Tim. Ultimately, I found that
setForegroundColor() and EVT_LEFT_UP() on a static text did the trick
for me.

···

On Sunday 27 April 2003 04:42 pm, Tim Hochberg wrote:

Chuck Esterbrook wrote:
>I want to put a clickable URL in my "About" panel:
> http://foobar.com/
>
>I'm guessing that wx.StaticText(), an EVT_LEFT_DOWN, and Python's
>webbrowser will do the trick, but I wanted to see if anyone on the
> list had already done this?

Hi Chuck,

I do this using a flattened button (so it looks just like a static
text or bitmap). The attached probably has a few outside dependencies
that I'm forgetting to include, but should give the general idea.

-tim

--
Chuck
http://ChuckEsterbrook.com

Chuck Esterbrook wrote:

···

On Sunday 27 April 2003 04:42 pm, Tim Hochberg wrote:

Chuck Esterbrook wrote:

I want to put a clickable URL in my "About" panel:
http://foobar.com/

I'm guessing that wx.StaticText(), an EVT_LEFT_DOWN, and Python's
webbrowser will do the trick, but I wanted to see if anyone on the
list had already done this?

Hi Chuck,

I do this using a flattened button (so it looks just like a static
text or bitmap). The attached probably has a few outside dependencies
that I'm forgetting to include, but should give the general idea.

-tim

Thanks for all the code, Tim. Ultimately, I found that setForegroundColor() and EVT_LEFT_UP() on a static text did the trick for me.

You may not want to do this since the wxStaticText widget on some platforms does not get mouse events. (For example, on wxGTK the native widget is not a true window but is just drawn on the parent...) Instead you may want to use the generic static text class from wxPython.lib.stattext.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hmmm, you sure? I just ran my code on GTK/Linux and other than the
webbrowser module bitching that it can't find a suitable web browser,
it seems to work. I subclass wx.StaticText and hook into the "left up"
event.

···

On Monday 28 April 2003 12:29 pm, Robin Dunn wrote:

Chuck Esterbrook wrote:
> On Sunday 27 April 2003 04:42 pm, Tim Hochberg wrote:
>>Chuck Esterbrook wrote:
>>>I want to put a clickable URL in my "About" panel:
>>> http://foobar.com/
>>>
>>>I'm guessing that wx.StaticText(), an EVT_LEFT_DOWN, and Python's
>>>webbrowser will do the trick, but I wanted to see if anyone on the
>>>list had already done this?
>>
>>Hi Chuck,
>>
>>I do this using a flattened button (so it looks just like a static
>>text or bitmap). The attached probably has a few outside
>> dependencies that I'm forgetting to include, but should give the
>> general idea.
>>
>>-tim
>
> Thanks for all the code, Tim. Ultimately, I found that
> setForegroundColor() and EVT_LEFT_UP() on a static text did the
> trick for me.

You may not want to do this since the wxStaticText widget on some
platforms does not get mouse events. (For example, on wxGTK the
native widget is not a true window but is just drawn on the
parent...) Instead you may want to use the generic static text class
from
wxPython.lib.stattext.

--
Chuck
http://ChuckEsterbrook.com

Chuck Esterbrook wrote:

You may not want to do this since the wxStaticText widget on some
platforms does not get mouse events. (For example, on wxGTK the
native widget is not a true window but is just drawn on the
parent...) Instead you may want to use the generic static text class
from
wxPython.lib.stattext.

Hmmm, you sure? I just ran my code on GTK/Linux and other than the webbrowser module bitching that it can't find a suitable web browser, it seems to work. I subclass wx.StaticText and hook into the "left up" event.

I guess something has changed...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!