summaryrefslogtreecommitdiff
path: root/grc/gui/Block.py
diff options
context:
space:
mode:
Diffstat (limited to 'grc/gui/Block.py')
-rw-r--r--grc/gui/Block.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 49c0361eb9..0ae624f94f 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -26,6 +26,7 @@ from Constants import \
BLOCK_LABEL_PADDING, \
PORT_SEPARATION, LABEL_SEPARATION, \
PORT_BORDER_SEPARATION, POSSIBLE_ROTATIONS
+import Actions
import pygtk
pygtk.require('2.0')
import gtk
@@ -43,6 +44,8 @@ class Block(Element):
Block contructor.
Add graphics related params to the block.
"""
+ self.W = 0
+ self.H = 0
#add the position param
self.get_params().append(self.get_parent().get_parent().Param(
block=self,
@@ -97,6 +100,12 @@ class Block(Element):
Args:
coor: the coordinate tuple (x, y)
"""
+ if Actions.TOGGLE_SNAP_TO_GRID.get_active():
+ offset_x, offset_y = (0, self.H/2) if self.is_horizontal() else (self.H/2, 0)
+ coor = (
+ Utils.align_to_grid(coor[0] + offset_x) - offset_x,
+ Utils.align_to_grid(coor[1] + offset_y) - offset_y
+ )
self.get_param('_coordinate').set_value(str(coor))
def get_rotation(self):
@@ -174,13 +183,23 @@ class Block(Element):
Utils.rotate_pixmap(gc, self.horizontal_label, self.vertical_label)
#calculate width and height needed
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.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_gui(), self.get_sinks_gui())] +
- [4*PORT_BORDER_SEPARATION + \
- sum([(port.H) + PORT_SEPARATION for port in ports]) - PORT_SEPARATION
- for ports in ([i for i in self.get_sources_gui() if i.get_type() == 'bus'], [i for i in self.get_sinks_gui() if i.get_type() == 'bus'])]
+ [ # labels
+ self.label_height + 2 * BLOCK_LABEL_PADDING
+ ] +
+ [ # ports
+ 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
+ for ports in (self.get_sources_gui(), self.get_sinks_gui())
+ ]
))
def draw(self, gc, window):
@@ -205,7 +224,8 @@ class Block(Element):
window.draw_drawable(gc, self.vertical_label, 0, 0, x+(self.H-self.label_height)/2, y+BLOCK_LABEL_PADDING, -1, -1)
#draw ports
for port in self.get_ports_gui():
- port.draw(gc, window)
+ if not port.get_hide():
+ port.draw(gc, window)
def what_is_selected(self, coor, coor_m=None):
"""