diff options
author | Tom Rondeau <tom@trondeau.com> | 2014-07-12 09:51:18 -0400 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2014-07-12 09:51:18 -0400 |
commit | fddb2ce2b0191aaf509895d362154ae173312a22 (patch) | |
tree | b0b3b2301611e09eaf0ba23802e9fb2ad478f43c | |
parent | 4a003bb6329cbe63debe8fbfca91747e6e1225f1 (diff) | |
parent | 9f4a4eae44cfbe146fd32b3015cd3b014673ed47 (diff) |
Merge remote-tracking branch 'gnuradio-wg-grc/grc_port_view_options'
-rw-r--r-- | grc/gui/ActionHandler.py | 5 | ||||
-rw-r--r-- | grc/gui/Actions.py | 4 | ||||
-rw-r--r-- | grc/gui/Bars.py | 3 | ||||
-rw-r--r-- | grc/gui/Element.py | 6 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 77 | ||||
-rw-r--r-- | grc/gui/Port.py | 64 | ||||
-rw-r--r-- | grc/gui/Preferences.py | 6 |
7 files changed, 123 insertions, 42 deletions
diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index 2c1c9942d7..18b7c9aee0 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 ): action.set_sensitive(True) if ParseXML.xml_failures: Messages.send_xml_errors_if_any(ParseXML.xml_failures) @@ -136,6 +137,7 @@ class ActionHandler: 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()) + Actions.TOGGLE_AUTO_HIDE_PORT_LABELS.set_active(Preferences.auto_hide_port_labels()) elif action == Actions.APPLICATION_QUIT: if self.main_window.close_pages(): gtk.main_quit() @@ -383,6 +385,9 @@ class ActionHandler: self.main_window.text_display.clear() elif action == Actions.TOGGLE_HIDE_DISABLED_BLOCKS: Actions.NOTHING_SELECT() + elif action == Actions.TOGGLE_AUTO_HIDE_PORT_LABELS: + Preferences.auto_hide_port_labels(action.get_active()) + self.main_window.get_flow_graph().create_shapes() ################################################## # Param Modifications ################################################## diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index a9ab41230d..484952b53a 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -242,6 +242,10 @@ TOGGLE_HIDE_DISABLED_BLOCKS = ToggleAction( 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', +) BLOCK_CREATE_HIER = Action( label='C_reate Hier', tooltip='Create hier block from selected blocks', diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py index 11e35c992b..8dae0f6981 100644 --- a/grc/gui/Bars.py +++ b/grc/gui/Bars.py @@ -97,6 +97,9 @@ MENU_BAR_LIST = ( Actions.TOGGLE_SCROLL_LOCK, Actions.CLEAR_REPORTS, None, + Actions.TOGGLE_HIDE_DISABLED_BLOCKS, + Actions.TOGGLE_AUTO_HIDE_PORT_LABELS, + None, Actions.ERRORS_WINDOW_DISPLAY, Actions.FIND_BLOCKS, ]), 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..bfe8fbfa4f 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 [ @@ -544,35 +546,56 @@ 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 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() diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 41a458cde6..b81b162f6e 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,12 +59,13 @@ 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(filter(lambda p: not p.get_hide(), ports)) #reverse the order of ports for these rotations @@ -65,27 +73,28 @@ class Port(Element): offset = (self.get_parent().H - length*self.H - (length-1)*PORT_SEPARATION)/2 #create areas and connector coordinates if (self.is_sink() and rotation == 0) or (self.is_source() and rotation == 180): - x = -1*self.W + x = -1*W y = (PORT_SEPARATION+self.H)*index+offset - self.add_area((x, y), (self.W, self.H)) + 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) + 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 + y = -1*W x = (PORT_SEPARATION+self.H)*index+offset - self.add_area((x, y), (self.H, self.W)) + 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) + 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..d2ffc71410 100644 --- a/grc/gui/Preferences.py +++ b/grc/gui/Preferences.py @@ -101,3 +101,9 @@ def scroll_lock(visible=None): else: try: return _config_parser.getboolean('main', 'scroll_lock') except: return True + +def auto_hide_port_labels(hide=None): + if hide is not None: _config_parser.set('main', 'auto_hide_port_labels', hide) + else: + try: return _config_parser.getboolean('main', 'auto_hide_port_labels') + except: return True |