"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
+Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
-import expr_utils
from .. base.Param import Param as _Param
from .. gui.Param import Param as _GUIParam
from .. gui.Param import EntryParam
file_dialog.set_local_only(True)
if gtk.RESPONSE_OK == file_dialog.run(): #run the dialog
file_path = file_dialog.get_filename() #get the file path
- self.entry.set_text(file_path)
+ self._input.set_text(file_path)
self._handle_changed()
file_dialog.destroy() #destroy the dialog
Get the repr (nice string format) for this param.
@return the string representation
"""
- if not self.is_valid(): return self.get_value()
+ ##################################################
+ # truncate helper method
+ ##################################################
+ def _truncate(string, style=0):
+ max_len = max(27 - len(self.get_name()), 3)
+ if len(string) > max_len:
+ if style < 0: #front truncate
+ string = '...' + string[3-max_len:]
+ elif style == 0: #center truncate
+ string = string[:max_len/2 -3] + '...' + string[-max_len/2:]
+ elif style > 0: #rear truncate
+ string = string[:max_len-3] + '...'
+ return string
+ ##################################################
+ # simple conditions
+ ##################################################
+ if not self.is_valid(): return _truncate(self.get_value())
if self.get_value() in self.get_option_keys(): return self.get_option(self.get_value()).get_name()
##################################################
# display logic for numbers
# split up formatting by type
##################################################
truncate = 0 #default center truncate
- max_len = max(27 - len(self.get_name()), 3)
e = self.get_evaluated()
t = self.get_type()
if isinstance(e, bool): return str(e)
truncate = -1
else: dt_str = str(e) #other types
##################################################
- # truncate
+ # done
##################################################
- if len(dt_str) > max_len:
- if truncate < 0: #front truncate
- dt_str = '...' + dt_str[3-max_len:]
- elif truncate == 0: #center truncate
- dt_str = dt_str[:max_len/2 -3] + '...' + dt_str[-max_len/2:]
- elif truncate > 0: #rear truncate
- dt_str = dt_str[:max_len-3] + '...'
- return dt_str
+ return _truncate(dt_str, truncate)
def get_input(self, *args, **kwargs):
if self.get_type() in ('file_open', 'file_save'): return FileParam(self, *args, **kwargs)
#########################
# Numeric Types
#########################
- elif t in ('raw', 'complex', 'real', 'int', 'complex_vector', 'real_vector', 'int_vector', 'hex', 'bool'):
+ elif t in ('raw', 'complex', 'real', 'int', 'hex', 'bool'):
#raise exception if python cannot evaluate this value
try: e = self.get_parent().get_parent().evaluate(v)
except Exception, e: raise Exception, 'Value "%s" cannot be evaluated:\n%s'%(v, e)
try: assert isinstance(e, INT_TYPES)
except AssertionError: raise Exception, 'Expression "%s" is invalid for type integer.'%str(e)
return e
- #########################
- # Numeric Vector Types
- #########################
- elif t == 'complex_vector':
+ elif t == 'hex': return hex(e)
+ elif t == 'bool':
+ try: assert isinstance(e, bool)
+ except AssertionError: raise Exception, 'Expression "%s" is invalid for type bool.'%str(e)
+ return e
+ else: raise TypeError, 'Type "%s" not handled'%t
+ #########################
+ # Numeric Vector Types
+ #########################
+ elif t in ('complex_vector', 'real_vector', 'int_vector'):
+ if not v: v = '()' #turn a blank string into an empty list, so it will eval
+ #raise exception if python cannot evaluate this value
+ try: e = self.get_parent().get_parent().evaluate(v)
+ except Exception, e: raise Exception, 'Value "%s" cannot be evaluated:\n%s'%(v, e)
+ #raise an exception if the data is invalid
+ if t == 'complex_vector':
if not isinstance(e, VECTOR_TYPES):
self._lisitify_flag = True
e = [e]
for ei in e: assert isinstance(ei, INT_TYPES)
except AssertionError: raise Exception, 'Expression "%s" is invalid for type integer vector.'%str(e)
return e
- elif t == 'hex': return hex(e)
- elif t == 'bool':
- try: assert isinstance(e, bool)
- except AssertionError: raise Exception, 'Expression "%s" is invalid for type bool.'%str(e)
- return e
- else: raise TypeError, 'Type "%s" not handled'%t
#########################
# String Types
#########################