On Mon, 2004-27-12 at 21:01 -0500, Francis Lavoie wrote: 
> David Eriksson wrote:
> 
> >On Sun, 2004-12-26 at 12:33 -0500, Francis Lavoie wrote:
> >  
> >
> >>Is there an easy way to put mail link and http link on a textlabel?
> >>
> >>I use pango markup like this : <span foreground="#000099" 
> >>underline="single" weight="bold">[EMAIL PROTECTED]</span>
> >>
> >>but it's not automaticly clickable to open the default mail-client.
> >>And it is not theme-friendly
> >>
> >>Is there another way to go that I mist?

> Thank you
> 
Here are some code snipits from our project.  I hope they help.  I did
not code it, Someone else patched it to use multiple links.  You can
find the project homepage along with a few screenshots here:
http://porthole.sourceforge.net/

The source file of the snipits, summary.py here:
http://cvs.sourceforge.net/viewcvs.py/porthole/porthole/summary.py?rev=1.20&view=auto



   def __init__(self):
        # Capture any mouse motion in this tab so we
        # can highlight URL links & change mouse pointer
        self.connect("motion_notify_event", self.on_mouse_motion)

        # List of active URLs in the tab
        self.url_tags = []
        self.underlined_url = False

    def on_url_event(self, tag, widget, event, iter):
        """ Catch when the user clicks the URL """
        if event.type == gtk.gdk.BUTTON_RELEASE:
            load_web_page(tag.get_property("name"))

    def on_mouse_motion(self, widget, event, data = None):
        # we need to call get_pointer, or we won't get any more events
        pointer = self.window.get_pointer()
        x, y, spam = self.window.get_pointer()
        x, y = self.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, x, y)
        tags = self.get_iter_at_location(x, y).get_tags()
        if self.underlined_url:

self.underlined_url.set_property("underline",pango.UNDERLINE_NONE)
            self.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(None)
            self.underlined_url = None
        for tag in tags:
            if tag in self.url_tags:
                tag.set_property("underline",pango.UNDERLINE_SINGLE)

self.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gtk.gdk.Cursor

(gtk.gdk.HAND2))
                self.underlined_url = tag
        return gtk.FALSE


        def append_url(text):
            """ Append URL to textbuffer and connect an event """
            tag = self.buffer.create_tag(text)
            tag.set_property("foreground","blue")
            tag.connect("event", self.on_url_event)
            self.url_tags.append(tag)
            append(text, tag.get_property("name"))


        # Insert homepage(s), if any
        x = 0
        if homepages:
            for homepage in homepages:
                if x > 0:
                    append( ', ')
                append_url(homepage)
                x += 1
            nl(2)
    


-- 
Brian <[EMAIL PROTECTED]>

_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to