Ignore:
Timestamp:
01/25/13 12:18:02 (15 months ago)
Author:
Ales Erjavec <ales.erjavec@…>
Branch:
default
Message:

Fixed an error which allowed the dialog to connect more than one connection to a single input channel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeCanvas/canvas/editlinksdialog.py

    r11277 r11283  
    3333 
    3434class EditLinksDialog(QDialog): 
    35     """A dialog for editing links. 
     35    """ 
     36    A dialog for editing links. 
    3637 
    3738    >>> dlg = EditLinksDialog() 
     
    151152    ["output",    # OutputSignal 
    152153     "input",     # InputSignal 
    153      "lineItem",  # QGraphicsLineItem 
     154     "lineItem",  # QGraphicsLineItem connecting the input to output 
    154155     ]) 
    155156 
    156157 
    157158class LinksEditWidget(QGraphicsWidget): 
    158     """A Graphics Widget for editing the links between two nodes. 
     159    """ 
     160    A Graphics Widget for editing the links between two nodes. 
    159161    """ 
    160162    def __init__(self, *args, **kwargs): 
     
    182184 
    183185    def removeItems(self, items): 
    184         """Remove child items form the widget and scene. 
    185  
     186        """ 
     187        Remove child items form the widget and scene. 
    186188        """ 
    187189        scene = self.scene() 
     
    192194 
    193195    def clear(self): 
    194         """Clear the editor state (source and sink nodes, channels ...). 
    195  
     196        """ 
     197        Clear the editor state (source and sink nodes, channels ...). 
    196198        """ 
    197199        if self.layout().count(): 
     
    203205 
    204206    def setNodes(self, source, sink): 
    205         """Set the source/sink nodes (`SchemeNode` instances) 
    206         between which to edit the links. 
     207        """ 
     208        Set the source/sink nodes (:class:`SchemeNode` instances) between 
     209        which to edit the links. 
     210 
     211        .. note:: Call this before `setLinks`. 
    207212 
    208213        """ 
     
    215220 
    216221    def setLinks(self, links): 
    217         """Set a list of links to display between the source and sink 
    218         nodes. The `links` is a list of (`OutputSignal`, `InputSignal`) 
    219         instances where the first element refers to the source node 
    220         and the second to the sink node. 
    221  
    222         """ 
     222        """ 
     223        Set a list of links to display between the source and sink 
     224        nodes. `links` must be a list of (`OutputSignal`, `InputSignal`) 
     225        tuples where the first element refers to the source node 
     226        and the second to the sink node (as set by `setNodes`). 
     227 
     228        """ 
     229        self.clearLinks() 
    223230        for output, input in links: 
    224231            self.addLink(output, input) 
    225232 
    226233    def links(self): 
    227         """Return the links between the source and sink node. 
     234        """ 
     235        Return the links between the source and sink node. 
    228236        """ 
    229237        return [(link.output, link.input) for link in self.__links] 
     
    291299                endChannel = endItem.channel() 
    292300                possible = False 
     301 
     302                # Make sure the drag was from input to output (or reversed) and 
     303                # not between input -> input or output -> output 
    293304                if type(startChannel) != type(endChannel): 
    294305                    if isinstance(startChannel, InputSignal): 
     
    307318 
    308319    def addLink(self, output, input): 
     320        """ 
     321        Add a link between `output` (:class:`OutputSignal`) and `input` 
     322        (:class:`InputSignal`). 
     323 
     324        """ 
    309325        if not compatible_channels(output, input): 
    310326            return 
     
    319335 
    320336        if input.single: 
    321             # Remove existing link 
     337            # Remove existing link if it exists. 
    322338            for s1, s2, _ in self.__links: 
    323339                if s2 == input: 
    324340                    self.removeLink(s1, s2) 
    325                 break 
    326341 
    327342        line = QGraphicsLineItem(self) 
     
    344359 
    345360    def removeLink(self, output, input): 
    346         """Remove a link between the source and sink channels. 
     361        """ 
     362        Remove a link between the `output` and `input` channels. 
    347363        """ 
    348364        for link in list(self.__links): 
     
    352368                break 
    353369        else: 
    354             raise ValueError("No such link {!0.name} -> {!1.name}." \ 
     370            raise ValueError("No such link {0.name!r} -> {1.name!r}." \ 
    355371                             .format(output, input)) 
    356372 
    357373    def clearLinks(self): 
    358         """Clear (remove) all the links. 
     374        """ 
     375        Clear (remove) all the links. 
    359376        """ 
    360377        for output, input, _ in list(self.__links): 
     
    362379 
    363380    def __updateState(self): 
    364         """Update the widget with the new source/sink node signal descriptions. 
    365  
     381        """ 
     382        Update the widget with the new source/sink node signal descriptions. 
    366383        """ 
    367384        widget = QGraphicsWidget() 
     
    432449 
    433450class EditLinksNode(QGraphicsWidget): 
    434     """A Node with channel anchors. 
     451    """ 
     452    A Node with channel anchors. 
    435453 
    436454    `direction` specifies the layout (default `Qt.LeftToRight` will 
     
    482500 
    483501    def setIconSize(self, size): 
    484         """Set the icon size for the node. 
     502        """ 
     503        Set the icon size for the node. 
    485504        """ 
    486505        if size != self.__iconSize: 
     
    494513 
    495514    def setIcon(self, icon): 
    496         """Set the icon to display. 
     515        """ 
     516        Set the icon to display. 
    497517        """ 
    498518        if icon != self.__icon: 
     
    505525 
    506526    def setSchemeNode(self, node): 
    507         """Set an instance of `SchemeNode`. The widget will be 
     527        """ 
     528        Set an instance of `SchemeNode`. The widget will be 
    508529        initialized with its icon and channels. 
    509530 
     
    570591 
    571592    def anchor(self, channel): 
    572         """Return the anchor item for the `channel` name. 
    573  
     593        """ 
     594        Return the anchor item for the `channel` name. 
    574595        """ 
    575596        for anchor in self.__channelAnchors: 
     
    593614 
    594615class GraphicsItemLayoutItem(QGraphicsLayoutItem): 
    595     """A graphics layout that handles the position of a general QGraphicsItem 
     616    """ 
     617    A graphics layout that handles the position of a general QGraphicsItem 
    596618    in a QGraphicsLayout. The items boundingRect is used as this items fixed 
    597619    sizeHint and the item is positioned at the top left corner of the this 
Note: See TracChangeset for help on using the changeset viewer.