Changeset 5064:66625cac3f45 in orange


Ignore:
Timestamp:
08/04/08 20:22:39 (6 years ago)
Author:
janezd <janez.demsar@…>
Branch:
default
Convert:
ecb65e5f6506cf42e63cba63be2291ebbc379413
Message:
  • saving values into contexts now makes at least shallow copies. Some widgets, at least Distributions, had problems because it saved a list which was then emptied by the OWGUI callback. Since the context held a reference, it was affected, too.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeWidgets/OWContexts.py

    r4850 r5064  
    289289                self.saveLow(context, widget, field.name, widget.getdeepattr(field.name), field.flags) 
    290290            else: 
    291                 context.values[field.name] = widget.getdeepattr(field.name) 
     291                value = widget.getdeepattr(field.name) 
     292                # shallow copy of the list 
     293                context.values[field.name] = type(value)(value) 
    292294                if hasattr(field, "selected"): 
    293295                    context.values[field.selected] = list(widget.getdeepattr(field.selected)) 
     
    298300                if name == field.name: 
    299301                    if field.flags & self.List: 
    300                         context.values[field.name] = value 
     302                        # shallow copy of the list 
     303                        context.values[field.name] = type(value)(value) 
    301304                    else: 
    302305                        self.saveLow(context, widget, name, value, field.flags) 
     
    307310 
    308311    def saveLow(self, context, widget, field, value, flags): 
     312        # The code below uses type(value)(value) to make at least a shallow copy of the 
     313        # attributes. This will mostly make copies of integers, floats and strings, but 
     314        # it is crucial to make copies of lists 
     315        value = type(value)(value) 
    309316        if isinstance(value, str): 
    310317            valtype = not flags & self.ExcludeOrdinaryAttributes and context.attributes.get(value, -1) 
     
    437444    def settingsFromWidget(self, widget, context): 
    438445        ContextHandler.settingsFromWidget(self, widget, context) 
    439         context.values = dict([(field, widget.getdeepattr(field)) for field in self.fields]) 
     446        # shallow copy! 
     447        values = context.values = {} 
     448        for field in self.fields: 
     449            value = widget.getdeepattr(field) 
     450            values[field] = type(value)(value) 
    440451 
    441452    def fastSave(self, context, widget, name, value): 
    442453        if context and name in self.fields: 
    443             context.values[name] = value 
     454            # shallow copy! 
     455            context.values[name] = type(value)(value) 
    444456 
    445457    def match(self, context, imperfect, classes): 
     
    497509                attr = [x[1] for x in context.metas if x[0] == value] 
    498510 
     511            value = type(value)(value) 
    499512            if attr: 
    500513                context.values[field] = value, attr[0] 
Note: See TracChangeset for help on using the changeset viewer.