grc bug fix from Dimitris Symeonidis
[debian/gnuradio] / grc / python / Param.py
index c64659a080690583a9de36441af90485bdbfca50..e04bc8fcb587589effbc2bcfef2fc61085bfba69 100644 (file)
@@ -17,7 +17,6 @@ along with this program; if not, write to the Free Software
 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
@@ -66,7 +65,7 @@ class FileParam(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
 
@@ -154,7 +153,7 @@ class Param(_Param, _GUIParam):
                return dt_str
 
        def get_input(self, *args, **kwargs):
-               if self.get_type() in ('file_open', 'file_save'): return FileParam(*args, **kwargs)
+               if self.get_type() in ('file_open', 'file_save'): return FileParam(self, *args, **kwargs)
                return _GUIParam.get_input(self, *args, **kwargs)
 
        def get_color(self):
@@ -251,10 +250,10 @@ class Param(_Param, _GUIParam):
                #########################
                # 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: %s'%(v, e)
+                       except Exception, e: raise Exception, 'Value "%s" cannot be evaluated:\n%s'%(v, e)
                        #raise an exception if the data is invalid
                        if t == 'raw': return e
                        elif t == 'complex':
@@ -269,10 +268,22 @@ class Param(_Param, _GUIParam):
                                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]
@@ -296,12 +307,6 @@ class Param(_Param, _GUIParam):
                                        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
                #########################
@@ -385,7 +390,7 @@ class Param(_Param, _GUIParam):
                        try: notebook_block = filter(lambda b: b.get_id() == notebook_id, notebook_blocks)[0]
                        except: raise Exception, 'Notebook id "%s" is not an existing notebook id.'%notebook_id
                        #check that page index exists
-                       try: assert int(page_index) in range(len(notebook_block.get_param('labels').get_evaluated()))
+                       try: assert int(page_index) in range(len(notebook_block.get_param('labels').evaluate()))
                        except: raise Exception, 'Page index "%s" is not a valid index number.'%page_index
                        return notebook_id, page_index
                #########################