[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 08/13: grc: add QT GUI hier blocks (#727)
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 08/13: grc: add QT GUI hier blocks (#727) |
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 dcc0f96034a4547d4ea71d67e5b1b244ee997045
Author: Sebastian Koslowski <address@hidden>
Date: Wed Jun 10 16:26:36 2015 +0200
grc: add QT GUI hier blocks (#727)
---
grc/base/Constants.py | 2 ++
grc/blocks/options.xml | 12 ++++++++----
grc/gui/ActionHandler.py | 2 +-
grc/python/Block.py | 15 +++++++++++++--
grc/python/Generator.py | 37 ++++++++++++++++++++++++++++++++++---
grc/python/flow_graph.tmpl | 33 +++++++++++++++++++++++++--------
6 files changed, 83 insertions(+), 18 deletions(-)
diff --git a/grc/base/Constants.py b/grc/base/Constants.py
index 0c5116c..1e83de6 100644
--- a/grc/base/Constants.py
+++ b/grc/base/Constants.py
@@ -41,6 +41,8 @@ DEFAULT_DOMAIN = GR_STREAM_DOMAIN
BLOCK_FLAG_THROTTLE = 'throttle'
BLOCK_FLAG_DISABLE_BYPASS = 'disable_bypass'
+BLOCK_FLAG_NEED_QT_GUI = 'need_qt_gui'
+BLOCK_FLAG_NEED_WX_GUI = 'need_ex_gui'
# Block States
BLOCK_DISABLED = 0
diff --git a/grc/blocks/options.xml b/grc/blocks/options.xml
index 9ec9494..dc02b83 100644
--- a/grc/blocks/options.xml
+++ b/grc/blocks/options.xml
@@ -19,7 +19,7 @@ import wx
from PyQt4 import Qt
import sys
#end if
-#if $generate_options() != 'hb'
+#if not $generate_options().startswith('hb')
from optparse import OptionParser
from gnuradio.eng_option import eng_option
from gnuradio import eng_notation
@@ -76,13 +76,17 @@ else: self.stop(); self.wait()</callback>
<name>Hier Block</name>
<key>hb</key>
</option>
+ <option>
+ <name>QT GUI Hier Block</name>
+ <key>hb_qt_gui</key>
+ </option>
</param>
<param>
<name>Category</name>
<key>category</key>
<value>Custom</value>
<type>string</type>
- <hide>#if $generate_options() == 'hb' then 'none' else
'all'#</hide>
+ <hide>#if $generate_options().startswith('hb') then 'none' else
'all'#</hide>
</param>
<param>
<name>Run Options</name>
@@ -129,7 +133,7 @@ else: self.stop(); self.wait()</callback>
<key>max_nouts</key>
<value>0</value>
<type>int</type>
- <hide>#if $generate_options() == 'hb'
+ <hide>#if $generate_options().startswith('hb')
all#slurp
#elif $max_nouts()
none#slurp
@@ -142,7 +146,7 @@ part#slurp
<key>realtime_scheduling</key>
<value></value>
<type>enum</type>
- <hide>#if $generate_options() == 'hb'
+ <hide>#if $generate_options().startswith('hb')
all#slurp
#elif $realtime_scheduling()
none#slurp
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 5dbfea0..1556512 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -18,7 +18,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA
"""
import os
-import signal
from Constants import IMAGE_FILE_EXTENSION
import Actions
import pygtk
@@ -39,6 +38,7 @@ from . Constants import DEFAULT_CANVAS_SIZE
gobject.threads_init()
+
class ActionHandler:
"""
The action handler will setup all the major window components,
diff --git a/grc/python/Block.py b/grc/python/Block.py
index 517019c..548c991 100644
--- a/grc/python/Block.py
+++ b/grc/python/Block.py
@@ -19,11 +19,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA
from collections import defaultdict
+from .. base.Constants import BLOCK_FLAG_NEED_QT_GUI, BLOCK_FLAG_NEED_WX_GUI
from .. base.Block import Block as _Block
from .. gui.Block import Block as _GUIBlock
from . FlowGraph import _variable_matcher
import extract_docs
+
class Block(_Block, _GUIBlock):
def is_virtual_sink(self): return self.get_key() == 'virtual_sink'
@@ -99,13 +101,22 @@ class Block(_Block, _GUIBlock):
self.get_parent().evaluate(value)
except Exception as err:
self.add_error_message('Value "%s" cannot be evaluated:\n%s' %
(value, err))
+
# check if this is a GUI block and matches the selected generate option
current_generate_option =
self.get_parent().get_option('generate_options')
- for label, option in (('WX GUI', 'wx_gui'), ('QT GUI', 'qt_gui')):
- if self.get_name().startswith(label) and current_generate_option
!= option:
+
+ def check_generate_mode(label, flag, valid_options):
+ block_requires_mode = (
+ flag in self.get_flags() or
+ self.get_name().upper().startswith(label)
+ )
+ if block_requires_mode and current_generate_option not in
valid_options:
self.add_error_message("Can't generate this block in mode " +
repr(current_generate_option))
+ check_generate_mode('WX GUI', BLOCK_FLAG_NEED_WX_GUI, ('wx_gui',))
+ check_generate_mode('QT GUI', BLOCK_FLAG_NEED_QT_GUI, ('qt_gui',
'hb_qt_gui'))
+
def rewrite(self):
"""
Add and remove ports to adjust for the nports.
diff --git a/grc/python/Generator.py b/grc/python/Generator.py
index d9e92cd..98b671d 100644
--- a/grc/python/Generator.py
+++ b/grc/python/Generator.py
@@ -27,6 +27,7 @@ from Cheetah.Template import Template
from .. gui import Messages
from .. base import ParseXML
from .. base import odict
+from .. base.Constants import BLOCK_FLAG_NEED_QT_GUI
from . Constants import TOP_BLOCK_FILE_MODE, FLOW_GRAPH_TEMPLATE, \
XTERM_EXECUTABLE, HIER_BLOCK_FILE_MODE, HIER_BLOCKS_LIB_DIR, BLOCK_DTD
@@ -47,9 +48,13 @@ class Generator(object):
"""
self._generate_options = flow_graph.get_option('generate_options')
if self._generate_options == 'hb':
- self._generator = HierBlockGenerator(flow_graph, file_path)
+ generator_cls = HierBlockGenerator
+ elif self._generate_options == 'hb_qt_gui':
+ generator_cls = QtHierBlockGenerator
else:
- self._generator = TopBlockGenerator(flow_graph, file_path)
+ generator_cls = TopBlockGenerator
+
+ self._generator = generator_cls(flow_graph, file_path)
def get_generate_options(self):
return self._generate_options
@@ -87,7 +92,7 @@ class TopBlockGenerator(object):
"""generate output and write it to files"""
# do throttle warning
throttling_blocks = filter(lambda b: b.throtteling(),
self._flow_graph.get_enabled_blocks())
- if not throttling_blocks and self._generate_options != 'hb':
+ if not throttling_blocks and not
self._generate_options.startswith('hb'):
Messages.send_warning("This flow graph may not have flow control: "
"no audio or RF hardware blocks found. "
"Add a Misc->Throttle block to your flow "
@@ -325,3 +330,29 @@ class HierBlockGenerator(TopBlockGenerator):
n = {'block': block_n}
return n
+
+
+class QtHierBlockGenerator(HierBlockGenerator):
+
+ def _build_block_n_from_flow_graph_io(self):
+ n = HierBlockGenerator._build_block_n_from_flow_graph_io(self)
+ block_n = n['block']
+
+ if not block_n['name'].upper().startswith('QT GUI'):
+ block_n['name'] = 'QT GUI ' + block_n['name']
+
+ block_n.insert_after('category', 'flags', BLOCK_FLAG_NEED_QT_GUI)
+
+ gui_hint_param = odict()
+ gui_hint_param['name'] = 'GUI Hint'
+ gui_hint_param['key'] = 'gui_hint'
+ gui_hint_param['value'] = ''
+ gui_hint_param['type'] = 'gui_hint'
+ gui_hint_param['hide'] = 'part'
+ block_n['param'].append(gui_hint_param)
+
+ block_n['make'] += (
+ "\n#set $win = 'self.%s' % $id"
+ "\n${gui_hint()($win)}"
+ )
+ return n
diff --git a/grc/python/flow_graph.tmpl b/grc/python/flow_graph.tmpl
index 814b513..3dd772b 100644
--- a/grc/python/flow_graph.tmpl
+++ b/grc/python/flow_graph.tmpl
@@ -1,4 +1,4 @@
-#if $generate_options != 'hb'
+#if not $generate_options.startswith('hb')
#!/usr/bin/env python2
#end if
########################################################
@@ -61,7 +61,8 @@ sys.path.append(os.environ.get('GRC_HIER_PATH',
os.path.expanduser('~/.grc_gnura
#end if
#for $imp in $imports
-$(imp.replace(" # grc-generated hier_block", ""))
+##$(imp.replace(" # grc-generated hier_block", ""))
+$imp
#end for
########################################################
@@ -76,6 +77,7 @@ $(imp.replace(" # grc-generated hier_block", ""))
#if $generate_options == 'wx_gui'
#import gtk
#set $icon = gtk.IconTheme().lookup_icon('gnuradio-grc', 32, 0)
+
class $(class_name)(grc_wxgui.top_block_gui):
def __init__($param_str):
@@ -85,7 +87,7 @@ class $(class_name)(grc_wxgui.top_block_gui):
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))
#end if
#elif $generate_options == 'qt_gui'
-from distutils.version import StrictVersion
+
class $(class_name)(gr.top_block, Qt.QWidget):
def __init__($param_str):
@@ -110,16 +112,21 @@ class $(class_name)(gr.top_block, Qt.QWidget):
self.settings = Qt.QSettings("GNU Radio", "$class_name")
self.restoreGeometry(self.settings.value("geometry").toByteArray())
-
#elif $generate_options == 'no_gui'
+
class $(class_name)(gr.top_block):
def __init__($param_str):
gr.top_block.__init__(self, "$title")
-#elif $generate_options == 'hb'
+#elif $generate_options.startswith('hb')
#set $in_sigs = $flow_graph.get_hier_block_stream_io('in')
#set $out_sigs = $flow_graph.get_hier_block_stream_io('out')
+
+#if $generate_options == 'hb_qt_gui'
+class $(class_name)(gr.hier_block2, Qt.QWidget):
+#else
class $(class_name)(gr.hier_block2):
+#end if
#def make_io_sig($io_sigs)
#set $size_strs = ['%s*%s'%(io_sig['size'], io_sig['vlen']) for io_sig in
$io_sigs]
#if len($io_sigs) == 0
@@ -143,6 +150,14 @@ gr.io_signaturev($(len($io_sigs)), $(len($io_sigs)), [$(',
'.join($size_strs))])
#for $pad in $flow_graph.get_hier_block_message_io('out')
self.message_port_register_hier_in("$pad['label']")
#end for
+ #if $generate_options == 'hb_qt_gui'
+
+ Qt.QWidget.__init__(self)
+ self.top_layout = Qt.QVBoxLayout()
+ self.top_grid_layout = Qt.QGridLayout()
+ self.top_layout.addLayout(self.top_grid_layout)
+ self.setLayout(self.top_layout)
+ #end if
#end if
#if $flow_graph.get_option('thread_safe_setters')
@@ -304,7 +319,7 @@ $param.get_make()#slurp
#end if
$short_id#slurp
#end def
-#if $generate_options != 'hb'
+#if not $generate_options.startswith('hb')
if __name__ == '__main__':
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
@@ -334,7 +349,8 @@ if __name__ == '__main__':
tb.Wait()
#end if
#elif $generate_options == 'qt_gui'
- if(StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0")):
+ from distutils.version import StrictVersion
+ if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"):
Qt.QApplication.setGraphicsSystem(gr.prefs().get_string('qtgui','style','raster'))
qapp = Qt.QApplication(sys.argv)
tb = $(class_name)($(', '.join($params_eq_list)))
@@ -346,6 +362,7 @@ if __name__ == '__main__':
#end if
#end if
tb.show()
+
def quitting():
tb.stop()
tb.wait()
@@ -358,7 +375,7 @@ if __name__ == '__main__':
sys.stderr.write("Monitor '{0}' does not have an enable ('en')
parameter.".format("tb.$m.get_id()"))
#end for
qapp.exec_()
- tb = None #to clean up Qt widgets
+ tb = None # to clean up Qt widgets
#elif $generate_options == 'no_gui'
tb = $(class_name)($(', '.join($params_eq_list)))
#set $run_options = $flow_graph.get_option('run_options')
- [Commit-gnuradio] [gnuradio] 12/13: Merge branch 'maint', (continued)
- [Commit-gnuradio] [gnuradio] 12/13: Merge branch 'maint', git, 2015/07/24
- [Commit-gnuradio] [gnuradio] 13/13: Merge remote-tracking branch 'gnuradio-wg-grc/master_grcwg', git, 2015/07/24
- [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 <=
- [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, 2015/07/24