Changeset 4151
- Timestamp:
- 06/17/08 16:53:07 (5 months ago)
- Files:
-
- trunk/ide/ClassDesignerEditor.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ide/ClassDesignerEditor.py
r3800 r4151 130 130 self._defaultWidth = 800 131 131 self._defaultHeight = 260 132 self._methodNamePat = re.compile(r"^def ([^\(]+)\(") 133 self._syntaxLinePat = re.compile(r"([^\(]+) \(.*, line (\d+)\)") 132 134 133 135 self._objHierarchy = [] … … 137 139 138 140 dui.dLabel(pnl, Caption=_("Object:"), RegID="lblObj") 139 dui.dDropdownList(pnl, RegID="ddObject" )141 dui.dDropdownList(pnl, RegID="ddObject", OnHit=self.onHitDDObject) 140 142 dui.dLabel(pnl, Caption=_("Method:"), RegID="lblMethod") 141 dui.dDropdownList(pnl, RegID="ddMethod" )143 dui.dDropdownList(pnl, RegID="ddMethod", OnHit=self.onHitDDMethod) 142 144 hs = dui.dSizer("h", DefaultBorder=8, DefaultBorderTop=True, 143 145 DefaultBorderBottom=True) … … 151 153 hs.append(self.ddMethod, 0) 152 154 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) 155 163 hs.append(self.btnSuperCode, 0) 156 164 hs.appendSpacer(8) … … 160 168 valign="middle") 161 169 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) 163 172 hs.append(self.btnImports, 0) 164 173 … … 286 295 """Make sure that any changes are saved.""" 287 296 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): 291 325 self.refreshStatus() 292 326 293 327 294 def onHit _ddMethod(self, evt):328 def onHitDDMethod(self, evt): 295 329 self.updateText() 296 330 dui.callAfter(self.setEditorCaption) … … 298 332 299 333 300 def on Hit_btnSuperCode(self, evt):334 def onSuperCode(self, evt): 301 335 self.Controller.onShowSuper(self.ddObject.KeyValue.classID, 302 336 self.ddMethod.StringValue) 303 337 304 338 305 def on Hit_btnNewMethod(self, evt):339 def onNewMethod(self, evt): 306 340 nm = dabo.ui.getString(_("Name of method?")) 307 341 if nm: … … 320 354 321 355 322 def on Hit_btnImports(self, evt):356 def onManageImports(self, evt): 323 357 self.Controller.onDeclareImports(evt) 324 358 … … 453 487 txt = ed.Value 454 488 mthd = ed.Method 455 456 489 mb = self._getMethodBase(mthd, None) 457 490 isEmpty = (txt.strip() == "") or (txt in mb) … … 461 494 # No code. Delete the key if it is found in the repository 462 495 if objCode is not None: 463 if objCode.has_key(mthd):496 try: 464 497 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 474 516 # Add it to the repository. 475 476 517 if hasattr(obj, "classID"): 477 518 # Make sure that it differs from the base code for this class. If not,
