[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r7609 - in grc/branches/grc_reloaded/src/grc: . elemen
From: |
jblum |
Subject: |
[Commit-gnuradio] r7609 - in grc/branches/grc_reloaded/src/grc: . elements platforms/gnuradio_python platforms/gnuradio_python/blocks platforms/gnuradio_python/blocks/operators platforms/gnuradio_python/blocks/variables |
Date: |
Fri, 8 Feb 2008 11:14:12 -0700 (MST) |
Author: jblum
Date: 2008-02-08 11:14:12 -0700 (Fri, 08 Feb 2008)
New Revision: 7609
Added:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_enum.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
Removed:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/misc/
Modified:
grc/branches/grc_reloaded/src/grc/__init__.py
grc/branches/grc_reloaded/src/grc/elements/Block.py
grc/branches/grc_reloaded/src/grc/elements/Connection.py
grc/branches/grc_reloaded/src/grc/elements/Element.py
grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py
grc/branches/grc_reloaded/src/grc/elements/Param.py
grc/branches/grc_reloaded/src/grc/elements/Platform.py
grc/branches/grc_reloaded/src/grc/elements/Port.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Port.py
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/block.dtd
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add.xml
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
Log:
work on contructors and variables
Modified: grc/branches/grc_reloaded/src/grc/__init__.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/__init__.py 2008-02-08 04:36:56 UTC
(rev 7608)
+++ grc/branches/grc_reloaded/src/grc/__init__.py 2008-02-08 18:14:12 UTC
(rev 7609)
@@ -22,5 +22,5 @@
from grc.platforms.gnuradio_python.Platform import Platform
-platform = Platform.make_platform()
+platform = Platform()
print platform.get_block_keys()
Modified: grc/branches/grc_reloaded/src/grc/elements/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Block.py 2008-02-08 04:36:56 UTC
(rev 7608)
+++ grc/branches/grc_reloaded/src/grc/elements/Block.py 2008-02-08 18:14:12 UTC
(rev 7609)
@@ -28,23 +28,39 @@
class Block(Element):
- ##static constructor for param
- Param = Param.make_param_from_n
- ##static constructor for source
- Source = Port.make_port_from_n
- ##static constructor for sink
- Sink = Port.make_port_from_n
-
- def __init__(self, flow_graph, doc, name, key, cat, params, checks,
sources, sinks):
+ def __init__(self, flow_graph, n):
+ """
+ Make a new block from nested data.
+ @param flow graph the parent element
+ @param n the nested odict
+ @return block a new block
+ """
+ #grab the data
+ name = n['name']
+ key = n['key']
+ cat = n['cat']
+ params = Utils.listify(n, 'param')
+ checks = Utils.listify(n, 'check')
+ sources = Utils.listify(n, 'source')
+ sinks = Utils.listify(n, 'sink')
+ #build the block
Element.__init__(self, flow_graph)
#store the data
- self._doc = doc
self._name = name
self._key = key
self._cat = cat
#create the param objects
self._params = odict()
- for param in map(self.Param, params):
+ #add the id param
+ self._params['id'] = self.get_parent().get_parent().Param(
+ self,
+ {
+ 'name': 'ID',
+ 'key': 'id',
+ 'type': 'block_id_key',
+ }
+ )
+ for param in map(lambda n:
self.get_parent().get_parent().Param(self, n), params):
key = param.get_key()
#test against repeated keys
try: assert(key not in self.get_param_keys())
@@ -55,7 +71,7 @@
self._checks = checks
#create the source objects
self._sources = odict()
- for source in map(self.Source, sources):
+ for source in map(lambda n:
self.get_parent().get_parent().Source(self, n), sources):
key = source.get_key()
#test against repeated keys
try: assert(key not in self.get_source_keys())
@@ -64,7 +80,7 @@
self._sources[key] = source
#create the sink objects
self._sinks = odict()
- for sink in map(self.Sink, sinks):
+ for sink in map(lambda n:
self.get_parent().get_parent().Sink(self, n), sinks):
key = sink.get_key()
#test against repeated keys
try: assert(key not in self.get_sink_keys())
@@ -99,6 +115,8 @@
def __str__(self): return 'Block: %s(%s)'%(self.get_name(),
self.get_key())
+ def is_block(self): return True
+
def get_doc(self): return self._doc
def get_name(self): return self._name
@@ -107,6 +125,8 @@
def get_category(self): return self._cat
+ def get_doc(self): return ''
+
##############################################
# Access Params
##############################################
@@ -166,39 +186,3 @@
Any param keys that do not exist will be ignored.
@param n the nested data odict
"""
-
- ##############################################
- ## Static Make Methods
- ##############################################
- def make_block_from_n(flow_graph, n):
- """
- Make a new block from nested data.
- @param flow graph the parent element
- @param n the nested odict
- @return block a new block
- """
- #grab the data
- doc = Utils.exists_or_else(n, 'doc', '')
- name = n['name']
- key = n['key']
- cat = n['cat']
- params = Utils.listify(n, 'param')
- checks = Utils.listify(n, 'check')
- sources = Utils.listify(n, 'source')
- sinks = Utils.listify(n, 'sink')
- #build the block
- return Block(
- flow_graph=flow_graph,
- doc=doc,
- name=name,
- key=key,
- cat=cat,
- params=params,
- checks=checks,
- sources=sources,
- sinks=sinks,
- )
- make_block_from_n = staticmethod(make_block_from_n)
-
-
-
Modified: grc/branches/grc_reloaded/src/grc/elements/Connection.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Connection.py 2008-02-08
04:36:56 UTC (rev 7608)
+++ grc/branches/grc_reloaded/src/grc/elements/Connection.py 2008-02-08
18:14:12 UTC (rev 7609)
@@ -27,8 +27,31 @@
class Connection(Element):
+ def __init__(self, flow_graph, porta, portb):
+ """!
+ Make a new connection given the parent and 2 ports.
+ @param flow_graph the parent of this element
+ @param porta a port (any direction)
+ @param portb a port (any direction)
+ @throws Error cannot make connection
+ @return a new connection
+ """
+ Element.__init__(self, flow_graph)
+ source = sink = None
+ #separate the source and sink
+ for port in (porta, portb):
+ if hasattr(port, 'is_source') and port.is_source():
source = port
+ if hasattr(port, 'is_sink') and port.is_sink(): sink =
port
+ #verify the source and sink
+ assert(source and sink)
+ #TODO how many connections allowed?
+ self._source = source
+ self._sink = sink
+
def __str__(self): return 'Connection: %s -> %s'%(self.get_source(),
self.get_sink())
+ def is_connection(self): return True
+
def validate(self):
"""
Validate the connections.
@@ -45,10 +68,6 @@
def get_sink(self): return self._sink
def get_source(self): return self._source
- def _load(self, n):
- self._sink = n['sink']
- self._source = n['source']
-
def make_connection_from_n(flow_graph, n):
"""!
Make a new connection given the parent and nested data.
@@ -76,30 +95,8 @@
source = source_block.get_source(source_key)
sink = sink_block.get_sink(sink_key)
#build the connection
- return make_connection_from_ports(flow_graph, source, sink)
+ return Connection(flow_graph, source, sink)
make_connection_from_n = staticmethod(make_connection_from_n)
- def make_connection_from_ports(flow_graph, porta, portb):
- """!
- Make a new connection given the parent and 2 ports.
- @param flow_graph the parent of this element
- @param porta a port (any direction)
- @param portb a port (any direction)
- @throws Error cannot make connection
- @return a new connection
- """
- source = sink = None
- #separate the source and sink
- for port in (porta, portb):
- if hasattr(port, 'is_source') and port.is_source():
source = port
- if hasattr(port, 'is_sink') and port.is_sink(): sink =
port
- #verify the source and sink
- assert(source and sink)
- #TODO how many connections allowed?
- n = {
- 'source': source,
- 'sink': sink,
- }
- return Connection(parent=flow_graph, n=n)
- make_connection_from_ports = staticmethod(make_connection_from_ports)
+
Modified: grc/branches/grc_reloaded/src/grc/elements/Element.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Element.py 2008-02-08
04:36:56 UTC (rev 7608)
+++ grc/branches/grc_reloaded/src/grc/elements/Element.py 2008-02-08
18:14:12 UTC (rev 7609)
@@ -67,5 +67,22 @@
for i, element in enumerate(elements + [error]):
err_str = err_str + '\n' + ''.join(' '*(i+2)) +
str(element)
err_str = err_str + '\n'
- exit(err_str)
+ exit(err_str)
+ ##############################################
+ ## Type testing methods
+ ##############################################
+
+ def is_element(self): return True
+
+ def is_platform(self): return False
+
+ def is_flow_graph(self): return False
+
+ def is_connection(self): return False
+
+ def is_block(self): return False
+
+ def is_port(self): return False
+
+ def is_param(self): return False
Modified: grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py 2008-02-08
04:36:56 UTC (rev 7608)
+++ grc/branches/grc_reloaded/src/grc/elements/FlowGraph.py 2008-02-08
18:14:12 UTC (rev 7609)
@@ -28,30 +28,32 @@
class FlowGraph(Element):
- ##static constructor for block
- Block = Block.make_block_from_n
- ##static constructor for connection
- Connection = Connection.make_connection_from_n
-
- def __init__(self, platforms):
- Element.__init__(self)
+ def __init__(self, platform):
+ """!
+ Make a flow graph from the arguments.
+ @param platforms a list of platforms to load
+ @return the flow graph object
+ """
+ Element.__init__(self, platform)
#load the platform modules
- self._platforms = odict()
- for key in platforms:
- try:
- platform_module = __import__(
- 'grc.platforms',
- globals=globals(),
- locals=locals(),
- fromlist=[key],
- level=-1,
- )
- platform = getattr(platform_module,
key).get_platform()
- self._platforms[platform.get_key()] = platform
- except ImportError, e: self._exit_with_error('Error
importing platform "%s": "%s"'%(key, e))
+ #self._platforms = odict()
+ #for key in platforms:
+ # try:
+ # platform_module = __import__(
+ # 'grc.platforms',
+ # globals=globals(),
+ # locals=locals(),
+ # fromlist=[key],
+ # level=-1,
+ # )
+ # platform = getattr(platform_module,
key).get_platform()
+ # self._platforms[platform.get_key()] = platform
+ # except ImportError, e: self._exit_with_error('Error
importing platform "%s": "%s"'%(key, e))
- def __str__(self): return 'FlowGraph: %s'%self.get_platform_keys()
+ def __str__(self): return 'FlowGraph: '
+ def is_flow_graph(self): return True
+
def evaluate(self, expr):
"""
Evaluate the expression.
@@ -69,12 +71,6 @@
#TODO
##############################################
- # Access Platforms
- ##############################################
- def get_platform_keys(self): return self._platforms.keys()
- def get_platform(self, key): return self._platforms[key]
-
- ##############################################
## Import/Export Methods
##############################################
def export_data(self):
@@ -91,16 +87,3 @@
Any blocks or connections in error will be ignored.
@param n the nested data odict
"""
-
- ##############################################
- ## Static Make Methods
- ##############################################
- def make_flow_graph(platforms):
- """!
- Make a flow graph from the arguments.
- @param platforms a list of platforms to load
- @return the flow graph object
- """
- return FlowGraph(platforms)
- make_flow_graph = staticmethod(make_flow_graph)
-
Modified: grc/branches/grc_reloaded/src/grc/elements/Param.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Param.py 2008-02-08 04:36:56 UTC
(rev 7608)
+++ grc/branches/grc_reloaded/src/grc/elements/Param.py 2008-02-08 18:14:12 UTC
(rev 7609)
@@ -83,7 +83,20 @@
##possible param types
TYPES = ['enum']
- def __init__(self, block, name, key, value, type, options):
+ def __init__(self, block, n):
+ """
+ Make a new param from nested data.
+ @param block the parent element
+ @param n the nested odict
+ @return a new param
+ """
+ #grab the data
+ name = n['name']
+ key = n['key']
+ value = Utils.exists_or_else(n, 'value', None)
+ type = n['type']
+ options = Utils.listify(n, 'option')
+ #build the param
Element.__init__(self, block)
self._name = name
self._key = key
@@ -136,6 +149,8 @@
def __str__(self): return 'Param: %s(%s)'%(self.get_name(),
self.get_key())
+ def is_param(self): return True
+
def get_name(self): return self._name
def get_key(self): return self._key
@@ -161,33 +176,5 @@
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()
-
- ##############################################
- ## Static Make Methods
- ##############################################
- def make_param_from_n(block, n):
- """
- Make a new param from nested data.
- @param block the parent element
- @param n the nested odict
- @return a new param
- """
- #grab the data
- name = n['name']
- key = n['key']
- value = Utils.exists_or_else(n, 'value', None)
- type = n['type']
- options = Utils.listify(n, 'option')
- #build the param
- return Param(
- block=block,
- name=name,
- key=key,
- value=value,
- type=type,
- options=options,
- )
- make_param_from_n = staticmethod(make_param_from_n)
-
-
+
Modified: grc/branches/grc_reloaded/src/grc/elements/Platform.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Platform.py 2008-02-08
04:36:56 UTC (rev 7608)
+++ grc/branches/grc_reloaded/src/grc/elements/Platform.py 2008-02-08
18:14:12 UTC (rev 7609)
@@ -22,20 +22,29 @@
import os
from grc import ParseXML
-from grc.elements.Element import Element
-from grc.elements.Block import Block
+from grc.elements.Element import Element as _Element
+from grc.elements.FlowGraph import FlowGraph as _FlowGraph
+from grc.elements.Connection import Connection as _Connection
+from grc.elements.Block import Block as _Block
+from grc.elements.Port import Port as _Port
+from grc.elements.Param import Param as _Param
-class Platform(Element):
+class Platform(_Element):
- ##static constructor for block
- Block = Block.make_block_from_n
-
def __init__(self, name, key, path):
- Element.__init__(self)
+ """!
+ Make a platform from the arguments.
+ @param name the platform name
+ @param key the unique platform key
+ @param path the file path to this platform
+ @return a platform object
+ """
+ _Element.__init__(self)
self._name = name
self._key = key
self._path = path
#load the blocks
+ flow_graph = self.FlowGraph(self)
self._blocks = dict()
for dirpath,dirnames,filenames in os.walk(self._path +
'/blocks/'):
for filename in filter(lambda f: f.endswith('.xml'),
filenames):
@@ -44,7 +53,7 @@
except ParseXML.ValidationError, e:
self._exit_with_error('Block definition "%s" failed: \n\t%s'%(f, e))
x = ParseXML.from_file(f)
n = ParseXML.from_xml(x)['block']
- block = self.Block(n)
+ block = self.Block(flow_graph, n)
key = block.get_key()
#test against repeated keys
try: assert(key not in self.get_block_keys())
@@ -54,6 +63,8 @@
def __str__(self): return 'Platform: %s(%s)'%(self.get_name(),
self.get_key())
+ def is_platform(self): return True
+
##############################################
# Access Blocks
##############################################
@@ -63,17 +74,13 @@
def get_name(self): return self._name
def get_key(self): return self._key
-
+
##############################################
- ## Static Make Methods
+ # Constructors
##############################################
- def make_platform(name, key, path):
- """!
- Make a platform from the arguments.
- @param name the platform name
- @param key the unique platform key
- @param path the file path to this platform
- @return a platform object
- """
- return Platform(name=name, key=key, path=path)
- make_platform = staticmethod(make_platform)
+ FlowGraph = _FlowGraph
+ Connection = _Connection
+ Block = _Block
+ Source = _Port
+ Sink = _Port
+ Param = _Param
Modified: grc/branches/grc_reloaded/src/grc/elements/Port.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/elements/Port.py 2008-02-08 04:36:56 UTC
(rev 7608)
+++ grc/branches/grc_reloaded/src/grc/elements/Port.py 2008-02-08 18:14:12 UTC
(rev 7609)
@@ -28,7 +28,18 @@
##possible port types
TYPES = []
- def __init__(self, block, name, key, type):
+ def __init__(self, block, n):
+ """
+ Make a new port from nested data.
+ @param block the parent element
+ @param n the nested odict
+ @return a new port
+ """
+ #grab the data
+ name = n['name']
+ key = n['key']
+ type = n['type']
+ #build the port
Element.__init__(self, block)
self._name = name
self._key = key
@@ -46,6 +57,8 @@
def __str__(self): return 'Port: %s(%s)'%(self.get_name(),
self.get_key())
+ def is_port(self): return True
+
def get_color(self): return '#FFFFFF'
def get_name(self): return self._name
@@ -84,27 +97,3 @@
@return true if empty
"""
return not self.get_connections()
-
- ##############################################
- ## Static Make Methods
- ##############################################
- def make_port_from_n(block, n):
- """
- Make a new port from nested data.
- @param block the parent element
- @param n the nested odict
- @return a new port
- """
- #grab the data
- name = n['name']
- key = n['key']
- type = n['type']
- #build the port
- return Port(
- block=block,
- name=name,
- key=key,
- type=type,
- )
- make_port_from_n = staticmethod(make_port_from_n)
-
Modified: grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py
2008-02-08 04:36:56 UTC (rev 7608)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Block.py
2008-02-08 18:14:12 UTC (rev 7609)
@@ -21,39 +21,39 @@
address@hidden Josh Blum
from grc.elements.Block import Block as _Block
-from Port import Port
-from Param import Param
from grc import Utils
class Block(_Block):
- ##override static constructor for param
- Param = Param.make_param_from_n
- ##override static constructor for source
- Source = Port.make_source_from_n
- ##override static constructor for sink
- Sink = Port.make_sink_from_n
-
##for make source to keep track of indexes
_source_count = 0
##for make sink to keep track of indexes
_sink_count = 0
- def __init__(self, flow_graph, doc, name, key, cat, deps, fcn,
callbacks, params, sources, sinks):
+ def __init__(self, flow_graph, n):
+ """
+ Make a new block from nested data.
+ @param flow graph the parent element
+ @param n the nested odict
+ @return block a new block
+ """
+ #grab the data
+ doc = Utils.exists_or_else(n, 'doc', '')
+ deps = Utils.listify(n, 'dep')
+ fcn = n['fcn']
+ callbacks = Utils.listify(n, 'callback')
+ #build the block
_Block.__init__(
self,
flow_graph=flow_graph,
- doc=doc,
- name=name,
- key=key,
- cat=cat,
- params=params,
- sources=sources,
- sinks=sinks,
+ n=n,
)
+ self._doc = doc
self._deps = deps
self._fcn = fcn
self._callbacks = callbacks
+
+ def get_doc(self): return self._doc
def get_deps(self): return self._deps
@@ -64,25 +64,8 @@
##############################################
## Static Make Methods
##############################################
- def make_block_from_n(flow_graph, n):
- """
- Make a new block from nested data.
- @param flow graph the parent element
- @param n the nested odict
- @return block a new block
- """
- #grab the data
- doc = Utils.exists_or_else(n, 'doc', '')
- name = n['name']
- key = n['key']
- cat = n['cat']
- deps = Utils.listify(n, 'dep')
- fcn = n['fcn']
- callbacks = Utils.listify(n, 'callback')
- params = Utils.listify(n, 'param')
- sources = Utils.listify(n, 'source')
- sinks = Utils.listify(n, 'sink')
- #build the block
+ def make_block_from_n():
+
return Block(
flow_graph=flow_graph,
doc=doc,
@@ -93,6 +76,7 @@
fcn=fcn,
callbacks=callbacks,
params=params,
+ checks=checks,
sources=sources,
sinks=sinks,
)
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py
2008-02-08 04:36:56 UTC (rev 7608)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/FlowGraph.py
2008-02-08 18:14:12 UTC (rev 7609)
@@ -26,11 +26,6 @@
class FlowGraph(_FlowGraph):
- ##override static constructor for block
- Block = Block.make_block_from_n
- ##override static constructor for connection
- Connection = Connection.make_connection_from_n
-
def evaluate(self, expr):
"""
Evaluate the expression.
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
2008-02-08 04:36:56 UTC (rev 7608)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Platform.py
2008-02-08 18:14:12 UTC (rev 7609)
@@ -22,17 +22,15 @@
import os
from grc.elements.Platform import Platform as _Platform
-from Block import Block
+from FlowGraph import FlowGraph as _FlowGraph
+from Connection import Connection as _Connection
+from Block import Block as _Block
+from Port import Source,Sink
+from Param import Param as _Param
class Platform(_Platform):
- ##override static constructor for block
- Block = Block.make_block_from_n
-
- ##############################################
- ## Static Make Methods
- ##############################################
- def make_platform():
+ def __init__(self):
"""!
Make a platform from the arguments.
@param name the platform name
@@ -40,10 +38,20 @@
@param path the file path to this platform
@return a platform object
"""
- return Platform(
+ _Platform.__init__(
+ self,
name='GNURadio Python',
key='gnuradio_python',
path=os.path.dirname(__file__),
- )
- make_platform = staticmethod(make_platform)
+ )
+
+ ##############################################
+ # Constructors
+ ##############################################
+ FlowGraph = _FlowGraph
+ Connection = _Connection
+ Block = _Block
+ Source = Source
+ Sink = Sink
+ Param = _Param
Modified: grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Port.py
===================================================================
--- grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Port.py
2008-02-08 04:36:56 UTC (rev 7608)
+++ grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/Port.py
2008-02-08 18:14:12 UTC (rev 7609)
@@ -28,13 +28,21 @@
##possible port types
TYPES = ['complex', 'float', 'int', 'short', 'byte']
- def __init__(self, block, name, key, type, vlen, nports, optional):
+ def __init__(self, block, n):
+ """
+ Make a new port from nested data.
+ @param block the parent element
+ @param n the nested odict
+ @return a new port
+ """
+ vlen = Utils.exists_or_else(n, 'vlen', '1')
+ nports = Utils.exists_or_else(n, 'nports', '')
+ optional = Utils.exists_or_else(n, 'optional', '')
+ #build the port
_Port.__init__(
- self,
- block=block,
- name=name,
- key=key,
- type=type,
+ self,
+ block=block,
+ n=n,
)
self._nports = nports
self._vlen = vlen
@@ -105,64 +113,19 @@
@return true if empty
"""
return not self.get_optional() and not self.get_connections()
-
- ##############################################
- ## Static Make Methods
- ##############################################
- def make_source_from_n(block, n):
- """
- Make a new port from nested data.
- @param block the parent element
- @param n the nested odict
- @return a new source port
- """
- #grab the data
- name = n['name']
- type = n['type']
- vlen = Utils.exists_or_else(n, 'vlen', '')
- nports = Utils.exists_or_else(n, 'nports', '')
- optional = Utils.exists_or_else(n, 'optional', '')
+
+class Source(Port):
+
+ def __init__(self, block, n):
#key is port index
- key = str(block._source_count)
+ n['key'] = str(block._source_count)
block._source_count = block._source_count + 1
- #build the port
- return Port(
- block=block,
- name=name,
- key=key,
- type=type,
- vlen=vlen,
- nports=nports,
- optional=optional,
- )
- make_source_from_n = staticmethod(make_source_from_n)
+ Port.__init__(self, block, n)
- def make_sink_from_n(block, n):
- """
- Make a new port from nested data.
- @param block the parent element
- @param n the nested odict
- @return a new sink port
- """
- #grab the data
- name = n['name']
- type = n['type']
- vlen = Utils.exists_or_else(n, 'vlen', '1')
- nports = Utils.exists_or_else(n, 'nports', '')
- optional = Utils.exists_or_else(n, 'optional', '')
+class Sink(Port):
+
+ def __init__(self, block, n):
#key is port index
- key = str(block._sink_count)
- block._sink_count = block._sink_count + 1
- #build the port
- return Port(
- block=block,
- name=name,
- key=key,
- type=type,
- vlen=vlen,
- nports=nports,
- optional=optional,
- )
- make_sink_from_n = staticmethod(make_sink_from_n)
-
-
+ n['key'] = str(block._sink_count)
+ block._sink_count = block._sink_count + 1
+ Port.__init__(self, block, n)
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/block.dtd
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/block.dtd
2008-02-08 04:36:56 UTC (rev 7608)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/block.dtd
2008-02-08 18:14:12 UTC (rev 7609)
@@ -26,7 +26,7 @@
Top level element.
A block contains a name, ...parameters list, and list of IO ports.
-->
-<!ELEMENT block (doc?, name, key, cat, dep*, fcn, callback*, param*, check*,
sink*, source*)>
+<!ELEMENT block (name, key, cat, dep*, fcn, callback*, param*, check*, sink*,
source*, doc?)>
<!--
Sub level elements.
-->
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add.xml
2008-02-08 04:36:56 UTC (rev 7608)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add.xml
2008-02-08 18:14:12 UTC (rev 7609)
@@ -10,7 +10,7 @@
<name>Add</name>
<key>add</key>
<cat>Operators</cat>
- <dep>gr</dep>
+ <dep>from gnuradio import gr</dep>
<fcn>$type:fcn($vec_len)</fcn>
<param>
<name>Num Inputs</name>
Modified:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
2008-02-08 04:36:56 UTC (rev 7608)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/operators/add_const.xml
2008-02-08 18:14:12 UTC (rev 7609)
@@ -10,7 +10,7 @@
<name>Add Const</name>
<key>add_const</key>
<cat>Operators</cat>
- <dep>gnuradio.gr</dep>
+ <dep>from gnuradio import gr</dep>
<fcn>$type:fcn($const)</fcn>
<callback>set_k($const)</callback>
<param>
Added:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
(rev 0)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable.xml
2008-02-08 18:14:12 UTC (rev 7609)
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!--
+###################################################
+##Variable block: a grc variable with key, value, min, max, step
+###################################################
+ -->
+<block>
+ <name>Variable</name>
+ <key>variable</key>
+ <cat>Variables</cat>
+ <fcn />
+ <param>
+ <name>Key</name>
+ <key>key</key>
+ <type>var_key</type>
+ </param>
+ <param>
+ <name>Value</name>
+ <key>value</key>
+ <type>raw</type>
+ </param>
+ <doc>
+This block maps a value to a variable name.
+The variable name must be unique and the value must evaluate to a python value.
+This variable block has no graphical representation.
+Use the variable slider, enum, or button for graphical options.
+ </doc>
+</block>
Added:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
(rev 0)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_button.xml
2008-02-08 18:14:12 UTC (rev 7609)
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!--
+###################################################
+##Variable block: a grc variable with key, value, min, max, step
+###################################################
+ -->
+<block>
+ <name>Variable Button</name>
+ <key>variable_button</key>
+ <cat>Variables</cat>
+ <fcn />
+ <param>
+ <name>Key</name>
+ <key>key</key>
+ <type>var_key</type>
+ </param>
+ <param>
+ <name>Off Value</name>
+ <key>off_value</key>
+ <value>0</value>
+ <type>raw</type>
+ </param>
+ <param>
+ <name>On Value</name>
+ <key>on_value</key>
+ <value>1</value>
+ <type>raw</type>
+ </param>
+</block>
Added:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_enum.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_enum.xml
(rev 0)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_enum.xml
2008-02-08 18:14:12 UTC (rev 7609)
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!--
+###################################################
+##Variable block: a grc variable with key, value, min, max, step
+###################################################
+ -->
+<block>
+ <name>Variable Enum</name>
+ <key>variable_enum</key>
+ <cat>Variables</cat>
+ <fcn />
+ <param>
+ <name>Key</name>
+ <key>key</key>
+ <type>var_key</type>
+ </param>
+ <param>
+ <name>Default Value</name>
+ <key>default_value</key>
+ <value>0</value>
+ <type>int</type>
+ </param>
+ <param>
+ <name>Choices</name>
+ <key>choices</key>
+ <value>[val0, val1, val2...]</value>
+ <type>raw</type>
+ </param>
+ <check>len($choices) > 0</check>
+ <check>$default_value in range(0, len($choices))</check>
+ <doc>
+This block creates a variable with a drop down.
+The variable name must be unique.
+The default value is the index of a particular choice.
+The choices must be a list of possible values.
+ </doc>
+</block>
Added:
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
===================================================================
---
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
(rev 0)
+++
grc/branches/grc_reloaded/src/grc/platforms/gnuradio_python/blocks/variables/variable_slider.xml
2008-02-08 18:14:12 UTC (rev 7609)
@@ -0,0 +1,38 @@
+<?xml version="1.0"?>
+<!DOCTYPE block SYSTEM "../block.dtd">
+<!--
+###################################################
+##Variable block: a grc variable with key, value, min, max, step
+###################################################
+ -->
+<block>
+ <name>Variable Slider</name>
+ <key>variable_slider</key>
+ <cat>Variables</cat>
+ <fcn />
+ <param>
+ <name>Key</name>
+ <key>key</key>
+ <type>var_key</type>
+ </param>
+ <param>
+ <name>Value</name>
+ <key>value</key>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Minimum</name>
+ <key>min</key>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Maximum</name>
+ <key>max</key>
+ <type>real</type>
+ </param>
+ <param>
+ <name>Step Size</name>
+ <key>step</key>
+ <type>real</type>
+ </param>
+</block>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r7609 - in grc/branches/grc_reloaded/src/grc: . elements platforms/gnuradio_python platforms/gnuradio_python/blocks platforms/gnuradio_python/blocks/operators platforms/gnuradio_python/blocks/variables,
jblum <=