From f358308919c1d902ba28dd5238c9cfc4e56c5b5f Mon Sep 17 00:00:00 2001 From: Sebastian Koslowski Date: Tue, 16 Sep 2014 22:01:26 -0400 Subject: [PATCH 1/2] grc: fix lagging drag and drop --- grc/gui/Block.py | 3 +-- grc/gui/Port.py | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/grc/gui/Block.py b/grc/gui/Block.py index 0ae624f..1a32f6c 100644 --- a/grc/gui/Block.py +++ b/grc/gui/Block.py @@ -224,8 +224,7 @@ 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(): - if not port.get_hide(): - port.draw(gc, window) + port.draw(gc, window) def what_is_selected(self, coor, coor_m=None): """ diff --git a/grc/gui/Port.py b/grc/gui/Port.py index 188281a..364ca6a 100644 --- a/grc/gui/Port.py +++ b/grc/gui/Port.py @@ -45,7 +45,7 @@ class Port(Element): """ Element.__init__(self) self.W = self.H = self.w = self.h = 0 - self._connector_coordinate = (0,0) + self._connector_coordinate = (0, 0) self._connector_length = 0 self._hovering = True self._force_label_unhidden = False @@ -53,11 +53,15 @@ class Port(Element): def create_shapes(self): """Create new areas and labels for the port.""" Element.create_shapes(self) + if self.get_hide(): + return # this port is hidden, no need to create shapes #get current rotation rotation = self.get_rotation() #get all sibling ports - if self.is_source(): ports = self.get_parent().get_sources_gui() - elif self.is_sink(): ports = self.get_parent().get_sinks_gui() + if self.is_source(): + ports = self.get_parent().get_sources_gui() + 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 PORT_LABEL_HIDDEN_WIDTH @@ -70,7 +74,8 @@ class Port(Element): return 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 + if rotation in (180, 270): + index = length-index-1 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): @@ -137,12 +142,13 @@ class Port(Element): Element.draw( self, gc, window, bg_color=self._bg_color, 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, + 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 not self._areas_list or self._label_hidden(): + return # this port is either hidden (no areas) or folded (no label) + 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(): window.draw_drawable(gc, self.horizontal_label, 0, 0, x+X+(self.W-self.w)/2, y+Y+(self.H-self.h)/2, -1, -1) elif self.is_vertical(): -- 1.9.3