mailr10655 - /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 February 04, 2010 - 19:14:
Author: bugman
Date: Thu Feb  4 19:14:17 2010
New Revision: 10655

URL: http://svn.gna.org/viewcvs/relax?rev=10655&view=rev
Log:
Made the link to the relax website clickable.

This involves changing the close() method to process_click(), determining the 
(x, y) coords of the
click (in event.GetX() and event.GetY()), opening the link if the correct 
position is clicked (the
link position coordinates are stored), and closing the widget.


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=10655&r1=10654&r2=10655&view=diff
==============================================================================
--- branches/bieri_gui/gui_bieri/about.py (original)
+++ branches/bieri_gui/gui_bieri/about.py Thu Feb  4 19:14:17 2010
@@ -24,6 +24,7 @@
 # Python module imports.
 from os import sep
 from textwrap import wrap
+import webbrowser
 import wx
 
 # relax module imports.
@@ -66,21 +67,7 @@
         self.Bind(wx.EVT_PAINT, self.generate)
 
         # Let the dialog be closable with a left button click.
-        self.Bind(wx.EVT_LEFT_DOWN, self.close)
-
-
-    def close(self, event):
-        """Close the dialog.
-
-        @param event:   The wx event.
-        @type event:    wx event
-        """
-
-        # Close.
-        self.Close()
-
-        # Terminate the event.
-        event.Skip()
+        self.Bind(wx.EVT_LEFT_DOWN, self.process_click)
 
 
     def generate(self, event):
@@ -240,14 +227,18 @@
         self.dc.SetFont(font)
         self.dc.SetTextForeground('#0017aa')
 
+        # Add a spacer.
+        self.offset(10)
+
         # The text extent.
         x, y = self.dc.GetTextExtent(self.info.website)
 
         # Draw the text, with a spacer.
-        text = self.dc.DrawText(self.info.website, self.boarder + 
(self.dim_x - x)/2, self.offset(10))
-
-        # Add the text extent.
-        self.offset(y)
+        text = self.dc.DrawText(self.info.website, self.boarder + 
(self.dim_x - x)/2, self.offset())
+
+        # Store the position of the text (and shift the offset down).
+        self.link_pos_x = [self.boarder + (self.dim_x - x)/2, self.boarder + 
(self.dim_x + x)/2]
+        self.link_pos_y = [self.offset(), self.offset(y)]
 
         # Restore the old font colour (black).
         self.dc.SetTextForeground('black')
@@ -326,3 +317,26 @@
 
         # Return.
         return self._offset_val
+
+
+    def process_click(self, event):
+        """Determine what to do with the mouse click.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Determine the mouse position.
+        x = event.GetX()
+        y = event.GetY()
+
+        # A click on the relax link.
+        if x > self.link_pos_x[0] and x < self.link_pos_x[1] and y > 
self.link_pos_y[0] and y < self.link_pos_y[1]:
+            webbrowser.open_new(self.info.website)
+
+        # Close the dialog on all clicks.
+        self.Close()
+
+        # Terminate the event.
+        event.Skip()
+




Related Messages


Powered by MHonArc, Updated Thu Feb 04 19:20:02 2010