Show
Ignore:
Timestamp:
07/05/08 09:43:06 (5 months ago)
Author:
rob
Message:

Fixed #393: added ApplySettingsSameMode? to make view settings default for current mode
* added ApplySettingsAll? to erase default values in the GlobalPrefs? for subclasses of FundamentalMode? so that the settings become the defaults for all modes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/peppy/lib/userparams.py

    r1440 r1457  
    13001300    def __call__(self, name): 
    13011301        return self._get(name) 
     1302     
     1303    def _getNameHierarchy(self): 
     1304        return GlobalPrefs.name_hierarchy[self.__dict__['_startSearch']] 
     1305 
     1306    def _getClassHierarchy(self): 
     1307        return GlobalPrefs.class_hierarchy[self.__dict__['_startSearch']] 
    13021308 
    13031309    def _get(self, name, user=True, default=True): 
     
    14691475    pass 
    14701476 
    1471  
    14721477class ClassPrefs(object): 
    14731478    """Base class to extend in order to support class prefs. 
     
    15091514                    #dprint("setting classpref %s to %s" % (param.keyword, self.classprefs._get(param.keyword))) 
    15101515                    self.classprefs._set(param.keyword, getattr(self.locals, param.keyword)) 
     1516     
     1517    @classmethod 
     1518    def classprefsSetDefaults(cls, new_locals): 
     1519        """Update the class defaults from the locals 
     1520        """ 
     1521        hier = cls.classprefs._getMRO() 
     1522        #dprint(hier) 
     1523        updated = {} 
     1524        for cls in hier: 
     1525            if 'default_classprefs' not in dir(cls): 
     1526                continue 
     1527            for param in cls.default_classprefs: 
     1528                if param.local and param.keyword in new_locals: 
     1529                    #dprint("setting classpref %s to %s" % (param.keyword, self.classprefs._get(param.keyword))) 
     1530                    cls.classprefs._set(param.keyword, new_locals[param.keyword]) 
     1531     
     1532    @classmethod 
     1533    def classprefsOverrideSubclassDefaults(cls, new_locals): 
     1534        """Override settings of this class and all subclasses 
     1535         
     1536        Remove all the user values from GlobalPrefs of items that would 
     1537        override these class settings definitions.  All subclasses of this 
     1538        class will have their settings removed so that this class becomes the 
     1539        default value for all of its subclasses. 
     1540         
     1541        This is used to change the settings of FundamentalMode so that 
     1542        subclasses like PythonMode or CPlusPlusMode will take their settings 
     1543        from Fundamental mode. 
     1544        """ 
     1545        cls.classprefsSetDefaults(new_locals) 
     1546        #dprint("fund: %s" % GlobalPrefs.user) 
     1547        #dprint("defaults: %s" % GlobalPrefs.default) 
     1548        #dprint("name: %s" % GlobalPrefs.name_hierarchy) 
     1549        parent = cls.__name__ 
     1550        for name, hier in GlobalPrefs.name_hierarchy.iteritems(): 
     1551            if parent in hier: 
     1552                if name == parent: 
     1553                    # Override fundamental mode defaults with user settings 
     1554                    #dprint("before: %s: %s" % (name, GlobalPrefs.user[name])) 
     1555                    for k in new_locals.keys(): 
     1556                        if k in GlobalPrefs.default[name] and GlobalPrefs.default[name] != new_locals[k]: 
     1557                            GlobalPrefs.user[name][k] = new_locals[k] 
     1558                    #dprint("after: %s: %s" % (name, GlobalPrefs.user[name])) 
     1559                else: 
     1560                    # erase user settings so that fundamental mode settings 
     1561                    # will show through 
     1562                    #dprint("before: %s: %s" % (name, GlobalPrefs.user[name])) 
     1563                    for k in new_locals.keys(): 
     1564                        if k in GlobalPrefs.user[name]: 
     1565                            del GlobalPrefs.user[name][k] 
     1566                    #dprint("after: %s: %s" % (name, GlobalPrefs.user[name])) 
     1567 
     1568    def classprefsDictFromLocals(self): 
     1569        """Return a dict copy of the local settings""" 
     1570        copy = {} 
     1571        for k in dir(self.locals): 
     1572            if not k.startswith('_'): 
     1573                copy[k] = getattr(self.locals, k) 
     1574        return copy 
    15111575     
    15121576    def classprefsUpdateLocals(self, new_locals):