mailr12904 - /1.3/gui/components/spectrum.py


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

Header


Content

Posted by edward on June 09, 2011 - 10:22:
Author: bugman
Date: Thu Jun  9 10:22:10 2011
New Revision: 12904

URL: http://svn.gna.org/viewcvs/relax?rev=12904&view=rev
Log:
The delay time textctrl can now only have a single '.' char in the peak list 
grid.


Modified:
    1.3/gui/components/spectrum.py

Modified: 1.3/gui/components/spectrum.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/gui/components/spectrum.py?rev=12904&r1=12903&r2=12904&view=diff
==============================================================================
--- 1.3/gui/components/spectrum.py (original)
+++ 1.3/gui/components/spectrum.py Thu Jun  9 10:22:10 2011
@@ -26,6 +26,7 @@
 
 # Python module imports.
 from os import sep
+from re import search
 import wx
 import wx.lib.buttons
 
@@ -324,7 +325,8 @@
         sizer.Add(self.delay_time, 0, 
wx.ALIGN_CENTER_VERTICAL|wx.ADJUST_MINSIZE, 0)
 
         # Bind the change of contents.
-        self.delay_time.Bind(wx.EVT_KEY_UP, self.change_delay)
+        self.delay_time.Bind(wx.EVT_KEY_DOWN, self.change_delay_down)
+        self.delay_time.Bind(wx.EVT_KEY_UP, self.change_delay_up)
 
         # Add the element to the box.
         box.Add(sizer, 0, wx.EXPAND|wx.SHAPED, 0)
@@ -390,8 +392,8 @@
         box.Add(sizer, 0, wx.ADJUST_MINSIZE, 0)
 
 
-    def change_delay(self, event):
-        """Handle updates to the delay time.
+    def change_delay_down(self, event):
+        """Handle changes to the delay time.
 
         @param event:   The wx event.
         @type event:    wx event
@@ -399,17 +401,32 @@
 
         # The key.
         key = event.GetKeyCode()
+
+        # Get the text.
+        text = str(self.delay_time.GetString(0, 
self.delay_time.GetLastPosition()))
 
         # Allowed keys.
         allowed = []
         allowed += [8]    # Backspace.
-        allowed += [46]    # Full stop.
+        if not search('\.', text):
+            allowed += [46]    # Only one full stop.
         allowed += [48, 49, 50, 51, 52, 53, 54, 55, 56, 57]    # Numbers.
         allowed += [127]    # Delete.
 
         # Disallowed values, so do nothing.
         if key not in allowed:
             return
+
+        # Normal event handling.
+        event.Skip()
+
+
+    def change_delay_up(self, event):
+        """Handle updates to the delay time.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
 
         # Normal event handling.
         event.Skip()
@@ -752,8 +769,10 @@
 
         # The time value.
         time = self.delay_time.GetString(0, 
self.delay_time.GetLastPosition())
-        if time != '':
+        try:
             time = float(time)
+        except ValueError:
+            time = ''
 
         # Loop over the rows.
         for i in range(self.grid.GetNumberRows()):




Related Messages


Powered by MHonArc, Updated Thu Jun 09 10:40:01 2011