Esempio n. 1
0
 def default(self, cell):
     o = wrapply(cell.col.getTypedValue, cell.row)
     if isinstance(o, TypedExceptionWrapper):
         return self.safe_error or str(o.exception)
     elif isinstance(o, TypedWrapper):
         return o.val
     elif isinstance(o, date):
         return cell.col.getDisplayValue(cell.row)
     return o
Esempio n. 2
0
def save_dot(vd, p, vs):
    unusedColors = 'orange green purple cyan red blue black'.split()
    assignedColors = {}

    srccol = vs.keyCols[0]
    dstcol = vs.keyCols[1]
    with p.open_text(mode='w') as fp:
        print('graph { concentrate=true;', file=fp)
        for row in Progress(vs.rows, 'saving'):
            src = srccol.getTypedValue(row)
            dst = dstcol.getTypedValue(row)
            if not is_valid(src) or not is_valid(dst):
                continue

            downsrc = clean_to_id(str(src)) or src
            downdst = clean_to_id(str(dst)) or dst
            edgenotes = [
                c.getTypedValue(row) for c in vs.nonKeyVisibleCols
                if not isNumeric(c)
            ]
            edgetype = '-'.join(str(x) for x in edgenotes if is_valid(x))
            color = assignedColors.get(edgetype, None)
            if not color:
                color = unusedColors.pop() if unusedColors else 'black'
                assignedColors[edgetype] = color

            if options.graphviz_edge_labels:
                nodelabels = [
                    wrapply(SI, c.getTypedValue(row))
                    for c in vs.nonKeyVisibleCols if isNumeric(c)
                ]
                label = '/'.join(str(x) for x in nodelabels if is_valid(x))
            else:
                label = ''
            print('\t%s[label="%s"];' % (downsrc, src), file=fp)
            print('\t%s[label="%s"];' % (downdst, dst), file=fp)
            print('\t%s -- %s[label="%s", color=%s];' %
                  (downsrc, downdst, label, color),
                  file=fp)

        print('label="%s"' % vs.name, file=fp)
        print('node[shape=plaintext];', file=fp)
        print('subgraph cluster_legend {', file=fp)
        print('label="Legend";', file=fp)
        for i, (k, color) in enumerate(assignedColors.items()):
            print('key%d[label="%s", fontcolor=%s];' % (i, k, color), file=fp)

        print('}', file=fp)  # legend subgraph
        print('}', file=fp)
Esempio n. 3
0
 def reload(self):
     self.rows = sorted(colors.keys(), key=lambda n: wrapply(int, n))
Esempio n. 4
0
    def getCell(self, row):
        'Return DisplayWrapper for displayable cell value.'
        cellval = wrapply(self.getValue, row)
        typedval = wrapply(self.type, cellval)

        if isinstance(typedval, TypedWrapper):
            if isinstance(cellval, TypedExceptionWrapper):  # calc failed
                exc = cellval.exception
                if cellval.forwarded:
                    dispval = str(
                        cellval
                    )  # traceback.format_exception_only(type(exc), exc)[-1].strip()
                else:
                    dispval = options.disp_error_val
                return DisplayWrapper(cellval.val,
                                      error=exc.stacktrace,
                                      display=dispval,
                                      note=options.note_getter_exc,
                                      notecolor='color_error')
            elif typedval.val is None:  # early out for strict None
                return DisplayWrapper(
                    None,
                    display='',  # force empty display for None
                    note=options.disp_note_none,
                    notecolor='color_note_type')
            elif isinstance(
                    typedval,
                    TypedExceptionWrapper):  # calc succeeded, type failed
                return DisplayWrapper(typedval.val,
                                      display=str(cellval),
                                      error=typedval.stacktrace,
                                      note=options.note_type_exc,
                                      notecolor='color_warning')
            else:
                return DisplayWrapper(typedval.val,
                                      display=str(typedval.val),
                                      error='unknown',
                                      note=options.note_type_exc,
                                      notecolor='color_warning')

        elif isinstance(typedval, threading.Thread):
            return DisplayWrapper(None,
                                  display=options.disp_pending,
                                  note=options.note_pending,
                                  notecolor='color_note_pending')

        dw = DisplayWrapper(cellval)

        try:
            dw.display = self.format(typedval) or ''

            # annotate cells with raw value type in anytype columns, except for strings
            if self.type is anytype and type(cellval) is not str:
                typedesc = typemap.get(type(cellval), None)
                if typedesc:
                    dw.note = typedesc.icon
                    dw.notecolor = 'color_note_type'

        except Exception as e:  # formatting failure
            e.stacktrace = stacktrace()
            dw.error = e.stacktrace
            try:
                dw.display = str(cellval)
            except Exception as e:
                dw.display = str(e)
            dw.note = options.note_format_exc
            dw.notecolor = 'color_warning'

        return dw
Esempio n. 5
0
 def _calcIntoCache(self, row):
     ret = wrapply(self.calcValue, row)
     if not isinstance(ret,
                       TypedExceptionWrapper) or ret.val is not INPROGRESS:
         self._cachedValues[self.sheet.rowid(row)] = ret
     return ret
Esempio n. 6
0
 def getTypedValue(self, row):
     'Returns the properly-typed value for the given row at this column, or a TypedWrapper object.'
     return wrapply(self.type, wrapply(self.getValue, row))