コード例 #1
0
ファイル: Generator.py プロジェクト: FOSSEE-Manipal/gnuradio
	def __str__(self):
		"""
		Convert the flow graph to python code.
		@return a string of python code
		"""
		title = self._flow_graph.get_option('title') or self._flow_graph.get_option('id').replace('_', ' ').title()
		imports = self._flow_graph.get_imports()
		variables = self._flow_graph.get_variables()
		parameters = self._flow_graph.get_parameters()
		#list of blocks not including variables and imports and parameters and disabled
		def _get_block_sort_text(block):
			code = block.get_make().replace(block.get_id(), ' ')
			try: code += block.get_param('notebook').get_value() #older gui markup w/ wxgui
			except: pass
			try: code += block.get_param('gui_hint').get_value() #newer gui markup w/ qtgui
			except: pass
			return code
		blocks = expr_utils.sort_objects(
			self._flow_graph.get_enabled_blocks(),
			lambda b: b.get_id(), _get_block_sort_text
		)
		#list of regular blocks (all blocks minus the special ones)
		blocks = filter(lambda b: b not in (imports + parameters), blocks)
		#list of connections where each endpoint is enabled
		connections = filter(lambda c: not (c.is_msg() or c.is_message()), self._flow_graph.get_enabled_connections())
		messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
		messages2 = filter(lambda c: c.is_message(), self._flow_graph.get_enabled_connections())
		#list of variable names
		var_ids = [var.get_id() for var in parameters + variables]
		#prepend self.
		replace_dict = dict([(var_id, 'self.%s'%var_id) for var_id in var_ids])
		#list of callbacks
		callbacks = [
			expr_utils.expr_replace(cb, replace_dict)
			for cb in sum([block.get_callbacks() for block in self._flow_graph.get_enabled_blocks()], [])
		]
		#map var id to callbacks
		var_id2cbs = dict(
			[(var_id, filter(lambda c: expr_utils.get_variable_dependencies(c, [var_id]), callbacks))
			for var_id in var_ids]
		)
		#load the namespace
		namespace = {
			'title': title,
			'imports': imports,
			'flow_graph': self._flow_graph,
			'variables': variables,
			'parameters': parameters,
			'blocks': blocks,
			'connections': connections,
			'messages': messages,
			'messages2': messages2,
			'generate_options': self._generate_options,
			'var_id2cbs': var_id2cbs,
		}
		#build the template
		t = Template(open(FLOW_GRAPH_TEMPLATE, 'r').read(), namespace)
		return str(t)
コード例 #2
0
ファイル: Generator.py プロジェクト: imushir/python_workspace
	def __str__(self):
		"""
		Convert the flow graph to python code.
		@return a string of python code
		"""
		title = self._flow_graph.get_option('title') or self._flow_graph.get_option('id').replace('_', ' ').title()
		imports = self._flow_graph.get_imports()
		variables = self._flow_graph.get_variables()
		parameters = self._flow_graph.get_parameters()
		#list of blocks not including variables and imports and parameters and disabled
		def _get_block_sort_text(block):
			code = block.get_make().replace(block.get_id(), ' ')
			try: code += block.get_param('notebook').get_value() #older gui markup w/ wxgui
			except: pass
			try: code += block.get_param('gui_hint').get_value() #newer gui markup w/ qtgui
			except: pass
			return code
		    blocks = expr_utils.sort_objects(
			self._flow_graph.get_enabled_blocks(),
			lambda b: b.get_id(), _get_block_sort_text
		)
		#list of regular blocks (all blocks minus the special ones)
		blocks = filter(lambda b: b not in (imports + parameters), blocks)
		#list of connections where each endpoint is enabled
		connections = filter(lambda c: not (c.is_msg() or c.is_message()), self._flow_graph.get_enabled_connections())
		messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
		messages2 = filter(lambda c: c.is_message(), self._flow_graph.get_enabled_connections())
		#list of variable names
		var_ids = [var.get_id() for var in parameters + variables]
		#prepend self.
		replace_dict = dict([(var_id, 'self.%s'%var_id) for var_id in var_ids])
		#list of callbacks
		callbacks = [
			expr_utils.expr_replace(cb, replace_dict)
			for cb in sum([block.get_callbacks() for block in self._flow_graph.get_enabled_blocks()], [])
		]
		#map var id to callbacks
		var_id2cbs = dict(
			[(var_id, filter(lambda c: expr_utils.get_variable_dependencies(c, [var_id]), callbacks))
			for var_id in var_ids]
		)
		#load the namespace
		namespace = {
			'title': title,
			'imports': imports,
			'flow_graph': self._flow_graph,
			'variables': variables,
			'parameters': parameters,
			'blocks': blocks,
			'connections': connections,
			'messages': messages,
			'messages2': messages2,
			'generate_options': self._generate_options,
			'var_id2cbs': var_id2cbs,
		}
		#build the template
		t = Template(open(FLOW_GRAPH_TEMPLATE, 'r').read(), namespace)
		return str(t)
