commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 40/101: grc: gtk3: remove coordinate getter


From: git
Subject: [Commit-gnuradio] [gnuradio] 40/101: grc: gtk3: remove coordinate getter/setter
Date: Thu, 16 Mar 2017 14:58:04 +0000 (UTC)

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

jcorgan pushed a commit to branch python3
in repository gnuradio.

commit 47ddd4c48916308817ff39919c1e39b0da3f9c3d
Author: Sebastian Koslowski <address@hidden>
Date:   Wed Jul 13 10:53:09 2016 +0200

    grc: gtk3: remove coordinate getter/setter
---
 grc/gui/ActionHandler.py |  8 ++---
 grc/gui/Block.py         | 16 +++++-----
 grc/gui/Connection.py    | 13 ++++----
 grc/gui/Element.py       | 80 +++++++++++++++++++++---------------------------
 grc/gui/FlowGraph.py     | 43 +++++++++++++-------------
 grc/gui/Port.py          |  4 +--
 6 files changed, 78 insertions(+), 86 deletions(-)

diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py
index 923d8d6..938f887 100644
--- a/grc/gui/ActionHandler.py
+++ b/grc/gui/ActionHandler.py
@@ -202,7 +202,7 @@ class ActionHandler:
         elif action == Actions.BLOCK_CREATE_HIER:
 
                         # keeping track of coordinates for pasting later
-                        coords = 
flow_graph.selected_blocks()[0].get_coordinate()
+                        coords = flow_graph.selected_blocks()[0].coordinate
                         x,y = coords
                         x_min = x
                         y_min = y
@@ -226,7 +226,7 @@ class ActionHandler:
 
 
                             # keep track of x,y mins for pasting later
-                            (x,y) = block.get_coordinate()
+                            (x,y) = block.coordinate
                             if x < x_min:
                                 x_min = x
                             if y < y_min:
@@ -240,10 +240,10 @@ class ActionHandler:
 
                                 # If connected block is not in the list of 
selected blocks create a pad for it
                                 if flow_graph.get_block(source_id) not in 
flow_graph.selected_blocks():
-                                    pads.append({'key': 
connection.sink_port.key, 'coord': connection.source_port.get_coordinate(), 
'block_id' : block.get_id(), 'direction': 'source'})
+                                    pads.append({'key': 
connection.sink_port.key, 'coord': connection.source_port.coordinate, 
'block_id' : block.get_id(), 'direction': 'source'})
 
                                 if flow_graph.get_block(sink_id) not in 
flow_graph.selected_blocks():
-                                    pads.append({'key': 
connection.source_port.key, 'coord': connection.sink_port.get_coordinate(), 
'block_id' : block.get_id(), 'direction': 'sink'})
+                                    pads.append({'key': 
connection.source_port.key, 'coord': connection.sink_port.coordinate, 
'block_id' : block.get_id(), 'direction': 'sink'})
 
 
                         # Copy the selected blocks and paste them into a new 
page
diff --git a/grc/gui/Block.py b/grc/gui/Block.py
index e089913..5efb571 100644
--- a/grc/gui/Block.py
+++ b/grc/gui/Block.py
@@ -60,7 +60,8 @@ class Block(_Block, Element):
         self._bg_color = Colors.BLOCK_ENABLED_COLOR
         self.has_busses = [False, False]  # source, sink
 
-    def get_coordinate(self):
+    @property
+    def coordinate(self):
         """
         Get the coordinate from the position param.
 
@@ -69,7 +70,8 @@ class Block(_Block, Element):
         """
         return self.states['_coordinate']
 
