summaryrefslogtreecommitdiff
path: root/grc/python
diff options
context:
space:
mode:
Diffstat (limited to 'grc/python')
-rw-r--r--grc/python/Generator.py24
-rw-r--r--grc/python/Param.py27
-rw-r--r--grc/python/Platform.py2
-rw-r--r--grc/python/flow_graph.tmpl55
4 files changed, 66 insertions, 42 deletions
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index d53802bef..b669fa65a 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -90,18 +90,20 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''')
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(),
+ 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 + variables + probes + notebooks), blocks) + probes
+ 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(), self._flow_graph.get_enabled_connections())
messages = filter(lambda c: c.is_msg(), self._flow_graph.get_enabled_connections())
@@ -125,8 +127,6 @@ Add a Misc->Throttle block to your flow graph to avoid CPU congestion.''')
'imports': imports,
'flow_graph': self._flow_graph,
'variables': variables,
- 'notebooks': notebooks,
- 'controls': controls,
'parameters': parameters,
'blocks': blocks,
'connections': connections,
diff --git a/grc/python/Param.py b/grc/python/Param.py
index 6dd008d1d..303ab3ed8 100644
--- a/grc/python/Param.py
+++ b/grc/python/Param.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
+Copyright 2008-2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
@@ -99,7 +99,7 @@ class Param(_Param, _GUIParam):
'hex', 'string', 'bool',
'file_open', 'file_save',
'id', 'stream_id',
- 'grid_pos', 'notebook',
+ 'grid_pos', 'notebook', 'gui_hint',
'import',
)
@@ -354,6 +354,29 @@ class Param(_Param, _GUIParam):
except: raise Exception, 'Stream ID "%s" is not found.'%v
return v
#########################
+ # GUI Position/Hint
+ #########################
+ elif t == 'gui_hint':
+ if ':' in v: tab, pos = v.split(':')
+ elif '@' in v: tab, pos = v, ''
+ else: tab, pos = '', v
+
+ if '@' in tab: tab, index = tab.split('@')
+ else: index = '?'
+
+ widget_str = ({
+ (True, True): 'self.%(tab)s_grid_layout_%(index)s.addWidget(%(widget)s, %(pos)s)',
+ (True, False): 'self.%(tab)s_layout_%(index)s.addWidget(%(widget)s)',
+ (False, True): 'self.top_grid_layout.addWidget(%(widget)s, %(pos)s)',
+ (False, False): 'self.top_layout.addWidget(%(widget)s)',
+ }[bool(tab), bool(pos)])%{'tab': tab, 'index': index, 'widget': '%s', 'pos': pos}
+
+ def gui_hint(ws, w):
+ if 'layout' in w: ws = ws.replace('addWidget', 'addLayout')
+ return ws%w
+
+ return lambda w: gui_hint(widget_str, w)
+ #########################
# Grid Position Type
#########################
elif t == 'grid_pos':
diff --git a/grc/python/Platform.py b/grc/python/Platform.py
index 04db0b9b0..ec3f94096 100644
--- a/grc/python/Platform.py
+++ b/grc/python/Platform.py
@@ -1,5 +1,5 @@
"""
-Copyright 2008, 2009, 2010 Free Software Foundation, Inc.
+Copyright 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
This file is part of GNU Radio
GNU Radio Companion is free software; you can redistribute it and/or
diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl
index a1a9308aa..5aaa99793 100644
--- a/grc/python/flow_graph.tmpl
+++ b/grc/python/flow_graph.tmpl
@@ -5,8 +5,6 @@
##@param imports the import statements
##@param flow_graph the flow_graph
##@param variables the variable blocks
-##@param notebooks a list of notebook blocks
-##@param controls the variables with gui controls
##@param parameters the paramater blocks
##@param blocks the signal blocks
##@param connections the connections
@@ -59,6 +57,17 @@ class $(class_name)(grc_wxgui.top_block_gui):
_icon_path = "$icon.get_filename()"
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
#end if
+#elif $generate_options == 'qt_gui'
+class $(class_name)(gr.top_block, Qt.QWidget):
+
+ def __init__($param_str):
+ gr.top_block.__init__(self, "$title")
+ Qt.QWidget.__init__(self)
+ self.setWindowTitle("$title")
+ self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
+ self.top_layout = Qt.QVBoxLayout(self)
+ self.top_grid_layout = Qt.QGridLayout()
+ self.top_layout.addLayout(self.top_grid_layout)
#elif $generate_options == 'no_gui'
class $(class_name)(gr.top_block):
@@ -112,30 +121,6 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])
$indent($var.get_var_make())
#end for
########################################################
-##Create Notebooks
-########################################################
-#if $notebooks
-
- $DIVIDER
- # Notebooks
- $DIVIDER
-#end if
-#for $notebook in $notebooks
- $indent($notebook.get_make())
-#end for
-########################################################
-##Create Controls
-########################################################
-#if $controls
-
- $DIVIDER
- # Controls
- $DIVIDER
-#end if
-#for $ctrl in $controls
- $indent($ctrl.get_make())
-#end for
-########################################################
##Create Message Queues
########################################################
#if $messages
@@ -157,7 +142,11 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(', '.join($size_strs))])
$DIVIDER
#end if
#for $blk in filter(lambda b: b.get_make(), $blocks)
+ #if $blk in $variables
+ $indent($blk.get_make())
+ #else
self.$blk.get_id() = $indent($blk.get_make())
+ #end if
#end for
########################################################
##Create Connections
@@ -196,6 +185,9 @@ self.$port.get_parent().get_id()#slurp
########################################################
#for $var in $parameters + $variables
#set $id = $var.get_id()
+ def get_$(id)(self):
+ return self.$id
+
def set_$(id)(self, $id):
self.$id = $id
#for $callback in $var_id2cbs[$id]
@@ -239,12 +231,21 @@ if __name__ == '__main__':
if gr.enable_realtime_scheduling() != gr.RT_OK:
print "Error: failed to enable realtime scheduling."
#end if
- tb = $(class_name)($(', '.join($params_eq_list)))
#if $generate_options == 'wx_gui'
+ tb = $(class_name)($(', '.join($params_eq_list)))
tb.Run($flow_graph.get_option('run'))
+ #elif $generate_options == 'qt_gui'
+ qapp = Qt.QApplication(sys.argv)
+ tb = $(class_name)($(', '.join($params_eq_list)))
+ #if $flow_graph.get_option('run')
+ tb.start()
+ #end if
+ tb.show()
+ qapp.exec_()
#elif $generate_options == 'no_gui'
#set $run_options = $flow_graph.get_option('run_options')
#if $run_options == 'prompt'
+ tb = $(class_name)($(', '.join($params_eq_list)))
tb.start()
raw_input('Press Enter to quit: ')
tb.stop()