diff options
Diffstat (limited to 'grc/gui')
-rw-r--r-- | grc/gui/ActionHandler.py | 34 | ||||
-rw-r--r-- | grc/gui/Actions.py | 28 | ||||
-rw-r--r-- | grc/gui/Bars.py | 6 | ||||
-rw-r--r-- | grc/gui/Block.py | 34 | ||||
-rw-r--r-- | grc/gui/Constants.py | 5 | ||||
-rw-r--r-- | grc/gui/DrawingArea.py | 4 | ||||
-rw-r--r-- | grc/gui/Element.py | 6 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 82 | ||||
-rw-r--r-- | grc/gui/Port.py | 76 | ||||
-rw-r--r-- | grc/gui/Preferences.py | 23 | ||||
-rw-r--r-- | grc/gui/Utils.py | 10 |
11 files changed, 219 insertions, 89 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 2c1c9942d7..dcc3c846eb 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -118,6 +118,7 @@ class ActionHandler: Actions.TYPES_WINDOW_DISPLAY, Actions.TOGGLE_BLOCKS_WINDOW, Actions.TOGGLE_REPORTS_WINDOW, Actions.TOGGLE_HIDE_DISABLED_BLOCKS, Actions.TOOLS_RUN_FDESIGN, Actions.TOGGLE_SCROLL_LOCK, Actions.CLEAR_REPORTS, + Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, Actions.TOGGLE_SNAP_TO_GRID ): action.set_sensitive(True) if ParseXML.xml_failures: Messages.send_xml_errors_if_any(ParseXML.xml_failures) @@ -133,9 +134,13 @@ class ActionHandler: if not self.get_page(): self.main_window.new_page() #ensure that at least a blank page exists self.main_window.btwin.search_entry.hide() - Actions.TOGGLE_REPORTS_WINDOW.set_active(Preferences.reports_window_visibility()) - Actions.TOGGLE_BLOCKS_WINDOW.set_active(Preferences.blocks_window_visibility()) - Actions.TOGGLE_SCROLL_LOCK.set_active(Preferences.scroll_lock()) + for action in ( + Actions.TOGGLE_REPORTS_WINDOW, + Actions.TOGGLE_BLOCKS_WINDOW, + Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, + Actions.TOGGLE_SCROLL_LOCK, + Actions.TOGGLE_SNAP_TO_GRID + ): action.load_from_preferences() elif action == Actions.APPLICATION_QUIT: if self.main_window.close_pages(): gtk.main_quit() @@ -361,28 +366,32 @@ class ActionHandler: elif action == Actions.ERRORS_WINDOW_DISPLAY: Dialogs.ErrorsDialog(self.get_flow_graph()) elif action == Actions.TOGGLE_REPORTS_WINDOW: - visible = action.get_active() - if visible: + if action.get_active(): self.main_window.reports_scrolled_window.show() else: self.main_window.reports_scrolled_window.hide() - Preferences.reports_window_visibility(visible) + action.save_to_preferences() elif action == Actions.TOGGLE_BLOCKS_WINDOW: - visible = action.get_active() - if visible: + if action.get_active(): self.main_window.btwin.show() else: self.main_window.btwin.hide() - Preferences.blocks_window_visibility(visible) + action.save_to_preferences() elif action == Actions.TOGGLE_SCROLL_LOCK: - visible = action.get_active() - self.main_window.text_display.scroll_lock = visible - if visible: + active = action.get_active() + self.main_window.text_display.scroll_lock = active + if active: self.main_window.text_display.scroll_to_end() + action.save_to_preferences() elif action == Actions.CLEAR_REPORTS: self.main_window.text_display.clear() elif action == Actions.TOGGLE_HIDE_DISABLED_BLOCKS: Actions.NOTHING_SELECT() + elif action == Actions.TOGGLE_AUTO_HIDE_PORT_LABELS: + action.save_to_preferences() + self.main_window.get_flow_graph().create_shapes() + elif action == Actions.TOGGLE_SNAP_TO_GRID: + action.save_to_preferences() ################################################## # Param Modifications ################################################## @@ -492,7 +501,6 @@ class ActionHandler: self.main_window.btwin.search_entry.show() self.main_window.btwin.search_entry.grab_focus() elif action == Actions.OPEN_HIER: - bn = []; for b in self.get_flow_graph().get_selected_blocks(): if b._grc_source: self.main_window.new_page(b._grc_source, show=True) diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index a9ab41230d..c41798aab8 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -21,6 +21,8 @@ import pygtk pygtk.require('2.0') import gtk +import Preferences + NO_MODS_MASK = 0 ######################################################################## @@ -127,7 +129,7 @@ class ToggleAction(gtk.ToggleAction, _ActionBase): Pass additional arguments such as keypresses. """ - def __init__(self, keypresses=(), name=None, label=None, tooltip=None, stock_id=None): + def __init__(self, keypresses=(), name=None, label=None, tooltip=None, stock_id=None, preference_name=None): """ Create a new ToggleAction instance. @@ -142,6 +144,15 @@ class ToggleAction(gtk.ToggleAction, _ActionBase): ) #register this action _ActionBase.__init__(self, label, keypresses) + self.preference_name = preference_name + + def load_from_preferences(self): + if self.preference_name is not None: + self.set_active(Preferences.bool_entry(self.preference_name)) + + def save_to_preferences(self): + if self.preference_name is not None: + Preferences.bool_entry(self.preference_name, self.get_active()) ######################################################################## # Actions @@ -236,12 +247,22 @@ BLOCK_DISABLE = Action( stock_id=gtk.STOCK_DISCONNECT, keypresses=(gtk.keysyms.d, NO_MODS_MASK), ) +TOGGLE_SNAP_TO_GRID = ToggleAction( + label='_Snap to grid', + tooltip='Snap blocks to a grid for an easier connection alignment', + preference_name='snap_to_grid' +) TOGGLE_HIDE_DISABLED_BLOCKS = ToggleAction( label='Hide _disabled blocks', tooltip='Toggle visibility of disabled blocks and connections', stock_id=gtk.STOCK_MISSING_IMAGE, keypresses=(gtk.keysyms.d, gtk.gdk.CONTROL_MASK), ) +TOGGLE_AUTO_HIDE_PORT_LABELS = ToggleAction( + label='Auto-hide port _labels', + tooltip='Automatically hide port labels', + preference_name='auto_hide_port_labels' +) BLOCK_CREATE_HIER = Action( label='C_reate Hier', tooltip='Create hier block from selected blocks', @@ -275,15 +296,18 @@ TOGGLE_REPORTS_WINDOW = ToggleAction( label='Show _Reports', tooltip='Toggle visibility of the Report widget', keypresses=(gtk.keysyms.r, gtk.gdk.CONTROL_MASK), + preference_name='reports_window_visible' ) TOGGLE_BLOCKS_WINDOW = ToggleAction( label='Show _Block Tree', tooltip='Toggle visibility of the block tree widget', keypresses=(gtk.keysyms.b, gtk.gdk.CONTROL_MASK), + preference_name='blocks_window_visible' ) TOGGLE_SCROLL_LOCK = ToggleAction( label='_Reports Scroll Lock', tooltip='Toggle scroll lock for the report window', + preference_name='scroll_lock' ) ABOUT_WINDOW_DISPLAY = Action( label='_About', @@ -310,7 +334,7 @@ FLOW_GRAPH_GEN = Action( FLOW_GRAPH_EXEC = Action( label='_Execute', tooltip='Execute the flow graph', - stock_id=gtk.STOCK_EXECUTE, + stock_id=gtk.STOCK_MEDIA_PLAY, keypresses=(gtk.keysyms.F6, NO_MODS_MASK), ) FLOW_GRAPH_KILL = Action( diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py index 11e35c992b..743345200e 100644 --- a/grc/gui/Bars.py +++ b/grc/gui/Bars.py @@ -97,10 +97,14 @@ MENU_BAR_LIST = ( Actions.TOGGLE_SCROLL_LOCK, Actions.CLEAR_REPORTS, None, + Actions.TOGGLE_HIDE_DISABLED_BLOCKS, + Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, + Actions.TOGGLE_SNAP_TO_GRID, + None, Actions.ERRORS_WINDOW_DISPLAY, Actions.FIND_BLOCKS, ]), - (gtk.Action('Build', '_Build', None, None), [ + (gtk.Action('Run', '_Run', None, None), [ Actions.FLOW_GRAPH_GEN, Actions.FLOW_GRAPH_EXEC, Actions.FLOW_GRAPH_KILL, 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): """ diff --git a/grc/gui/Constants.py b/grc/gui/Constants.py index 7fabcfc0a0..c82449b6b6 100644 --- a/grc/gui/Constants.py +++ b/grc/gui/Constants.py @@ -53,7 +53,7 @@ BLOCK_LABEL_PADDING = 7 PORT_LABEL_PADDING = 2 #port constraint dimensions -PORT_SEPARATION = 17 +PORT_SEPARATION = 32 PORT_BORDER_SEPARATION = 9 PORT_MIN_WIDTH = 20 @@ -81,3 +81,6 @@ SCROLL_DISTANCE = 15 #How close the mouse click can be to a line and register a connection select. LINE_SELECT_SENSITIVITY = 5 + +# canvas grid size +CANVAS_GRID_SIZE = 8
\ No newline at end of file diff --git a/grc/gui/DrawingArea.py b/grc/gui/DrawingArea.py index 448948e7f4..d22a2c6d5f 100644 --- a/grc/gui/DrawingArea.py +++ b/grc/gui/DrawingArea.py @@ -37,6 +37,7 @@ class DrawingArea(gtk.DrawingArea): main_window: the main_window containing all flow graphs """ self.ctrl_mask = False + self.mod1_mask = False self._flow_graph = flow_graph gtk.DrawingArea.__init__(self) self.set_size_request(MIN_WINDOW_WIDTH, MIN_WINDOW_HEIGHT) @@ -88,6 +89,7 @@ class DrawingArea(gtk.DrawingArea): """ self.grab_focus() self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK + self.mod1_mask = event.state & gtk.gdk.MOD1_MASK if event.button == 1: self._flow_graph.handle_mouse_selector_press( double_click=(event.type == gtk.gdk._2BUTTON_PRESS), coordinate=(event.x, event.y), @@ -102,6 +104,7 @@ class DrawingArea(gtk.DrawingArea): Forward button release information to the flow graph. """ self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK + self.mod1_mask = event.state & gtk.gdk.MOD1_MASK if event.button == 1: self._flow_graph.handle_mouse_selector_release( coordinate=(event.x, event.y), ) @@ -111,6 +114,7 @@ class DrawingArea(gtk.DrawingArea): Forward mouse motion information to the flow graph. """ self.ctrl_mask = event.state & gtk.gdk.CONTROL_MASK + self.mod1_mask = event.state & gtk.gdk.MOD1_MASK self._flow_graph.handle_mouse_motion( coordinate=(event.x, event.y), ) diff --git a/grc/gui/Element.py b/grc/gui/Element.py index c43f0eb35c..95a4e2edab 100644 --- a/grc/gui/Element.py +++ b/grc/gui/Element.py @@ -262,3 +262,9 @@ class Element(object): if rotation not in POSSIBLE_ROTATIONS: raise Exception('"%s" is not one of the possible rotations: (%s)'%(rotation, POSSIBLE_ROTATIONS)) self.rotation = rotation + + def mouse_over(self): + pass + + def mouse_out(self): + pass diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index 2b3d08628a..31017a9923 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -51,6 +51,8 @@ class FlowGraph(Element): #selected ports self._old_selected_port = None self._new_selected_port = None + # current mouse hover element + self.element_under_mouse = None #context menu self._context_menu = gtk.Menu() for action in [ @@ -82,6 +84,7 @@ class FlowGraph(Element): def set_size(self, *args): self.get_drawing_area().set_size_request(*args) def get_scroll_pane(self): return self.drawing_area.get_parent() def get_ctrl_mask(self): return self.drawing_area.ctrl_mask + def get_mod1_mask(self): return self.drawing_area.mod1_mask def new_pixmap(self, *args): return self.get_drawing_area().new_pixmap(*args) def add_new_block(self, key, coor=None): @@ -544,35 +547,60 @@ class FlowGraph(Element): def handle_mouse_motion(self, coordinate): """ - The mouse has moved, respond to mouse dragging. + The mouse has moved, respond to mouse dragging or notify elements 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 # (no longer checking pending events via gtk.events_pending() - always true in Windows) - if not self.mouse_pressed: 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') - #remove the connection if selected in drag event - if len(self.get_selected_elements()) == 1 and self.get_selected_element().is_connection(): - Actions.ELEMENT_DELETE() - #move the selected elements and record the new coordinate - X, Y = self.get_coordinate() - if not self.get_ctrl_mask(): self.move_selected((int(x - X), int(y - Y))) - self.set_coordinate((x, y)) - #queue draw for animation - self.queue_draw() + if not self.mouse_pressed: + # only continue if mouse-over stuff is enabled (just the auto-hide port label stuff for now) + if not Actions.TOGGLE_AUTO_HIDE_PORT_LABELS.get_active(): return + redraw = False + for element in reversed(self.get_elements()): + over_element = element.what_is_selected(coordinate) + if not over_element: continue + if over_element != self.element_under_mouse: # over sth new + if self.element_under_mouse: + redraw |= self.element_under_mouse.mouse_out() or False + self.element_under_mouse = over_element + redraw |= over_element.mouse_over() or False + break + else: + if self.element_under_mouse: + redraw |= self.element_under_mouse.mouse_out() or False + self.element_under_mouse = None + if redraw: + #self.create_labels() + self.create_shapes() + self.queue_draw() + else: + #perform auto-scrolling + 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') + #remove the connection if selected in drag event + if len(self.get_selected_elements()) == 1 and self.get_selected_element().is_connection(): + Actions.ELEMENT_DELETE() + #move the selected elements and record the new coordinate + if not self.get_ctrl_mask(): + X, Y = self.get_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)) + #queue draw for animation + self.queue_draw() diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 8b4edfa430..c56432d2b5 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -23,14 +23,18 @@ from Constants import \ CONNECTOR_EXTENSION_INCREMENT, \ PORT_LABEL_PADDING, PORT_MIN_WIDTH import Utils +import Actions import Colors import pygtk pygtk.require('2.0') import gtk +PORT_HIDDEN_MARKUP_TMPL="""\ +<span foreground="black" font_desc="Sans 7.5"> </span>""" PORT_MARKUP_TMPL="""\ <span foreground="black" font_desc="Sans 7.5">$encode($port.get_name())</span>""" + class Port(Element): """The graphical port.""" @@ -40,7 +44,10 @@ class Port(Element): Create list of connector coordinates. """ Element.__init__(self) - self.connector_coordinates = dict() + self.W = self.H = self.w = self.h = 0 + self._connector_coordinate = (0,0) + self._connector_length = 0 + self._label_hidden = True def create_shapes(self): """Create new areas and labels for the port.""" @@ -52,40 +59,42 @@ class Port(Element): elif self.is_sink(): ports = self.get_parent().get_sinks_gui() #get the max width self.W = max([port.W for port in ports] + [PORT_MIN_WIDTH]) + W = self.W if not self.label_hidden() else 10 #get a numeric index for this port relative to its sibling ports try: index = ports.index(self) except: if hasattr(self, '_connector_length'): - del self._connector_length; + del self._connector_length return - length = len(ports) + length = len(filter(lambda p: not p.get_hide(), ports)) #reverse the order of ports for these rotations if rotation in (180, 270): index = length-index-1 - offset = (self.get_parent().H - length*self.H - (length-1)*PORT_SEPARATION)/2 + offset = (self.get_parent().H - (length-1)*PORT_SEPARATION - self.H)/2 #create areas and connector coordinates if (self.is_sink() and rotation == 0) or (self.is_source() and rotation == 180): - x = -1*self.W - y = (PORT_SEPARATION+self.H)*index+offset - self.add_area((x, y), (self.W, self.H)) + x = -1*W + y = PORT_SEPARATION*index+offset + self.add_area((x, y), (W, self.H)) self._connector_coordinate = (x-1, y+self.H/2) elif (self.is_source() and rotation == 0) or (self.is_sink() and rotation == 180): x = self.get_parent().W - y = (PORT_SEPARATION+self.H)*index+offset - self.add_area((x, y), (self.W, self.H)) - self._connector_coordinate = (x+1+self.W, y+self.H/2) + y = PORT_SEPARATION*index+offset + self.add_area((x, y), (W, self.H)) + self._connector_coordinate = (x+1+W, y+self.H/2) elif (self.is_source() and rotation == 90) or (self.is_sink() and rotation == 270): - y = -1*self.W - x = (PORT_SEPARATION+self.H)*index+offset - self.add_area((x, y), (self.H, self.W)) + y = -1*W + x = PORT_SEPARATION*index+offset + self.add_area((x, y), (self.H, W)) self._connector_coordinate = (x+self.H/2, y-1) elif (self.is_sink() and rotation == 90) or (self.is_source() and rotation == 270): y = self.get_parent().W - x = (PORT_SEPARATION+self.H)*index+offset - self.add_area((x, y), (self.H, self.W)) - self._connector_coordinate = (x+self.H/2, y+1+self.W) + x = PORT_SEPARATION*index+offset + self.add_area((x, y), (self.H, W)) + self._connector_coordinate = (x+self.H/2, y+1+W) #the connector length self._connector_length = CONNECTOR_EXTENSION_MINIMAL + CONNECTOR_EXTENSION_INCREMENT*index + def modify_height(self, start_height): type_dict = {'bus':(lambda a: a * 3)}; @@ -102,8 +111,8 @@ class Port(Element): layout = gtk.DrawingArea().create_pango_layout('') layout.set_markup(Utils.parse_template(PORT_MARKUP_TMPL, port=self)) self.w, self.h = layout.get_pixel_size() - self.W, self.H = 2*PORT_LABEL_PADDING+self.w, 2*PORT_LABEL_PADDING+self.h - self.H = self.modify_height(self.H); + self.W, self.H = 2*PORT_LABEL_PADDING + self.w, 2*PORT_LABEL_PADDING+self.h + self.H = self.modify_height(self.H) #create the pixmap pixmap = self.get_parent().get_parent().new_pixmap(self.w, self.h) gc = pixmap.new_gc() @@ -129,6 +138,8 @@ class Port(Element): border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or self.get_parent().is_dummy_block() and Colors.MISSING_BLOCK_BORDER_COLOR or Colors.BORDER_COLOR, ) + if self.label_hidden(): + return X,Y = self.get_coordinate() (x,y),(w,h) = self._areas_list[0] #use the first area's sizes to place the labels if self.is_horizontal(): @@ -143,9 +154,9 @@ class Port(Element): Returns: the connector coordinate (x, y) tuple """ - x,y = self._connector_coordinate - X,Y = self.get_coordinate() - return (x+X, y+Y) + x, y = self._connector_coordinate + X, Y = self.get_coordinate() + return (x + X, y + Y) def get_connector_direction(self): """ @@ -222,3 +233,26 @@ class Port(Element): the parent's highlighting status """ return self.get_parent().is_highlighted() + + def label_hidden(self): + """ + Figure out if the label should be shown + + Returns: + true if the label should be hidden + """ + return self._label_hidden and Actions.TOGGLE_AUTO_HIDE_PORT_LABELS.get_active() + + def mouse_over(self): + """ + Called from flow graph on mouse-over + """ + self._label_hidden = False + return Actions.TOGGLE_AUTO_HIDE_PORT_LABELS.get_active() # only redraw if necessary + + def mouse_out(self): + """ + Called from flow graph on mouse-out + """ + self._label_hidden = True + return Actions.TOGGLE_AUTO_HIDE_PORT_LABELS.get_active() # only redraw if necessary diff --git a/grc/gui/Preferences.py b/grc/gui/Preferences.py index a6bd0d6603..1d6675da32 100644 --- a/grc/gui/Preferences.py +++ b/grc/gui/Preferences.py @@ -84,20 +84,11 @@ def blocks_window_position(pos=None): try: return _config_parser.getint('main', 'blocks_window_position') or 1 #greater than 0 except: return -1 -def reports_window_visibility(visible=None): - if visible is not None: _config_parser.set('main', 'reports_window_visible', visible) +def bool_entry(key, active=None, default=True): + if active is not None: + _config_parser.set('main', key, active) else: - try: return _config_parser.getboolean('main', 'reports_window_visible') - except: return True - -def blocks_window_visibility(visible=None): - if visible is not None: _config_parser.set('main', 'blocks_window_visible', visible) - else: - try: return _config_parser.getboolean('main', 'blocks_window_visible') - except: return True - -def scroll_lock(visible=None): - if visible is not None: _config_parser.set('main', 'scroll_lock', visible) - else: - try: return _config_parser.getboolean('main', 'scroll_lock') - except: return True + try: + return _config_parser.getboolean('main', key) + except: + return default
\ No newline at end of file diff --git a/grc/gui/Utils.py b/grc/gui/Utils.py index ebd5aefca7..9a0a59cda7 100644 --- a/grc/gui/Utils.py +++ b/grc/gui/Utils.py @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ -from Constants import POSSIBLE_ROTATIONS +from Constants import POSSIBLE_ROTATIONS, CANVAS_GRID_SIZE from Cheetah.Template import Template import pygtk pygtk.require('2.0') @@ -108,3 +108,11 @@ def parse_template(tmpl_str, **kwargs): # print tmpl_str # print str(kwargs['param'].get_error_messages()) return str(Template(tmpl_str, kwargs)) + +def align_to_grid(coor): + _align = lambda: int(round(x / (1.0 * CANVAS_GRID_SIZE)) * CANVAS_GRID_SIZE) + try: + return [_align() for x in coor] + except TypeError: + x = coor + return _align()
\ No newline at end of file |