diff options
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/Block.py | 51 | ||||
-rw-r--r-- | grc/gui/Connection.py | 2 | ||||
-rw-r--r-- | grc/gui/Constants.py | 1 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 4 | ||||
-rw-r--r-- | grc/gui/Port.py | 20 |
5 files changed, 40 insertions, 38 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py index db147738b6..d1f67d6586 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -55,8 +55,9 @@ class Block(CoreBlock, Element): self._surface_layout_offsets = 0, 0 self._comment_layout = None + self._border_color = (Colors.MISSING_BLOCK_BORDER_COLOR if self.is_dummy_block else + Colors.BORDER_COLOR) self._bg_color = Colors.BLOCK_ENABLED_COLOR - self.has_busses = [False, False] # source, sink @property def coordinate(self): @@ -113,7 +114,8 @@ class Block(CoreBlock, Element): elif self.is_vertical(): self.areas.append([0, 0, self.height, self.width]) - for ports, has_busses in zip((self.active_sources, self.active_sinks), self.has_busses): + bussified = self.current_bus_structure['source'], self.current_bus_structure['sink'] + for ports, has_busses in zip((self.active_sources, self.active_sinks), bussified): if not ports: continue port_separation = PORT_SEPARATION if not has_busses else ports[0].height + PORT_SPACING @@ -177,25 +179,26 @@ class Block(CoreBlock, Element): self.create_port_labels() - def get_min_height_for_ports(): + def get_min_height_for_ports(ports): min_height = 2 * PORT_BORDER_SEPARATION + len(ports) * PORT_SEPARATION if ports: min_height -= ports[-1].height return min_height - height = max( - [ # labels - height - ] + - [ # ports - get_min_height_for_ports() for ports in (self.active_sources, self.active_sinks) - ] + - [ # bus ports only - 2 * PORT_BORDER_SEPARATION + - sum([port.height + PORT_SPACING for port in ports if port.get_type() == 'bus']) - PORT_SPACING - for ports in (self.get_sources_gui(), self.get_sinks_gui()) - ] - ) + height = max(height, + get_min_height_for_ports(self.active_sinks), + get_min_height_for_ports(self.active_sources)) + + def get_min_height_for_bus_ports(ports): + return 2 * PORT_BORDER_SEPARATION + sum( + port.height + PORT_SPACING for port in ports if port.get_type() == 'bus' + ) - PORT_SPACING + + if self.current_bus_structure['sink']: + height = max(height, get_min_height_for_bus_ports(self.active_sinks)) + if self.current_bus_structure['source']: + height = max(height, get_min_height_for_bus_ports(self.active_sources)) + self.width, self.height = width, height = Utils.align_to_grid((width, height)) self._surface_layout_offsets = [ @@ -203,10 +206,6 @@ class Block(CoreBlock, Element): (height - label_height) / 2.0 ] - self.has_busses = [ - any(port.get_type() == 'bus' for port in ports) - for ports in (self.get_sources_gui(), self.get_sinks_gui()) - ] self.create_comment_layout() def create_port_labels(self): @@ -226,9 +225,9 @@ class Block(CoreBlock, Element): complexity = utils.calculate_flowgraph_complexity(self.parent) markups.append( '<span foreground="#444" size="medium" font_desc="{font}">' - '<b>Complexity: {num}bal</b></span>'.format(num=utils.num_to_str(complexity), font=BLOCK_FONT) + '<b>Complexity: {num}bal</b></span>'.format(num=Utils.num_to_str(complexity), font=BLOCK_FONT) ) - comment = self.get_comment() # Returns None if there are no comments + comment = self.comment # Returns None if there are no comments if comment: if markups: markups.append('<span></span>') @@ -242,16 +241,12 @@ class Block(CoreBlock, Element): else: self._comment_layout = None - def draw(self, widget, cr): + def draw(self, widget, cr, border_color=None, bg_color=None): """ Draw the signal block with label and inputs/outputs. """ bg_color = self._bg_color - border_color = ( - Colors.HIGHLIGHT_COLOR if self.highlighted else - Colors.MISSING_BLOCK_BORDER_COLOR if self.is_dummy_block else - Colors.BORDER_COLOR - ) + border_color = Colors.HIGHLIGHT_COLOR if self.highlighted else self._border_color # draw main block Element.draw(self, widget, cr, border_color, bg_color) for port in self.active_ports(): diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py index b6e84f8c89..9b483383ac 100644 --- a/grc/gui/Connection.py +++ b/grc/gui/Connection.py @@ -152,7 +152,7 @@ class Connection(Element, _Connection): # create right-angled connector self.lines.append([p0, p1, point, p2, p3]) - def draw(self, widget, cr): + def draw(self, widget, cr, border_color=None, bg_color=None): """ Draw the connection. """ diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py index 5c55c4180e..516aaf92f4 100644 --- a/grc/gui/Constants.py +++ b/grc/gui/Constants.py @@ -72,6 +72,7 @@ PORT_SEPARATION = 32 PORT_MIN_WIDTH = 20 PORT_LABEL_HIDDEN_WIDTH = 10 +PORT_EXTRA_BUS_HEIGHT = 40 # minimal length of connector CONNECTOR_EXTENSION_MINIMAL = 11 diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index a3dd379074..6ff4507df2 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -153,8 +153,8 @@ class FlowGraph(Element, _Flowgraph): try: self.connect(self._old_selected_port, self._new_selected_port) Actions.ELEMENT_CREATE() - except: - Messages.send_fail_connection() + except Exception as e: + Messages.send_fail_connection(e) self._old_selected_port = None self._new_selected_port = None return True diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 991036cb99..6776963c63 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -42,8 +42,9 @@ class Port(_Port, Element): self._connector_coordinate = (0, 0) self._hovering = False self.force_show_label = False - self._bg_color = (0, 0, 0) + self._bg_color = 0, 0, 0 self._line_width_factor = 1.0 + self._label_layout_offsets = 0, 0 self.width_with_label = self.height = 0 self.connector_length = 0 @@ -109,8 +110,10 @@ class Port(_Port, Element): self.width = 2 * Constants.PORT_LABEL_PADDING + label_width self.height = 2 * Constants.PORT_LABEL_PADDING + label_height + self._label_layout_offsets = [0, Constants.PORT_LABEL_PADDING] if self.get_type() == 'bus': - self.height += 2 * label_height + self.height += Constants.PORT_EXTRA_BUS_HEIGHT + self._label_layout_offsets[1] += Constants.PORT_EXTRA_BUS_HEIGHT / 2 self.height += self.height % 2 # uneven height def draw(self, widget, cr, border_color, bg_color): @@ -126,7 +129,7 @@ class Port(_Port, Element): if self.is_vertical(): cr.rotate(-math.pi / 2) cr.translate(-self.width, 0) - cr.translate(0, Constants.PORT_LABEL_PADDING) + cr.translate(*self._label_layout_offsets) PangoCairo.update_layout(cr, self.label_layout) PangoCairo.show_layout(cr, self.label_layout) @@ -138,8 +141,11 @@ class Port(_Port, Element): Returns: the connector coordinate (x, y) tuple """ - return [sum(c) for c in zip(self._connector_coordinate, self.coordinate, - self.parent_block.coordinate)] + return [sum(c) for c in zip( + self._connector_coordinate, # relative to port + self.coordinate, # relative to block + self.parent_block.coordinate # abs + )] def get_connector_direction(self): """ @@ -167,7 +173,7 @@ class Port(_Port, Element): Args: direction: degrees to rotate """ - self.parent.rotate(direction) + self.parent_block.rotate(direction) def move(self, delta_coor): """ @@ -176,7 +182,7 @@ class Port(_Port, Element): Args: delta_corr: the (delta_x, delta_y) tuple """ - self.parent.move(delta_coor) + self.parent_block.move(delta_coor) @property def highlighted(self): |