From d796f30a241ed29831d597ee27df01556a80d2f1 Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Tue, 30 Aug 2016 17:52:09 +0200
Subject: [PATCH 14/22] qtgui: replace templated xml files with search and
 replace for qt4

---
 gr-qtgui/grc/CMakeLists.txt                        | 32 +++++++++++++++++-----
 ...ber_sink_b.xml.cmakein => qtgui_ber_sink_b.xml} |  2 +-
 ...block_tree.xml.cmakein => qtgui_block_tree.xml} |  0
 ...i_check_box.xml.cmakein => qtgui_check_box.xml} |  2 +-
 ...qtgui_chooser.xml.cmakein => qtgui_chooser.xml} |  4 +--
 ...t_sink_x.xml.cmakein => qtgui_const_sink_x.xml} |  2 +-
 ..._box_msg.xml.cmakein => qtgui_edit_box_msg.xml} |  2 +-
 .../{qtgui_entry.xml.cmakein => qtgui_entry.xml}   |  2 +-
 ...eq_sink_x.xml.cmakein => qtgui_freq_sink_x.xml} |  2 +-
 ...nk_x.xml.cmakein => qtgui_histogram_sink_x.xml} |  2 +-
 .../{qtgui_label.xml.cmakein => qtgui_label.xml}   |  2 +-
 ...mber_sink.xml.cmakein => qtgui_number_sink.xml} |  2 +-
 ...sh_button.xml.cmakein => qtgui_push_button.xml} |  2 +-
 .../{qtgui_range.xml.cmakein => qtgui_range.xml}   |  0
 .../{qtgui_sink_x.xml.cmakein => qtgui_sink_x.xml} |  2 +-
 ...tab_widget.xml.cmakein => qtgui_tab_widget.xml} |  2 +-
 ...aster_x.xml.cmakein => qtgui_time_raster_x.xml} |  2 +-
 ...me_sink_x.xml.cmakein => qtgui_time_sink_x.xml} |  2 +-
 ..._sink_f.xml.cmakein => qtgui_vector_sink_f.xml} |  2 +-
 ...nk_x.xml.cmakein => qtgui_waterfall_sink_x.xml} |  2 +-
 20 files changed, 43 insertions(+), 25 deletions(-)
 rename gr-qtgui/grc/{qtgui_ber_sink_b.xml.cmakein => qtgui_ber_sink_b.xml} (99%)
 rename gr-qtgui/grc/{qtgui_block_tree.xml.cmakein => qtgui_block_tree.xml} (100%)
 rename gr-qtgui/grc/{qtgui_check_box.xml.cmakein => qtgui_check_box.xml} (97%)
 rename gr-qtgui/grc/{qtgui_chooser.xml.cmakein => qtgui_chooser.xml} (98%)
 rename gr-qtgui/grc/{qtgui_const_sink_x.xml.cmakein => qtgui_const_sink_x.xml} (99%)
 rename gr-qtgui/grc/{qtgui_edit_box_msg.xml.cmakein => qtgui_edit_box_msg.xml} (98%)
 rename gr-qtgui/grc/{qtgui_entry.xml.cmakein => qtgui_entry.xml} (97%)
 rename gr-qtgui/grc/{qtgui_freq_sink_x.xml.cmakein => qtgui_freq_sink_x.xml} (99%)
 rename gr-qtgui/grc/{qtgui_histogram_sink_x.xml.cmakein => qtgui_histogram_sink_x.xml} (99%)
 rename gr-qtgui/grc/{qtgui_label.xml.cmakein => qtgui_label.xml} (97%)
 rename gr-qtgui/grc/{qtgui_number_sink.xml.cmakein => qtgui_number_sink.xml} (99%)
 rename gr-qtgui/grc/{qtgui_push_button.xml.cmakein => qtgui_push_button.xml} (97%)
 rename gr-qtgui/grc/{qtgui_range.xml.cmakein => qtgui_range.xml} (100%)
 rename gr-qtgui/grc/{qtgui_sink_x.xml.cmakein => qtgui_sink_x.xml} (98%)
 rename gr-qtgui/grc/{qtgui_tab_widget.xml.cmakein => qtgui_tab_widget.xml} (99%)
 rename gr-qtgui/grc/{qtgui_time_raster_x.xml.cmakein => qtgui_time_raster_x.xml} (99%)
 rename gr-qtgui/grc/{qtgui_time_sink_x.xml.cmakein => qtgui_time_sink_x.xml} (99%)
 rename gr-qtgui/grc/{qtgui_vector_sink_f.xml.cmakein => qtgui_vector_sink_f.xml} (99%)
 rename gr-qtgui/grc/{qtgui_waterfall_sink_x.xml.cmakein => qtgui_waterfall_sink_x.xml} (99%)

