Changeset 4151

Show
Ignore:
Timestamp:
06/17/08 16:53:07 (5 months ago)
Author:
ed
Message:

Modified the editor so that if you change the method name in the code, it is changed in the design. Thanks to Nate Lowrie for the suggestion.

Also added a 'check syntax' button that will do a quick compile of your code and catch errors. If an error is found, a dialog tells you what the error is, and the line containing the error is hilited.

Files:

Legend:

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

    r3800 r4151  
    130130        self._defaultWidth = 800 
    131131        self._defaultHeight = 260 
     132        self._methodNamePat = re.compile(r"^def ([^\(]+)\(") 
     133        self._syntaxLinePat = re.compile(r"([^\(]+) \(.*, line (\d+)\)") 
    132134 
    133135        self._objHierarchy = [] 
     
    137139 
    138140        dui.dLabel(pnl, Caption=_("Object:"), RegID="lblObj") 
    139         dui.dDropdownList(pnl, RegID="ddObject"
     141        dui.dDropdownList(pnl, RegID="ddObject", OnHit=self.onHitDDObject
    140142        dui.dLabel(pnl, Caption=_("Method:"), RegID="lblMethod") 
    141         dui.dDropdownList(pnl, RegID="ddMethod"
     143        dui.dDropdownList(pnl, RegID="ddMethod", OnHit=self.onHitDDMethod
    142144        hs = dui.dSizer("h", DefaultBorder=8, DefaultBorderTop=True, 
    143145                DefaultBorderBottom=True) 
     
    151153        hs.append(self.ddMethod, 0) 
    152154        hs.appendSpacer(4) 
    153         dui.dButton(pnl, Caption=_("super"), RegID="btnSuperCode", Enabled=False) 
    154         dui.dButton(pnl, Caption=_("New"), RegID="btnNewMethod") 
     155        dui.dBitmapButton(pnl, Picture="checkMark", RegID="btnCheckSyntax",  
     156                ToolTipText=_("Check Syntax"), OnHit=self.onCheckSyntax) 
     157        dui.dButton(pnl, Caption=_("super"), RegID="btnSuperCode", Enabled=False,  
     158                ToolTipText=_("Show Superclass Code"), OnHit=self.onSuperCode) 
     159        dui.dButton(pnl, Caption=_("New"), RegID="btnNewMethod",  
     160                ToolTipText=_("Create New Method"), OnHit=self.onNewMethod) 
     161        hs.append(self.btnCheckSyntax, 0, border=3, valign="middle") 
     162        hs.appendSpacer(4) 
    155163        hs.append(self.btnSuperCode, 0) 
    156164        hs.appendSpacer(8) 
     
    160168                valign="middle") 
    161169        hs.appendSpacer(8) 
    162         dui.dButton(pnl, Caption=_("Manage Imports"), RegID="btnImports") 
     170        dui.dButton(pnl, Caption=_("Manage Imports"), RegID="btnImports", 
     171                ToolTipText=_("Manage Class-wide imports"), OnHit=self.onManageImports) 
    163172        hs.append(self.btnImports, 0) 
    164173 
     
    286295        """Make sure that any changes are saved.""" 
    287296        self.updateText() 
    288          
    289          
    290     def onHit_ddObject(self, evt): 
     297 
     298 
     299    def onCheckSyntax(self, evt): 
     300        ed = self.editor 
     301        txt = ed.Value 
     302        try: 
     303            compile(txt.strip(), "", "exec") 
     304            dabo.ui.exclaim(_("No syntax errors found!"), _("Compilation Succeeded")) 
     305        except SyntaxError, e: 
     306            errMsg = "%s" % e 
     307            try: 
     308                msg, num = self._syntaxLinePat.findall(errMsg)[0] 
     309            except (ValueError, IndexError): 
     310                msg = errMsg 
     311                num = None 
     312            if num is not None: 
     313                num = int(num) 
     314                # Numbers are zero-based, so convert for display 
     315                disp = _("Error: %s\nLine: %s") % (msg, num) 
     316                ed.LineNumber = num-3 
     317                ed.showCurrentLine() 
     318                ed.hiliteLine(num-1) 
     319            else: 
     320                disp = msg 
     321            dabo.ui.stop(disp, _("Compilation Failed")) 
     322 
     323 
     324    def onHitDDObject(self, evt): 
    291325        self.refreshStatus() 
    292326 
    293327 
    294     def onHit_ddMethod(self, evt): 
     328    def onHitDDMethod(self, evt): 
    295329        self.updateText() 
    296330        dui.callAfter(self.setEditorCaption) 
     
    298332 
    299333 
    300     def onHit_btnSuperCode(self, evt): 
     334    def onSuperCode(self, evt): 
    301335        self.Controller.onShowSuper(self.ddObject.KeyValue.classID,  
    302336                self.ddMethod.StringValue) 
    303337     
    304338     
    305     def onHit_btnNewMethod(self, evt): 
     339    def onNewMethod(self, evt): 
    306340        nm = dabo.ui.getString(_("Name of method?")) 
    307341        if nm: 
     
    320354 
    321355 
    322     def onHit_btnImports(self, evt): 
     356    def onManageImports(self, evt): 
    323357        self.Controller.onDeclareImports(evt) 
    324358 
     
    453487        txt = ed.Value 
    454488        mthd = ed.Method 
    455  
    456489        mb = self._getMethodBase(mthd, None) 
    457490        isEmpty = (txt.strip() == "") or (txt in mb) 
     
    461494            # No code. Delete the key if it is found in the repository 
    462495            if objCode is not None: 
    463                 if objCode.has_key(mthd)
     496                try
    464497                    del objCode[mthd] 
    465         else: 
    466             # There is some text. First check if it is compilable, and 
    467             # display a message if it isn't. 
    468             # Maybe put this as a preference if they want continuous code checking? 
    469 #           try: 
    470 #               compile(txt.strip(), "", "exec") 
    471 #           except SyntaxError, e: 
    472 #               dabo.errorLog.write(_("Method '%s' of object '%s' has the following error: %s") 
    473 #                       % (mthd, obj.Name, e)) 
     498                except KeyError: 
     499                    # Method hadn't been stored yet; no biggie 
     500                    pass 
     501        else: 
     502            # There is some text. First make sure that the name of the method wasn't changed 
     503            try: 
     504                codeMthd = self._methodNamePat.match(txt).groups()[0] 
     505            except IndexError: 
     506                codeMthd = None 
     507            if codeMthd and (codeMthd != mthd): 
     508                if objCode is not None: 
     509                    try: 
     510                        del objCode[mthd] 
     511                    except KeyError: 
     512                        # Method hadn't been stored yet; no biggie 
     513                        pass 
     514                mthd = codeMthd 
     515 
    474516            # Add it to the repository. 
    475              
    476517            if hasattr(obj, "classID"): 
    477518                # Make sure that it differs from the base code for this class. If not,