diff options
-rw-r--r-- | grc/base/Block.py | 6 | ||||
-rw-r--r-- | grc/base/Param.py | 41 | ||||
-rw-r--r-- | grc/base/Port.py | 9 | ||||
-rw-r--r-- | grc/python/Param.py | 29 | ||||
-rw-r--r-- | grc/python/Port.py | 9 | ||||
-rw-r--r-- | grc/python/flow_graph.tmpl | 4 | ||||
-rw-r--r-- | grc/todo.txt | 1 |
7 files changed, 55 insertions, 44 deletions
diff --git a/grc/base/Block.py b/grc/base/Block.py index d2266e783..737010305 100644 --- a/grc/base/Block.py +++ b/grc/base/Block.py @@ -91,7 +91,7 @@ class Block(Element): 'hide': 'all', }) )) - for param in map(lambda n: self.get_parent().get_parent().Param(self, n), params): + for param in map(lambda n: self.get_parent().get_parent().Param(block=self, n=n), params): key = param.get_key() #test against repeated keys try: assert key not in self.get_param_keys() @@ -100,7 +100,7 @@ class Block(Element): self.get_params().append(param) #create the source objects self._sources = list() - for source in map(lambda n: self.get_parent().get_parent().Port(self, n, dir='source'), sources): + for source in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='source'), sources): key = source.get_key() #test against repeated keys try: assert key not in self.get_source_keys() @@ -109,7 +109,7 @@ class Block(Element): self.get_sources().append(source) #create the sink objects self._sinks = list() - for sink in map(lambda n: self.get_parent().get_parent().Port(self, n, dir='sink'), sinks): + for sink in map(lambda n: self.get_parent().get_parent().Port(block=self, n=n, dir='sink'), sinks): key = sink.get_key() #test against repeated keys try: assert key not in self.get_sink_keys() diff --git a/grc/base/Param.py b/grc/base/Param.py index 93c1c52bd..d1b22454f 100644 --- a/grc/base/Param.py +++ b/grc/base/Param.py @@ -88,6 +88,11 @@ class EnumEntryParam(InputParam): else: #from enum, make white background self._input.get_child().modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff')) +def _get_keys(lst): return [elem.get_key() for elem in lst] +def _get_elem(lst, key): + try: return lst[_get_keys(lst).index(key)] + except ValueError: raise ValueError, 'Key "%s" not found in %s.'%(key, _get_keys(lst)) + class Option(Element): def __init__(self, param, n): @@ -123,16 +128,14 @@ class Option(Element): class Param(Element): - ##possible param types - TYPES = ['enum', 'raw'] - - def __init__(self, block, n): + def __init__(self, block, n, types): """ Make a new param from nested data. @param block the parent element @param n the nested odict - @return a new param + @param types a list of possible types """ + self._types = types #grab the data self._name = n.find('name') self._key = n.find('key') @@ -142,22 +145,22 @@ class Param(Element): #build the param Element.__init__(self, block) #create the Option objects from the n data - self._options = odict() - for option in map(lambda o: Option(self, o), n.findall('option')): + self._options = list() + for option in map(lambda o: Option(param=self, n=o), n.findall('option')): key = option.get_key() #test against repeated keys try: assert key not in self.get_option_keys() except AssertionError: raise Exception, 'Key "%s" already exists in options'%key #store the option - self._options[key] = option + self.get_options().append(option) #test the enum options if self.is_enum(): #test against options with identical keys - try: assert len(set(self.get_option_keys())) == len(self._options) + try: assert len(set(self.get_option_keys())) == len(self.get_options()) except AssertionError: raise Exception, 'Options keys "%s" are not unique.'%self.get_option_keys() #test against inconsistent keys in options - opt_keys = self._options.values()[0].get_opt_keys() - for option in self._options.values(): + opt_keys = self.get_options()[0].get_opt_keys() + for option in self.get_options(): try: assert set(opt_keys) == set(option.get_opt_keys()) except AssertionError: raise Exception, 'Opt keys "%s" are not identical across all options.'%opt_keys #if a value is specified, it must be in the options keys @@ -180,7 +183,7 @@ class Param(Element): The value must be evaluated and type must a possible type. """ Element.validate(self) - try: assert self.get_type() in self.TYPES + try: assert self.get_type() in self._types except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type()) def get_evaluated(self): raise NotImplementedError @@ -197,7 +200,7 @@ class Param(Element): def is_param(self): return True def get_name(self): return self._name def get_key(self): return self._key - def get_hide(self): return self.get_parent().resolve_dependencies(self._hide) + def get_hide(self): return self.get_parent().resolve_dependencies(self._hide).strip() def get_value(self): value = self._value @@ -238,16 +241,16 @@ class Param(Element): ############################################## # Access Options ############################################## - def get_option_keys(self): return self._options.keys() - def get_option(self, key): return self._options[key] - def get_options(self): return self._options.values() + def get_option_keys(self): return _get_keys(self.get_options()) + def get_option(self, key): return _get_elem(self.get_options(), key) + def get_options(self): return self._options ############################################## # Access Opts ############################################## - def get_opt_keys(self): return self._options[self.get_value()].get_opt_keys() - def get_opt(self, key): return self._options[self.get_value()].get_opt(key) - def get_opts(self): return self._options[self.get_value()].get_opts() + def get_opt_keys(self): return self.get_option(self.get_value()).get_opt_keys() + def get_opt(self, key): return self.get_option(self.get_value()).get_opt(key) + def get_opts(self): return self.get_option(self.get_value()).get_opts() ############################################## ## Import/Export Methods diff --git a/grc/base/Port.py b/grc/base/Port.py index 8e60d5093..81076684a 100644 --- a/grc/base/Port.py +++ b/grc/base/Port.py @@ -21,16 +21,15 @@ from Element import Element class Port(Element): - ##possible port types - TYPES = [] - - def __init__(self, block, n, dir): + def __init__(self, block, n, dir, types): """ Make a new port from nested data. @param block the parent element @param n the nested odict @param dir the direction source or sink + @param types a list of possible types """ + self._types = types #build the port Element.__init__(self, block) #grab the data @@ -45,7 +44,7 @@ class Port(Element): The port must be non-empty and type must a possible type. """ Element.validate(self) - try: assert self.get_type() in self.TYPES + try: assert self.get_type() in self._types except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type()) def __str__(self): diff --git a/grc/python/Param.py b/grc/python/Param.py index 2ca1d0ec0..dd18d1c44 100644 --- a/grc/python/Param.py +++ b/grc/python/Param.py @@ -83,21 +83,30 @@ COMPLEX_TYPES = tuple(COMPLEX_TYPES + REAL_TYPES + INT_TYPES) REAL_TYPES = tuple(REAL_TYPES + INT_TYPES) INT_TYPES = tuple(INT_TYPES) +##possible param types +TYPES = [ + 'raw', 'enum', + 'complex', 'real', 'int', + 'complex_vector', 'real_vector', 'int_vector', + 'hex', 'string', 'bool', + 'file_open', 'file_save', + 'id', 'stream_id', + 'grid_pos', 'notebook', + 'import', +] + class Param(_Param): _init = False _hostage_cells = list() - ##possible param types - TYPES = _Param.TYPES + [ - 'complex', 'real', 'int', - 'complex_vector', 'real_vector', 'int_vector', - 'hex', 'string', 'bool', - 'file_open', 'file_save', - 'id', 'stream_id', - 'grid_pos', 'notebook', - 'import', - ] + def __init__(self, block, n, **kwargs): + _Param.__init__( + self, + block=block, + n=n, + types=TYPES, + ) def __repr__(self): """ diff --git a/grc/python/Port.py b/grc/python/Port.py index d6c622c46..3214d937a 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -49,12 +49,12 @@ def _get_source_from_virtual_source_port(vsp, traversed=[]): ) except: raise Exception, 'Could not resolve source for virtual source port %s'%vsp -class Port(_Port): +##possible port types +TYPES = ['complex', 'float', 'int', 'short', 'byte', 'msg', ''] - ##possible port types - TYPES = ['complex', 'float', 'int', 'short', 'byte', 'msg'] +class Port(_Port): - def __init__(self, block, n, dir): + def __init__(self, block, n, dir, **kwargs): """ Make a new port from nested data. @param block the parent element @@ -75,6 +75,7 @@ class Port(_Port): block=block, n=n, dir=dir, + types=TYPES, ) self._nports = n.find('nports') or '' self._vlen = n.find('vlen') or '' diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl index bd12e82e9..dce4037d5 100644 --- a/grc/python/flow_graph.tmpl +++ b/grc/python/flow_graph.tmpl @@ -171,11 +171,11 @@ self.$port.get_parent().get_id()#slurp #set $source = $con.get_source() #set $sink = $con.get_sink() ##resolve virtual sources to the actual sources - #if $source.is_virtual_source() + #if $source.get_parent().is_virtual_source() #set $source = $source.resolve_virtual_source() #end if ##do not generate connections with virtual sinks - #if not $sink.is_virtual_sink() + #if not $sink.get_parent().is_virtual_sink() self.connect(($make_port_name($source), $source.get_key()), ($make_port_name($sink), $sink.get_key())) #end if #end for diff --git a/grc/todo.txt b/grc/todo.txt index ef94abfb5..e9c407c5e 100644 --- a/grc/todo.txt +++ b/grc/todo.txt @@ -73,7 +73,6 @@ * will not update for non-enum params * needs to account for added or removed params * example with grid params need update after notebook change -* use .strip() on the hide property so we can do away with #slurp(s) in the templates ################################################## # Future |