summaryrefslogtreecommitdiff
path: root/grc/src/platforms/base
diff options
context:
space:
mode:
Diffstat (limited to 'grc/src/platforms/base')
-rw-r--r--grc/src/platforms/base/Block.py259
-rw-r--r--grc/src/platforms/base/Connection.py94
-rw-r--r--grc/src/platforms/base/Constants.py.in30
-rw-r--r--grc/src/platforms/base/Element.py96
-rw-r--r--grc/src/platforms/base/FlowGraph.py224
-rw-r--r--grc/src/platforms/base/Makefile.am46
-rw-r--r--grc/src/platforms/base/Param.py271
-rw-r--r--grc/src/platforms/base/Platform.py143
-rw-r--r--grc/src/platforms/base/Port.py80
-rw-r--r--grc/src/platforms/base/__init__.py1
10 files changed, 0 insertions, 1244 deletions
diff --git a/grc/src/platforms/base/Block.py b/grc/src/platforms/base/Block.py
deleted file mode 100644
index 25688472c..000000000
--- a/grc/src/platforms/base/Block.py
+++ /dev/null
@@ -1,259 +0,0 @@
-"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
-
-from ... utils import odict
-from Element import Element
-from Param import Param
-from Port import Port
-
-from Cheetah.Template import Template
-from UserDict import UserDict
-
-class TemplateArg(UserDict):
- """
- A cheetah template argument created from a param.
- The str of this class evaluates to the param's to code method.
- The use of this class as a dictionary (enum only) will reveal the enum opts.
- The __call__ or () method can return the param evaluated to a raw python data type.
- """
-
- def __init__(self, param):
- UserDict.__init__(self)
- self._param = param
- if param.is_enum():
- for key in param.get_opt_keys():
- self[key] = str(param.get_opt(key))
-
- def __str__(self):
- return str(self._param.to_code())
-
- def __call__(self):
- return self._param.evaluate()
-
-class Block(Element):
-
- 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
- """
- #build the block
- Element.__init__(self, flow_graph)
- #grab the data
- params = n.findall('param')
- sources = n.findall('source')
- sinks = n.findall('sink')
- self._name = n.find('name')
- self._key = n.find('key')
- self._category = n.find('category') or ''
- self._block_wrapper_path = n.find('block_wrapper_path')
- #create the param objects
- self._params = odict()
- #add the id param
- self._params['id'] = self.get_parent().get_parent().Param(
- self,
- odict({
- 'name': 'ID',
- 'key': 'id',
- 'type': 'id',
- })
- )
- self._params['_enabled'] = self.get_parent().get_parent().Param(
- self,
- odict({
- 'name': 'Enabled',
- 'key': '_enabled',
- 'type': 'raw',
- 'value': 'True',
- 'hide': 'all',
- })
- )
- 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())
- except AssertionError: self._exit_with_error('Key "%s" already exists in params'%key)
- #store the param
- self._params[key] = param
- #create the source objects
- self._sources = odict()
- 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())
- except AssertionError: self._exit_with_error('Key "%s" already exists in sources'%key)
- #store the port
- self._sources[key] = source
- #create the sink objects
- self._sinks = odict()
- 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())
- except AssertionError: self._exit_with_error('Key "%s" already exists in sinks'%key)
- #store the port
- self._sinks[key] = sink
- #begin the testing
- self.test()
-
- def test(self):
- """
- Call test on all children.
- """
- map(lambda c: c.test(), self.get_params() + self.get_sinks() + self.get_sources())
-
- def get_enabled(self):
- """
- Get the enabled state of the block.
- @return true for enabled
- """
- try: return eval(self.get_param('_enabled').get_value())
- except: return True
-
- def set_enabled(self, enabled):
- """
- Set the enabled state of the block.
- @param enabled true for enabled
- """
- self.get_param('_enabled').set_value(str(enabled))
-
- def validate(self):
- """
- Validate the block.
- All ports and params must be valid.
- All checks must evaluate to true.
- """
- for c in self.get_params() + self.get_ports() + self.get_connections():
- try: assert(c.is_valid())
- except AssertionError:
- for msg in c.get_error_messages():
- self._add_error_message('>>> %s:\n\t%s'%(c, msg))
-
- def __str__(self): return 'Block - %s - %s(%s)'%(self.get_id(), self.get_name(), self.get_key())
-
- def get_id(self): return self.get_param('id').get_value()
- def is_block(self): return True
- def get_name(self): return self._name
- def get_key(self): return self._key
- def get_category(self): return self._category
- def get_doc(self): return ''
- def get_ports(self): return self.get_sources() + self.get_sinks()
- def get_block_wrapper_path(self): return self._block_wrapper_path
-
- ##############################################
- # Access Params
- ##############################################
- def get_param_keys(self): return self._params.keys()
- def get_param(self, key): return self._params[key]
- def get_params(self): return self._params.values()
-
- ##############################################
- # Access Sinks
- ##############################################
- def get_sink_keys(self): return self._sinks.keys()
- def get_sink(self, key): return self._sinks[key]
- def get_sinks(self): return self._sinks.values()
-
- ##############################################
- # Access Sources
- ##############################################
- def get_source_keys(self): return self._sources.keys()
- def get_source(self, key): return self._sources[key]
- def get_sources(self): return self._sources.values()
-
- def get_connections(self):
- return sum([port.get_connections() for port in self.get_ports()], [])
-
- def resolve_dependencies(self, tmpl):
- """
- Resolve a paramater dependency with cheetah templates.
- @param tmpl the string with dependencies
- @return the resolved value
- """
- tmpl = str(tmpl)
- if '$' not in tmpl: return tmpl
- n = dict((p.get_key(), TemplateArg(p)) for p in self.get_params())
- try: return str(Template(tmpl, n))
- except Exception, e: return "-------->\n%s: %s\n<--------"%(e, tmpl)
-
- ##############################################
- # Controller Modify
- ##############################################
- def type_controller_modify(self, direction):
- """
- Change the type controller.
- @param direction +1 or -1
- @return true for change
- """
- changed = False
- type_param = None
- for param in filter(lambda p: p.is_enum(), self.get_params()):
- children = self.get_ports() + self.get_params()
- #priority to the type controller
- if param.get_key() in ' '.join(map(lambda p: p._type, children)): type_param = param
- #use param if type param is unset
- if not type_param: type_param = param
- if type_param:
- #try to increment the enum by direction
- try:
- keys = type_param.get_option_keys()
- old_index = keys.index(type_param.get_value())
- new_index = (old_index + direction + len(keys))%len(keys)
- type_param.set_value(keys[new_index])
- changed = True
- except: pass
- return changed
-
- def port_controller_modify(self, direction):
- """
- Change the port controller.
- @param direction +1 or -1
- @return true for change
- """
- return False
-
- ##############################################
- ## Import/Export Methods
- ##############################################
- def export_data(self):
- """
- Export this block's params to nested data.
- @return a nested data odict
- """
- n = odict()
- n['key'] = self.get_key()
- n['param'] = map(lambda p: p.export_data(), self.get_params())
- return n
-
- def import_data(self, n):
- """
- Import this block's params from nested data.
- Any param keys that do not exist will be ignored.
- @param n the nested data odict
- """
- params_n = n.findall('param')
- for param_n in params_n:
- key = param_n.find('key')
- value = param_n.find('value')
- #the key must exist in this block's params
- if key in self.get_param_keys():
- self.get_param(key).set_value(value)
- self.validate()
diff --git a/grc/src/platforms/base/Connection.py b/grc/src/platforms/base/Connection.py
deleted file mode 100644
index b8b75ac13..000000000
--- a/grc/src/platforms/base/Connection.py
+++ /dev/null
@@ -1,94 +0,0 @@
-"""
-Copyright 2008 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
-
-from Element import Element
-from ... utils import odict
-
-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 port.is_source(): source = port
- if port.is_sink(): sink = port
- assert(source and sink)
- #ensure that this connection (source -> sink) is unique
- for connection in self.get_parent().get_connections():
- assert not (connection.get_source() is source and connection.get_sink() is sink)
- self._source = source
- self._sink = sink
-
- def __str__(self):
- return 'Connection (\n\t%s\n\t\t%s\n\t%s\n\t\t%s\n)'%(
- self.get_source().get_parent(),
- self.get_source(),
- self.get_sink().get_parent(),
- self.get_sink(),
- )
-
- def is_connection(self): return True
-
- def validate(self):
- """
- Validate the connections.
- The ports must match in type.
- """
- source_type = self.get_source().get_type()
- sink_type = self.get_sink().get_type()
- try: assert source_type == sink_type
- except AssertionError: self._add_error_message('Source type "%s" does not match sink type "%s".'%(source_type, sink_type))
-
- def get_enabled(self):
- """
- Get the enabled state of this connection.
- @return true if source and sink blocks are enabled
- """
- return self.get_source().get_parent().get_enabled() and \
- self.get_sink().get_parent().get_enabled()
-
- #############################
- # Access Ports
- #############################
- def get_sink(self): return self._sink
- def get_source(self): return self._source
-
- ##############################################
- ## Import/Export Methods
- ##############################################
- def export_data(self):
- """
- Export this connection's info.
- @return a nested data odict
- """
- n = odict()
- n['source_block_id'] = self.get_source().get_parent().get_id()
- n['sink_block_id'] = self.get_sink().get_parent().get_id()
- n['source_key'] = self.get_source().get_key()
- n['sink_key'] = self.get_sink().get_key()
- return n
diff --git a/grc/src/platforms/base/Constants.py.in b/grc/src/platforms/base/Constants.py.in
deleted file mode 100644
index da958a6f4..000000000
--- a/grc/src/platforms/base/Constants.py.in
+++ /dev/null
@@ -1,30 +0,0 @@
-"""
-Copyright 2008 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
-
-import os
-
-#package and version constants
-PACKAGE = '@PACKAGE@'
-VERSION = '@VERSION@'
-
-#setup paths
-PKG_DIR = os.environ.get('GR_DATADIR', '@pkgdatadir@')
-DATA_DIR = os.path.join(PKG_DIR, '@reldatadir@')
-FLOW_GRAPH_DTD = os.path.join(DATA_DIR, 'flow_graph.dtd')
-BLOCK_TREE_DTD = os.path.join(DATA_DIR, 'block_tree.dtd')
diff --git a/grc/src/platforms/base/Element.py b/grc/src/platforms/base/Element.py
deleted file mode 100644
index a16be9127..000000000
--- a/grc/src/platforms/base/Element.py
+++ /dev/null
@@ -1,96 +0,0 @@
-"""
-Copyright 2008 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
-
-class Element(object):
-
- def __init__(self, parent=None):
- self._parent = parent
- self._error_messages = []
- self.flag()
-
- def test(self):
- """
- Test the element against failures.
- Overload this method in sub-classes.
- """
- pass
-
- def validate(self):
- """
- Validate the data in this element.
- Set the error message non blank for errors.
- Overload this method in sub-classes.
- """
- pass
-
- def is_valid(self):
- self._error_messages = []#reset err msgs
- if self.get_enabled():
- try: self.validate()
- except: pass
- return not self.get_error_messages()
-
- def get_enabled(self): return True
-
- def _add_error_message(self, msg):
- self._error_messages.append(msg)
-
- def get_error_messages(self):
- return self._error_messages
-
- def get_parent(self):
- return self._parent
-
- def _exit_with_error(self, error):
- parent = self
- #build hier list of elements
- elements = list()
- while(parent):
- elements.insert(0, parent)
- parent = parent.get_parent()
- #build error string
- err_str = ">>> Error:"
- 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)
-
- ##############################################
- ## Update flagging
- ##############################################
- def is_flagged(self): return self._flag
- def flag(self):
- self._flag = True
- if self.get_parent(): self.get_parent().flag()
- def deflag(self):
- self._flag = False
- if self.get_parent(): self.get_parent().deflag()
-
- ##############################################
- ## 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_source(self): return False
- def is_sink(self): return False
- def is_port(self): return False
- def is_param(self): return False
diff --git a/grc/src/platforms/base/FlowGraph.py b/grc/src/platforms/base/FlowGraph.py
deleted file mode 100644
index 6aeef2fa7..000000000
--- a/grc/src/platforms/base/FlowGraph.py
+++ /dev/null
@@ -1,224 +0,0 @@
-"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
-
-from ... utils import odict
-from Element import Element
-from Block import Block
-from Connection import Connection
-from ... gui import Messages
-
-class FlowGraph(Element):
-
- def __init__(self, platform):
- """
- Make a flow graph from the arguments.
- @param platform a platforms with blocks and contrcutors
- @return the flow graph object
- """
- #initialize
- Element.__init__(self, platform)
- #inital blank import
- self.import_data()
-
- def _get_unique_id(self, base_id=''):
- """
- Get a unique id starting with the base id.
- @param base_id the id starts with this and appends a count
- @return a unique id
- """
- index = 0
- while True:
- id = '%s_%d'%(base_id, index)
- index = index + 1
- #make sure that the id is not used by another block
- if not filter(lambda b: b.get_id() == id, self.get_blocks()): return id
-
- def __str__(self): return 'FlowGraph - %s(%s)'%(self.get_option('title'), self.get_option('id'))
-
- def get_option(self, key):
- """
- Get the option for a given key.
- The option comes from the special options block.
- @param key the param key for the options block
- @return the value held by that param
- """
- return self._options_block.get_param(key).evaluate()
-
- def is_flow_graph(self): return True
-
- ##############################################
- ## Access Elements
- ##############################################
- def get_block(self, id): return filter(lambda b: b.get_id() == id, self.get_blocks())[0]
- def get_blocks(self): return filter(lambda e: e.is_block(), self.get_elements())
- def get_connections(self): return filter(lambda e: e.is_connection(), self.get_elements())
- def get_elements(self):
- """
- Get a list of all the elements.
- Always ensure that the options block is in the list (only once).
- @return the element list
- """
- options_block_count = self._elements.count(self._options_block)
- if not options_block_count:
- self._elements.append(self._options_block)
- for i in range(options_block_count-1):
- self._elements.remove(self._options_block)
- return self._elements
-
- def get_enabled_blocks(self):
- """
- Get a list of all blocks that are enabled.
- @return a list of blocks
- """
- return filter(lambda b: b.get_enabled(), self.get_blocks())
-
- def get_enabled_connections(self):
- """
- Get a list of all connections that are enabled.
- @return a list of connections
- """
- return filter(lambda c: c.get_enabled(), self.get_connections())
-
- def get_new_block(self, key):
- """
- Get a new block of the specified key.
- Add the block to the list of elements.
- @param key the block key
- @return the new block or None if not found
- """
- self.flag()
- if key not in self.get_parent().get_block_keys(): return None
- block = self.get_parent().get_new_block(self, key)
- self.get_elements().append(block)
- return block
-
- def connect(self, porta, portb):
- """
- Create a connection between porta and portb.
- @param porta a port
- @param portb another port
- @throw Exception bad connection
- @return the new connection
- """
- self.flag()
- connection = self.get_parent().Connection(self, porta, portb)
- self.get_elements().append(connection)
- return connection
-
- def remove_element(self, element):
- """
- Remove the element from the list of elements.
- If the element is a port, remove the whole block.
- If the element is a block, remove its connections.
- If the element is a connection, just remove the connection.
- """
- self.flag()
- if element not in self.get_elements(): return
- #found a port, set to parent signal block
- if element.is_port():
- element = element.get_parent()
- #remove block, remove all involved connections
- if element.is_block():
- for port in element.get_ports():
- map(self.remove_element, port.get_connections())
- self.get_elements().remove(element)
-
- def evaluate(self, expr):
- """
- Evaluate the expression.
- @param expr the string expression
- @throw NotImplementedError
- """
- raise NotImplementedError
-
- def validate(self):
- """
- Validate the flow graph.
- All connections and blocks must be valid.
- """
- for c in self.get_elements():
- try: assert c.is_valid()
- except AssertionError: self._add_error_message('Element "%s" is not valid.'%c)
-
- ##############################################
- ## Import/Export Methods
- ##############################################
- def export_data(self):
- """
- Export this flow graph to nested data.
- Export all block and connection data.
- @return a nested data odict
- """
- import time
- n = odict()
- n['timestamp'] = time.ctime()
- n['block'] = [block.export_data() for block in self.get_blocks()]
- n['connection'] = [connection.export_data() for connection in self.get_connections()]
- return odict({'flow_graph': n})
-
- def import_data(self, n=None):
- """
- Import blocks and connections into this flow graph.
- Clear this flowgraph of all previous blocks and connections.
- Any blocks or connections in error will be ignored.
- @param n the nested data odict
- """
- #remove previous elements
- self._elements = list()
- #use blank data if none provided
- fg_n = n and n.find('flow_graph') or odict()
- blocks_n = fg_n.findall('block')
- connections_n = fg_n.findall('connection')
- #create option block
- self._options_block = self.get_parent().get_new_block(self, 'options')
- #build the blocks
- for block_n in blocks_n:
- key = block_n.find('key')
- if key == 'options': block = self._options_block
- else: block = self.get_new_block(key)
- #only load the block when the block key was valid
- if block: block.import_data(block_n)
- else: Messages.send_error_load('Block key "%s" not found in %s'%(key, self.get_parent()))
- #build the connections
- for connection_n in connections_n:
- #try to make the connection
- try:
- #get the block ids
- source_block_id = connection_n.find('source_block_id')
- sink_block_id = connection_n.find('sink_block_id')
- #get the port keys
- source_key = connection_n.find('source_key')
- sink_key = connection_n.find('sink_key')
- #verify the blocks
- block_ids = map(lambda b: b.get_id(), self.get_blocks())
- assert(source_block_id in block_ids)
- assert(sink_block_id in block_ids)
- #get the blocks
- source_block = self.get_block(source_block_id)
- sink_block = self.get_block(sink_block_id)
- #verify the ports
- assert(source_key in source_block.get_source_keys())
- assert(sink_key in sink_block.get_sink_keys())
- #get the ports
- source = source_block.get_source(source_key)
- sink = sink_block.get_sink(sink_key)
- #build the connection
- self.connect(source, sink)
- except AssertionError: Messages.send_error_load('Connection between %s(%s) and %s(%s) could not be made.'%(source_block_id, source_key, sink_block_id, sink_key))
- self.validate()
diff --git a/grc/src/platforms/base/Makefile.am b/grc/src/platforms/base/Makefile.am
deleted file mode 100644
index 805c7b2b3..000000000
--- a/grc/src/platforms/base/Makefile.am
+++ /dev/null
@@ -1,46 +0,0 @@
-#
-# Copyright 2008,2009 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# GNU Radio is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 3, or (at your option)
-# any later version.
-#
-# GNU Radio is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with GNU Radio; see the file COPYING. If not, write to
-# the Free Software Foundation, Inc., 51 Franklin Street,
-# Boston, MA 02110-1301, USA.
-#
-
-include $(top_srcdir)/grc/Makefile.inc
-
-ourpythondir = $(grc_src_prefix)/platforms/base
-
-ourpython_PYTHON = \
- Block.py \
- Connection.py \
- Constants.py \
- Element.py \
- FlowGraph.py \
- Param.py \
- Platform.py \
- Port.py \
- __init__.py
-
-Constants.py: $(srcdir)/Constants.py.in Makefile
- sed \
- -e 's|@PACKAGE[@]|$(PACKAGE)|g' \
- -e 's|@VERSION[@]|$(VERSION)|g' \
- -e 's|@pkgdatadir[@]|$(pkgdatadir)|g' \
- -e 's|@reldatadir[@]|$(grc_base_data_reldir)|g' \
- $< > $@
-
-EXTRA_DIST = $(srcdir)/Constants.py.in
-BUILT_SOURCES = Constants.py
diff --git a/grc/src/platforms/base/Param.py b/grc/src/platforms/base/Param.py
deleted file mode 100644
index 81783c791..000000000
--- a/grc/src/platforms/base/Param.py
+++ /dev/null
@@ -1,271 +0,0 @@
-"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
-
-from ... utils import odict
-from Element import Element
-import pygtk
-pygtk.require('2.0')
-import gtk
-
-class InputParam(gtk.HBox):
- """The base class for an input parameter inside the input parameters dialog."""
-
- def __init__(self, param, _handle_changed):
- gtk.HBox.__init__(self)
- self.param = param
- self._handle_changed = _handle_changed
- self.label = gtk.Label('') #no label, markup is added by set_markup
- self.label.set_size_request(150, -1)
- self.pack_start(self.label, False)
- self.set_markup = lambda m: self.label.set_markup(m)
- self.tp = None
- def set_color(self, color): pass
-
-class EntryParam(InputParam):
- """Provide an entry box for strings and numbers."""
-
- def __init__(self, *args, **kwargs):
- InputParam.__init__(self, *args, **kwargs)
- self.entry = input = gtk.Entry()
- input.set_text(self.param.get_value())
- input.connect('changed', self._handle_changed)
- self.pack_start(input, True)
- self.get_text = input.get_text
- #tool tip
- self.tp = gtk.Tooltips()
- self.tp.set_tip(self.entry, '')
- self.tp.enable()
- def set_color(self, color): self.entry.modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
-
-class EnumParam(InputParam):
- """Provide an entry box for Enum types with a drop down menu."""
-
- def __init__(self, *args, **kwargs):
- InputParam.__init__(self, *args, **kwargs)
- self._input = gtk.combo_box_new_text()
- for option in self.param.get_options(): self._input.append_text(option.get_name())
- self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
- self._input.connect('changed', self._handle_changed)
- self.pack_start(self._input, False)
- def get_text(self): return self.param.get_option_keys()[self._input.get_active()]
-
-class EnumEntryParam(InputParam):
- """Provide an entry box and drop down menu for Raw Enum types."""
-
- def __init__(self, *args, **kwargs):
- InputParam.__init__(self, *args, **kwargs)
- self._input = gtk.combo_box_entry_new_text()
- for option in self.param.get_options(): self._input.append_text(option.get_name())
- try: self._input.set_active(self.param.get_option_keys().index(self.param.get_value()))
- except:
- self._input.set_active(-1)
- self._input.get_child().set_text(self.param.get_value())
- self._input.connect('changed', self._handle_changed)
- self._input.get_child().connect('changed', self._handle_changed)
- self.pack_start(self._input, False)
- def get_text(self):
- if self._input.get_active() == -1: return self._input.get_child().get_text()
- return self.param.get_option_keys()[self._input.get_active()]
- def set_color(self, color):
- if self._input.get_active() == -1: #custom entry, use color
- self._input.get_child().modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse(color))
- else: #from enum, make white background
- self._input.get_child().modify_base(gtk.STATE_NORMAL, gtk.gdk.color_parse('#ffffff'))
-
-class Option(Element):
-
- def __init__(self, param, n):
- Element.__init__(self, param)
- self._name = n.find('name')
- self._key = n.find('key')
- self._opts = dict()
- opts = n.findall('opt')
- #test against opts when non enum
- try: assert self.get_parent().is_enum() or not opts
- except AssertionError: self._exit_with_error('Options for non-enum types cannot have sub-options')
- #extract opts
- for opt in opts:
- #separate the key:value
- try: key, value = opt.split(':')
- except: self._exit_with_error('Error separating "%s" into key:value'%opt)
- #test against repeated keys
- try: assert not self._opts.has_key(key)
- except AssertionError: self._exit_with_error('Key "%s" already exists in option'%key)
- #store the option
- self._opts[key] = value
-
- def __str__(self): return 'Option %s(%s)'%(self.get_name(), self.get_key())
- def get_name(self): return self._name
- def get_key(self): return self._key
-
- ##############################################
- # Access Opts
- ##############################################
- def get_opt_keys(self): return self._opts.keys()
- def get_opt(self, key): return self._opts[key]
- def get_opts(self): return self._opts.values()
-
-class Param(Element):
-
- ##possible param types
- TYPES = ['enum', 'raw']
-
- 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
- self._name = n.find('name')
- self._key = n.find('key')
- value = n.find('value') or ''
- self._type = n.find('type')
- self._hide = n.find('hide') or ''
- #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')):
- key = option.get_key()
- #test against repeated keys
- try: assert(key not in self.get_option_keys())
- except AssertionError: self._exit_with_error('Key "%s" already exists in options'%key)
- #store the option
- self._options[key] = 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))
- except AssertionError: self._exit_with_error('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():
- try: assert(set(opt_keys) == set(option.get_opt_keys()))
- except AssertionError: self._exit_with_error('Opt keys "%s" are not identical across all options.'%opt_keys)
- #if a value is specified, it must be in the options keys
- self._value = value or self.get_option_keys()[0]
- try: assert(self.get_value() in self.get_option_keys())
- except AssertionError: self._exit_with_error('The value "%s" is not in the possible values of "%s".'%(self.get_value(), self.get_option_keys()))
- else: self._value = value or ''
-
- def test(self):
- """
- call test on all children
- """
- map(lambda c: c.test(), self.get_options())
-
- def validate(self):
- """
- Validate the param.
- The value must be evaluated and type must a possible type.
- """
- try:
- assert(self.get_type() in self.TYPES)
- try: self.evaluate()
- except:
- #if the evaluate failed but added no error messages, add the generic one below
- if not self.get_error_messages():
- self._add_error_message('Value "%s" cannot be evaluated.'%self.get_value())
- except AssertionError: self._add_error_message('Type "%s" is not a possible type.'%self.get_type())
-
- def evaluate(self):
- """
- Evaluate the value of this param.
- @throw NotImplementedError
- """
- raise NotImplementedError
-
- def to_code(self):
- """
- Convert the value to code.
- @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
- 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_value(self):
- value = self._value
- if self.is_enum() and value not in self.get_option_keys():
- value = self.get_option_keys()[0]
- self.set_value(value)
- return value
-
- def set_value(self, value):
- self.flag()
- self._value = str(value) #must be a string
-
- def get_type(self): return self.get_parent().resolve_dependencies(self._type)
- def is_enum(self): return self._type == 'enum'
-
- def __repr__(self):
- """
- Get the repr (nice string format) for this param.
- Just return the value (special case enum).
- Derived classes can handle complex formatting.
- @return the string representation
- """
- if self.is_enum(): return self.get_option(self.get_value()).get_name()
- return self.get_value()
-
- def get_input_class(self):
- """
- Get the graphical gtk class to represent this parameter.
- An enum requires and combo parameter.
- A non-enum with options gets a combined entry/combo parameter.
- All others get a standard entry parameter.
- @return gtk input class
- """
- if self.is_enum(): return EnumParam
- if self.get_options(): return EnumEntryParam
- return EntryParam
-
- ##############################################
- # 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()
-
- ##############################################
- # 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()
-
- ##############################################
- ## Import/Export Methods
- ##############################################
- def export_data(self):
- """
- Export this param's key/value.
- @return a nested data odict
- """
- n = odict()
- n['key'] = self.get_key()
- n['value'] = self.get_value()
- return n
diff --git a/grc/src/platforms/base/Platform.py b/grc/src/platforms/base/Platform.py
deleted file mode 100644
index 35227d99f..000000000
--- a/grc/src/platforms/base/Platform.py
+++ /dev/null
@@ -1,143 +0,0 @@
-"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
-
-import os
-from ... utils import ParseXML
-from Element import Element as _Element
-from FlowGraph import FlowGraph as _FlowGraph
-from Connection import Connection as _Connection
-from Block import Block as _Block
-from Port import Port as _Port
-from Param import Param as _Param
-from Constants import BLOCK_TREE_DTD
-
-class Platform(_Element):
-
- def __init__(self, name, key, block_paths, block_dtd, block_tree, default_flow_graph, generator):
- """
- Make a platform from the arguments.
- @param name the platform name
- @param key the unique platform key
- @param block_paths the file paths to blocks in this platform
- @param block_dtd the dtd validator for xml block wrappers
- @param block_tree the nested tree of block keys and categories
- @param default_flow_graph the default flow graph file path
- @param load_one a single file to load into this platform or None
- @return a platform object
- """
- _Element.__init__(self)
- self._name = name
- self._key = key
- self._block_paths = block_paths
- self._block_dtd = block_dtd
- self._block_tree = block_tree
- self._default_flow_graph = default_flow_graph
- self._generator = generator
- #create a dummy flow graph for the blocks
- self._flow_graph = _Element(self)
- #load the blocks
- self._blocks = dict()
- self._blocks_n = dict()
- for block_path in self._block_paths:
- if os.path.isfile(block_path): self._load_blocks(block_path)
- elif os.path.isdir(block_path):
- for dirpath, dirnames, filenames in os.walk(block_path):
- for filename in filter(lambda f: f.endswith('.xml'), filenames):
- self._load_blocks(os.path.join(dirpath, filename))
-
- def _load_blocks(self, f):
- """
- Load the block wrappers from the file path.
- The block wrapper must pass validation.
- If any of the checks fail, exit with error.
- @param f the file path
- """
- try: ParseXML.validate_dtd(f, self._block_dtd)
- except ParseXML.XMLSyntaxError, e: self._exit_with_error('Block definition "%s" failed: \n\t%s'%(f, e))
- n = ParseXML.from_file(f).find('block')
- #inject block wrapper path
- n['block_wrapper_path'] = f
- block = self.Block(self._flow_graph, n)
- key = block.get_key()
- #test against repeated keys
- try: assert(key not in self.get_block_keys())
- except AssertionError: self._exit_with_error('Key "%s" already exists in blocks'%key)
- #store the block
- self._blocks[key] = block
- self._blocks_n[key] = n
-
- def load_block_tree(self, block_tree):
- """
- Load a block tree with categories and blocks.
- Step 1: Load all blocks from the xml specification.
- Step 2: Load blocks with builtin category specifications.
- @param block_tree the block tree object
- """
- #recursive function to load categories and blocks
- def load_category(cat_n, parent=[]):
- #add this category
- parent = parent + [cat_n.find('name')]
- block_tree.add_block(parent)
- #recursive call to load sub categories
- map(lambda c: load_category(c, parent), cat_n.findall('cat'))
- #add blocks in this category
- for block_key in cat_n.findall('block'):
- block_tree.add_block(parent, self.get_block(block_key))
- #load the block tree
- f = self._block_tree
- try: ParseXML.validate_dtd(f, BLOCK_TREE_DTD)
- except ParseXML.XMLSyntaxError, e: self._exit_with_error('Block tree "%s" failed: \n\t%s'%(f, e))
- #add all blocks in the tree
- load_category(ParseXML.from_file(f).find('cat'))
- #add all other blocks, use the catgory
- for block in self.get_blocks():
- #blocks with empty categories are in the xml block tree or hidden
- if block.get_category(): block_tree.add_block(block.get_category(), block)
-
- def __str__(self): return 'Platform - %s(%s)'%(self.get_key(), self.get_name())
-
- def is_platform(self): return True
-
- def get_new_flow_graph(self): return self.FlowGraph(self)
-
- def get_default_flow_graph(self): return self._default_flow_graph
-
- def get_generator(self): return self._generator
-
- ##############################################
- # Access Blocks
- ##############################################
- def get_block_keys(self): return self._blocks.keys()
- def get_block(self, key): return self._blocks[key]
- def get_blocks(self): return self._blocks.values()
- def get_new_block(self, flow_graph, key): return self.Block(flow_graph, n=self._blocks_n[key])
-
- def get_name(self): return self._name
-
- def get_key(self): return self._key
-
- ##############################################
- # Constructors
- ##############################################
- FlowGraph = _FlowGraph
- Connection = _Connection
- Block = _Block
- Source = _Port
- Sink = _Port
- Param = _Param
diff --git a/grc/src/platforms/base/Port.py b/grc/src/platforms/base/Port.py
deleted file mode 100644
index f46a81195..000000000
--- a/grc/src/platforms/base/Port.py
+++ /dev/null
@@ -1,80 +0,0 @@
-"""
-Copyright 2008, 2009 Free Software Foundation, Inc.
-This file is part of GNU Radio
-
-GNU Radio Companion is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License
-as published by the Free Software Foundation; either version 2
-of the License, or (at your option) any later version.
-
-GNU Radio Companion is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
-"""
-
-from Element import Element
-
-class Port(Element):
-
- ##possible port types
- TYPES = []
-
- 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
- self._type = type
-
- def validate(self):
- """
- Validate the port.
- The port must be non-empty and type must a possible type.
- """
- 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):
- if self.is_source():
- return 'Source - %s(%s)'%(self.get_name(), self.get_key())
- if self.is_sink():
- return 'Sink - %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
- def get_key(self): return self._key
- def is_sink(self): return self in self.get_parent().get_sinks()
- def is_source(self): return self in self.get_parent().get_sources()
- def get_type(self): return self.get_parent().resolve_dependencies(self._type)
-
- def get_connections(self):
- """
- Get all connections that use this port.
- @return a list of connection objects
- """
- connections = self.get_parent().get_parent().get_connections()
- connections = filter(lambda c: c.get_source() is self or c.get_sink() is self, connections)
- return connections
-
- def get_enabled_connections(self):
- """
- Get all enabled connections that use this port.
- @return a list of connection objects
- """
- return filter(lambda c: c.get_enabled(), self.get_connections())
diff --git a/grc/src/platforms/base/__init__.py b/grc/src/platforms/base/__init__.py
deleted file mode 100644
index 8b1378917..000000000
--- a/grc/src/platforms/base/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-