summaryrefslogtreecommitdiff
path: root/grc/src
diff options
context:
space:
mode:
authorjblum2009-01-29 06:20:41 +0000
committerjblum2009-01-29 06:20:41 +0000
commit69d1bd245aedd437f8550417ea5bf6847dd74619 (patch)
treed6504e869c6a697a82f7ca81d73f0b85f117932a /grc/src
parentf711b9f7cb5eca6071034462a43ce09745763eb2 (diff)
downloadgnuradio-69d1bd245aedd437f8550417ea5bf6847dd74619.tar.gz
gnuradio-69d1bd245aedd437f8550417ea5bf6847dd74619.tar.bz2
gnuradio-69d1bd245aedd437f8550417ea5bf6847dd74619.zip
added eng notation to slider gui control
git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@10333 221aa14e-8319-0410-a670-987f0aec2ac5
Diffstat (limited to 'grc/src')
-rw-r--r--grc/src/grc_gnuradio/wxgui/callback_controls.py41
1 files changed, 27 insertions, 14 deletions
diff --git a/grc/src/grc_gnuradio/wxgui/callback_controls.py b/grc/src/grc_gnuradio/wxgui/callback_controls.py
index 4c64cd12a..2f474cf9f 100644
--- a/grc/src/grc_gnuradio/wxgui/callback_controls.py
+++ b/grc/src/grc_gnuradio/wxgui/callback_controls.py
@@ -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 @@ class _control_base(wx.BoxSizer):
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 @@ class _slider_control_base(_control_base):
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 @@ class _slider_control_base(_control_base):
"""
return self._value
- def _set_slider_value(self, real_value):
+ def set_value(self, value):
+ """
+ Set the current set value.
+ @param value the value (float)
"""
- 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
+ self._value = value
+ self._update_slider()
+ self._update_text_box()
+
+ def _update_slider(self):
"""
- slider_value = (float(real_value) - self.min)*self.num_steps/(self.max - self.min)
+ 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 @@ class _slider_control_base(_control_base):
"""
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