-    def set_coordinate(self, coor):
+    @coordinate.setter
+    def coordinate(self, coor):
         """
         Set the coordinate into the position param.
 
@@ -121,12 +123,12 @@ class Block(_Block, Element):
             for index, port in enumerate(ports):
                 port.create_shapes()
 
-                port.set_coordinate({
+                port.coordinate = {
                     0: (+self.width, offset),
                     90: (offset, -port.width),
                     180: (-port.width, offset),
                     270: (offset, +self.width),
-                }[port.get_connector_direction()])
+                }[port.get_connector_direction()]
                 offset += PORT_SEPARATION if not has_busses else port.height + 
PORT_SPACING
 
                 port.connector_length = Constants.CONNECTOR_EXTENSION_MINIMAL 
+ \
@@ -281,8 +283,8 @@ class Block(_Block, Element):
         """
         for port in self.active_ports():
             port_selected = port.what_is_selected(
-                coor=[a - b for a, b in zip(coor, self.get_coordinate())],
-                coor_m=[a - b for a, b in zip(coor, self.get_coordinate())] if 
coor_m is not None else None
+                coor=[a - b for a, b in zip(coor, self.coordinate)],
+                coor_m=[a - b for a, b in zip(coor, self.coordinate)] if 
coor_m is not None else None
             )
             if port_selected:
                 return port_selected
@@ -291,7 +293,7 @@ class Block(_Block, Element):
     def draw_comment(self, widget, cr):
         if not self._comment_layout:
             return
-        x, y = self.get_coordinate()
+        x, y = self.coordinate
 
         if self.is_horizontal():
             y += self.height + BLOCK_LABEL_PADDING
diff --git a/grc/gui/Connection.py b/grc/gui/Connection.py
index 5bd25fb..33fe104 100644
--- a/grc/gui/Connection.py
+++ b/grc/gui/Connection.py
@@ -46,7 +46,8 @@ class Connection(Element, _Connection):
         self._sink_rot = self._source_rot = None
         self._sink_coor = self._source_coor = None
 
-    def get_coordinate(self):
+    @property_nop_write
+    def coordinate(self):
         return self.source_port.get_connector_coordinate()
 
     @property_nop_write
@@ -107,7 +108,7 @@ class Connection(Element, _Connection):
         source_dir = source.get_connector_direction()
         sink_dir = sink.get_connector_direction()
 
-        x_pos, y_pos = self.get_coordinate()
+        x_pos, y_pos = self.coordinate
         x_start, y_start = source.get_connector_coordinate()
         x_end, y_end = sink.get_connector_coordinate()
 
@@ -161,10 +162,10 @@ class Connection(Element, _Connection):
             self._sink_rot = sink.rotation
             self._source_rot = source.rotation
 
-        elif self._sink_coor != sink.parent_block.get_coordinate() or 
self._source_coor != source.parent_block.get_coordinate():
+        elif self._sink_coor != sink.parent_block.coordinate or 
self._source_coor != source.parent_block.coordinate:
             self._update_after_move()
