diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2013-12-26 22:50:17 +0100 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2014-03-15 18:00:05 +0100 |
commit | bd857db80dab56523ecbc76886cd6fa5c1183890 (patch) | |
tree | 897537c7746920ab06aab7cd0d46cc98a7a34da4 | |
parent | 69dcaa75b629af4ebc465a073f54af84b7c75a11 (diff) |
grc: show dummy blocks when opening grc blocks
-rw-r--r-- | grc/base/Element.py | 1 | ||||
-rw-r--r-- | grc/base/FlowGraph.py | 66 | ||||
-rw-r--r-- | grc/blocks/dummy.xml | 11 | ||||
-rw-r--r-- | grc/gui/Block.py | 5 |
4 files changed, 69 insertions, 14 deletions
diff --git a/grc/base/Element.py b/grc/base/Element.py index 17b2234a8c..be73ab264f 100644 --- a/grc/base/Element.py +++ b/grc/base/Element.py @@ -89,6 +89,7 @@ class Element(object): def is_flow_graph(self): return False def is_connection(self): return False def is_block(self): return False + def is_dummy_block(self): return False def is_source(self): return False def is_sink(self): return False def is_port(self): return False diff --git a/grc/base/FlowGraph.py b/grc/base/FlowGraph.py index c85e3ce233..3c249ff71b 100644 --- a/grc/base/FlowGraph.py +++ b/grc/base/FlowGraph.py @@ -268,16 +268,20 @@ class FlowGraph(Element): #build the blocks for block_n in blocks_n: key = block_n.find('key') - if key == 'options': block = self._options_block - else: block = self.get_new_block(key) - #only load the block when the block key was valid - if block: block.import_data(block_n) - else: Messages.send_error_load('Block key "%s" not found in %s'%(key, self.get_parent())) + block = self._options_block if key == 'options' else self.get_new_block(key) + + if not block: # looks like this block key cannot be found + # create a dummy block instead + block = self.get_new_block('dummy_block') + # Ugly ugly ugly + _initialize_dummy_block(block, block_n) + Messages.send_error_load('Block key "%s" not found in %s' % (key, self.get_parent())) + + block.import_data(block_n) #build the connections block_ids = map(lambda b: b.get_id(), self.get_blocks()) for connection_n in connections_n: - #try to make the connection - try: + try: # to make the connection #get the block ids source_block_id = connection_n.find('source_block_id') sink_block_id = connection_n.find('sink_block_id') @@ -297,9 +301,17 @@ class FlowGraph(Element): sink_key = self.update_message_port_key(sink_key, sink_block.get_sinks()) #verify the ports if source_key not in source_block.get_source_keys(): - raise LookupError('source key "%s" not in source block keys'%source_key) + # dummy blocks learn their ports here + if source_block.is_dummy_block(): + _dummy_block_add_port(source_block, source_key, dir='source') + else: + raise LookupError('source key "%s" not in source block keys' % source_key) if sink_key not in sink_block.get_sink_keys(): - raise LookupError('sink key "%s" not in sink block keys'%sink_key) + # dummy blocks learn their ports here + if sink_block.is_dummy_block(): + _dummy_block_add_port(sink_block, sink_key, dir='sink') + else: + raise LookupError('sink key "%s" not in sink block keys' % sink_key) #get the ports source = source_block.get_source(source_key) sink = sink_block.get_sink(sink_key) @@ -327,7 +339,35 @@ class FlowGraph(Element): :returns: the updated key or the original one """ if key.isdigit(): # don't bother current message port keys - port = ports[int(key)] # get port (assuming liner indexed keys) - if port.get_type() == "message": - return port.get_key() # for message ports get updated key - return key # do nothing
\ No newline at end of file + try: + port = ports[int(key)] # get port (assuming liner indexed keys) + if port.get_type() == "message": + return port.get_key() # for message ports get updated key + except IndexError: + pass + return key # do nothing + + +def _initialize_dummy_block(block, block_n): + """This is so ugly... dummy-fy a block + + Modify block object to get the behaviour for a missing block + """ + block._key = block_n.find('key') + block.is_dummy_block = lambda: True + block.is_valid = lambda: False + block.get_enabled = lambda: False + for param_n in block_n.findall('param'): + if param_n['key'] not in block.get_param_keys(): + new_param_n = odict({'key': param_n['key'], 'name': param_n['key'], 'type': 'string'}) + block.get_params().append(block.get_parent().get_parent().Param(block=block, n=new_param_n)) + + +def _dummy_block_add_port(block, key, dir): + """This is so ugly... Add a port to a dummy-fied block""" + port_n = odict({'name': '?', 'key': key, 'type': ''}) + port = block.get_parent().get_parent().Port(block=block, n=port_n, dir=dir) + if port.is_source(): + block.get_sources().append(port) + else: + block.get_sinks().append(port)
\ No newline at end of file diff --git a/grc/blocks/dummy.xml b/grc/blocks/dummy.xml new file mode 100644 index 0000000000..c0ca3b6698 --- /dev/null +++ b/grc/blocks/dummy.xml @@ -0,0 +1,11 @@ +<?xml version="1.0"?> +<!-- +################################################### +##Dummy Block +################################################### +--> +<block> + <name>Missing Block</name> + <key>dummy_block</key> + <make>raise NotImplementedError()</make> +</block> diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 30031866c0..c35ce1c505 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -139,7 +139,10 @@ class Block(Element): layout.set_markup(Utils.parse_template(BLOCK_MARKUP_TMPL, block=self)) self.label_width, self.label_height = layout.get_pixel_size() #display the params - markups = [param.get_markup() for param in self.get_params() if param.get_hide() not in ('all', 'part')] + if self.is_dummy_block(): + markups = ['<span foreground="black" font_desc="Sans 7.5"><b>key: </b>{}</span>'.format(self._key)] + else: + markups = [param.get_markup() for param in self.get_params() if param.get_hide() not in ('all', 'part')] if markups: layout = gtk.DrawingArea().create_pango_layout('') layout.set_spacing(LABEL_SEPARATION*pango.SCALE) |