commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 17/23: grc: preserve block spacing when dra


From: git
Subject: [Commit-gnuradio] [gnuradio] 17/23: grc: preserve block spacing when dragging multiple blocks into canvas boundary
Date: Sat, 28 Nov 2015 21:18:08 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit dcc09deb064453f4add1ece3502ee99f12f3cb25
Author: Glenn Richardson <address@hidden>
Date:   Thu Nov 19 20:34:55 2015 -0500

    grc: preserve block spacing when dragging multiple blocks into canvas 
boundary
---
 grc/gui/Block.py     | 34 ++++++++++++++++++++++++++++++++++
 grc/gui/FlowGraph.py |  3 +++
 2 files changed, 37 insertions(+)

diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index 6a2e496..8c74fcb 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -127,6 +127,40 @@ class Block(Element):
             )
         self.get_param('_coordinate').set_value(str(coor))
 
+    def bound_move_delta(self, delta_coor):
+        """
+        Limit potential moves from exceeding the bounds of the canvas
+
+        Args:
+            delta_coor: requested delta coordinate (dX, dY) to move
+
+        Returns:
+            The delta coordinate possible to move while keeping the block on 
the canvas 
+            or the input (dX, dY) on failure
+        """
+        dX, dY = delta_coor 
+
+        try:
+            fgW, fgH = self.get_parent().get_size()
+            x, y = map(int, eval(self.get_param("_coordinate").get_value()))
+            if self.is_horizontal():
+               sW, sH = self.W, self.H
+            else:
+               sW, sH = self.H, self.W
+        
+            if x + dX < 0:
+                dX = -x
+            elif dX + x + sW >= fgW:
+                dX = fgW - x - sW
+            if y + dY < 0:
+                dY = -y
+            elif dY + y + sH >= fgH:
+               dY = fgH - y - sH
+        except:
+            pass
+
+        return ( dX, dY ) 
+
     def get_rotation(self):
         """
         Get the rotation from the position param.
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 6d712e5..867a7cd 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -280,6 +280,9 @@ class FlowGraph(Element):
             delta_coordinate: the change in coordinates
         """
         for selected_block in self.get_selected_blocks():
+            delta_coordinate = 
selected_block.bound_move_delta(delta_coordinate)
+ 
+        for selected_block in self.get_selected_blocks():
             selected_block.move(delta_coordinate)
             self.element_moved = True
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]