-            self._sink_coor = sink.parent_block.get_coordinate()
-            self._source_coor = source.parent_block.get_coordinate()
+            self._sink_coor = sink.parent_block.coordinate
+            self._source_coor = source.parent_block.coordinate
         # draw
         color1, color2 = (
             Colors.HIGHLIGHT_COLOR if self.highlighted else
@@ -175,7 +176,7 @@ class Connection(Element, _Connection):
 
         if color1 != color2:
             cr.save()
-            x_pos, y_pos = self.get_coordinate()
+            x_pos, y_pos = self.coordinate
             cr.translate(-x_pos, -y_pos)
             cr.set_dash([5.0, 5.0], 5.0)
             Element.draw(self, widget, cr, color2, 
Colors.FLOWGRAPH_BACKGROUND_COLOR)
diff --git a/grc/gui/Element.py b/grc/gui/Element.py
index 50cb4aa..3b077dc 100644
--- a/grc/gui/Element.py
+++ b/grc/gui/Element.py
@@ -34,9 +34,9 @@ class Element(object):
         """
         Make a new list of rectangular areas and lines, and set the coordinate 
and the rotation.
         """
-        self.set_coordinate((0, 0))
-        self.highlighted = False
+        self.coordinate = (0, 0)
         self.rotation = 0
+        self.highlighted = False
 
         self.areas = []
         self.lines = []
@@ -101,11 +101,8 @@ class Element(object):
             border_color: the color for lines and rectangle borders
             bg_color: the color for the inside of the rectangle
         """
-        X, Y = self.get_coordinate()
-        cr.translate(X, Y)
+        cr.translate(*self.coordinate)
         for area in self.areas:
-            # aX = X + rX
-            # aY = Y + rY
             cr.set_source_rgb(*bg_color)
             cr.rectangle(*area)
             cr.fill()
@@ -129,23 +126,6 @@ class Element(object):
         """
         self.rotation = (self.rotation + rotation) % 360
 
-    def set_coordinate(self, coor):
-        """
-        Set the reference coordinate.
-
-        Args:
-            coor: the coordinate tuple (x,y)
-        """
-        self.coor = coor
-
-    def get_coordinate(self):
-        """Get the coordinate.
-
-        Returns:
-            the coordinate tuple (x,y)
-        """
-        return self.coor
-
     def move(self, delta_coor):
         """
         Move the element by adding the delta_coor to the current coordinate.
@@ -153,9 +133,9 @@ class Element(object):
         Args:
             delta_coor: (delta_x,delta_y) tuple
         """
-        deltaX, deltaY = delta_coor
-        X, Y = self.get_coordinate()
-        self.set_coordinate((X + deltaX, Y + deltaY))
+        x, y = self.coordinate
+        dx, dy = delta_coor
+        self.coordinate = (x + dx, y + dy)
 
     def what_is_selected(self, coor, coor_m=None):
         """
@@ -173,40 +153,50 @@ class Element(object):
         Returns:
             self if one of the areas/lines encompasses coor, else None.
         """
-        #function to test if p is between a and b (inclusive)
-        in_between = lambda p, a, b: p >= min(a, b) and p <= max(a, b)
-        #relative coordinate
-        x, y = [a-b for a,b in zip(coor, self.get_coordinate())]
+        # function to test if p is between a and b (inclusive)
+        def in_between(p, a, b):
+            # return min(a, b) <= p <= max(a, b)
+            return a <= p <= b or b <= p <= a
+        # relative coordinate
+        x, y = [a - b for a, b in zip(coor, self.coordinate)]
         if coor_m:
-            x_m, y_m = [a-b for a,b in zip(coor_m, self.get_coordinate())]
-            #handle rectangular areas
+            x_m, y_m = [a - b for a, b in zip(coor_m, self.coordinate)]
+            # handle rectangular areas
             for x1, y1, w, h in self.areas:
-                if in_between(x1, x, x_m) and in_between(y1, y, y_m) or \
-                    in_between(x1+w, x, x_m) and in_between(y1, y, y_m) or \
-                    in_between(x1, x, x_m) and in_between(y1+h, y, y_m) or \
-                    in_between(x1+w, x, x_m) and in_between(y1+h, y, y_m):
+                if (
+                    in_between(x1,     x, x_m) and in_between(y1,     y, y_m) 
or
+                    in_between(x1 + w, x, x_m) and in_between(y1,     y, y_m) 
or
+                    in_between(x1,     x, x_m) and in_between(y1 + h, y, y_m) 
or
+                    in_between(x1 + w, x, x_m) and in_between(y1 + h, y, y_m)
+                ):
                     return self
-            #handle horizontal or vertical lines
+            # handle horizontal or vertical lines
             for line in self.lines:
                 last_point = line[0]
                 for x2, y2 in line[1:]:
                     (x1, y1), last_point = last_point, (x2, y2)
-                    if in_between(x1, x, x_m) and in_between(y1, y, y_m) or \
-                        in_between(x2, x, x_m) and in_between(y2, y, y_m):
+                    if (
+                        in_between(x1, x, x_m) and in_between(y1, y, y_m) or
+                        in_between(x2, x, x_m) and in_between(y2, y, y_m)
+                    ):
                         return self
             return None
         else:
-            #handle rectangular areas
+            # handle rectangular areas
             for x1, y1, w, h in self.areas:
-                if in_between(x, x1, x1+w) and in_between(y, y1, y1+h): return 
self
-            #handle horizontal or vertical lines
+                if in_between(x, x1, x1+w) and in_between(y, y1, y1+h):
+                    return self
+            # handle horizontal or vertical lines
             for line in self.lines:
                 last_point = line[0]
                 for x2, y2 in line[1:]:
                     (x1, y1), last_point = last_point, (x2, y2)
-                    if x1 == x2: x1, x2 = x1-LINE_SELECT_SENSITIVITY, 
x2+LINE_SELECT_SENSITIVITY
-                    if y1 == y2: y1, y2 = y1-LINE_SELECT_SENSITIVITY, 
y2+LINE_SELECT_SENSITIVITY
-                    if in_between(x, x1, x2) and in_between(y, y1, y2): return 
self
+                    if x1 == x2:
+                        x1, x2 = x1 - LINE_SELECT_SENSITIVITY, x2 + 
LINE_SELECT_SENSITIVITY
+                    if y1 == y2:
+                        y1, y2 = y1 - LINE_SELECT_SENSITIVITY, y2 + 
LINE_SELECT_SENSITIVITY
+                    if in_between(x, x1, x2) and in_between(y, y1, y2):
+                        return self
             return None
 
     def mouse_over(self):
diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py
index 5de3887..c357123 100644
--- a/grc/gui/FlowGraph.py
+++ b/grc/gui/FlowGraph.py
@@ -142,7 +142,7 @@ class FlowGraph(Element, _Flowgraph):
         )
         #get the new block
         block = self.new_block(key)
