From 9988664127b367fa8fee4409f8460673d6f265e1 Mon Sep 17 00:00:00 2001 From: jblum Date: Tue, 23 Jun 2009 20:38:18 +0000 Subject: Merging r11186:11273 from grc branch. Fixes, features, and reorganization for grc. Minor fixes and features for wxgui forms. git-svn-id: http://gnuradio.org/svn/gnuradio/trunk@11274 221aa14e-8319-0410-a670-987f0aec2ac5 --- gr-wxgui/src/python/forms/converters.py | 17 ++++++++++++----- gr-wxgui/src/python/forms/forms.py | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'gr-wxgui/src/python') diff --git a/gr-wxgui/src/python/forms/converters.py b/gr-wxgui/src/python/forms/converters.py index 123aefeb0..e535cb2dd 100644 --- a/gr-wxgui/src/python/forms/converters.py +++ b/gr-wxgui/src/python/forms/converters.py @@ -85,22 +85,28 @@ class eval_converter(abstract_converter): Possible uses, set a complex number, constellation points. Used in text box. """ - def external_to_internal(self, s): - return str(s) + def __init__(self, formatter=lambda x: '%s'%(x)): + self._formatter = formatter + def external_to_internal(self, v): + return self._formatter(v) def internal_to_external(self, s): return eval(s) def help(self): return "Value must be evaluatable by python's eval." class str_converter(abstract_converter): + def __init__(self, formatter=lambda x: '%s'%(x)): + self._formatter = formatter def external_to_internal(self, v): - return str(v) + return self._formatter(v) def internal_to_external(self, s): return str(s) class int_converter(abstract_converter): + def __init__(self, formatter=lambda x: '%d'%round(x)): + self._formatter = formatter def external_to_internal(self, v): - return str(int(round(v))) + return self._formatter(v) def internal_to_external(self, s): return int(s, 0) def help(self): @@ -127,7 +133,8 @@ class slider_converter(abstract_converter): self._scaler = float(maximum - minimum)/num_steps self._cast = cast def external_to_internal(self, v): - return (v - self._offset)/self._scaler + #slider's internal representation is an integer + return int(round((v - self._offset)/self._scaler)) def internal_to_external(self, v): return self._cast(v*self._scaler + self._offset) def help(self): diff --git a/gr-wxgui/src/python/forms/forms.py b/gr-wxgui/src/python/forms/forms.py index 10f6a4823..c69315b03 100644 --- a/gr-wxgui/src/python/forms/forms.py +++ b/gr-wxgui/src/python/forms/forms.py @@ -115,7 +115,6 @@ class _form_base(pubsub, wx.BoxSizer): self.subscribe(INT_KEY, update) self.subscribe(INT_KEY, self._translate_internal_to_external) self.subscribe(EXT_KEY, self._translate_external_to_internal) - if self._callback: self.subscribe(EXT_KEY, self._callback) def _translate_external_to_internal(self, external): try: @@ -134,6 +133,7 @@ class _form_base(pubsub, wx.BoxSizer): except Exception, e: self._err_msg(internal, e) self[EXT_KEY] = self[EXT_KEY] #reset to last good setting + if self._callback: self._callback(self[EXT_KEY]) def _err_msg(self, value, e): print >> sys.stderr, self, 'Error translating value: "%s"\n\t%s\n\t%s'%(value, e, self._converter.help()) -- cgit