commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r10333 - gnuradio/trunk/grc/src/grc_gnuradio/wxgui


From: jblum
Subject: [Commit-gnuradio] r10333 - gnuradio/trunk/grc/src/grc_gnuradio/wxgui
Date: Wed, 28 Jan 2009 23:20:43 -0700 (MST)

Author: jblum
Date: 2009-01-28 23:20:41 -0700 (Wed, 28 Jan 2009)
New Revision: 10333

Modified:
   gnuradio/trunk/grc/src/grc_gnuradio/wxgui/callback_controls.py
Log:
added eng notation to slider gui control

Modified: gnuradio/trunk/grc/src/grc_gnuradio/wxgui/callback_controls.py
===================================================================
--- gnuradio/trunk/grc/src/grc_gnuradio/wxgui/callback_controls.py      
2009-01-29 03:04:09 UTC (rev 10332)
+++ gnuradio/trunk/grc/src/grc_gnuradio/wxgui/callback_controls.py      
2009-01-29 06:20:41 UTC (rev 10333)
@@ -20,6 +20,7 @@
 
 import wx
 import sys
+from gnuradio import eng_notation
 
 class LabelText(wx.StaticText):
        """Label text class for uniform labels among all controls."""
@@ -44,6 +45,8 @@
 
        def get_value(self): raise NotImplementedError
 
+       def set_value(self): raise NotImplementedError
+
 class _chooser_control_base(_control_base):
        """House a drop down or radio buttons for variable control."""
 
@@ -184,13 +187,11 @@
                try: slider.SetRange(0, num_steps)
                except Exception, e:
                        print >> sys.stderr, 'Error in set slider range: 
"%s".'%e
-                       sys.exit(-1)
+                       exit(-1)
                slider.Bind(wx.EVT_SCROLL, self._handle_scroll) #bind the 
scrolling event
                self.Add(slider, 0, wx.ALIGN_CENTER)
                #init slider and text box
-               self._value = value
-               self._set_slider_value(self._value) #sets the slider's value
-               self.text_box.SetValue(str(self._value))
+               self.set_value(value)
 
        def get_value(self):
                """
@@ -199,23 +200,36 @@
                """
                return self._value
 
-       def _set_slider_value(self, real_value):
+       def set_value(self, value):
                """
-               Translate the real numerical value into a slider value and,
-               write the value to the slider.
-               @param real_value the numeric value the slider should represent
+               Set the current set value.
+               @param value the value (float)
                """
-               slider_value = (float(real_value) - 
self.min)*self.num_steps/(self.max - self.min)
+               self._value = value
+               self._update_slider()
+               self._update_text_box()
+
+       def _update_slider(self):
+               """
+               Translate the real numerical value into a slider value.
+               """
+               slider_value = (float(self.get_value()) - 
self.min)*self.num_steps/(self.max - self.min)
                self.slider.SetValue(slider_value)
 
+       def _update_text_box(self):
+               """
+               Update the text box value.
+               Convert the value into engineering notation.
+               """
+               
self.text_box.SetValue(eng_notation.num_to_str(self.get_value()))
+
        def _handle_scroll(self, event=None):
                """
                A scroll event is detected. Read the slider, call the callback.
                """
                slider_value = self.slider.GetValue()
                new_value = slider_value*(self.max - self.min)/self.num_steps + 
self.min
-               self.text_box.SetValue(str(new_value))
-               self._value = new_value
+               self.set_value(new_value)
                try: self.call()
                except Exception, e: print >> sys.stderr, 'Error in exec 
callback from handle scroll.\n', e
 
@@ -223,9 +237,8 @@
                """
                An enter key was pressed. Read the text box, call the callback.
                """
-               new_value = float(self.text_box.GetValue())
-               self._set_slider_value(new_value)
-               self._value = new_value
+               new_value = eng_notation.str_to_num(self.text_box.GetValue())
+               self.set_value(new_value)
                try: self.call()
                except Exception, e: print >> sys.stderr, 'Error in exec 
callback from handle enter.\n', e
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]