| | 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 |