Replaced TYPES in Port and Param with types parameter.
authorJosh Blum <josh@joshknows.com>
Sat, 29 Aug 2009 08:04:58 +0000 (01:04 -0700)
committerJosh Blum <josh@joshknows.com>
Sat, 29 Aug 2009 08:04:58 +0000 (01:04 -0700)
Replaced odict in options for storing options with a list.
Fix virtual port check in flow graph template.

grc/base/Block.py
grc/base/Param.py
grc/base/Port.py
grc/python/Param.py
grc/python/Port.py
grc/python/flow_graph.tmpl
grc/todo.txt

index d2266e7836524d05ff1650d19bd4b7ce24f1823a..7370103052664d1ad39ca1b8ffad11ff15076a70 100644 (file)
@@ -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()
index 93c1c52bdef38114ccc948c9d08dfe1b5856e9dd..d1b22454f1c51665f81b81637dab1f1220c09b0a 100644 (file)
@@ -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
index 8e60d50931c3e91f60203c6d3c93c9d911c472f4..81076684ab21b856b02f590d3974cf6719faa621 100644 (file)
@@ -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):
index 2ca1d0ec00c3e02a7038539ed05bab5b1023cb4a..dd18d1c4459977e41ccfffe5efe7b896d1b9bcc9 100644 (file)
@@ -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):
                """
index d6c622c461243cc7ad8df0abe80e9ea6824c35f2..3214d937a503721e2e4765342bb0679a6b8cf827 100644 (file)
@@ -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 ''
index bd12e82e91d6719926055b643f8abd25410a11e4..dce4037d58a4a9cde77cf99ca7bd10120f81b279 100644 (file)
@@ -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
index ef94abfb5ff00afb8984262abc5b4f839925de5a..e9c407c5e8a7d239a01493639c7fac66687c2f24 100644 (file)
@@ -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