コード例 #3
0
    def __str__(self):
        """
		Convert the flow graph to python code.
		@return a string of python code
		"""
        title = self._flow_graph.get_option("title") or self._flow_graph.get_option("id").replace("_", " ").title()
        imports = self._flow_graph.get_imports()
        variables = self._flow_graph.get_variables()
        parameters = self._flow_graph.get_parameters()
        # list of variables with controls
        controls = filter(lambda v: v.get_make(), variables)
        # list of blocks not including variables and imports and parameters and disabled
        blocks = sorted(self._flow_graph.get_enabled_blocks(), lambda x, y: cmp(x.get_id(), y.get_id()))
        probes = filter(lambda b: b.get_key().startswith("probe_"), blocks)  # ensure probes are last in the block list
        # get a list of notebooks and sort them according dependencies
        notebooks = expr_utils.sort_objects(
            filter(lambda b: b.get_key() == "notebook", blocks),
            lambda n: n.get_id(),
            lambda n: n.get_param("notebook").get_value(),
        )
        # list of regular blocks (all blocks minus the special ones)
        blocks = filter(lambda b: b not in (imports + parameters + variables + probes + notebooks), blocks) + probes
        # list of connections where each endpoint is enabled
        connections = self._flow_graph.get_enabled_connections()
        # list of variable names
        var_ids = [var.get_id() for var in parameters + variables]
        # prepend self.
        replace_dict = dict([(var_id, "self.%s" % var_id) for var_id in var_ids])
        # list of callbacks
        callbacks = [
            expr_utils.expr_replace(cb, replace_dict)
            for cb in sum([block.get_callbacks() for block in self._flow_graph.get_enabled_blocks()], [])
        ]
        # map var id to callbacks
        var_id2cbs = dict(
            [
                (var_id, filter(lambda c: expr_utils.get_variable_dependencies(c, [var_id]), callbacks))
                for var_id in var_ids
            ]
        )
        # load the namespace
        namespace = {
            "title": title,
            "imports": imports,
            "flow_graph": self._flow_graph,
            "variables": variables,
            "notebooks": notebooks,
            "controls": controls,
            "parameters": parameters,
            "blocks": blocks,
            "connections": connections,
            "generate_options": self._generate_options,
            "var_id2cbs": var_id2cbs,
        }
        # build the template
        t = Template(open(FLOW_GRAPH_TEMPLATE, "r").read(), namespace)
        return str(t)
