Changeset 4673:68c7d0621474 in orange


Ignore:
Timestamp:
05/19/08 08:02:23 (6 years ago)
Author:
gregor <gregor@…>
Branch:
default
Convert:
4ec3eaee3dcb7cb82518932256835bae02d7f2b7
Message:
  • nicer output of exceptions
  • don't replace <> with () anymore
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/OrangeCanvas/orngOutput.py

    r4605 r4673  
    9595    # simple printing of text called by print calls 
    9696    def write(self, text): 
    97         text = str(text) 
    98         text = text.replace("<", "(").replace(">", ")")    # since this is rich text control, we have to replace special characters 
    99         text = text.replace("(br)", "<br>") 
    100         text = text.replace("(nobr)", "<nobr>").replace("(/nobr)", "</nobr>") 
    101         text = text.replace("(b)", "<b>").replace("(/b)", "</b>") 
    102         text = text.replace("(i)", "<i>").replace("(/i)", "</i>") 
    103         text = text.replace("(hr)", "<hr>") 
     97        text = self.getSafeString(text) 
    10498        text = text.replace("\n", "<br>\n")   # replace new line characters with <br> otherwise they don't get shown correctly in html output 
    10599        #text = "<nobr>" + text + "</nobr>" 
     
    133127            self.textOutput.copy() 
    134128 
     129    def getSafeString(self, s): 
     130        return str(s).replace("<", "&lt;").replace(">", "&gt;") 
     131 
    135132    def exceptionHandler(self, type, value, tracebackInfo): 
    136133        if self.focusOnCatchException: 
     
    140137        text = "" 
    141138        t = localtime() 
    142         text += "<hr><nobr>Unhandled exception of type <b>%s </b> occured at %d:%02d:%02d:</nobr><br><nobr>Traceback:</nobr><br>" % ( str(type).replace("<", "(").replace(">", ")") , t[3],t[4],t[5]) 
     139        text += "<hr><nobr>Unhandled exception of type %s occured at %d:%02d:%02d:</nobr><br><nobr>Traceback:</nobr><br>\n" % ( self.getSafeString(type.__name__), t[3],t[4],t[5]) 
    143140 
    144141        if self.printException: 
     
    147144        # TO DO:repair this code to shown full traceback. when 2 same errors occur, only the first one gets full traceback, the second one gets only 1 item 
    148145        list = traceback.extract_tb(tracebackInfo, 10) 
    149         space = "&nbsp &nbsp " 
     146        space = "&nbsp; " 
    150147        totalSpace = space 
    151148        for i in range(len(list)): 
     
    153150            if code == None: continue 
    154151            (dir, filename) = os.path.split(file) 
    155             text += "<nobr>" + totalSpace + "File: <u>" + filename + "</u>  in line %4d</nobr><br>" %(line) 
    156             text += "<nobr>" + totalSpace + "<nobr>Function name: %s</nobr><br>" % (funct) 
    157             if i == len(list)-1: 
    158                 text += "<nobr>" + totalSpace + "Code: <b>" + code + "</b></nobr><br>" 
    159             else: 
    160                 text += "<nobr>" + totalSpace + "Code: " + code + "</nobr><br>" 
    161                 totalSpace += space 
     152            text += "<nobr>" + totalSpace + "File: <b>" + filename + "</b>, line %4d" %(line) + " in <b>%s</b></nobr><br>\n" % (self.getSafeString(funct)) 
     153            text += "<nobr>" + totalSpace + "Code: " + code + "</nobr><br>\n" 
     154            totalSpace += space 
    162155 
    163         value = str(value).replace("<", "(").replace(">", ")")    # since this is rich text control, we have to replace special characters 
    164         text += "<nobr>" + totalSpace + "Exception type: <b>" + str(type).replace("<", "(").replace(">", ")") + "</b></nobr><br>" 
    165         text += "<nobr>" + totalSpace + "Exception value: <b>" + value+ "</b></nobr><br><hr>" 
     156        lines = traceback.format_exception_only(type, value) 
     157        for line in lines[:-1]: 
     158            text += "<nobr>" + totalSpace + self.getSafeString(line) + "</nobr><br>\n" 
     159        text += "<nobr><b>" + totalSpace + self.getSafeString(lines[-1]) + "</b></nobr><br>\n" 
     160         
     161        text += "<hr>\n" 
    166162        self.textOutput.setText(str(self.textOutput.text()) + text) 
    167163        self.textOutput.ensureVisible(0, self.textOutput.contentsHeight()) 
Note: See TracChangeset for help on using the changeset viewer.