From: Robin Dunn Date: Fri, 14 Jun 2002 23:28:54 +0000 (+0000) Subject: PyCrust update X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6fc4b6483fa12515df736d697db2f06d18264a09 PyCrust update git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15844 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/wxPython/wxPython/lib/PyCrust/filling.py b/wxPython/wxPython/lib/PyCrust/filling.py index 15c627ce60..b2ce11ced3 100644 --- a/wxPython/wxPython/lib/PyCrust/filling.py +++ b/wxPython/wxPython/lib/PyCrust/filling.py @@ -104,14 +104,18 @@ class FillingTree(wxTreeCtrl): self.setText('') return object = self.GetPyData(item) + otype = type(object) text = '' text += self.getFullName(item) - text += '\n\nType: ' + str(type(object)) - value = str(object) - if type(object) is types.StringType: - value = repr(value) + text += '\n\nType: ' + str(otype) + try: + value = str(object) + except: + value = '' + if otype is types.StringType or otype is types.UnicodeType: + value = repr(object) text += '\n\nValue: ' + value - if type(object) is types.InstanceType: + if otype is types.InstanceType: try: text += '\n\nClass Definition:\n\n' + \ inspect.getsource(object.__class__) diff --git a/wxPython/wxPython/lib/PyCrust/introspect.py b/wxPython/wxPython/lib/PyCrust/introspect.py index bcb4fa31a1..d568dc6c6f 100644 --- a/wxPython/wxPython/lib/PyCrust/introspect.py +++ b/wxPython/wxPython/lib/PyCrust/introspect.py @@ -74,8 +74,13 @@ def getAllAttributeNames(object): # !!! Do Not use hasattr() as a test anywhere in this function, # !!! because it is unreliable with remote objects - xmlrpc, soap, etc. # !!! They always return true for hasattr(). - # !!! - key = str(object) + # !!! + try: + # Yes, this can fail if object is an instance of a class with + # __str__ (or __repr__) having a bug or raising an exception. :-( + key = str(object) + except: + key = 'anonymous' # Wake up sleepy objects - a hack for ZODB objects in "ghost" state. wakeupcall = dir(object) del wakeupcall diff --git a/wxPython/wxPython/lib/PyCrust/shell.py b/wxPython/wxPython/lib/PyCrust/shell.py index 65d7c00aef..e5105389d8 100644 --- a/wxPython/wxPython/lib/PyCrust/shell.py +++ b/wxPython/wxPython/lib/PyCrust/shell.py @@ -176,6 +176,8 @@ class Shell(wxStyledTextCtrl): # Assign handlers for keyboard events. EVT_KEY_DOWN(self, self.OnKeyDown) EVT_CHAR(self, self.OnChar) + # Assign handlers for wxSTC events. + EVT_STC_UPDATEUI(self, id, self.OnUpdateUI) # Configure various defaults and user preferences. self.config() # Display the introductory banner information. @@ -291,6 +293,37 @@ class Shell(wxStyledTextCtrl): self.StyleSetSpec(wxSTC_P_COMMENTBLOCK, "fore:#7F7F7F") self.StyleSetSpec(wxSTC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eolfilled" % faces) + def OnUpdateUI(self, evt): + """Check for matching braces.""" + braceAtCaret = -1 + braceOpposite = -1 + charBefore = None + caretPos = self.GetCurrentPos() + if caretPos > 0: + charBefore = self.GetCharAt(caretPos - 1) + styleBefore = self.GetStyleAt(caretPos - 1) + + # Check before. + if charBefore and chr(charBefore) in '[]{}()' \ + and styleBefore == wxSTC_P_OPERATOR: + braceAtCaret = caretPos - 1 + + # Check after. + if braceAtCaret < 0: + charAfter = self.GetCharAt(caretPos) + styleAfter = self.GetStyleAt(caretPos) + if charAfter and chr(charAfter) in '[]{}()' \ + and styleAfter == wxSTC_P_OPERATOR: + braceAtCaret = caretPos + + if braceAtCaret >= 0: + braceOpposite = self.BraceMatch(braceAtCaret) + + if braceAtCaret != -1 and braceOpposite == -1: + self.BraceBadLight(braceAtCaret) + else: + self.BraceHighlight(braceAtCaret, braceOpposite) + def OnChar(self, event): """Keypress event handler.