thomasvs - in flumotion/branches/doc-1: . flumotion/admin/gtk flumotion/common flumotion/worker/checks

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Tue Feb 27 20:09:14 CET 2007


Author: thomasvs
Date: Tue Feb 27 20:09:12 2007
New Revision: 4534

Modified:
   flumotion/branches/doc-1/ChangeLog.branch
   flumotion/branches/doc-1/flumotion/admin/gtk/message.py
   flumotion/branches/doc-1/flumotion/common/messages.py
   flumotion/branches/doc-1/flumotion/worker/checks/check.py
Log:
	* flumotion/common/messages.py:
	  first try; add helpLink and helpDescription
	* flumotion/admin/gtk/message.py:
	  make them clickable
	* flumotion/worker/checks/check.py:
	  add link and description to one of them to test



Modified: flumotion/branches/doc-1/ChangeLog.branch
==============================================================================
--- flumotion/branches/doc-1/ChangeLog.branch	(original)
+++ flumotion/branches/doc-1/ChangeLog.branch	Tue Feb 27 20:09:12 2007
@@ -1,3 +1,12 @@
+2007-02-27  Thomas Vander Stichele  <thomas at apestaart dot org>
+
+	* flumotion/common/messages.py:
+	  first try; add helpLink and helpDescription
+	* flumotion/admin/gtk/message.py:
+	  make them clickable
+	* flumotion/worker/checks/check.py:
+	  add link and description to one of them to test
+
 2007-02-21  Thomas Vander Stichele  <thomas at apestaart dot org>
 
 	* flumotion/common/doc.py:

Modified: flumotion/branches/doc-1/flumotion/admin/gtk/message.py
==============================================================================
--- flumotion/branches/doc-1/flumotion/admin/gtk/message.py	(original)
+++ flumotion/branches/doc-1/flumotion/admin/gtk/message.py	Tue Feb 27 20:09:12 2007
@@ -26,6 +26,7 @@
 
 import os
 import gtk
+import pango
 
 _stock_icons = {messages.ERROR: gtk.STOCK_DIALOG_ERROR,
                 messages.WARNING: gtk.STOCK_DIALOG_WARNING,
@@ -141,6 +142,81 @@
             self.label.set_markup('<b>%s</b>'
                                   % _headings.get(m.level, _('Message')))
 
+            # if we have help information, add it to the end of the text view
+            if hasattr(m, 'helpLink'):
+                iter = buf.get_end_iter()
+                # we set the 'link' data field on tags to identify them
+                tag = buf.create_tag(m.helpDescription)
+                tag.set_property('underline', pango.UNDERLINE_SINGLE)
+                tag.set_data('link', m.helpLink)
+                #tag.connect("event", on_helpLink, m)
+                buf.insert_with_tags_by_name(iter, m.helpDescription,
+                    tag.get_property('name'))
+                # FIXME: the textview is reused, so don't we have multiple
+                # handlers asfter a while ?
+                # connect signals to act on the hyperlink
+                self.textview.connect('event-after',
+                    on_event_after)
+                self.textview.connect('motion-notify-event',
+                    on_motion_notify_event)
+
+
+        def on_helpLink(tag, textview, event, iter, m):
+            #import code; code.interact(local=locals())
+            print "helpLink", event
+            if event.type == gtk.gdk.MOTION_NOTIFY:
+                x, y = textview.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT, event.x, event.y)
+            tags = textview.get_iter_at_location(x, y).get_tags()
+            print "tags", tags
+            textview.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(gtk.gdk.Cursor)
+            if event.type != gtk.gdk.BUTTON_RELEASE:
+                return
+            # FIXME: do better
+            os.system('firefox %s' % m.helpLink)
+
+        # when the mouse cursor moves, set the cursor image accordingly
+        def on_motion_notify_event(textview, event):
+            #print "motion", textview, event
+            x, y = textview.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET,
+                int(event.x), int(event.y))
+            tags = textview.get_iter_at_location(x, y).get_tags()
+            # without this call, further motion notify events don't get
+            # triggered
+            textview.window.get_pointer()
+            #print "tags", tags
+
+            # if any of the tags is a link, show a hand
+            cursor = None
+            for tag in tags:
+                if tag.get_data('link'):
+                    cursor = gtk.gdk.Cursor(gtk.gdk.HAND2)
+            textview.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(cursor)
+            return False
+
+        def on_event_after(textview, event):
+            if event.type != gtk.gdk.BUTTON_RELEASE:
+                return False
+            if event.button != 1:
+                return False
+            buffer = text_view.get_buffer()
+
+            # we shouldn't follow a link if the user has selected something
+            try:
+                start, end = buffer.get_selection_bounds()
+            except ValueError:
+                # If there is nothing selected, None is return
+                pass
+            else:
+                if start.get_offset() != end.get_offset():
+                    return False
+
+            x, y = text_view.window_to_buffer_coords(gtk.TEXT_WINDOW_WIDGET,
+                int(event.x), int(event.y))
+            iter = text_view.get_iter_at_location(x, y)
+
+            self.follow_if_link(text_view, iter)
+            return False
+
         # FIXME:this clears all messages with the same id as the new one.
         # effectively replacing.  Is this what we want ?
         self.clear_message(m.id)

Modified: flumotion/branches/doc-1/flumotion/common/messages.py
==============================================================================
--- flumotion/branches/doc-1/flumotion/common/messages.py	(original)
+++ flumotion/branches/doc-1/flumotion/common/messages.py	Tue Feb 27 20:09:12 2007
@@ -226,6 +226,10 @@
         self.debug = debug
         self.id = id
         self.priority = priority
+
+        self.helpLink = None
+        self.helpDescription = None
+
         self.add(translatable)
 
     def __repr__(self):

Modified: flumotion/branches/doc-1/flumotion/worker/checks/check.py
==============================================================================
--- flumotion/branches/doc-1/flumotion/worker/checks/check.py	(original)
+++ flumotion/branches/doc-1/flumotion/worker/checks/check.py	Tue Feb 27 20:09:12 2007
@@ -45,7 +45,9 @@
                     N_("Could not open device '%s' for reading.  Check permissions on the device."), device))
             elif gerror.code == int(gst.RESOURCE_ERROR_OPEN_READ_WRITE):
                 m = messages.Error(T_(
-                    N_("Could not open device '%s'.  Check permissions on the device."), device))
+                    N_("Could not open device '%s'.  Check permissions on the device.\n"), device))
+                m.helpLink = "http://www.google.com"
+                m.helpDescription = N_("Google")
             elif gerror.code == int(gst.RESOURCE_ERROR_BUSY):
                 m = messages.Error(T_(
                     N_("Device '%s' is already in use."), device))


More information about the flumotion-commit mailing list