diff --git a/gr-qtgui/grc/CMakeLists.txt b/gr-qtgui/grc/CMakeLists.txt
index d01bcc52c4..74e6958639 100644
--- a/gr-qtgui/grc/CMakeLists.txt
+++ b/gr-qtgui/grc/CMakeLists.txt
@@ -18,12 +18,30 @@
 # Boston, MA 02110-1301, USA.
 
 ########################################################################
-file(GLOB xml_cmakein_files "*.xml.cmakein")
+file(GLOB xml_files "*.xml")
 
-foreach(xml_cmakein_file IN ITEMS ${xml_cmakein_files})
-	get_filename_component(FILE_NAME ${xml_cmakein_file} NAME_WE)
-	configure_file(${xml_cmakein_file} "${CMAKE_CURRENT_BINARY_DIR}/${FILE_NAME}.xml" @ONLY)
-	set(xml_files ${xml_files} "${CMAKE_CURRENT_BINARY_DIR}/${FILE_NAME}.xml")
-endforeach(xml_cmakein_file)
+macro(REPLACE_IN_FILE _xml_block match replace)
+    set(xml_block_src "${CMAKE_CURRENT_SOURCE_DIR}/${_xml_block}")
+    set(xml_block     "${CMAKE_CURRENT_BINARY_DIR}/${_xml_block}")
 
-install(FILES ${xml_files} DESTINATION ${GRC_BLOCKS_DIR} COMPONENT "qtgui_python")
+    list(REMOVE_ITEM xml_files "${xml_block_src}")
+    file(READ "${xml_block_src}" xml_block_src_text)
+    string(REPLACE "${match}" "${replace}"
+           xml_block_text "${xml_block_src_text}")
+    file(WRITE "${xml_block}" "${xml_block_text}")
+
+    list(APPEND generated_xml_files "${xml_block}")
+endmacro()
+
+
+if(DESIRED_QT_VERSION EQUAL 4)
+    foreach(xml_block_src ${xml_files})
+        get_filename_component(xml_block "${xml_block_src}" NAME)
+        REPLACE_IN_FILE("${xml_block}" "PyQt5" "PyQt4")
+    endforeach()
+endif()
+
+install(
+    FILES ${xml_files} ${generated_xml_files}
+    DESTINATION "${GRC_BLOCKS_DIR}"
+)
diff --git a/gr-qtgui/grc/qtgui_ber_sink_b.xml.cmakein b/gr-qtgui/grc/qtgui_ber_sink_b.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_ber_sink_b.xml.cmakein
rename to gr-qtgui/grc/qtgui_ber_sink_b.xml
index 91a87ce595..05a36dfbc0 100644
--- a/gr-qtgui/grc/qtgui_ber_sink_b.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_ber_sink_b.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Bercurve Sink</name>
   <key>qtgui_bercurve_sink</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>import sip</import>
   <import>import numpy</import>
