mailr11997 - /branches/bieri_gui/gui_bieri/about.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on December 28, 2010 - 20:37:
Author: bugman
Date: Tue Dec 28 20:37:53 2010
New Revision: 11997

URL: http://svn.gna.org/viewcvs/relax?rev=11997&view=rev
Log:
The about base class draw_wrapped_text() method is now parsing for and 
handling URLs in the text.


Modified:
    branches/bieri_gui/gui_bieri/about.py

Modified: branches/bieri_gui/gui_bieri/about.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/bieri_gui/gui_bieri/about.py?rev=11997&r1=11996&r2=11997&view=diff
==============================================================================
--- branches/bieri_gui/gui_bieri/about.py (original)
+++ branches/bieri_gui/gui_bieri/about.py Tue Dec 28 20:37:53 2010
@@ -235,8 +235,23 @@
 
         # Draw.
         for line in lines:
+            # Find and break out the URLs from the text.
+            text_elements, url = self.split_refs(line)
+
             # Draw the text.
-            self.dc.DrawText(line, self.border, self.offset())
+            x_pos = self.border
+            for i in range(len(text_elements)):
+                # URL text.
+                if url[i]:
+                    self.draw_link(link_text=text_elements[i])
+
+                # Add the text.
+                else:
+                    self.dc.DrawText(text_elements[i], x_pos, self.offset())
+
+                # The new x position.
+                x, y = self.dc.GetTextExtent(text_elements[i])
+                x_pos += x
 
             # Update the offset.
             self.offset(max_y + 1)
@@ -291,6 +306,58 @@
         # A gradient.
         elif self.colour1 and self.colour2:
             self.dc.GradientFillLinear((0, 0, self.virt_x, self.virt_y), 
self.colour1, self.colour2, wx.SOUTH)
+
+
+    def split_refs(self, text):
+        """Split up text based on the location of URLs.
+
+        @param text:    The text to parse and split up.
+        @type text:     str
+        @return:        The list of text elements, and a list of flags which 
if True indicates a corresponding URL in the text list.
+        @rtype:         list of str, list of bool
+        """
+
+        # Init.
+        elements = []
+        url = []
+
+        # Walk over the characters.
+        for i in range(len(text)):
+            # End.
+            if len(text) - i < 7:
+                break
+
+            # Search for a url.
+            if text[i:i+7] == 'http://':
+                # Add the text up to here to the list.
+                elements.append(text[0:i])
+                url.append(False)
+
+                # Find the end.
+                end_char = [')', ' ']
+                for j in range(i+7, len(text)):
+                    if text[j] in end_char:
+                        end_i = j
+                        break
+
+                # The url.
+                elements.append(text[i:j])
+                url.append(True)
+
+                # The rest of the text.
+                elements.append(text[j:])
+                url.append(False)
+                
+                # Terminate.
+                break
+
+        # No URLs.
+        if not len(elements):
+            elements.append(text)
+            url.append(False)
+
+        # Return the data structures.
+        return elements, url
 
 
     def virtual_size(self):




Related Messages


Powered by MHonArc, Updated Tue Dec 28 21:00:02 2010