-        block.set_coordinate(coor)
+        block.coordinate = coor
         block.get_param('id').set_value(id)
         Actions.ELEMENT_CREATE()
         return id
@@ -211,9 +211,9 @@ class FlowGraph(Element, _Flowgraph):
         if not blocks:
             return None
         #calc x and y min
-        x_min, y_min = blocks[0].get_coordinate()
+        x_min, y_min = blocks[0].coordinate
         for block in blocks:
-            x, y = block.get_coordinate()
+            x, y = block.coordinate
             x_min = min(x, x_min)
             y_min = min(y, y_min)
         #get connections between selected blocks
@@ -358,9 +358,9 @@ class FlowGraph(Element, _Flowgraph):
             return False
 
         # compute common boundary of selected objects
-        min_x, min_y = max_x, max_y = blocks[0].get_coordinate()
+        min_x, min_y = max_x, max_y = blocks[0].coordinate
         for selected_block in blocks:
-            x, y = selected_block.get_coordinate()
+            x, y = selected_block.coordinate
             min_x, min_y = min(min_x, x), min(min_y, y)
             x += selected_block.width
             y += selected_block.height
@@ -378,9 +378,9 @@ class FlowGraph(Element, _Flowgraph):
         }.get(calling_action, lambda *args: args)
 
         for selected_block in blocks:
-            x, y = selected_block.get_coordinate()
+            x, y = selected_block.coordinate
             w, h = selected_block.width, selected_block.height
-            selected_block.set_coordinate(transform(x, y, w, h))
+            selected_block.coordinate = transform(x, y, w, h)
 
         return True
 
@@ -397,22 +397,21 @@ class FlowGraph(Element, _Flowgraph):
         if not any(self.selected_blocks()):
             return False
         #initialize min and max coordinates
-        min_x, min_y = self.selected_block.get_coordinate()
-        max_x, max_y = self.selected_block.get_coordinate()
-        #rotate each selected block, and find min/max coordinate
+        min_x, min_y = max_x, max_y = self.selected_block.coordinate
+        # rotate each selected block, and find min/max coordinate
         for selected_block in self.selected_blocks():
             selected_block.rotate(rotation)
             #update the min/max coordinate
-            x, y = selected_block.get_coordinate()
+            x, y = selected_block.coordinate
             min_x, min_y = min(min_x, x), min(min_y, y)
             max_x, max_y = max(max_x, x), max(max_y, y)
         #calculate center point of slected blocks
         ctr_x, ctr_y = (max_x + min_x)/2, (max_y + min_y)/2
         #rotate the blocks around the center point
         for selected_block in self.selected_blocks():
-            x, y = selected_block.get_coordinate()
+            x, y = selected_block.coordinate
             x, y = Utils.get_rotated_coordinate((x - ctr_x, y - ctr_y), 
rotation)
-            selected_block.set_coordinate((x + ctr_x, y + ctr_y))
+            selected_block.coordinate = (x + ctr_x, y + ctr_y)
         return True
 
     def remove_selected(self):