diff --git a/gr-qtgui/grc/qtgui_block_tree.xml.cmakein b/gr-qtgui/grc/qtgui_block_tree.xml
similarity index 100%
rename from gr-qtgui/grc/qtgui_block_tree.xml.cmakein
rename to gr-qtgui/grc/qtgui_block_tree.xml
diff --git a/gr-qtgui/grc/qtgui_check_box.xml.cmakein b/gr-qtgui/grc/qtgui_check_box.xml
similarity index 97%
rename from gr-qtgui/grc/qtgui_check_box.xml.cmakein
rename to gr-qtgui/grc/qtgui_check_box.xml
index 9edacb24d8..ccee59dd92 100644
--- a/gr-qtgui/grc/qtgui_check_box.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_check_box.xml
@@ -8,7 +8,7 @@
 <block>
 	<name>QT GUI Check Box</name>
 	<key>variable_qtgui_check_box</key>
-	<import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+	<import>from PyQt5 import Qt</import>
 	<var_make>self.$(id) = $(id) = $value</var_make>
 	<make>#set $win = '_%s_check_box'%$id
 #if not $label()
diff --git a/gr-qtgui/grc/qtgui_chooser.xml.cmakein b/gr-qtgui/grc/qtgui_chooser.xml
similarity index 98%
rename from gr-qtgui/grc/qtgui_chooser.xml.cmakein
rename to gr-qtgui/grc/qtgui_chooser.xml
index 40c782bede..f79bb8ccb3 100644
--- a/gr-qtgui/grc/qtgui_chooser.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_chooser.xml
@@ -8,8 +8,8 @@
 <block>
 	<name>QT GUI Chooser</name>
 	<key>variable_qtgui_chooser</key>
-	<import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
-	<import>from PyQt@DESIRED_QT_VERSION@.QtCore import QObject, pyqtSlot</import>
+	<import>from PyQt5 import Qt</import>
+	<import>from PyQt5.QtCore import QObject, pyqtSlot</import>
 	<var_make>self.$(id) = $(id) = $value</var_make>
 	<make>#slurp
 #set $all_options = [$option0, $option1, $option2, $option3, $option4][:int($num_opts())]
diff --git a/gr-qtgui/grc/qtgui_const_sink_x.xml.cmakein b/gr-qtgui/grc/qtgui_const_sink_x.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_const_sink_x.xml.cmakein
rename to gr-qtgui/grc/qtgui_const_sink_x.xml
index 6fa725acb1..10f82cce82 100644
--- a/gr-qtgui/grc/qtgui_const_sink_x.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_const_sink_x.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Constellation Sink</name>
   <key>qtgui_const_sink_x</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>import sip</import>
   <make>#set $win = 'self._%s_win'%$id
diff --git a/gr-qtgui/grc/qtgui_edit_box_msg.xml.cmakein b/gr-qtgui/grc/qtgui_edit_box_msg.xml
similarity index 98%
rename from gr-qtgui/grc/qtgui_edit_box_msg.xml.cmakein
rename to gr-qtgui/grc/qtgui_edit_box_msg.xml
index 75ff93349f..d77a4b3e1b 100644
--- a/gr-qtgui/grc/qtgui_edit_box_msg.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_edit_box_msg.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Message Edit Box</name>
   <key>qtgui_edit_box_msg</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>import sip</import>
   <make>#set $win = 'self._%s_win'%$id
diff --git a/gr-qtgui/grc/qtgui_entry.xml.cmakein b/gr-qtgui/grc/qtgui_entry.xml
similarity index 97%
rename from gr-qtgui/grc/qtgui_entry.xml.cmakein
rename to gr-qtgui/grc/qtgui_entry.xml
index da61ee723a..fc0f4089d1 100644
--- a/gr-qtgui/grc/qtgui_entry.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_entry.xml
@@ -8,7 +8,7 @@
 <block>
 	<name>QT GUI Entry</name>
 	<key>variable_qtgui_entry</key>
