summaryrefslogtreecommitdiff
path: root/grc
diff options
context:
space:
mode:
Diffstat (limited to 'grc')
-rw-r--r--grc/src/platforms/gui/Block.py23
-rw-r--r--grc/src/platforms/gui/Constants.py7
-rw-r--r--grc/src/platforms/gui/FlowGraph.py2
-rw-r--r--grc/src/platforms/gui/Port.py60
4 files changed, 48 insertions, 44 deletions
diff --git a/grc/src/platforms/gui/Block.py b/grc/src/platforms/gui/Block.py
index 7589540b9..a2b5048ec 100644
--- a/grc/src/platforms/gui/Block.py
+++ b/grc/src/platforms/gui/Block.py
@@ -23,8 +23,7 @@ import Utils
import Colors
from ... gui.Constants import BORDER_PROXIMITY_SENSITIVITY
from Constants import \
- BLOCK_FONT, LABEL_PADDING_WIDTH, \
- LABEL_PADDING_HEIGHT, PORT_HEIGHT, \
+ BLOCK_FONT, BLOCK_LABEL_PADDING, \
PORT_SEPARATION, LABEL_SEPARATION, \
PORT_BORDER_SEPARATION, POSSIBLE_ROTATIONS
import pygtk
@@ -116,12 +115,15 @@ class Block(Element):
self.bg_color = self.get_enabled() and Colors.BG_COLOR or Colors.DISABLED_BG_COLOR
self.clear()
self._create_labels()
- self.W = self.label_width + 2*LABEL_PADDING_WIDTH
- max_ports = max(len(self.get_sinks()), len(self.get_sources()), 1)
- self.H = max(self.label_height+2*LABEL_PADDING_HEIGHT, 2*PORT_BORDER_SEPARATION + max_ports*PORT_HEIGHT + (max_ports-1)*PORT_SEPARATION)
- if self.is_horizontal(): self.add_area((0,0),(self.W,self.H))
- elif self.is_vertical(): self.add_area((0,0),(self.H,self.W))
- map(lambda p: p.update(), self.get_sinks() + self.get_sources())
+ self.W = self.label_width + 2*BLOCK_LABEL_PADDING
+ self.H = max(*(
+ [self.label_height+2*BLOCK_LABEL_PADDING] + [2*PORT_BORDER_SEPARATION + \
+ sum([port.H + PORT_SEPARATION for port in ports]) - PORT_SEPARATION
+ for ports in (self.get_sources(), self.get_sinks())]
+ ))
+ if self.is_horizontal(): self.add_area((0, 0), (self.W, self.H))
+ elif self.is_vertical(): self.add_area((0, 0), (self.H, self.W))
+ map(lambda p: p.update(), self.get_ports())
def _create_labels(self):
"""Create the labels for the signal block."""
@@ -164,6 +166,7 @@ class Block(Element):
self.vertical_label = vimage = gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), height, width)
for i in range(width):
for j in range(height): vimage.put_pixel(j, width-i-1, image.get_pixel(i, j))
+ map(lambda p: p._create_labels(), self.get_ports())
def draw(self, window):
"""
@@ -176,9 +179,9 @@ class Block(Element):
#draw label image
gc = self.get_gc()
if self.is_horizontal():
- window.draw_image(gc, self.horizontal_label, 0, 0, x+LABEL_PADDING_WIDTH, y+(self.H-self.label_height)/2, -1, -1)
+ window.draw_image(gc, self.horizontal_label, 0, 0, x+BLOCK_LABEL_PADDING, y+(self.H-self.label_height)/2, -1, -1)
elif self.is_vertical():
- window.draw_image(gc, self.vertical_label, 0, 0, x+(self.H-self.label_height)/2, y+LABEL_PADDING_WIDTH, -1, -1)
+ window.draw_image(gc, self.vertical_label, 0, 0, x+(self.H-self.label_height)/2, y+BLOCK_LABEL_PADDING, -1, -1)
#draw ports
map(lambda p: p.draw(window), self.get_ports())
diff --git a/grc/src/platforms/gui/Constants.py b/grc/src/platforms/gui/Constants.py
index b2e9bfed5..00899cb78 100644
--- a/grc/src/platforms/gui/Constants.py
+++ b/grc/src/platforms/gui/Constants.py
@@ -21,13 +21,12 @@
#label constraint dimensions
LABEL_SEPARATION = 3
-LABEL_PADDING_WIDTH = 9
-LABEL_PADDING_HEIGHT = 9
+BLOCK_LABEL_PADDING = 7
+PORT_LABEL_PADDING = 2
#port constraint dimensions
PORT_SEPARATION = 17
-PORT_HEIGHT = 15
-PORT_WIDTH = 25
PORT_BORDER_SEPARATION = 9
+PORT_MIN_WIDTH = 20
#fonts
PARAM_LABEL_FONT = 'Sans 9.5'
PARAM_FONT = 'Sans 7.5'
diff --git a/grc/src/platforms/gui/FlowGraph.py b/grc/src/platforms/gui/FlowGraph.py
index 60bb57528..2de4482ab 100644
--- a/grc/src/platforms/gui/FlowGraph.py
+++ b/grc/src/platforms/gui/FlowGraph.py
@@ -213,7 +213,7 @@ class FlowGraph(Element):
"""
changed = False
for selected_block in self.get_selected_blocks():
- for ports in selected_block.get_ports():
+ for ports in (selected_block.get_sinks(), selected_block.get_sources()):
if ports and hasattr(ports[0], 'get_nports') and ports[0].get_nports():
#find the param that controls port0
for param in selected_block.get_params():
diff --git a/grc/src/platforms/gui/Port.py b/grc/src/platforms/gui/Port.py
index aeab85ea0..85d9fea5a 100644
--- a/grc/src/platforms/gui/Port.py
+++ b/grc/src/platforms/gui/Port.py
@@ -19,9 +19,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
from Element import Element
from Constants import \
- PORT_HEIGHT, PORT_SEPARATION, \
- PORT_WIDTH, CONNECTOR_EXTENSION_MINIMAL, \
- CONNECTOR_EXTENSION_INCREMENT, PORT_FONT
+ PORT_SEPARATION, CONNECTOR_EXTENSION_MINIMAL, \
+ CONNECTOR_EXTENSION_INCREMENT, PORT_FONT, \
+ PORT_LABEL_PADDING, PORT_MIN_WIDTH
import Colors
import pygtk
pygtk.require('2.0')
@@ -42,63 +42,65 @@ class Port(Element):
def update(self):
"""Create new areas and labels for the port."""
self.clear()
- self.BG_color = Colors.get_color(self.get_color())
- self._create_labels()
#get current rotation
rotation = self.get_rotation()
#get all sibling ports
if self.is_source(): ports = self.get_parent().get_sources()
elif self.is_sink(): ports = self.get_parent().get_sinks()
+ #get the max width
+ self.W = max([port.W for port in ports] + [PORT_MIN_WIDTH])
#get a numeric index for this port relative to its sibling ports
index = ports.index(self)
length = len(ports)
#reverse the order of ports for these rotations
if rotation in (180, 270): index = length-index-1
- offset = (self.get_parent().H - length*PORT_HEIGHT - (length-1)*PORT_SEPARATION)/2
+ offset = (self.get_parent().H - length*self.H - (length-1)*PORT_SEPARATION)/2
#create areas and connector coordinates
if (self.is_sink() and rotation == 0) or (self.is_source() and rotation == 180):
- x = -1*PORT_WIDTH
- y = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
- self.add_area((x, y), (PORT_WIDTH, PORT_HEIGHT))
- self._connector_coordinate = (x-1, y+PORT_HEIGHT/2)
+ x = -1*self.W
+ y = (PORT_SEPARATION+self.H)*index+offset
+ self.add_area((x, y), (self.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+PORT_HEIGHT)*index+offset
- self.add_area((x, y), (PORT_WIDTH, PORT_HEIGHT))
- self._connector_coordinate = (x+1+PORT_WIDTH, y+PORT_HEIGHT/2)
+ y = (PORT_SEPARATION+self.H)*index+offset
+ self.add_area((x, y), (self.W, self.H))
+ self._connector_coordinate = (x+1+self.W, y+self.H/2)
elif (self.is_source() and rotation == 90) or (self.is_sink() and rotation == 270):
- y = -1*PORT_WIDTH
- x = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
- self.add_area((x, y), (PORT_HEIGHT, PORT_WIDTH))
- self._connector_coordinate = (x+PORT_HEIGHT/2, y-1)
+ y = -1*self.W
+ x = (PORT_SEPARATION+self.H)*index+offset
+ self.add_area((x, y), (self.H, self.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+PORT_HEIGHT)*index+offset
- self.add_area((x, y), (PORT_HEIGHT, PORT_WIDTH))
- self._connector_coordinate = (x+PORT_HEIGHT/2, y+1+PORT_WIDTH)
+ x = (PORT_SEPARATION+self.H)*index+offset
+ self.add_area((x, y), (self.H, self.W))
+ self._connector_coordinate = (x+self.H/2, y+1+self.W)
#the connector length
self._connector_length = CONNECTOR_EXTENSION_MINIMAL + CONNECTOR_EXTENSION_INCREMENT*index
def _create_labels(self):
"""Create the labels for the socket."""
+ self.BG_color = Colors.get_color(self.get_color())
#create the layout
layout = gtk.DrawingArea().create_pango_layout(self.get_name())
desc = pango.FontDescription(PORT_FONT)
layout.set_font_description(desc)
- w,h = self.w,self.h = layout.get_pixel_size()
+ self.w, self.h = layout.get_pixel_size()
+ self.W, self.H = 2*PORT_LABEL_PADDING+self.w, 2*PORT_LABEL_PADDING+self.h
#create the pixmap
- pixmap = gtk.gdk.Pixmap(self.get_parent().get_parent().get_window(), w, h, -1)
+ pixmap = gtk.gdk.Pixmap(self.get_parent().get_parent().get_window(), self.w, self.h, -1)
gc = pixmap.new_gc()
gc.foreground = self.BG_color
- pixmap.draw_rectangle(gc, True, 0, 0, w, h)
+ pixmap.draw_rectangle(gc, True, 0, 0, self.w, self.h)
gc.foreground = Colors.TXT_COLOR
pixmap.draw_layout(gc, 0, 0, layout)
#create the images
- self.horizontal_label = image = pixmap.get_image(0, 0, w, h)
+ self.horizontal_label = image = pixmap.get_image(0, 0, self.w, self.h)
if self.is_vertical():
- self.vertical_label = vimage = gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), h, w)
- for i in range(w):
- for j in range(h): vimage.put_pixel(j, w-i-1, image.get_pixel(i, j))
+ self.vertical_label = vimage = gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), self.h, self.w)
+ for i in range(self.w):
+ for j in range(self.h): vimage.put_pixel(j, self.w-i-1, image.get_pixel(i, j))
def draw(self, window):
"""
@@ -111,9 +113,9 @@ class Port(Element):
X,Y = self.get_coordinate()
(x,y),(w,h) = self.areas_dict[self.get_rotation()][0] #use the first area's sizes to place the labels
if self.is_horizontal():
- window.draw_image(gc, self.horizontal_label, 0, 0, x+X+(PORT_WIDTH-self.w)/2, y+Y+(PORT_HEIGHT-self.h)/2, -1, -1)
+ window.draw_image(gc, self.horizontal_label, 0, 0, x+X+(self.W-self.w)/2, y+Y+(self.H-self.h)/2, -1, -1)
elif self.is_vertical():
- window.draw_image(gc, self.vertical_label, 0, 0, x+X+(PORT_HEIGHT-self.h)/2, y+Y+(PORT_WIDTH-self.w)/2, -1, -1)
+ window.draw_image(gc, self.vertical_label, 0, 0, x+X+(self.H-self.h)/2, y+Y+(self.W-self.w)/2, -1, -1)
def get_connector_coordinate(self):
"""