daboide Commit
Revision 728
Date: 2006-12-30 10:04:47 -0800 (Sat, 30 Dec 2006)
Author: Ed
Changed:
U trunk/ClassDesigner.py
U trunk/ClassDesignerComponents.py
Log:
These changes improve the handling of inheritance in cdxml-based classes.
Diff:
Modified: trunk/ClassDesigner.py
===================================================================
--- trunk/ClassDesigner.py 2006-12-30 01:37:32 UTC (rev 727)
+++ trunk/ClassDesigner.py 2006-12-30 18:04:47 UTC (rev 728)
@@ -26,7 +26,6 @@
from dabo.lib.DesignerXmlConverter import DesignerXmlConverter
import ClassDesignerMenu
import dabo.lib.xmltodict as xtd
-import dabo.lib.DesignerUtils as desUtil
from dabo.lib.utils import dictStringify
from ClassDesignerExceptions import PropertyUpdateException
@@ -443,20 +442,38 @@
"""
xml = open(pth).read()
try:
- dct = xtd.xmltodict(xml)
+ dct = xtd.xmltodict(xml, addCodeFile=True)
except:
raise IOError, _("This does not appear to be a valid
class file.")
- # Get the associated code file, if any
- codePth = "%s-code.py" % os.path.splitext(pth)[0]
- if os.path.exists(codePth):
- try:
- codeDict =
desUtil.parseCodeFile(open(codePth).read())
- desUtil.addCodeToClassDict(dct, codeDict)
- except StandardError, e:
- print "Failed to parse code file:", e
+
+ # Traverse the dct, looking for superclass information
+ super = xtd.flattenClassDict(dct)
+ if super:
+ # We need to modify the info to incorporate the
superclass info
+ self._addInheritedInfo(dct, super)
return dct
+ def _addInheritedInfo(self, src, super):
+ """Called recursively on the class container structure,
+ modifying the attributes and code to incorporate superclass
+ information.
+ """
+ atts = src.get("attributes", {})
+ kids = src.get("children", [])
+ code = src.get("code", {})
+ classID = atts.get("classID", "")
+ if classID:
+ superInfo = super.get(classID, {"attributes": {},
"code": {}})
+ src["attributes"] = superInfo["attributes"].copy()
+ src["attributes"].update(atts)
+ src["code"] = superInfo["code"].copy()
+ src["code"].update(code)
+ if kids:
+ for kid in kids:
+ self._addInheritedInfo(kid, super)
+
+
def _findSizerInClassDict(self, clsd):
"""Recursively search until a child is found with sizer
information.
If no such child is found, return False.
@@ -574,13 +591,13 @@
dabo.lib.utils.resolveAttributePathing(atts,
self._basePath)
clsname = self._extractKey(atts, "designerClass", "")
# See if this is a saved class inserted into another
design
- if os.path.exists(clsname) and atts.has_key("classID"):
- # Add the custom class. The method will return
- # the added object.
- obj = self.addCustomClass(clsname)
- # Now apply any custom changes saved in this
class
- self.setCustomChanges(obj, dct)
- return obj
+# if os.path.exists(clsname) and atts.has_key("classID"):
+# # Add the custom class. The method will return
+# # the added object.
+# obj = self.addCustomClass(clsname)
+# # Now apply any custom changes saved in this
class
+# self.setCustomChanges(obj, dct)
+# return obj
cls = dct["name"]
kids = dct.get("children", None)
code = dct.get("code", {})
@@ -765,6 +782,9 @@
for pos, kid in enumerate(kids):
pg = obj.Pages[pos]
kidatts =
kid.get("attributes", {})
+ kidClassID =
self._extractKey(kidatts, "classID", "")
+ if kidClassID:
+ pg.classID =
kidClassID
pg.setPropertiesFromAtts(kidatts)
kidcode =
kid.get("code", {})
if kidcode:
Modified: trunk/ClassDesignerComponents.py
===================================================================
--- trunk/ClassDesignerComponents.py 2006-12-30 01:37:32 UTC (rev 727)
+++ trunk/ClassDesignerComponents.py 2006-12-30 18:04:47 UTC (rev 728)
@@ -63,7 +63,9 @@
classID =
"?????"
ra["classID"] = "%s-%s" % (classID, myID)
self.classID = ra["classID"]
-
+ else:
+ if hasattr(self, "classID"):
+ ra["classID"] = self.classID
ret["name"] = self.getClass()
ret["cdata"] = ""
if insideClass and classDict:
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev