diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2014-07-04 21:58:26 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2014-07-11 23:25:31 +0200 |
commit | 02db08d26e992a0c9c90b382ce9809d39283a910 (patch) | |
tree | 769f2a91551d0876b7d7699d798eb37773542a9c /grc | |
parent | 085c35a375468179929b690a0d7f037dc6ef23bf (diff) |
grc: auto-hide port labels
Diffstat (limited to 'grc')
-rw-r--r-- | grc/gui/Element.py | 6 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 73 | ||||
-rw-r--r-- | grc/gui/Port.py | 47 |
3 files changed, 85 insertions, 41 deletions
diff --git a/grc/gui/Element.py b/grc/gui/Element.py index 915bdfb915..bca7a03699 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 1103aa1639..2fb452fe2d 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 [ @@ -550,29 +552,48 @@ class FlowGraph(Element): """ #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: + 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 e542797ea6..2b8facfcff 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -28,6 +28,8 @@ 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>""" @@ -40,7 +42,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 +57,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(ports) #reverse the order of ports for these rotations @@ -65,27 +71,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 +109,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 +136,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 +152,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 +231,11 @@ class Port(Element): the parent's highlighting status """ return self.get_parent().is_highlighted() + + def mouse_over(self): + self._label_hidden = False + return True + + def mouse_out(self): + self._label_hidden = True + return True
\ No newline at end of file |