[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r8810 - in grc/trunk/src/grc: . gui/elements
From: |
jblum |
Subject: |
[Commit-gnuradio] r8810 - in grc/trunk/src/grc: . gui/elements |
Date: |
Sun, 6 Jul 2008 13:41:35 -0600 (MDT) |
Author: jblum
Date: 2008-07-06 13:41:34 -0600 (Sun, 06 Jul 2008)
New Revision: 8810
Modified:
grc/trunk/src/grc/ActionHandler.py
grc/trunk/src/grc/Actions.py
grc/trunk/src/grc/gui/elements/FlowGraph.py
Log:
selection handling
Modified: grc/trunk/src/grc/ActionHandler.py
===================================================================
--- grc/trunk/src/grc/ActionHandler.py 2008-07-06 08:28:35 UTC (rev 8809)
+++ grc/trunk/src/grc/ActionHandler.py 2008-07-06 19:41:34 UTC (rev 8810)
@@ -195,16 +195,9 @@
##############################################################################################
# Selections
##############################################################################################
- elif state == BLOCK_SELECT or state == PORT_SELECT:
- for action in (ELEMENT_DELETE, BLOCK_PARAM_MODIFY,
BLOCK_ROTATE_RIGHT, BLOCK_ROTATE_LEFT):
- get_action_from_name(action).set_sensitive(True)
- elif state == CONNECTION_SELECT:
- get_action_from_name(ELEMENT_DELETE).set_sensitive(True)
- for action in (BLOCK_PARAM_MODIFY, BLOCK_ROTATE_RIGHT,
BLOCK_ROTATE_LEFT):
-
get_action_from_name(action).set_sensitive(False)
+ elif state == ELEMENT_SELECT:
+ self.get_flow_graph().update()
elif state == NOTHING_SELECT:
- for action in (ELEMENT_DELETE, BLOCK_PARAM_MODIFY,
BLOCK_ROTATE_RIGHT, BLOCK_ROTATE_LEFT):
-
get_action_from_name(action).set_sensitive(False)
self.get_flow_graph().unselect()
##############################################################################################
# Enable/Disable
@@ -248,7 +241,7 @@
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
self.handle_states(NOTHING_SELECT)
self.get_page().set_saved(False)
- elif state == CONNECTION_CREATE or state == BLOCK_CREATE:
+ elif state == ELEMENT_CREATE:
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
self.handle_states(NOTHING_SELECT)
self.get_page().set_saved(False)
@@ -365,6 +358,11 @@
##############################################################################################
# Global Actions for all States
##############################################################################################
+ #update general buttons
+
get_action_from_name(ELEMENT_DELETE).set_sensitive(bool(self.get_flow_graph().get_selected_element()))
+
get_action_from_name(BLOCK_PARAM_MODIFY).set_sensitive(bool(self.get_flow_graph().get_selected_block()))
+
get_action_from_name(BLOCK_ROTATE_RIGHT).set_sensitive(bool(self.get_flow_graph().get_selected_block()))
+
get_action_from_name(BLOCK_ROTATE_LEFT).set_sensitive(bool(self.get_flow_graph().get_selected_block()))
#update cut/copy/paste
get_action_from_name(BLOCK_CUT).set_sensitive(bool(self.get_flow_graph().get_selected_block()))
get_action_from_name(BLOCK_COPY).set_sensitive(bool(self.get_flow_graph().get_selected_block()))
Modified: grc/trunk/src/grc/Actions.py
===================================================================
--- grc/trunk/src/grc/Actions.py 2008-07-06 08:28:35 UTC (rev 8809)
+++ grc/trunk/src/grc/Actions.py 2008-07-06 19:41:34 UTC (rev 8810)
@@ -32,17 +32,11 @@
APPLICATION_INITIALIZE = 'app init'
APPLICATION_QUIT = 'app quit'
-PORT_SELECT = 'port select'
-
-NOTHING_SELECT = 'nothing select'
-
PARAM_MODIFY = 'param modify'
-BLOCK_SELECT = 'block select'
BLOCK_MOVE = 'block move'
BLOCK_ROTATE_LEFT = 'block rotate left'
BLOCK_ROTATE_RIGHT = 'block rotate right'
-BLOCK_CREATE = 'block create'
BLOCK_PARAM_MODIFY = 'block param modify'
BLOCK_INC_TYPE = 'block increment type'
BLOCK_DEC_TYPE = 'block decrement type'
@@ -56,9 +50,10 @@
PORT_CONTROLLER_INC = 'port controller increment'
PORT_CONTROLLER_DEC = 'port controller decrement'
-CONNECTION_SELECT = 'connection select'
-CONNECTION_CREATE = 'conection create'
-ELEMENT_DELETE = 'element remove'
+ELEMENT_CREATE = 'element create'
+ELEMENT_DELETE = 'element delete'
+ELEMENT_SELECT = 'element select'
+NOTHING_SELECT = 'nothing select'
FLOW_GRAPH_OPEN = 'flow graph open'
FLOW_GRAPH_UNDO = 'flow graph undo'
Modified: grc/trunk/src/grc/gui/elements/FlowGraph.py
===================================================================
--- grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-06 08:28:35 UTC (rev
8809)
+++ grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-06 19:41:34 UTC (rev
8810)
@@ -52,8 +52,8 @@
#important vars dealing with mouse event tracking
self.has_moved = False
self.mouse_pressed = False
- self.selected_element = None
- self.is_selected = lambda: bool(self.selected_element)
+ self._selected_element = None
+ self.is_selected = lambda: bool(self.get_selected_element())
self.time = 0
def get_drawing_area(self): return self.drawing_area
@@ -104,7 +104,7 @@
if not (key.startswith('_') or
key.startswith('gui') or key == 'id'):
block.get_param(key).set_value(value)
#handle new state
- self.handle_states(BLOCK_CREATE)
+ self.handle_states(ELEMENT_CREATE)
self.update()
return
@@ -143,7 +143,7 @@
"""
if self.get_selected_block():
for get_ports_attr in ('get_sources', 'get_sinks'):
- ports = getattr(self.selected_element,
get_ports_attr)()
+ ports = getattr(self.get_selected_element(),
get_ports_attr)()
if ports and hasattr(ports[0], 'get_nports')
and ports[0].get_nports():
#find the param that controls port0
for param in
self.get_selected_block().get_params():
@@ -185,8 +185,8 @@
Move the element and by the change in coordinates.
@param delta_coordinate the change in coordinates
"""
- if self.selected_element:
- self.selected_element.move(delta_coordinate)
+ if self.get_selected_element():
+ self.get_selected_element().move(delta_coordinate)
self.has_moved = True
self.draw()
@@ -196,9 +196,9 @@
@param direction DIR_LEFT or DIR_RIGHT
@return true if rotated, otherwise false.
"""
- if self.selected_element and (self.selected_element.is_block()
or \
- self.selected_element.is_source() or
self.selected_element.is_sink()):
- self.selected_element.rotate(direction)
+ if self.get_selected_element() and
(self.get_selected_element().is_block() or \
+ self.get_selected_element().is_source() or
self.get_selected_element().is_sink()):
+ self.get_selected_element().rotate(direction)
self.draw()
return True
return False
@@ -208,18 +208,16 @@
If an element is selected, remove it and its attached parts
from the element list.
@return true if the element was deleted, otherwise false.
"""
- if self.selected_element:
- self.remove_element(self.selected_element)
+ if self.get_selected_element():
+ self.remove_element(self.get_selected_element())
self.unselect()
return True
return False
def unselect(self):
- """If an element is selected, un-highlight it and set selected
to None."""
- if self.selected_element:
- self.selected_element.set_highlighted(False)
- self.selected_element = None
- self.update()
+ """Set selected element to None and update."""
+ self._selected_element = None
+ self.update()
def what_is_selected(self, coor):
"""!
@@ -238,18 +236,25 @@
self.get_elements().append(element)
return element.what_is_selected(coor)
return None
-
+
+ def get_selected_element(self):
+ """!
+ Get the selected element.
+ @return a block, port, or connection or None
+ """
+ return self._selected_element
+
def get_selected_block(self):
"""!
Get the selected block when a block or port is selected.
@return a block or None
"""
#determine the selected block or None
- if self.selected_element and self.selected_element.is_block():
- return self.selected_element
- elif self.selected_element and
(self.selected_element.is_source() or self.selected_element.is_sink()):
- return self.selected_element.get_parent()
- else: return None
+ if self.get_selected_element() and
self.get_selected_element().is_block():
+ return self.get_selected_element()
+ elif self.get_selected_element() and
(self.get_selected_element().is_source() or
self.get_selected_element().is_sink()):
+ return self.get_selected_element().get_parent()
+ else: return None
def draw(self):
"""Draw the background and then all of the Elements in this
FlowGraph on the pixmap,
@@ -269,16 +274,25 @@
points.append((i*grid_size,
j*grid_size))
self.get_gc().foreground = TXT_COLOR
self.get_pixmap().draw_points(self.get_gc(),
points)
- #draw signal blocks first, then connections on the top
- for element in self.get_blocks() +
self.get_connections():
+ #draw blocks on top of connections
+ for element in self.get_connections() +
self.get_blocks():
element.draw(self.get_pixmap())
#draw any selected element as the topmost
- if self.mouse_pressed and self.selected_element:
- self.selected_element.draw(self.get_pixmap())
+ if self.get_selected_element():
+
self.get_selected_element().draw(self.get_pixmap())
self.get_drawing_area().draw()
def update(self):
- """Call update on all elements."""
+ """!
+ Update highlighting so only the selected is highlighted.
+ Call update on all elements.
+ Resize the window if size changed.
+ """
+ #update highlighting
+ map(lambda e: e.set_highlighted(False), self.get_elements())
+ if self.get_selected_element():
+ self.get_selected_element().set_highlighted(True)
+ #update all elements
map(lambda e: e.update(), self.get_elements())
#set the size of the flow graph area
old_x, old_y = self.get_size()
@@ -294,40 +308,33 @@
def handle_mouse_button_press(self, left_click, double_click,
coordinate):
"""!
- A mouse button is pressed. Record the state of the mouse, find
the selected element,
- set the Element highlighted, handle the state change, and
redraw the FlowGraph.
+ A mouse button is pressed, only respond to left clicks.
+ Find the selected element. Attempt a new connection if possible.
+ Open the block params window on a double click.
+ Update the selection state of the flow graph.
"""
self.set_coordinate(coordinate)
if left_click:
- if self.selected_element:
self.selected_element.set_highlighted(False)
self.time = 0
self.mouse_pressed = True
- old_selection = self.selected_element
- self.selected_element =
self.what_is_selected(self.get_coordinate())
- #handle the state change with the new selection
- if not self.selected_element:
- self.handle_states(NOTHING_SELECT)
- elif self.selected_element.is_connection():
- self.handle_states(CONNECTION_SELECT)
- elif self.selected_element.is_source() or
self.selected_element.is_sink():
- self.handle_states(PORT_SELECT)
- elif self.selected_element.is_block():
- self.handle_states(BLOCK_SELECT)
+ old_selection = self.get_selected_element()
+ self._selected_element =
self.what_is_selected(self.get_coordinate())
#this selection and the last were ports, try to connect
them
- if old_selection and self.selected_element and
old_selection is not self.selected_element and\
- (self.selected_element.is_source() or
self.selected_element.is_sink()) and\
+ if old_selection and self.get_selected_element() and \
+ old_selection is not
self.get_selected_element() and \
+ (self.get_selected_element().is_source() or
self.get_selected_element().is_sink()) and \
(old_selection.is_source() or
old_selection.is_sink()):
try:
- self.connect(old_selection,
self.selected_element)
- self.update()
- self.handle_states(CONNECTION_CREATE)
+ self.connect(old_selection,
self.get_selected_element())
+ self.handle_states(ELEMENT_CREATE)
except: Messages.send_fail_connection()
- if self.selected_element:
self.selected_element.set_highlighted(True)
#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.draw()
+ #handle the state change with the new selection
+ if self.get_selected_element():
self.handle_states(ELEMENT_SELECT)
+ else: self.handle_states(NOTHING_SELECT)
def handle_mouse_button_release(self, left_click, coordinate):
"""!
@@ -335,12 +342,13 @@
"""
self.set_coordinate(coordinate)
if left_click:
+ self.time = 0
self.mouse_pressed = False
if self.has_moved:
from grc import Preferences
if Preferences.snap_to_grid():
grid_size = Preferences.get_grid_size()
- X,Y =
self.selected_element.get_coordinate()
+ 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
@@ -353,13 +361,14 @@
def handle_mouse_motion(self, coordinate):
"""!
- The mouse has moved. If mouse_pressed is true, react to the
motions:
- If an Element is highlighted, this will move the Element by
redrawing it at the new position.
+ The mouse has moved, respond to mouse dragging.
+ 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, an element
selected, timediff large enough.
if time.time() - self.time >=
MOTION_DETECT_REDRAWING_SENSITIVITY and \
self.mouse_pressed and\
- self.selected_element:
+ self.get_selected_element():
#The event coordinates must be within BPS pixels away
from the bounds of the flow graph.
fgW,fgH = self.get_size()
x,y = coordinate
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r8810 - in grc/trunk/src/grc: . gui/elements,
jblum <=