]> git.gag.com Git - debian/gnuradio/commitdiff
port and param types from an overloaded method
authorJosh Blum <josh@joshknows.com>
Sun, 30 Aug 2009 16:35:55 +0000 (09:35 -0700)
committerJosh Blum <josh@joshknows.com>
Sun, 30 Aug 2009 16:35:55 +0000 (09:35 -0700)
grc/base/Param.py
grc/base/Port.py
grc/python/Param.py
grc/python/Port.py

index d1b22454f1c51665f81b81637dab1f1220c09b0a..21d306592c9414d0628037e801341ccd63a1ea73 100644 (file)
@@ -128,14 +128,12 @@ class Option(Element):
 
 class Param(Element):
 
-       def __init__(self, block, n, types):
+       def __init__(self, block, n):
                """
                Make a new param from nested data.
                @param block the parent element
                @param n the nested odict
-               @param types a list of possible types
                """
-               self._types = types
                #grab the data
                self._name = n.find('name')
                self._key = n.find('key')
@@ -183,7 +181,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.get_types()
                except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
 
        def get_evaluated(self): raise NotImplementedError
@@ -195,6 +193,13 @@ class Param(Element):
                """
                raise NotImplementedError
 
+       def get_types(self):
+               """
+               Get a list of all possible param types.
+               @throw NotImplementedError
+               """
+               raise NotImplementedError
+
        def get_color(self): return '#FFFFFF'
        def __str__(self): return 'Param - %s(%s)'%(self.get_name(), self.get_key())
        def is_param(self): return True
index 81076684ab21b856b02f590d3974cf6719faa621..494ea894f7bdcf55551fc403845472b3aef1207d 100644 (file)
@@ -21,15 +21,13 @@ from Element import Element
 
 class Port(Element):
 
-       def __init__(self, block, n, dir, types):
+       def __init__(self, block, n, dir):
                """
                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
@@ -44,7 +42,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.get_types()
                except AssertionError: self.add_error_message('Type "%s" is not a possible type.'%self.get_type())
 
        def __str__(self):
@@ -53,6 +51,13 @@ class Port(Element):
                if self.is_sink():
                        return 'Sink - %s(%s)'%(self.get_name(), self.get_key())
 
+       def get_types(self):
+               """
+               Get a list of all possible port types.
+               @throw NotImplementedError
+               """
+               raise NotImplementedError
+
        def is_port(self): return True
        def get_color(self): return '#FFFFFF'
        def get_name(self): return self._name
index dd18d1c4459977e41ccfffe5efe7b896d1b9bcc9..d574b513e111d121d537bccd417c6fc1a51ea670 100644 (file)
@@ -83,30 +83,27 @@ 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()
-
-       def __init__(self, block, n, **kwargs):
+       def __init__(self, block, n):
                _Param.__init__(
                        self,
                        block=block,
                        n=n,
-                       types=TYPES,
                )
+               self._init = False
+               self._hostage_cells = list()
+
+       def get_types(self): return (
+               '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',
+       )
 
        def __repr__(self):
                """
index 3214d937a503721e2e4765342bb0679a6b8cf827..a714844efb99db7761ec16146e05fc7557ca8c5d 100644 (file)
@@ -49,12 +49,9 @@ def _get_source_from_virtual_source_port(vsp, traversed=[]):
        )
        except: raise Exception, 'Could not resolve source for virtual source port %s'%vsp
 
-##possible port types
-TYPES = ['complex', 'float', 'int', 'short', 'byte', 'msg', '']
-
 class Port(_Port):
 
-       def __init__(self, block, n, dir, **kwargs):
+       def __init__(self, block, n, dir):
                """
                Make a new port from nested data.
                @param block the parent element
@@ -75,12 +72,13 @@ class Port(_Port):
                        block=block,
                        n=n,
                        dir=dir,
-                       types=TYPES,
                )
                self._nports = n.find('nports') or ''
                self._vlen = n.find('vlen') or ''
                self._optional = bool(n.find('optional'))
 
+       def get_types(self): return ('complex', 'float', 'int', 'short', 'byte', 'msg', '')
+
        def validate(self):
                _Port.validate(self)
                try: assert self.get_enabled_connections() or self.get_optional()