diff options
author | Tom Rondeau <tom@trondeau.com> | 2014-03-17 16:47:52 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2014-03-17 16:47:52 -0400 |
commit | 363fc298e991f1c583df9d6127a3fdc412392b5e (patch) | |
tree | bb36dfdd9b9657d8a0853f62a94c4b62faebcfbb | |
parent | 719ef7ecdfe956cf49a4966dbc79fad5b834ac1a (diff) | |
parent | 0ab8e89d5b4ef978b039fffbf95650292a85841f (diff) |
Merge remote-tracking branch 'skoslowski/grc_show_missing_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 | 11 | ||||
-rw-r--r-- | grc/gui/Colors.py | 3 | ||||
-rw-r--r-- | grc/gui/Port.py | 3 |
6 files changed, 78 insertions, 17 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..b2b391246e 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -131,7 +131,8 @@ class Block(Element): def create_labels(self): """Create the labels for the signal block.""" Element.create_labels(self) - self._bg_color = self.get_enabled() and Colors.BLOCK_ENABLED_COLOR or Colors.BLOCK_DISABLED_COLOR + self._bg_color = self.is_dummy_block() and Colors.MISSING_BLOCK_BACKGROUND_COLOR or \ + self.get_enabled() and Colors.BLOCK_ENABLED_COLOR or Colors.BLOCK_DISABLED_COLOR layouts = list() #create the main layout layout = gtk.DrawingArea().create_pango_layout('') @@ -139,7 +140,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) @@ -191,7 +195,8 @@ class Block(Element): #draw main block Element.draw( self, gc, window, bg_color=self._bg_color, - border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or Colors.BORDER_COLOR, + border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or + self.is_dummy_block() and Colors.MISSING_BLOCK_BORDER_COLOR or Colors.BORDER_COLOR, ) #draw label image if self.is_horizontal(): diff --git a/grc/gui/Colors.py b/grc/gui/Colors.py index 5f92bb07a9..541d8db0b2 100644 --- a/grc/gui/Colors.py +++ b/grc/gui/Colors.py @@ -26,6 +26,9 @@ try: HIGHLIGHT_COLOR = get_color('#00FFFF') BORDER_COLOR = get_color('black') + # missing blocks stuff + MISSING_BLOCK_BACKGROUND_COLOR = get_color('#FFF2F2') + MISSING_BLOCK_BORDER_COLOR = get_color('red') #param entry boxes PARAM_ENTRY_TEXT_COLOR = get_color('black') ENTRYENUM_CUSTOM_COLOR = get_color('#EEEEEE') diff --git a/grc/gui/Port.py b/grc/gui/Port.py index fe1dc5070a..e542797ea6 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -126,7 +126,8 @@ class Port(Element): """ Element.draw( self, gc, window, bg_color=self._bg_color, - border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or Colors.BORDER_COLOR, + border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or + self.get_parent().is_dummy_block() and Colors.MISSING_BLOCK_BORDER_COLOR or Colors.BORDER_COLOR, ) X,Y = self.get_coordinate() (x,y),(w,h) = self._areas_list[0] #use the first area's sizes to place the labels |