commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r9085 - grc/trunk/src/grc/gui/elements


From: jblum
Subject: [Commit-gnuradio] r9085 - grc/trunk/src/grc/gui/elements
Date: Wed, 30 Jul 2008 23:27:08 -0600 (MDT)

Author: jblum
Date: 2008-07-30 23:27:07 -0600 (Wed, 30 Jul 2008)
New Revision: 9085

Modified:
   grc/trunk/src/grc/gui/elements/FlowGraph.py
Log:
control mask cleanup

Modified: grc/trunk/src/grc/gui/elements/FlowGraph.py
===================================================================
--- grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-31 03:42:27 UTC (rev 
9084)
+++ grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-31 05:27:07 UTC (rev 
9085)
@@ -446,12 +446,40 @@
                """
                return self.get_selected_elements() and 
self.get_selected_elements()[0] or None
 
-       def update_selected_elements(self, selected_elements):
+       def update_selected_elements(self):
                """!
                Update the selected elements.
+               The update behavior depends on the state of the mouse button.
+               When the mouse button pressed the selection will change when
+               the control mask is set or the new selection is not in the 
current group.
+               When the mouse button is released the selection will change when
+               the mouse has moved and the control mask is set or the current 
group is empty.
+               Attempt to make a new connection if the old and ports are 
filled.
                If the control mask is set, merge with the current elements.
-               @param selected_elements a list or set of elements
                """
+               selected_elements = None
+               if self.mouse_pressed:
+                       new_selection = 
self.what_is_selected(self.get_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._ctrl or not (
+                               new_selection and new_selection[0] in 
self.get_selected_elements()
+                       ): selected_elements = new_selection
+               else: #called from a mouse release
+                       if not self.element_moved and (not 
self.get_selected_elements() or self._ctrl):
+                               selected_elements = 
self.what_is_selected(self.get_coordinate(), self.press_coor)
+               #this selection and the last were ports, try to connect them
+               if self._old_selected_port and self._new_selected_port and \
+                       self._old_selected_port is not self._new_selected_port:
+                       try:
+                               self.connect(self._old_selected_port, 
self._new_selected_port)
+                               self.handle_states(ELEMENT_CREATE)
+                       except: Messages.send_fail_connection()
+                       self._old_selected_port = None
+                       self._new_selected_port = None
+                       return
+               #update selected elements
+               if selected_elements is None: return
                old_elements = set(self.get_selected_elements())
                self._selected_elements = list(set(selected_elements))
                new_elements = set(self.get_selected_elements())
@@ -472,54 +500,39 @@
                Open the block params window on a double click.
                Update the selection state of the flow graph.
                """
+               if not left_click: return
                self.press_coor = coordinate
                self.set_coordinate(coordinate)
-               if left_click:
-                       self.time = 0
-                       self.mouse_pressed = True
-                       new_selection = 
self.what_is_selected(self.get_coordinate())
-                       #update the selections if the new selection is not in 
the selected
-                       #allows us to move entire selected groups of elements
-                       if self._ctrl or not (
-                               new_selection and new_selection[0] in 
self.get_selected_elements()
-                       ): self.update_selected_elements(new_selection)
-                       #this selection and the last were ports, try to connect 
them
-                       if self._old_selected_port and self._new_selected_port 
and \
-                               self._old_selected_port is not 
self._new_selected_port:
-                               try:
-                                       self.connect(self._old_selected_port, 
self._new_selected_port)
-                                       self.handle_states(ELEMENT_CREATE)
-                               except: Messages.send_fail_connection()
-                               self._old_selected_port = None
-                               self._new_selected_port = None
-                       #double click detected, bring up params dialog if 
possible
-                       if double_click and self.get_selected_block():
-                               self.mouse_pressed = False
-                               self.handle_states(BLOCK_PARAM_MODIFY)
+               self.time = 0
+               self.mouse_pressed = True
+               self.update_selected_elements()
+               #double click detected, bring up params dialog if possible
+               if double_click and self.get_selected_block():
+                       self.mouse_pressed = False
+                       self.handle_states(BLOCK_PARAM_MODIFY)
 
        def handle_mouse_button_release(self, left_click, coordinate):
                """!
                A mouse button is released, record the state.
                """
+               if not left_click: return
                self.set_coordinate(coordinate)
