daboide Commit Revision 729 Date: 2006-12-30 15:41:12 -0800 (Sat, 30 Dec 2006) Author: Ed
Changed: U trunk/ClassDesigner.py U trunk/ClassDesignerComponents.py U trunk/ClassDesignerControlMixin.py U trunk/ClassDesignerEditor.py
Log: Added the handling of inherited code to the Class Designer. Objects now only save their code if it has been modified from the superclass version.
There are still some bugs in handling inherited code and attributes when running from a cdxml file; fixing those are next on the agenda.
Improved the way that composite classes, such as paged controls, handle things when their child class (e.g., dPageFrame.PageClass) is a path to a cdxml file.
Removed some leftover debugging print statements.
Diff: Modified: trunk/ClassDesigner.py =================================================================== --- trunk/ClassDesigner.py 2006-12-30 18:04:47 UTC (rev 728) +++ trunk/ClassDesigner.py 2006-12-30 23:41:12 UTC (rev 729) @@ -53,11 +53,14 @@ self._srcObj = None self._srcPos = None self._codeDict = {} + self._classCodeDict = {} self._classPropDict = {} self._classImportDict = {} self._classDefaultVals = {} self._mixedControlClasses = {} -# self.isClosing = False + # Tuple of all paged-control classes + self.pagedControls = (dui.dPageFrame, dui.dPageList, dui.dPageSelect, + dui.dPageFrameNoTabs) self.MainFormClass = None self.setAppInfo("appName", "Class Designer") # Create the clipboard @@ -99,9 +102,6 @@ gsa["MaxDimension"] = atts["MaxDimension"] # Get rid of the update/refresh delays dabo.useUpdateDelays = False - # Tuple of all paged-control classes - self.pagedControls = (dui.dPageFrame, dui.dPageList, dui.dPageSelect, - dui.dPageFrameNoTabs) # Define the controls that can be added to the ClassDesigner. The @@ -451,6 +451,9 @@ if super: # We need to modify the info to incorporate the superclass info self._addInheritedInfo(dct, super) + # Store the base code so that we can determine if instances have + # modified it. + self._updateClassCodeRepository(super) return dct @@ -474,6 +477,25 @@ self._addInheritedInfo(kid, super) + def _updateClassCodeRepository(self, dct): + """Take a flattened dict of class IDs and store any code + associated with those IDs, so that we can later compare it to + an object's code in order to determine if it has been changed. + """ + cds = [(kk, vv["code"]) for kk, vv in dct.items() + if vv["code"]] + for cd in cds: + self._classCodeDict.update({cd[0]: cd[1]}) + + + def _getClassMethod(self, clsID, mthd): + """Given a class ID and a method name, returns the code for that + classID/method combination (if any) from self._classCodeDict. + """ + cd = self._classCodeDict.get(clsID, {}) + return cd.get(mthd, "") + + def _findSizerInClassDict(self, clsd): """Recursively search until a child is found with sizer information. If no such child is found, return False. @@ -2201,12 +2223,14 @@ obj.Panel2.Sizer = LayoutSizer("v") LayoutPanel(obj.Panel2) except AttributeError: pass - - if isPageControl: pgCls = obj.PageClass if isinstance(pgCls, basestring): # Saved class; let the control handle it obj.PageCount = pcount + # This is the key that marks it as a class, and not a base object. + prop = LayoutSaverMixin.classFlagProp + for pg in obj.Pages: + pg.__setattr__(prop, pgCls) pg0panel = obj.Pages[0] else: pgCtlCls = self.getControlClass(pgCls)
Modified: trunk/ClassDesignerComponents.py =================================================================== --- trunk/ClassDesignerComponents.py 2006-12-30 18:04:47 UTC (rev 728) +++ trunk/ClassDesignerComponents.py 2006-12-30 23:41:12 UTC (rev 729) @@ -111,7 +111,9 @@ and isinstance(self.Parent, dabo.ui.dSplitter)) desProps = self.DesignerProps.keys() if isinstance(self, dabo.ui.dForm) and hasattr(self, "UseSizers"): - desProps = desProps + ["UseSizers"] + desProps += ["UseSizers"] + elif isinstance(self, self.Controller.pagedControls) and isinstance(self.PageClass, basestring): + desProps += ["PageClass"] for prop in desProps: if prop.startswith("Sizer_"): continue
Modified: trunk/ClassDesignerControlMixin.py =================================================================== --- trunk/ClassDesignerControlMixin.py 2006-12-30 18:04:47 UTC (rev 728) +++ trunk/ClassDesignerControlMixin.py 2006-12-30 23:41:12 UTC (rev 729) @@ -141,14 +141,10 @@ tmpPgCls = cnt.getControlClass(dabo.ui.dPage) pg = self.insertPage(pos, tmpPgCls, ignoreOverride=True) classID = self._extractKey(atts, "classID", "") - - print "PAGE CLSID", pg.setPropertiesFromAtts(atts) pg.classID = classID prop = LayoutSaverMixin.classFlagProp pg.__setattr__(prop, pgCls) - - print pg.classID pth = dabo.lib.utils.relativePath(pgCls) pth = os.path.abspath(os.path.split(pth)[0]) cnt._basePath = pth
Modified: trunk/ClassDesignerEditor.py =================================================================== --- trunk/ClassDesignerEditor.py 2006-12-30 18:04:47 UTC (rev 728) +++ trunk/ClassDesignerEditor.py 2006-12-30 23:41:12 UTC (rev 729) @@ -220,6 +220,9 @@ if objCode: txt = objCode.get(mthd, "") if not txt: + if hasattr(obj, "classID"): + txt = self.Controller._getClassMethod(obj.classID, mthd) + if not txt: mvPointer = True if nonEvent is None: nonEvent = mthd not in self.Controller.getClassEvents(obj._baseClass) @@ -438,7 +441,7 @@ mthd = pg.method mb = self._getMethodBase(mthd, None) - isEmpty = (txt.strip() == "") or (txt in self._getMethodBase(mthd, None)) + isEmpty = (txt.strip() == "") or (txt in mb) obj = pg.object objCode = rep.get(obj) if isEmpty: @@ -456,6 +459,15 @@ # dabo.errorLog.write(_("Method '%s' of object '%s' has the following error: %s") # % (mthd, obj.Name, e)) # Add it to the repository. + + if hasattr(obj, "classID"): + # Make sure that it differs from the base code for this class. If not, + # don't save it. + cid = obj.classID + cb = self._getClassMethod(cid, mthd) + if txt.rstrip() == cb.rstrip(): + # Identical; store nothing + txt = "" if objCode: txt = self._extractImports(txt) objCode[mthd] = txt @@ -471,7 +483,13 @@ dabo.ui.setAfterInterval(4000, self, "StatusText", curr) + def _getClassMethod(self, clsID, mthd): + return self.Controller._getClassMethod(clsID, mthd) + + def _extractImports(self, cd): + if not cd: + return "" codeLines = cd.splitlines() for pos, ln in enumerate(codeLines): if ln.lstrip()[:4] == "def ": @@ -484,6 +502,10 @@ return ret + def _getCodeRepository(self): + return self.Controller.getCodeDict() + + def _getController(self): try: return self._controller @@ -498,10 +520,6 @@ self._properties["Controller"] = val - def _getCodeRepository(self): - return self.Controller.getCodeDict() - - CodeRepository = property(_getCodeRepository, None, None, _("""Reference to the Controller dictionary of all objects and their method code (dict)""") )
©2006 Ed Leafe |
|