def toDisplayText(value, sep=", "): if value in (None, False, "undefined"): return "" elif value is True: return "on" elif isinstance(value, datetime.date): try: return value.strftime("%Y-%m-%d %H:%M") except ValueError: return "" elif isinstance(value, MemSize): return "{0:.2cM}".format(value) elif isinstance(value, basestring): return toUnicode(value) elif isIterable(value): return sep.join((toDisplayText(v, sep) for v in value)) else: return toUnicode(value)
def __init__(self, *args, **kwargs): flags = kwargs.pop("flags", None) roles = kwargs.pop("roles", None) super(QuickTreeItem, self).__init__(*args, **kwargs) treeWidget = self.treeWidget() flags = flags if flags is not None else treeWidget.defaultFlags if flags is not None: self.setFlags(flags) defaultRoles = treeWidget.defaultRoles if roles is None: roles = defaultRoles.copy() elif defaultRoles: roles.update((k, v) for k, v in defaultRoles.iteritems() if k not in roles) if roles: for role, args in roles.iteritems(): column, value = args if isIterable(column): for c in column: self.setData(c, role, value) else: self.setData(column, role, value)
def toEditText(value, sep=", "): if value is None: return "" elif isinstance(value, basestring): return toUnicode(value) elif isinstance(value, bool): return toUnicode(int(value)) elif isIterable(value): return sep.join((toEditText(v, sep) for v in value)) else: return toUnicode(value)