[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r5692 - in grc/branches/jblum_work/src: . SignalBlockD
From: |
jblum |
Subject: |
[Commit-gnuradio] r5692 - in grc/branches/jblum_work/src: . SignalBlockDefs |
Date: |
Tue, 5 Jun 2007 12:46:33 -0600 (MDT) |
Author: jblum
Date: 2007-06-05 12:46:33 -0600 (Tue, 05 Jun 2007)
New Revision: 5692
Modified:
grc/branches/jblum_work/src/Editor.py
grc/branches/jblum_work/src/ExecFlowGraph.py
grc/branches/jblum_work/src/ExecFlowGraphGUI.py
grc/branches/jblum_work/src/SignalBlockDefs/GraphicalSinks.py
Log:
created ExecFlowGraph for running flow graphs without wx
Modified: grc/branches/jblum_work/src/Editor.py
===================================================================
--- grc/branches/jblum_work/src/Editor.py 2007-06-05 17:02:01 UTC (rev
5691)
+++ grc/branches/jblum_work/src/Editor.py 2007-06-05 18:46:33 UTC (rev
5692)
@@ -47,7 +47,7 @@
import xml.dom.ext
import gnuradio
except ImportError, e: #print error and exit
- print 'Missing critical component: "%s"\nExiting!'%(e,)
+ print '\nMissing critical component: "%s"\nExiting!'%(e,)
exit(-1)
# end import of modules #
from ActionHandler import ActionHandler
Modified: grc/branches/jblum_work/src/ExecFlowGraph.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraph.py 2007-06-05 17:02:01 UTC
(rev 5691)
+++ grc/branches/jblum_work/src/ExecFlowGraph.py 2007-06-05 18:46:33 UTC
(rev 5692)
@@ -20,7 +20,96 @@
"""
ExecFlowGraph.py
Josh Blum
- Use a xml input file to build and run a gnu radio flow graph with wx
GUI elements.
+ Use a xml input file to build and run a gnu radio flow graph without
graphics.
"""
-#TODO: create this!
\ No newline at end of file
+import ParseXML
+import Variables
+import SignalBlockDefs
+from Elements import SignalBlock
+from gnuradio import gr
+import os
+from Constants import DEFAULT_FILE_EXTENSION
+from optparse import OptionParser
+
+##############################################################################################
+# Flow Graph Builder
+##############################################################################################
+class FlowGraphBuilder(gr.flow_graph):
+ """ Parse the input file to build the gnuradio flow graph.
+ Register the variables, handle signal block callbacks. """
+ def __init__(self, file_path):
+ nested_data = ParseXML.from_xml(ParseXML.from_file(file_path))
+ gr.flow_graph.__init__(self)
+ self.callbacks = list()
+ self.var_keys = list()
+ self.parse_nested_data(nested_data)
+
+ def add_window(self, window, type='', title=''):
+ ''' Empty method for adding a window in the GUI flow graph.
'''
+ pass
+
+ def get_panel(self):
+ ''' Empty method for getting the wx panel in the GUI flow
graph. '''
+ print '''
+Graphical Sinks are not supported in ExecFlowGraph.py:
+ use ExecFlowGraphGUI.py [-d] or remove the Graphical Sink.
+Exiting!'''
+ exit(-1)
+
+ def add_callback(self, function, data_type_params):
+ """ Register a callback function with its associated data.
"""
+ self.callbacks.append((function, data_type_params))
+
+ def parse_callbacks(self):
+ """ For each call back, parse all of the data and
+ call the registered callback function on that data. """
+ for function, data_type_params in self.callbacks:
+ try:
+ if type(data_type_params) in (type(list()),
type(tuple())):
+ function(*map(lambda param:
param.parse(), data_type_params))
+ else: function(data_type_params.parse())
+ except: print "error parsing a callback -> ignoring..."
+
+ def parse_nested_data(self, nested_data):
+ """ Parse nested data from a flow graph file and build the
graphics.
+ This code is partially copied from FlowGraph.py, with
unnecessary code removed. """
+ find_data = ParseXML.find_data
+ flow_graph = find_data([nested_data], 'flow_graph')
+ vars = find_data(flow_graph, 'vars')
+ signal_blocks = find_data(flow_graph, 'signal_blocks')
+ connections = find_data(flow_graph, 'connections')
+ self.var_keys = Variables.from_nested_data(vars)
+ signal_blocks_dict = dict()
+ for signal_block in signal_blocks:
+ signal_block,runnable_signal_block =
SignalBlock.from_nested_data(None, signal_block, SignalBlock)
+ data_type_params = list()
+ data_type_params.append(self)#put the flow graph in the
front of the list
+ for param in signal_block.get_params(): #load the list
of arguments to the runnable block
+ data_type_params.append(param.get_data_type())
+ signal_blocks_dict[signal_block.get_id()] =
runnable_signal_block(*data_type_params)
+ for connection in connections:
+ connection = find_data([connection], 'connection')
+ input_signal_block_id = find_data(connection,
'input_signal_block_id')
+ input_socket_index = int(find_data(connection,
'input_socket_index'))
+ output_signal_block_id = find_data(connection,
'output_signal_block_id')
+ output_socket_index = int(find_data(connection,
'output_socket_index'))
+ self.connect(# use this flow graph's connect method
#
+ (signal_blocks_dict[output_signal_block_id],
output_socket_index),
+ (signal_blocks_dict[input_signal_block_id],
input_socket_index))
+
+if __name__ == '__main__':
+ usage = "usage: %prog [-p] flow_graph"+DEFAULT_FILE_EXTENSION
+ parser = OptionParser(usage=usage)
+ parser.add_option("-p", "--pid_file", action="store", type="string",
dest="pid_file", help="record process id")
+ (options, args) = parser.parse_args()
+ if options.pid_file:
+ try: open(options.pid_file, 'w').write('%d\n' % os.getpid())
+ except: print "could not create pid file: %s"%options.pid_file
+ if len(args): #only create the flow graph if a file was passed
+ fg = FlowGraphBuilder(args[0])
+ fg.start()
+ raw_input('Flow Graph Running...\nPress Enter to Exit: ')
+ fg.stop()
+ else: parser.print_help()
+
\ No newline at end of file
Modified: grc/branches/jblum_work/src/ExecFlowGraphGUI.py
===================================================================
--- grc/branches/jblum_work/src/ExecFlowGraphGUI.py 2007-06-05 17:02:01 UTC
(rev 5691)
+++ grc/branches/jblum_work/src/ExecFlowGraphGUI.py 2007-06-05 18:46:33 UTC
(rev 5692)
@@ -19,17 +19,14 @@
"""
"""
ExecFlowGraphGUI.py
- Josh Blum
- Use a xml input file to build and run a gnu radio flow graph without
graphics.
+ Josh Blum
+ Use a xml input file to build and run a gnu radio flow graph with wx
GUI elements.
"""
-import ParseXML
import Variables
-import SignalBlockDefs
-from Elements import SignalBlock
-from gnuradio import gr
+from ExecFlowGraph import FlowGraphBuilder
import wx
-import sys,os
+import os
from Constants import *
import math
from optparse import OptionParser
@@ -124,8 +121,8 @@
##############################################################################################
# Flow Graph Frame
##############################################################################################
-class FlowGraphFrame(wx.Frame, gr.flow_graph):
- """ A FlowGraphFrame is a wx.Frame and a gr.flow_graph.
+class FlowGraphFrame(wx.Frame, FlowGraphBuilder):
+ """ A FlowGraphFrame is a wx.Frame and a FlowGraphBuilder.
This flow graph frame parses a saved flow graph file,
houses all the sliders and graphical sinks,
and starts the flow graph. """
@@ -134,11 +131,8 @@
wx.Frame.__init__(self, None , -1, MAIN_WINDOW_PREFIX+' -
Executing: '+file_path)
if WX_APP_ICON: self.SetIcon(wx.Icon(WX_APP_ICON,
wx.BITMAP_TYPE_ANY))
self.SetSizeHints(200, 100)
- gr.flow_graph.__init__(self)
- self.callbacks = list()
+ # create holder for sliders and graphs #
self.sliders_dict = dict()
- self.text_box_dict = dict()
- # create holder for scopes and ffts #
self.sink_windows = dict()
graphs_box = wx.GridSizer(1, 1, 0, 0)
self.panel = panel = wx.ScrolledWindow(self, -1)
@@ -149,9 +143,9 @@
main_box.Add(self.sliders_box, 0, wx.ALIGN_CENTER)
main_box.Add(panel, 0, wx.EXPAND)
self.Bind(wx.EVT_CLOSE, self.Quit)
- nested_data = ParseXML.from_xml(ParseXML.from_file(file_path))
- # fill in all the sliders and graphs #
- self.parse_nested_data(nested_data)
+ # fill in all the sliders and graphs #
+ FlowGraphBuilder.__init__(self, file_path)
+ self.create_sliders()
graphs_box.SetCols(int(math.sqrt(len(self.sink_windows))))
for key in sorted(self.sink_windows.keys()):
graphs_box.Add(self.sink_windows[key], 0, wx.EXPAND)
self.SetSizerAndFit(main_box)
@@ -174,32 +168,12 @@
''' Get the panel that will parent the graphical blocks.
'''
return self.panel
- def add_callback(self, function, data_type_params):
- """ Register a callback function with its associated data.
"""
- self.callbacks.append((function, data_type_params))
-
- def parse_callbacks(self):
- """ For each call back, parse all of the data and
- call the registered callback function on that data. """
- for function, data_type_params in self.callbacks:
- try:
- if type(data_type_params) in (type(list()),
type(tuple())):
- function(*map(lambda param:
param.parse(), data_type_params))
- else: function(data_type_params.parse())
- except: print "error parsing a callback -> ignoring..."
-
- def parse_nested_data(self, nested_data):
- """ Parse nested data from a flow graph file and build the
graphics.
- This code is partially copied from FlowGraph.py, with
unnecessary code removed. """
- find_data = ParseXML.find_data
- flow_graph = find_data([nested_data], 'flow_graph')
- vars = find_data(flow_graph, 'vars')
- signal_blocks = find_data(flow_graph, 'signal_blocks')
- connections = find_data(flow_graph, 'connections')
- len = 0
- keys = Variables.from_nested_data(vars)
- for key in keys:
- value, min, max, step = Variables.get_values(key)
+ def create_sliders(self):
+ ''' Using the list of variable keys imported by the builder,
+ create sliders for those variables with ranges. '''
+ len = 0
+ for key in self.var_keys:
+ value, min, max, step = Variables.get_values(key)
if Variables.is_ranged(key):
variable_control = VariableControl(self, key,
self.parse_callbacks)
width = variable_control.get_slider_width()
@@ -210,25 +184,7 @@
self.sliders_box.Add(slider_box, 0,
wx.ALIGN_CENTER)
slider_box.Add(variable_control, 0,
wx.ALIGN_CENTER)
len = len + width
- ################ done with sliders and variables
#######################
- signal_blocks_dict = dict()
- for signal_block in signal_blocks:
- signal_block,runnable_signal_block =
SignalBlock.from_nested_data(None, signal_block, SignalBlock)
- data_type_params = list()
- data_type_params.append(self)#put the flow graph thing
here
- for param in signal_block.get_params(): #load the list
of arguments to the runnable block
- data_type_params.append(param.get_data_type())
- signal_blocks_dict[signal_block.get_id()] =
runnable_signal_block(*data_type_params)
- for connection in connections:
- connection = find_data([connection], 'connection')
- input_signal_block_id = find_data(connection,
'input_signal_block_id')
- input_socket_index = int(find_data(connection,
'input_socket_index'))
- output_signal_block_id = find_data(connection,
'output_signal_block_id')
- output_socket_index = int(find_data(connection,
'output_socket_index'))
- self.connect(# use this flow graph's connect method
#
- (signal_blocks_dict[output_signal_block_id],
output_socket_index),
- (signal_blocks_dict[input_signal_block_id],
input_socket_index))
-
+
##############################################################################################
# Flow Graph App
##############################################################################################
Modified: grc/branches/jblum_work/src/SignalBlockDefs/GraphicalSinks.py
===================================================================
--- grc/branches/jblum_work/src/SignalBlockDefs/GraphicalSinks.py
2007-06-05 17:02:01 UTC (rev 5691)
+++ grc/branches/jblum_work/src/SignalBlockDefs/GraphicalSinks.py
2007-06-05 18:46:33 UTC (rev 5692)
@@ -86,7 +86,6 @@
baseband_freq=baseband_freq.parse(),
fft_rate=fft_rate.parse())
block.set_average(average) #set the
average option outside the contructor
fg.add_window(block.win, waterfall_display_priority,
title.parse())
- fg.add_callback(block.set_sample_rate, samp_rate)
fg.add_callback(block.set_baseband_freq, baseband_freq)
th = gr.throttle(type.parse()[1].get_num_bytes(),
samp_rate.parse())
fg.connect(th, block)
@@ -115,7 +114,6 @@
sample_rate=samp_rate.parse(),
frame_decim=frame_decim.parse(),
v_scale=v_scale, t_scale=t_scale.parse())
fg.add_window(block.win, scope_display_priority, title.parse())
- fg.add_callback(block.set_sample_rate, samp_rate)
th = gr.throttle(type.parse()[1].get_num_bytes(),
samp_rate.parse())
fg.connect(th, block)
return th
@@ -140,7 +138,6 @@
elif marker == 1: block.win.set_format_dot()
elif marker == 2: block.win.set_format_line()
fg.add_window(block.win, constellation_display_pritority,
title.parse())
- fg.add_callback(block.set_sample_rate, samp_rate)
th = gr.throttle(Complex().get_num_bytes(), samp_rate.parse())
fg.connect(th, block)
return th
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r5692 - in grc/branches/jblum_work/src: . SignalBlockDefs,
jblum <=