Ignore:
Timestamp:
01/18/12 12:10:44 (2 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
7697029528f864d7cd0afbbbd24674f3f806cb0e
Message:

Moved channel names backwards compatilility in orngSignalManager (also works for loading saved applications)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeCanvas/orngSignalManager.py

    r9212 r9548  
    1717NonDefault = 16 
    1818 
    19 Dynamic = 32 #Dynamic output signal 
     19Explicit = 32 # Explicit - only connected if specifically requested or the only possibility  
     20 
     21Dynamic = 64 #Dynamic output signal 
    2022 
    2123 
     
    3840        self.single = parameters & Single 
    3941        self.default = parameters & Default 
     42        self.explicit = parameters & Explicit 
    4043         
    4144         
     
    5356        self.single = parameters & Single 
    5457        self.default = parameters & Default 
     58        self.explicit = parameters & Explicit 
     59         
    5560        self.dynamic = parameters & Dynamic 
    5661        if self.dynamic and self.single: 
    5762            print "Output signal can not be Multiple and Dynamic" 
    5863            self.dynamic = 0 
    59          
    60                  
     64             
     65             
    6166def canConnect(output, input, dynamic=False): 
    6267    ret = issubclass(output.type, input.type) 
     
    6671 
    6772 
    68  
    6973class SignalLink(object): 
    7074    def __init__(self, widgetFrom, outputSignal, widgetTo, inputSignal, enabled=True): 
     
    9296     
    9397     
    94  
    9598# class that allows to process only one signal at a time 
    9699class SignalWrapper(object): 
     
    318321         
    319322        def weight(outS, inS): 
    320             check = [not outS.dynamic, inS.name not in alreadyConnected, bool(inS.default), bool(outS.default)] #Dynamic signals are lasts 
    321             weights = [2**i for i in range(len(check), 0, -1)] 
    322              
    323             return sum([w for w, c in zip(weights, check) if c]) 
     323            if outS.explicit or inS.explicit: 
     324                # Zero weight for explicit signals 
     325                weight = 0 
     326            else: 
     327                check = [not outS.dynamic, inS.name not in alreadyConnected, bool(inS.default), bool(outS.default)] #Dynamic signals are lasts 
     328                weights = [2**i for i in range(len(check), 0, -1)] 
     329                weight = sum([w for w, c in zip(weights, check) if c]) 
     330            return weight 
    324331         
    325332        possibleLinks = [] 
     
    351358        # check if signal names still exist 
    352359        found = 0 
    353         for o in widgetFrom.outputs: 
    354             output = OutputSignal(*o) 
    355             if output.name == signalNameFrom: found=1 
     360        output_names = [t[0] for t in widgetFrom.outputs] 
     361        found = signalNameFrom in output_names 
     362         
     363        if not found: 
     364            if signalNameFrom in _CHANNEL_NAME_MAP and \ 
     365                    _CHANNEL_NAME_MAP[signalNameFrom] in output_names: 
     366                self.addEvent("Widget changed its output signal  %r name. Changed to %r." % (signalNameFrom, _CHANNEL_NAME_MAP[signalNameFrom]), 
     367                              eventVerbosity=1) 
     368                signalNameFrom = _CHANNEL_NAME_MAP[signalNameFrom] 
     369                found = 1 
     370                 
    356371        if not found: 
    357372            print "Error. Widget %s changed its output signals. It does not have signal %s anymore." % (str(getattr(widgetFrom, "captionTitle", "")), signalNameFrom) 
     
    359374 
    360375        found = 0 
    361         for i in widgetTo.inputs: 
    362             input = InputSignal(*i) 
    363             if input.name == signalNameTo: found=1 
     376        input_names = [t[0] for t in widgetTo.inputs] 
     377        found = signalNameTo in input_names 
     378         
     379        if not found: 
     380            if signalNameTo in _CHANNEL_NAME_MAP and \ 
     381                    _CHANNEL_NAME_MAP[signalNameTo] in input_names: 
     382                self.addEvent("Widget changed its input signal  %r name. Changed to %r." % (signalNameFrom, _CHANNEL_NAME_MAP[signalNameTo]), 
     383                              eventVerbosity=1) 
     384                signalNameTo = _CHANNEL_NAME_MAP[signalNameTo] 
     385                found = 1 
     386                 
    364387        if not found: 
    365388            print "Error. Widget %s changed its input signals. It does not have signal %s anymore." % (str(getattr(widgetTo, "captionTitle", "")), signalNameTo) 
    366389            return 0 
    367  
    368390 
    369391        if self.links.has_key(widgetFrom): 
     
    672694        link.widgetFrom.emit(QtCore.SIGNAL("dynamicLinkEnabledChanged(PyQt_PyObject, bool)"), link, enabled) 
    673695         
    674      
     696 
     697# Channel renames. 
     698 
     699_CHANNEL_NAME_MAP = \ 
     700    {'Additional Tables': 'Additional Data', 
     701     'Attribute Definitions': 'Feature Definitions', 
     702     'Attribute List': 'Features', 
     703     'Attribute Pair': 'Interacting Features', 
     704     'Attribute Selection List': 'Features', 
     705     'Attribute Statistics': 'Feature Statistics', 
     706     'Attribute selection': 'Features', 
     707     'Attributes': 'Features', 
     708     'Choosen Tree': 'Selected Tree', 
     709     'Covered Examples': 'Covered Data', 
     710     'Data Instances': 'Data', 
     711     'Data Table': 'Data', 
     712     'Distance Matrix': 'Distances', 
     713     'Distance matrix': 'Distances', 
     714     'Example Subset': 'Data Subset', 
     715     'Example Table': 'Data', 
     716     'Examples': 'Data', 
     717     'Examples A': 'Data A', 
     718     'Examples B': 'Data B', 
     719     'Graph with ExampleTable': 'Graph with Data', 
     720     'Input Data': 'Data', 
     721     'Input Table': 'Data', 
     722     'Instances': 'Data', 
     723     'Items Distance Matrix': 'Distances', 
     724     'Items Subset': 'Item Subset', 
     725     'Items to Mark': 'Marked Itenms', 
     726     'KNN Classifier': 'kNN Classifier', 
     727     'Marked Examples': 'Marked Data', 
     728     'Matching Examples': 'Merged Data', 
     729     'Mismatching Examples': 'Mismatched Data', 
     730     'Output Data': 'Data', 
     731     'Output Table': 'Data', 
     732     'Preprocessed Example Table': 'Preprocessed Data', 
     733     'Primary Table': 'Primary Data', 
     734     'Reduced Example Table': 'Reduced Data', 
     735     'Remaining Examples': 'Remaining Data', 
     736     'SOMMap': 'SOM', 
     737     'Sample': 'Data Sample', 
     738     'Selected Attributes List': 'Selected Features', 
     739     'Selected Examples': 'Selected Data', 
     740     'Selected Instances': 'Selected Data', 
     741     'Selected Items Distance Matrix': 'Distance Matrix', 
     742     'Shuffled Data Table': 'Shuffled Data', 
     743     'Train Data': 'Training Data', 
     744     'Training data': 'Data', 
     745     'Unselected Examples': 'Other Data', 
     746     'Unselected Items': 'Other Items', 
     747     }     
    675748 
    676749# create a global instance of signal manager 
    677750globalSignalManager = SignalManager() 
    678          
    679       
     751 
Note: See TracChangeset for help on using the changeset viewer.