[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 10/13: grc: add struct variable block
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 10/13: grc: add struct variable block |
Date: |
Fri, 24 Jul 2015 15:33:49 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit b82987acb6b1e4c368384753c43ad4d2a373659f
Author: Sebastian Koslowski <address@hidden>
Date: Tue Jun 9 14:07:50 2015 +0200
grc: add struct variable block
---
grc/blocks/.gitignore | 1 +
grc/blocks/CMakeLists.txt | 22 ++++++++-
grc/blocks/variable_struct.xml.py | 98 +++++++++++++++++++++++++++++++++++++++
3 files changed, 120 insertions(+), 1 deletion(-)
diff --git a/grc/blocks/.gitignore b/grc/blocks/.gitignore
new file mode 100644
index 0000000..2ac4a79
--- /dev/null
+++ b/grc/blocks/.gitignore
@@ -0,0 +1 @@
+variable_struct.xml
diff --git a/grc/blocks/CMakeLists.txt b/grc/blocks/CMakeLists.txt
index 98b6512..0c2a1f7 100644
--- a/grc/blocks/CMakeLists.txt
+++ b/grc/blocks/CMakeLists.txt
@@ -18,6 +18,26 @@
# Boston, MA 02110-1301, USA.
########################################################################
+include(GrPython)
+
file(GLOB xml_files "*.xml")
-install(FILES ${xml_files} DESTINATION ${GRC_BLOCKS_DIR} COMPONENT "grc")
+macro(GEN_BLOCK_XML _generator _xml_block)
+ set(generator ${CMAKE_CURRENT_SOURCE_DIR}/${_generator})
+ set(xml_block ${CMAKE_CURRENT_BINARY_DIR}/${_xml_block})
+ list(APPEND generated_xml_files ${xml_block})
+ add_custom_command(
+ DEPENDS ${generator} OUTPUT ${xml_block}
+ COMMAND ${PYTHON_EXECUTABLE} ${generator} ${xml_block}
+ )
+endmacro(GEN_BLOCK_XML)
+
+GEN_BLOCK_XML(variable_struct.xml.py variable_struct.xml)
+
+add_custom_target(grc_generated_xml ALL DEPENDS ${generated_xml_files})
+
+install(
+ FILES ${xml_files} ${generated_xml_files}
+ DESTINATION ${GRC_BLOCKS_DIR}
+ COMPONENT "grc"
+)
diff --git a/grc/blocks/variable_struct.xml.py
b/grc/blocks/variable_struct.xml.py
new file mode 100644
index 0000000..e432008
--- /dev/null
+++ b/grc/blocks/variable_struct.xml.py
@@ -0,0 +1,98 @@
+#!/usr/bin/env python
+
+MAX_NUM_FIELDS = 20
+
+HEADER = """\
+<block>
+ <name>Struct Variable</name>
+ <key>variable_struct</key>
+ <category>Variables</category>
+ <import>def struct(data): return type('Struct', (object,), data)()</import>
+ <var_make>self.$id = $id = struct({{#slurp
+#for $i in range({0}):
+#set $field = $getVar('field' + str(i))
+#if len(str($field)) > 2
+$field: $getVar('value' + str(i)), #slurp
+#end if
+#end for
+}})</var_make>
+ <var_value>struct({{#slurp
+#for $i in range({0}):
+#set $field = $getVar('field' + str(i))
+#if len(str($field)) > 2
+$field: $getVar('value' + str(i)), #slurp
+#end if
+#end for
+}})</var_value>
+ <make></make>
+"""
+
+FIELD0 = """\
+ <param>
+ <name>Field 0</name>
+ <key>field0</key>
+ <value>field0</value>
+ <type>string</type>
+ <hide>part</hide>
+ <tab>Fields</tab>
+ </param>
+"""
+
+FIELDS = """\
+ <param>
+ <name>Field {0}</name>
+ <key>field{0}</key>
+ <value></value>
+ <type>string</type>
+ <hide>part</hide>
+ <tab>Fields</tab>
+ </param>
+"""
+
+VALUES = """\
+ <param>
+ <name>$field{0}()</name>
+ <key>value{0}</key>
+ <value>0</value>
+ <type>raw</type>
+ <hide>#if $field{0}() then 'none' else 'all'#</hide>
+ </param>
+"""
+
+CHECKS = """\
+ <check>($str($field{0}) or "a")[0].isalpha()</check>
+ <check>($str($field{0}) or "a").isalnum()</check>
+"""
+
+FOOTER = """\
+ <doc>This is a simple struct/record like variable.
+
+Attribute/field names can be specified in the tab 'Fields'.
+For each non-empty field a parameter with type raw is shown.
+Value access via the dot operator, e.g. "variable_struct_0.field0"
+ </doc>
+</block>
+"""
+
+
+def make_xml(num_fields):
+ return ''.join((
+ HEADER.format(num_fields),
+ FIELD0, ''.join(FIELDS.format(i) for i in range(1, num_fields)),
+ ''.join(VALUES.format(i) for i in range(num_fields)),
+ ''.join(CHECKS.format(i) for i in range(num_fields)),
+ FOOTER
+ ))
+
+
+if __name__ == '__main__':
+ import sys
+ try:
+ filename = sys.argv[1]
+ except IndexError:
+ filename = __file__[:-3]
+
+ data = make_xml(MAX_NUM_FIELDS)
+
+ with open(filename, 'w') as fp:
+ fp.write(data.encode())
- [Commit-gnuradio] [gnuradio] 06/13: grc: align default flowgraph block with canvas grid, (continued)
- [Commit-gnuradio] [gnuradio] 06/13: grc: align default flowgraph block with canvas grid, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 11/13: grc: clean-up Block port counters, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 02/13: grc: show preview of generated code in each blocks properties dialog, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 07/13: grc: fix bus ports spacing in gui, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 03/13: grc: add default value to ToggleActions, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 04/13: grc: only show code preview tab after user enables it, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 01/13: grc: refactor Preferences.py, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 05/13: grc: add user settings for canvas default size and canvas font size (+ clean-ups), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 08/13: grc: add QT GUI hier blocks (#727), git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 09/13: grc: add support for dynamic param names, git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 10/13: grc: add struct variable block,
git <=