diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2015-07-17 13:49:06 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2015-07-17 15:48:18 +0200 |
commit | 72048e6e8144d4e0a342a41753ec68d357beb04c (patch) | |
tree | 7d2efe12077649d8702c5bf7ce56c81d10d807f3 | |
parent | b48f0e137b969f175aecc7a0de6257464b2723e5 (diff) |
grc: fix bus ports spacing in gui
-rw-r--r-- | grc/gui/Block.py | 22 | ||||
-rw-r--r-- | grc/gui/Port.py | 26 |
2 files changed, 30 insertions, 18 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 83706ed1aa..11273a537b 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -22,10 +22,10 @@ import Utils import Colors from .. base import odict from Constants import BORDER_PROXIMITY_SENSITIVITY -from Constants import \ - BLOCK_LABEL_PADDING, \ - PORT_SEPARATION, LABEL_SEPARATION, \ +from Constants import ( + BLOCK_LABEL_PADDING, PORT_SPACING, PORT_SEPARATION, LABEL_SEPARATION, PORT_BORDER_SEPARATION, POSSIBLE_ROTATIONS, BLOCK_FONT, PARAM_FONT +) import Actions import pygtk pygtk.require('2.0') @@ -72,6 +72,7 @@ class Block(Element): )) Element.__init__(self) self._comment_pixmap = None + self.has_busses = [False, False] # source, sink def get_coordinate(self): """ @@ -190,13 +191,14 @@ class Block(Element): self.vertical_label = self.get_parent().new_pixmap(height, width) Utils.rotate_pixmap(gc, self.horizontal_label, self.vertical_label) #calculate width and height needed - self.W = self.label_width + 2*BLOCK_LABEL_PADDING + self.W = self.label_width + 2 * BLOCK_LABEL_PADDING + def get_min_height_for_ports(): visible_ports = filter(lambda p: not p.get_hide(), ports) H = 2*PORT_BORDER_SEPARATION + len(visible_ports) * PORT_SEPARATION if visible_ports: H -= ports[0].H return H - self.H = max(*( + self.H = max( [ # labels self.label_height + 2 * BLOCK_LABEL_PADDING ] + @@ -204,11 +206,15 @@ class Block(Element): get_min_height_for_ports() for ports in (self.get_sources_gui(), self.get_sinks_gui()) ] + [ # bus ports only - 4 * PORT_BORDER_SEPARATION + - sum([port.H + PORT_SEPARATION for port in ports if port.get_type() == 'bus']) - PORT_SEPARATION + 2 * PORT_BORDER_SEPARATION + + sum([port.H + PORT_SPACING for port in ports if port.get_type() == 'bus']) - PORT_SPACING for ports in (self.get_sources_gui(), self.get_sinks_gui()) ] - )) + ) + 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_label() def create_comment_label(self): diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 5310c1f73b..93372ead93 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -18,10 +18,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ from Element import Element -from Constants import \ - PORT_SEPARATION, CONNECTOR_EXTENSION_MINIMAL, \ - CONNECTOR_EXTENSION_INCREMENT, \ +from Constants import ( + PORT_SEPARATION, PORT_SPACING, CONNECTOR_EXTENSION_MINIMAL, + CONNECTOR_EXTENSION_INCREMENT, CANVAS_GRID_SIZE, PORT_LABEL_PADDING, PORT_MIN_WIDTH, PORT_LABEL_HIDDEN_WIDTH, PORT_FONT +) from .. base.Constants import DEFAULT_DOMAIN, GR_MESSAGE_DOMAIN import Utils import Actions @@ -79,26 +80,31 @@ class Port(Element): #reverse the order of ports for these rotations if rotation in (180, 270): index = length-index-1 - offset = (self.get_parent().H - (length-1)*PORT_SEPARATION - self.H)/2 + + port_separation = PORT_SEPARATION \ + if self.get_parent().has_busses[self.is_source()] \ + else max([port.H for port in ports]) + PORT_SPACING + + offset = (self.get_parent().H - (length-1)*port_separation - self.H)/2 #create areas and connector coordinates if (self.is_sink() and rotation == 0) or (self.is_source() and rotation == 180): - x = -1*W - y = PORT_SEPARATION*index+offset + x = -W + y = port_separation*index+offset self.add_area((x, y), (W, self.H)) self._connector_coordinate = (x-1, y+self.H/2) elif (self.is_source() and rotation == 0) or (self.is_sink() and rotation == 180): x = self.get_parent().W - y = PORT_SEPARATION*index+offset + y = port_separation*index+offset self.add_area((x, y), (W, self.H)) self._connector_coordinate = (x+1+W, y+self.H/2) elif (self.is_source() and rotation == 90) or (self.is_sink() and rotation == 270): - y = -1*W - x = PORT_SEPARATION*index+offset + y = -W + x = port_separation*index+offset self.add_area((x, y), (self.H, W)) self._connector_coordinate = (x+self.H/2, y-1) elif (self.is_sink() and rotation == 90) or (self.is_source() and rotation == 270): y = self.get_parent().W - x = PORT_SEPARATION*index+offset + x = port_separation*index+offset self.add_area((x, y), (self.H, W)) self._connector_coordinate = (x+self.H/2, y+1+W) #the connector length |