@@ -490,7 +489,7 @@ class FlowGraph(Element, _Flowgraph):
         # draw multi select rectangle
         if self.mouse_pressed and (not self.selected_elements or 
self.get_ctrl_mask()):
             x1, y1 = self.press_coor
-            x2, y2 = self.get_coordinate()
+            x2, y2 = self.coordinate
             x, y = int(min(x1, x2)), int(min(y1, y2))
             w, h = int(abs(x1 - x2)), int(abs(y1 - y2))
             cr.set_source_rgba(
@@ -520,7 +519,7 @@ class FlowGraph(Element, _Flowgraph):
         """
         selected_elements = None
         if self.mouse_pressed:
-            new_selections = self.what_is_selected(self.get_coordinate())
+            new_selections = self.what_is_selected(self.coordinate)
             # update the selections if the new selection is not in the current 
selections
             # allows us to move entire selected groups of elements
             if self.get_ctrl_mask() or new_selections not in 
self.selected_elements:
@@ -535,7 +534,7 @@ class FlowGraph(Element, _Flowgraph):
 
         else:  # called from a mouse release
             if not self.element_moved and (not self.selected_elements or 
self.get_ctrl_mask()):
-                selected_elements = 
self.what_is_selected(self.get_coordinate(), self.press_coor)
+                selected_elements = self.what_is_selected(self.coordinate, 
self.press_coor)
 
         # this selection and the last were ports, try to connect them
         if self.make_connection():
@@ -650,7 +649,7 @@ class FlowGraph(Element, _Flowgraph):
         """
         selections = self.what_is_selected(coordinate)
         if not selections.intersection(self.selected_elements):
-            self.set_coordinate(coordinate)
+            self.coordinate = coordinate
             self.mouse_pressed = True
             self.update_selected_elements()
             self.mouse_pressed = False
@@ -664,7 +663,7 @@ class FlowGraph(Element, _Flowgraph):
         Update the selection state of the flow graph.
         """
         self.press_coor = coordinate
-        self.set_coordinate(coordinate)
+        self.coordinate = coordinate
         self.mouse_pressed = True
 
         if double_click:
@@ -681,7 +680,7 @@ class FlowGraph(Element, _Flowgraph):
         Update the state, handle motion (dragging).
         And update the selected flowgraph elements.
         """
-        self.set_coordinate(coordinate)
+        self.coordinate = coordinate
         self.mouse_pressed = False
         if self.element_moved:
             Actions.BLOCK_MOVE()
@@ -733,19 +732,19 @@ class FlowGraph(Element, _Flowgraph):
         # move the selected elements and record the new coordinate
         x, y = coordinate
         if not self.get_ctrl_mask():
-            X, Y = self.get_coordinate()
+            X, Y = self.coordinate
             dX, dY = int(x - X), int(y - Y)
             active = Actions.TOGGLE_SNAP_TO_GRID.get_active() or 
self.get_mod1_mask()
             if not active or abs(dX) >= Utils.CANVAS_GRID_SIZE or abs(dY) >= 
Utils.CANVAS_GRID_SIZE:
                 self.move_selected((dX, dY))
-                self.set_coordinate((x, y))
+                self.coordinate = (x, y)
         # queue draw for animation
         self.queue_draw()
 
     def get_max_coords(self, initial=(0, 0)):
         w, h = initial
         for block in self.blocks:
-            x, y = block.get_coordinate()
+            x, y = block.coordinate
             w = max(w, x + block.width)
             h = max(h, y + block.height)
         return w, h
diff --git a/grc/gui/Port.py b/grc/gui/Port.py
index 24dde67..d8a180b 100644
--- a/grc/gui/Port.py
+++ b/grc/gui/Port.py
@@ -138,8 +138,8 @@ class Port(_Port, Element):
         Returns:
             the connector coordinate (x, y) tuple
         """
-        return [sum(c) for c in zip(self._connector_coordinate, 
self.get_coordinate(),
-                                    self.parent_block.get_coordinate())]
+        return [sum(c) for c in zip(self._connector_coordinate, 
self.coordinate,
+                                    self.parent_block.coordinate)]
 
     def get_connector_direction(self):
         """



reply via email to

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