-	<import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+	<import>from PyQt5 import Qt</import>
 	<import>from gnuradio import eng_notation</import>
 	<var_make>self.$(id) = $(id) = $value</var_make>
 	<make>#set $win = 'self._%s_tool_bar'%$id
diff --git a/gr-qtgui/grc/qtgui_freq_sink_x.xml.cmakein b/gr-qtgui/grc/qtgui_freq_sink_x.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_freq_sink_x.xml.cmakein
rename to gr-qtgui/grc/qtgui_freq_sink_x.xml
index aaf0d75271..ed39db7781 100644
--- a/gr-qtgui/grc/qtgui_freq_sink_x.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_freq_sink_x.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Frequency Sink</name>
   <key>qtgui_freq_sink_x</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>from gnuradio.filter import firdes</import>
   <import>import sip</import>
diff --git a/gr-qtgui/grc/qtgui_histogram_sink_x.xml.cmakein b/gr-qtgui/grc/qtgui_histogram_sink_x.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_histogram_sink_x.xml.cmakein
rename to gr-qtgui/grc/qtgui_histogram_sink_x.xml
index d04a44da13..9e3dcb104f 100644
--- a/gr-qtgui/grc/qtgui_histogram_sink_x.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_histogram_sink_x.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Histogram Sink</name>
   <key>qtgui_histogram_sink_x</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>import sip</import>
   <make>#set $win = 'self._%s_win'%$id
diff --git a/gr-qtgui/grc/qtgui_label.xml.cmakein b/gr-qtgui/grc/qtgui_label.xml
similarity index 97%
rename from gr-qtgui/grc/qtgui_label.xml.cmakein
rename to gr-qtgui/grc/qtgui_label.xml
index c546e09dcc..946cee36ab 100644
--- a/gr-qtgui/grc/qtgui_label.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_label.xml
@@ -9,7 +9,7 @@
 <block>
   <name>QT GUI Label</name>
   <key>variable_qtgui_label</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import eng_notation</import>
   <var_make>self.$(id) = $(id) = $value</var_make>
   <make>#set $win = 'self._%s_tool_bar'%$id
diff --git a/gr-qtgui/grc/qtgui_number_sink.xml.cmakein b/gr-qtgui/grc/qtgui_number_sink.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_number_sink.xml.cmakein
rename to gr-qtgui/grc/qtgui_number_sink.xml
index d4b4c5808f..06837493c3 100644
--- a/gr-qtgui/grc/qtgui_number_sink.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_number_sink.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Number Sink</name>
   <key>qtgui_number_sink</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>import sip</import>
   <make>#set $win = 'self._%s_win'%$id
diff --git a/gr-qtgui/grc/qtgui_push_button.xml.cmakein b/gr-qtgui/grc/qtgui_push_button.xml
similarity index 97%
rename from gr-qtgui/grc/qtgui_push_button.xml.cmakein
rename to gr-qtgui/grc/qtgui_push_button.xml
index d99f230acf..49c2e9d6f0 100644
--- a/gr-qtgui/grc/qtgui_push_button.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_push_button.xml
@@ -8,7 +8,7 @@
 <block>
 	<name>QT GUI Push Button</name>
 	<key>variable_qtgui_push_button</key>
-	<import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+	<import>from PyQt5 import Qt</import>
 	<var_make>self.$(id) = $(id) = $value</var_make>
 	<make>#set $win = '_%s_push_button'%$id
 #if not $label()
diff --git a/gr-qtgui/grc/qtgui_range.xml.cmakein b/gr-qtgui/grc/qtgui_range.xml
similarity index 100%
rename from gr-qtgui/grc/qtgui_range.xml.cmakein
rename to gr-qtgui/grc/qtgui_range.xml
diff --git a/gr-qtgui/grc/qtgui_sink_x.xml.cmakein b/gr-qtgui/grc/qtgui_sink_x.xml
similarity index 98%
rename from gr-qtgui/grc/qtgui_sink_x.xml.cmakein
rename to gr-qtgui/grc/qtgui_sink_x.xml
index 1c75921a75..a9bc469cd2 100644
--- a/gr-qtgui/grc/qtgui_sink_x.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_sink_x.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Sink</name>
   <key>qtgui_sink_x</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>from gnuradio.filter import firdes</import>
   <import>import sip</import>
