Ignore:
Timestamp:
11/28/12 12:31:29 (17 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Fixed anchor point layout order reset while dragging (creating) a new link.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/canvas/items/nodeitem.py

    r11186 r11207  
    55 
    66from xml.sax.saxutils import escape 
    7  
    8 import numpy 
    97 
    108from PyQt4.QtGui import ( 
     
    2321from ...registry import NAMED_COLORS 
    2422from ...resources import icon_loader 
     23from .utils import uniform_linear_layout 
    2524 
    2625 
     
    282281        self.__dottedStroke = None 
    283282 
    284         self.__layoutRequested = False 
    285  
    286283    def parentNodeItem(self): 
    287284        """Return a parent `NodeItem` or `None` if this anchor's 
     
    403400        del self.__pointPositions[index] 
    404401 
    405         self.__scheduleDelayedLayout() 
    406  
    407402    def anchorPoints(self): 
    408403        """Return a list of anchor points. 
     
    421416        """ 
    422417        if self.__pointPositions != positions: 
    423             self.__pointPositions = positions 
     418            self.__pointPositions = list(positions) 
    424419 
    425420            self.__updatePositions() 
    426421 
    427422    def anchorPositions(self): 
    428         """Return the positions of anchor points as a list floats where 
     423        """Return the positions of anchor points as a list of floats where 
    429424        each float is between 0 and 1 and specifies where along the anchor 
    430425        path does the point lie (0 is at start 1 is at the end). 
    431426 
    432427        """ 
    433         return self.__pointPositions 
     428        return list(self.__pointPositions) 
    434429 
    435430    def shape(self): 
     
    448443        return QGraphicsPathItem.hoverLeaveEvent(self, event) 
    449444 
    450     def __scheduleDelayedLayout(self): 
    451         if not self.__layoutRequested: 
    452             self.__layoutRequested = True 
    453             QTimer.singleShot(0, self.__updatePositions) 
    454  
    455445    def __updatePositions(self): 
    456446        """Update anchor points positions. 
     
    459449            pos = self.__anchorPath.pointAtPercent(t) 
    460450            point.setPos(pos) 
    461  
    462         self.__layoutRequested = False 
    463451 
    464452 
     
    587575 
    588576 
    589 def linspace(count): 
    590     return map(float, numpy.linspace(0.0, 1.0, count + 2, endpoint=True)[1:-1]) 
    591  
    592  
    593577class NodeItem(QGraphicsObject): 
    594578    """An widget node item in the canvas. 
     
    840824 
    841825        anchor = AnchorPoint() 
    842         self.inputAnchorItem.addAnchor(anchor) 
    843  
    844         self.inputAnchorItem.setAnchorPositions( 
    845             linspace(self.inputAnchorItem.count()) 
    846         ) 
     826        self.inputAnchorItem.addAnchor(anchor, position=1.0) 
     827 
     828        positions = self.inputAnchorItem.anchorPositions() 
     829        positions = uniform_linear_layout(positions) 
     830        self.inputAnchorItem.setAnchorPositions(positions) 
    847831 
    848832        return anchor 
     
    853837        self.inputAnchorItem.removeAnchor(anchor) 
    854838 
    855         self.inputAnchorItem.setAnchorPositions( 
    856             linspace(self.inputAnchorItem.count()) 
    857         ) 
     839        positions = self.inputAnchorItem.anchorPositions() 
     840        positions = uniform_linear_layout(positions) 
     841        self.inputAnchorItem.setAnchorPositions(positions) 
    858842 
    859843    def newOutputAnchor(self): 
     
    864848 
    865849        anchor = AnchorPoint(self) 
    866         self.outputAnchorItem.addAnchor(anchor) 
    867  
    868         self.outputAnchorItem.setAnchorPositions( 
    869             linspace(self.outputAnchorItem.count()) 
    870         ) 
     850        self.outputAnchorItem.addAnchor(anchor, position=1.0) 
     851 
     852        positions = self.outputAnchorItem.anchorPositions() 
     853        positions = uniform_linear_layout(positions) 
     854        self.outputAnchorItem.setAnchorPositions(positions) 
    871855 
    872856        return anchor 
     
    877861        self.outputAnchorItem.removeAnchor(anchor) 
    878862 
    879         self.outputAnchorItem.setAnchorPositions( 
    880             linspace(self.outputAnchorItem.count()) 
    881         ) 
     863        positions = self.outputAnchorItem.anchorPositions() 
     864        positions = uniform_linear_layout(positions) 
     865        self.outputAnchorItem.setAnchorPositions(positions) 
    882866 
    883867    def inputAnchors(self): 
Note: See TracChangeset for help on using the changeset viewer.