Changeset 3667:5aaa0335567e in orange


Ignore:
Timestamp:
05/18/07 09:37:55 (7 years ago)
Author:
Gregor <Gregor@…>
Branch:
default
Convert:
a481dff82a8274cfc37a2aebfd8565b7695ae9b1
Message:
  • fixed connection of widgets, when does the signal manager popup, ...
Location:
orange/OrangeCanvas
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeCanvas/orngDlgs.py

    r3613 r3667  
    241241        self.signals = [] 
    242242        self._links = [] 
     243        self.allSignalsTaken = 0 
    243244 
    244245        # GUI 
     
    327328 
    328329 
    329     def getPossibleConnections(self, outputs, inputs, outConnected, inConnected): 
     330    def getPossibleConnections(self, outputs, inputs): 
    330331        possibleLinks = [] 
    331         canConnect = 0 
    332         sameType = 0 
    333332        for outS in outputs: 
    334333            outType = self.outWidget.instance.getOutputType(outS.name) 
    335             if outType == None: 
    336                 #print "Unable to find signal type for signal %s. Check the definition of the widget." % (outS.name) 
    337                 #return []                                         # report error 
     334            if outType == None:     #print "Unable to find signal type for signal %s. Check the definition of the widget." % (outS.name) 
    338335                continue 
    339336            for inS in inputs: 
    340337                inType = self.inWidget.instance.getInputType(inS.name) 
    341338                if inType == None: 
    342                     continue 
    343                     #print "Unable to find signal type for signal %s. Check the definition of the widget." % (inS.name) 
    344                     #return None                                        # report error 
     339                    continue        #print "Unable to find signal type for signal %s. Check the definition of the widget." % (inS.name) 
    345340                if issubclass(outType, inType): 
    346                     canConnect = 1 
    347                     if (outS.name in outConnected) or (inS.name in inConnected): continue 
    348                     if issubclass(inType, outType): 
    349                         possibleLinks.insert(sameType, (outS.name, inS.name)) 
    350                         sameType += 1 
    351                     else: 
    352                         possibleLinks.append((outS.name, inS.name)) 
    353         return possibleLinks, canConnect, sameType 
     341                    possibleLinks.append((outS.name, inS.name)) 
     342        return possibleLinks 
    354343 
    355344    def addDefaultLinks(self): 
     
    359348        self.multiplePossibleConnections = 0    # can we connect some signal with more than one widget 
    360349 
    361         allInputs = self.inWidget.widget.getInputs() 
    362         allOutputs = self.outWidget.widget.getOutputs() 
    363350        minorInputs = self.inWidget.widget.getMinorInputs() 
    364351        minorOutputs = self.outWidget.widget.getMinorOutputs() 
    365         majorInputs = [] 
    366         majorOutputs = [] 
    367         for s in allInputs: 
    368             if s not in minorInputs: majorInputs.append(s) 
    369  
    370         for s in allOutputs: 
    371             if s not in minorOutputs: majorOutputs.append(s) 
     352        majorInputs = self.inWidget.widget.getMajorInputs() 
     353        majorOutputs = self.outWidget.widget.getMajorOutputs() 
    372354 
    373355        inConnected = self.inWidget.getInConnectedSignalNames() 
    374356        outConnected = self.outWidget.getOutConnectedSignalNames() 
    375357 
     358        # input connections that can be simultaneously connected to multiple outputs are not to be considered as already connected  
    376359        for i in inConnected[::-1]: 
    377360            if not self.inWidget.instance.signalIsOnlySingleConnection(i): 
     
    379362 
    380363        # rebuild registry if necessary 
    381         for s in allInputs: 
    382             if not self.inWidget.instance.hasInputName(s.name): return -1 
    383         for s in allOutputs: 
    384             if not self.outWidget.instance.hasOutputName(s.name): return -1 
    385  
    386         pL1,can1,sameType1 = self.getPossibleConnections(majorOutputs, majorInputs, [], []) 
    387         pL2,can2,sameType2 = self.getPossibleConnections(majorOutputs, minorInputs, [], [v[1] for v in pL1]) 
    388         pL3,can3,sameType3 = self.getPossibleConnections(minorOutputs, majorInputs, [], [v[1] for v in pL1+pL2]) 
    389         pL4,can4,sameType4 = self.getPossibleConnections(minorOutputs, minorInputs, [], [v[1] for v in pL1+pL2+pL3]) 
    390  
    391         all = pL1 + pL2 + pL3 + pL4 
    392  
    393         # try to find if there are links to any inputs that haven't been previously connected 
     364        for s in majorInputs + minorInputs: 
     365            if not self.inWidget.instance.hasInputName(s.name): 
     366                return -1 
     367        for s in majorOutputs + minorOutputs: 
     368            if not self.outWidget.instance.hasOutputName(s.name): 
     369                return -1 
     370 
     371        pl1 = self.getPossibleConnections(majorOutputs, majorInputs) 
     372        pl2 = self.getPossibleConnections(majorOutputs, minorInputs) 
     373        pl3 = self.getPossibleConnections(minorOutputs, majorInputs) 
     374        pl4 = self.getPossibleConnections(minorOutputs, minorInputs) 
     375 
     376        all = pl1 + pl2 + pl3 + pl4 
     377 
     378        if not all: return 0 
     379         
     380        # try to find a link to any inputs that hasn't been previously connected 
     381        self.allSignalsTaken = 1 
    394382        for (o,i) in all: 
    395             if not 1 in [i == s for s in inConnected]: 
     383            if i not in inConnected: 
    396384                all.remove((o,i)) 
    397385                all.insert(0, (o,i)) 
     386                self.allSignalsTaken = 0       # we found an unconnected link. no need to show the signal dialog 
    398387                break 
    399  
    400         if not all: return 0 
    401  
    402388        self.addLink(all[0][0], all[0][1])  # add only the best link 
    403389 
    404         same = [sameType1, sameType2, sameType3, sameType4] 
    405         can = [can1, can2, can3, can4] 
    406         self.multiplePossibleConnections = (same[can.index(1)] != 1 and sum(can) > 1) 
     390        # there are multiple possible connections if we have in the same priority class more than one possible unconnected link 
     391        for pl in [pl1, pl2, pl3, pl4]: 
     392            #if len(pl) > 1 and sum([i not in inConnected for (o,i) in pl]) > 1: # if we have more than one valid 
     393            if len(pl) > 1:     # if we have more than one valid  
     394                self.multiplePossibleConnections = 1 
     395            if len(pl) > 0:     # when we find a first non-empty list we stop searching 
     396                break 
    407397        return len(all) > 0 
    408  
    409  
    410398 
    411399    def addLink(self, outName, inName): 
  • orange/OrangeCanvas/orngDoc.py

    r3568 r3667  
    117117            return 
    118118 
    119  
    120119        # if there are multiple choices, how to connect this two widget, then show the dialog 
    121         if self.ctrlPressed or len(dialog.getLinks()) > 1 or dialog.multiplePossibleConnections or dialog.getLinks() == []: 
     120        if self.ctrlPressed or len(dialog.getLinks()) > 1 or dialog.multiplePossibleConnections or dialog.allSignalsTaken or dialog.getLinks() == []: 
    122121            res = dialog.exec_loop() 
    123122            if dialog.result() == QDialog.Rejected: 
  • orange/OrangeCanvas/orngTabs.py

    r3508 r3667  
    126126        return self.widgetTabs.widgetInfo[self.nameKey]["outputs"] 
    127127 
     128    def getMajorInputs(self): 
     129        ret = [] 
     130        for signal in self.widgetTabs.widgetInfo[self.nameKey]["inputs"]: 
     131            if signal.default: 
     132                ret.append(signal) 
     133        return ret 
     134 
     135    def getMajorOutputs(self): 
     136        ret = [] 
     137        for signal in self.widgetTabs.widgetInfo[self.nameKey]["outputs"]: 
     138            if signal.default: 
     139                ret.append(signal) 
     140        return ret 
     141 
    128142    def getMinorInputs(self): 
    129143        ret = [] 
    130144        for signal in self.widgetTabs.widgetInfo[self.nameKey]["inputs"]: 
    131             if not signal.default: ret.append(signal) 
     145            if not signal.default: 
     146                ret.append(signal) 
    132147        return ret 
    133148 
     
    135150        ret = [] 
    136151        for signal in self.widgetTabs.widgetInfo[self.nameKey]["outputs"]: 
    137             if not signal.default: ret.append(signal) 
     152            if not signal.default: 
     153                ret.append(signal) 
    138154        return ret 
    139155 
Note: See TracChangeset for help on using the changeset viewer.