コード例 #4
0
ファイル: Generator.py プロジェクト: jinjoh/SDR
	def __str__(self):
		"""
		Convert the flow graph to python code.
		@return a string of python code
		"""
		title = self._flow_graph.get_option('title') or self._flow_graph.get_option('id').replace('_', ' ').title()
		imports = self._flow_graph.get_imports()
		variables = self._flow_graph.get_variables()
		parameters = self._flow_graph.get_parameters()
		#list of variables with controls
		controls = filter(lambda v: v.get_make(), variables)
		#list of blocks not including variables and imports and parameters and disabled
		blocks = sorted(self._flow_graph.get_enabled_blocks(), lambda x, y: cmp(x.get_id(), y.get_id()))
		probes = filter(lambda b: b.get_key().startswith('probe_'), blocks) #ensure probes are last in the block list
		#get a list of notebooks and sort them according dependencies
		notebooks = expr_utils.sort_objects(
			filter(lambda b: b.get_key() == 'notebook', blocks),
			lambda n: n.get_id(), lambda n: n.get_param('notebook').get_value(),
		)
		#list of regular blocks (all blocks minus the special ones)
		blocks = filter(lambda b: b not in (imports + parameters + variables + probes + notebooks), blocks) + probes
		#list of connections where each endpoint is enabled
		connections = filter(lambda c: not c.is_msg(), self._flow_graph.get_enabled_connections())
		messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
		#list of variable names
		var_ids = [var.get_id() for var in parameters + variables]
		#prepend self.
		replace_dict = dict([(var_id, 'self.%s'%var_id) for var_id in var_ids])
		#list of callbacks
		callbacks = [
			expr_utils.expr_replace(cb, replace_dict)
			for cb in sum([block.get_callbacks() for block in self._flow_graph.get_enabled_blocks()], [])
		]
		#map var id to callbacks
		var_id2cbs = dict(
			[(var_id, filter(lambda c: expr_utils.get_variable_dependencies(c, [var_id]), callbacks))
			for var_id in var_ids]
		)
		#load the namespace
		namespace = {
			'title': title,
			'imports': imports,
			'flow_graph': self._flow_graph,
			'variables': variables,
			'notebooks': notebooks,
			'controls': controls,
			'parameters': parameters,
			'blocks': blocks,
			'connections': connections,
			'messages': messages,
			'generate_options': self._generate_options,
			'var_id2cbs': var_id2cbs,
		}
		#build the template
		t = Template(open(FLOW_GRAPH_TEMPLATE, 'r').read(), namespace)
		return str(t)
コード例 #5
0
	def __str__(self):
		"""
		Convert the flow graph to python code.
		@return a string of python code
		"""
		title = self._flow_graph.get_option('title') or self._flow_graph.get_option('id').replace('_', ' ').title()
		imports = self._flow_graph.get_imports()
		variables = self._flow_graph.get_variables()
		parameters = self._flow_graph.get_parameters()
		#list of variables with controls
		controls = filter(lambda v: v.get_make(), variables)
		#list of blocks not including variables and imports and parameters and disabled
		blocks = sorted(self._flow_graph.get_enabled_blocks(), lambda x, y: cmp(x.get_id(), y.get_id()))
		probes = filter(lambda b: b.get_key().startswith('probe_'), blocks) #ensure probes are last in the block list
		#get a list of notebooks and sort them according dependencies
		notebooks = expr_utils.sort_objects(
			filter(lambda b: b.get_key() == 'notebook', blocks),
			lambda n: n.get_id(), lambda n: n.get_param('notebook').get_value(),
		)
		#list of regular blocks (all blocks minus the special ones)
		blocks = filter(lambda b: b not in (imports + parameters + variables + probes + notebooks), blocks) + probes
		#list of connections where each endpoint is enabled
		connections = filter(lambda c: not c.is_msg(), self._flow_graph.get_enabled_connections())
		messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
		#list of variable names
		var_ids = [var.get_id() for var in parameters + variables]
		#prepend self.
		replace_dict = dict([(var_id, 'self.%s'%var_id) for var_id in var_ids])
		#list of callbacks
		callbacks = [
			expr_utils.expr_replace(cb, replace_dict)
			for cb in sum([block.get_callbacks() for block in self._flow_graph.get_enabled_blocks()], [])
		]
		#map var id to callbacks
		var_id2cbs = dict(
			[(var_id, filter(lambda c: expr_utils.get_variable_dependencies(c, [var_id]), callbacks))
			for var_id in var_ids]
		)
		#load the namespace
		namespace = {
			'title': title,
			'imports': imports,
			'flow_graph': self._flow_graph,
			'variables': variables,
			'notebooks': notebooks,
			'controls': controls,
			'parameters': parameters,
			'blocks': blocks,
			'connections': connections,
			'messages': messages,
			'generate_options': self._generate_options,
			'var_id2cbs': var_id2cbs,
		}
		#build the template
		t = Template(open(FLOW_GRAPH_TEMPLATE, 'r').read(), namespace)
		return str(t)