Changeset 4122

Show
Ignore:
Timestamp:
06/08/08 09:45:28 (6 months ago)
Author:
ed
Message:

Changed the idiom that uses has_key() to try/except KeyError?.

Optimized the performance of the evtsForClass() method.

Added properties to labels, panels, html controls and scroll panels.

Added workaround for trailing period oddity on Mac OS X and file names.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ide/ClassDesigner.py

    r4085 r4122  
    354354 
    355355        def evtsForClass(cls): 
    356             ret = [] 
    357             for kk, vv in dEvents.__dict__.items(): 
    358                 if kk in baseEvents: 
    359                     # These are superclasses of individual events. 
    360                     continue 
     356            def safeApplies(itm, cls): 
    361357                try: 
    362                     if vv.appliesToClass(cls): 
    363                         ret.append("on%s" % kk) 
    364                 except: 
    365                     pass 
     358                    return itm.appliesToClass(cls) 
     359                except (AttributeError, NameError): 
     360                    return False 
     361            ret = ["on%s" % k for k,v in dEvents.__dict__.items()  
     362                    if safeApplies(v,cls)] 
    366363            ret.sort() 
    367364            return ret 
     
    808805                slots = int(self._extractKey(atts, "SlotCount", "1")) 
    809806                useBox, boxCaption = None, None 
     807#               defSpacing = int(self._extractKey(atts, "DefaultSpacing", "0")) 
    810808                if clsname == "LayoutBorderSizer": 
    811809                    useBox = True 
     
    815813                szCont = sz.ControllingSizer 
    816814                itm = sz.ControllingSizerItem 
    817  
     815#               if defSpacing: 
     816#                   # Need to set this *after* the design has been created, or else 
     817#                   # it will create non-Designer spacers that will confuse things. 
     818#                   def setLater(sz, spc): 
     819#                       sz.DefaultSpacing = spc 
     820#                   dabo.ui.callAfter(setLater, sz, defSpacing) 
    818821                is2D = isinstance(szCont, dabo.ui.dGridSizer) 
    819822                defaults = {True: szItemDefaults[2], 
     
    20482051                if adding: 
    20492052                    prop = data["propName"] 
    2050                 if not self._classPropDict.has_key(obj): 
     2053                try: 
     2054                    self._classPropDict.["obj"] 
     2055                except KeyError: 
    20512056                    self._classPropDict[obj] = {} 
    20522057                # Make sure that there are no single quotes in the comment 
     
    25332538            props["ColumnClass"] = self.getControlClass(dui.dColumn) 
    25342539            newCols = None 
    2535             if not props.has_key("ColumnCount"): 
     2540            try: 
     2541                props["ColumnCount"] 
     2542            except KeyError: 
    25362543                try: 
    25372544                    newCols = int(dui.getString(_("How many columns?"), 
    25382545                            _("New Grid Control"), "3")) 
    2539                 except
     2546                except ValueError
    25402547                    newCols = 3 
    25412548 
  • trunk/ide/ClassDesignerComponents.py

    r4106 r4122  
    178178            # If it hasn't changed from the default, skip it 
    179179            if not allProps: 
    180                 if defVals.has_key(prop): 
    181                     if prop not in propsToInclude: 
    182                         dv = defVals[prop] 
    183                         if not isinstance(val, basestring) and isinstance(dv, basestring): 
    184                             # Try to convert 
    185                             if isinstance(val, bool): 
    186                                 dv = (dv.lower() == "true") 
    187                             elif isinstance(val, int): 
    188                                 dv = int(dv) 
    189                             elif isinstance(val, long): 
    190                                 dv = long(dv) 
    191                             elif isinstance(val, float): 
    192                                 dv = float(dv) 
    193                             elif isinstance(val, (list, tuple, dict)): 
    194                                 dv = eval(dv) 
    195                             elif dv == "None": 
    196                                 dv = None 
    197                         if dv == val: 
    198                             continue 
     180                try: 
     181                    defVals[prop] 
     182                except KeyError: 
     183                    continue 
     184                if prop not in propsToInclude: 
     185                    dv = defVals[prop] 
     186                    if not isinstance(val, basestring) and isinstance(dv, basestring): 
     187                        # Try to convert 
     188                        if isinstance(val, bool): 
     189                            dv = (dv.lower() == "true") 
     190                        elif isinstance(val, int): 
     191                            dv = int(dv) 
     192                        elif isinstance(val, long): 
     193                            dv = long(dv) 
     194                        elif isinstance(val, float): 
     195                            dv = float(dv) 
     196                        elif isinstance(val, (list, tuple, dict)): 
     197                            dv = eval(dv) 
     198                        elif dv == "None": 
     199                            dv = None 
     200                    if dv == val: 
     201                        continue 
    199202 
    200203            if isinstance(val, basestring): 
  • trunk/ide/ClassDesignerControlMixin.py

    r4085 r4122  
    746746        imageProps = {"ScaleMode" : {"type" : list, "readonly" : False, 
    747747                    "values" : ["Clip", "Proportional", "Stretch"]}} 
     748        labelProps = {"AutoResize": {"type" : bool, "readonly" : False}} 
    748749        multiSelectProps = {"MultipleSelect": {"type" : bool, "readonly" : False}} 
    749750        nodeProps = {"Image": {"type" : "path", "readonly" : False,  
    750751                    "customEditor": "editStdPicture"}} 
    751         panelProps = {"Buffered" : {"type" : bool, "readonly" : False}, 
    752                 "AlwaysResetSizer": {"type" : bool, "readonly" : False}} 
     752        panelProps = {"AlwaysResetSizer": {"type" : bool, "readonly" : False}, 
     753                "Buffered" : {"type" : bool, "readonly" : False}, 
     754                "MinSizerHeight": {"type" : int, "readonly" : False}, 
     755                "MinSizerWidth": {"type" : int, "readonly" : False}} 
    753756        pictureProps = {"Picture": {"type" : "path", "readonly" : False,  
    754757                    "customEditor": "editStdPicture"}} 
     
    792795                    "values" : ["Upper", "Lower", "Title", "None"]},         
    793796                "ReadOnly" : {"type" : bool, "readonly" : False}} 
    794         htmlTextProps = {"HorizontalScroll": {"type" : bool, "readonly" : False}, 
    795                 "Page": {"type" : unicode, "readonly" : False}, 
     797        htmlTextProps = {"Page": {"type" : unicode, "readonly" : False}, 
    796798                "RespondToLinks": {"type" : bool, "readonly" : False}, 
    797799                "ShowScrollBars": {"type" : bool, "readonly" : False}, 
     800                "Source": {"type" : unicode, "readonly" : False}} 
     801        scrollProps = {"HorizontalScroll": {"type" : bool, "readonly" : False}, 
    798802                "VerticalScroll": {"type" : bool, "readonly" : False}} 
    799803        treeProps = {"Editable" : {"type" : bool, "readonly" : False}, 
     
    883887            ret.update(imageProps) 
    884888        elif isinstance(self, dabo.ui.dLabel): 
     889            ret.update(labelProps) 
    885890            ret.update(colorProps) 
    886891            ret.update(captionProps) 
     
    942947        elif isinstance(self, dabo.ui.dScrollPanel): 
    943948            ret.update(panelProps) 
     949            ret.update(scrollProps) 
    944950            ret.update(colorProps) 
    945951        elif isinstance(self, dabo.ui.dPanel): 
     
    967973        elif isinstance(self, dabo.ui.dHtmlBox): 
    968974            ret.update(htmlTextProps) 
     975            ret.update(scrollProps) 
    969976        elif isinstance(self, dabo.ui.dTimer): 
    970977            pass 
  • trunk/ide/ClassDesignerFormMixin.py

    r3800 r4122  
    449449                    return 
    450450                else: 
    451                     if not os.path.splitext(self._classFile)[1] == ".cdxml": 
     451                    self._classFile = self._classFile.rstrip(".") 
     452                    if not self._classFile.endswith(".cdxml"): 
    452453                        self._classFile += ".cdxml" 
    453454            fname = self._classFile 
     
    484485        # IOErrorrror that the calling method can catch. 
    485486        open(fname, "wb").write(xml) 
    486         if not singleFile: 
    487             # Now write out the code file 
    488             cfName = "%s-code.py" % os.path.splitext(fname)[0] 
     487        cfName = "%s-code.py" % os.path.splitext(fname)[0] 
     488        if singleFile: 
     489            # Delete the code file if present. 
     490            if os.path.exists(cfName): 
     491                os.remove(cfName) 
     492        else: 
     493            # Write out the code file 
    489494            open(cfName, "wb").write(self._createDesignerCode(codeDict)) 
    490495        if currForm: 
     
    10021007        if ctl is None: 
    10031008            return 
    1004         if self.handles.has_key(ctl)
     1009        try
    10051010            hnd = self.handles[ctl] 
    1006            for nm,h in hnd.items()
    1007                h.Visible = False 
    1008                if release
    1009                    h.release() 
     1011        except KeyError
     1012            return 
     1013        for nm,h in hnd.items()
     1014            h.Visible = False 
    10101015            if release: 
    1011                 del self.handles[ctl] 
     1016                h.release() 
     1017        if release: 
     1018            del self.handles[ctl] 
    10121019 
    10131020 
  • trunk/ide/ClassDesignerPropSheet.py

    r3851 r4122  
    319319            dabo.ui.stop(_("Could not set property '%s' to value '%s'\nReason: '%s'")  
    320320                    % (prop, val, e)) 
    321             self.updateGridValues()         
     321            self.updateGridValues()  
    322322 
    323323