diff --git a/gr-qtgui/grc/qtgui_tab_widget.xml.cmakein b/gr-qtgui/grc/qtgui_tab_widget.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_tab_widget.xml.cmakein
rename to gr-qtgui/grc/qtgui_tab_widget.xml
index f5a1a73cdc..805542cc8b 100644
--- a/gr-qtgui/grc/qtgui_tab_widget.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_tab_widget.xml
@@ -7,7 +7,7 @@
 <block>
 	<name>QT GUI Tab Widget</name>
 	<key>qtgui_tab_widget</key>
-	<import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+	<import>from PyQt5 import Qt</import>
 	<make>#set $win = 'self.%s'%$id
 Qt.QTabWidget()
 #set $all_labels = [$label0, $label1, $label2, $label3, $label4,
diff --git a/gr-qtgui/grc/qtgui_time_raster_x.xml.cmakein b/gr-qtgui/grc/qtgui_time_raster_x.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_time_raster_x.xml.cmakein
rename to gr-qtgui/grc/qtgui_time_raster_x.xml
index 94b7ef136a..d458f67eb9 100644
--- a/gr-qtgui/grc/qtgui_time_raster_x.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_time_raster_x.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Time Raster Sink</name>
   <key>qtgui_time_raster_sink_x</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>import sip</import>
   <make>#set $win = 'self._%s_win'%$id
diff --git a/gr-qtgui/grc/qtgui_time_sink_x.xml.cmakein b/gr-qtgui/grc/qtgui_time_sink_x.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_time_sink_x.xml.cmakein
rename to gr-qtgui/grc/qtgui_time_sink_x.xml
index d239917907..d4347950ea 100644
--- a/gr-qtgui/grc/qtgui_time_sink_x.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_time_sink_x.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Time Sink</name>
   <key>qtgui_time_sink_x</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>from gnuradio.filter import firdes</import>
   <import>import sip</import>
diff --git a/gr-qtgui/grc/qtgui_vector_sink_f.xml.cmakein b/gr-qtgui/grc/qtgui_vector_sink_f.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_vector_sink_f.xml.cmakein
rename to gr-qtgui/grc/qtgui_vector_sink_f.xml
index 8b928eb7ea..0f456323bf 100644
--- a/gr-qtgui/grc/qtgui_vector_sink_f.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_vector_sink_f.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Vector Sink</name>
   <key>qtgui_vector_sink_f</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>import sip</import>
   <make>#set $win = 'self._%s_win'%$id
diff --git a/gr-qtgui/grc/qtgui_waterfall_sink_x.xml.cmakein b/gr-qtgui/grc/qtgui_waterfall_sink_x.xml
similarity index 99%
rename from gr-qtgui/grc/qtgui_waterfall_sink_x.xml.cmakein
rename to gr-qtgui/grc/qtgui_waterfall_sink_x.xml
index d198ca084a..a684492246 100644
--- a/gr-qtgui/grc/qtgui_waterfall_sink_x.xml.cmakein
+++ b/gr-qtgui/grc/qtgui_waterfall_sink_x.xml
@@ -7,7 +7,7 @@
 <block>
   <name>QT GUI Waterfall Sink</name>
   <key>qtgui_waterfall_sink_x</key>
-  <import>from PyQt@DESIRED_QT_VERSION@ import Qt</import>
+  <import>from PyQt5 import Qt</import>
   <import>from gnuradio import qtgui</import>
   <import>from gnuradio.filter import firdes</import>
   <import>import sip</import>
-- 
2.11.0