-               if left_click:
-                       self.time = 0
-                       self.mouse_pressed = False
-                       if self.element_moved:
-                               if Preferences.snap_to_grid():
-                                       grid_size = Preferences.get_grid_size()
-                                       X,Y = 
self.get_selected_element().get_coordinate()
-                                       deltaX = X%grid_size
-                                       if deltaX < grid_size/2: deltaX = -1 * 
deltaX
-                                       else: deltaX = grid_size - deltaX
-                                       deltaY = Y%grid_size
-                                       if deltaY < grid_size/2: deltaY = -1 * 
deltaY
-                                       else: deltaY = grid_size - deltaY
-                                       self.move_selected((deltaX, deltaY))
-                               self.handle_states(BLOCK_MOVE)
-                               self.element_moved = False
-                       elif not self.element_moved and (not 
self.get_selected_elements() or self._ctrl):
-                               
self.update_selected_elements(self.what_is_selected(self.get_coordinate(), 
self.press_coor))
+               self.time = 0
+               self.mouse_pressed = False
+               if self.element_moved:
+                       if Preferences.snap_to_grid():
+                               grid_size = Preferences.get_grid_size()
+                               X,Y = 
self.get_selected_element().get_coordinate()
+                               deltaX = X%grid_size
+                               if deltaX < grid_size/2: deltaX = -1 * deltaX
+                               else: deltaX = grid_size - deltaX
+                               deltaY = Y%grid_size
+                               if deltaY < grid_size/2: deltaY = -1 * deltaY
+                               else: deltaY = grid_size - deltaY
+                               self.move_selected((deltaX, deltaY))
+                       self.handle_states(BLOCK_MOVE)
+                       self.element_moved = False
+               self.update_selected_elements()
                self.draw()
 
        def handle_mouse_motion(self, coordinate):
@@ -528,28 +541,29 @@
                Move a selected element to the new coordinate.
                Auto-scroll the scroll bars at the boundaries.
                """
-               #to perform a movement, the mouse must be pressed, timediff 
large enough.
-               if time.time() - self.time >= 
MOTION_DETECT_REDRAWING_SENSITIVITY and self.mouse_pressed:
-                       #perform autoscrolling
-                       width, height = self.get_size()
-                       x, y = coordinate
-                       h_adj = self.get_scroll_pane().get_hadjustment()
-                       v_adj = self.get_scroll_pane().get_vadjustment()
-                       for pos, length, adj, adj_val, adj_len in (
-                               (x, width, h_adj, h_adj.get_value(), 
h_adj.page_size),
-                               (y, height, v_adj, v_adj.get_value(), 
v_adj.page_size),
-                       ):
-                               #scroll if we moved near the border
-                               if pos-adj_val > 
adj_len-SCROLL_PROXIMITY_SENSITIVITY and adj_val+SCROLL_DISTANCE < 
length-adj_len:
-                                       adj.set_value(adj_val+SCROLL_DISTANCE)
-                                       adj.emit('changed')
-                               elif pos-adj_val < SCROLL_PROXIMITY_SENSITIVITY:
-                                       adj.set_value(adj_val-SCROLL_DISTANCE)
-                                       adj.emit('changed')
-                       #move the selected element and record the new coordinate
-                       X, Y = self.get_coordinate()
-                       if not self._ctrl: self.move_selected((int(x - X), 
int(y - Y)))
-                       self.draw()
-                       self.set_coordinate((x, y))
-                       #update time
-                       self.time = time.time()
+               #to perform a movement, the mouse must be pressed, timediff 
large enough
+               if not self.mouse_pressed: return
+               if time.time() - self.time < 
MOTION_DETECT_REDRAWING_SENSITIVITY: return
+               #perform autoscrolling
+               width, height = self.get_size()
+               x, y = coordinate
+               h_adj = self.get_scroll_pane().get_hadjustment()
+               v_adj = self.get_scroll_pane().get_vadjustment()
+               for pos, length, adj, adj_val, adj_len in (
+                       (x, width, h_adj, h_adj.get_value(), h_adj.page_size),
+                       (y, height, v_adj, v_adj.get_value(), v_adj.page_size),
+               ):
+                       #scroll if we moved near the border
+                       if pos-adj_val > adj_len-SCROLL_PROXIMITY_SENSITIVITY 
and adj_val+SCROLL_DISTANCE < length-adj_len:
+                               adj.set_value(adj_val+SCROLL_DISTANCE)
+                               adj.emit('changed')
+                       elif pos-adj_val < SCROLL_PROXIMITY_SENSITIVITY:
+                               adj.set_value(adj_val-SCROLL_DISTANCE)
+                               adj.emit('changed')
+               #move the selected element and record the new coordinate
+               X, Y = self.get_coordinate()
+               if not self._ctrl: self.move_selected((int(x - X), int(y - Y)))
+               self.draw()
+               self.set_coordinate((x, y))
+               #update time
+               self.time = time.time()





reply via email to

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