From 8c0064a3230629ab1ff1c5240179922f645b8715 Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Thu, 25 Sep 2014 11:58:49 -0400 Subject: [PATCH] DataTreeWidget uses TableWidget to represent arrays --- examples/DataTreeWidget.py | 2 +- pyqtgraph/widgets/DataTreeWidget.py | 34 ++++++++++------------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/examples/DataTreeWidget.py b/examples/DataTreeWidget.py index 8365db2a..2c2b00f9 100644 --- a/examples/DataTreeWidget.py +++ b/examples/DataTreeWidget.py @@ -19,7 +19,7 @@ d = { 'y': 2, 'z': 'three' }, - 'array1 (20x20)': np.ones((10,10)) + 'array1 (40x10)': np.random.randint(10, size=(40,10)) } tree = pg.DataTreeWidget(data=d) diff --git a/pyqtgraph/widgets/DataTreeWidget.py b/pyqtgraph/widgets/DataTreeWidget.py index 29e60319..b8215b06 100644 --- a/pyqtgraph/widgets/DataTreeWidget.py +++ b/pyqtgraph/widgets/DataTreeWidget.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from ..Qt import QtGui, QtCore from ..pgcollections import OrderedDict +from .TableWidget import TableWidget import types, traceback import numpy as np @@ -29,12 +30,8 @@ class DataTreeWidget(QtGui.QTreeWidget): def setData(self, data, hideRoot=False): """data should be a dictionary.""" self.clear() + self.tables = [] self.buildTree(data, self.invisibleRootItem(), hideRoot=hideRoot) - #node = self.mkNode('', data) - #while node.childCount() > 0: - #c = node.child(0) - #node.removeChild(c) - #self.invisibleRootItem().addChild(c) self.expandToDepth(3) self.resizeColumnToContents(0) @@ -62,22 +59,15 @@ class DataTreeWidget(QtGui.QTreeWidget): elif isinstance(data, list) or isinstance(data, tuple): for i in range(len(data)): self.buildTree(data[i], node, str(i)) + elif isinstance(data, np.ndarray): + desc = "<%s shape=%s dtype=%s>" % (data.__class__.__name__, data.shape, data.dtype) + node.setText(2, desc) + subnode = QtGui.QTreeWidgetItem(["", "", ""]) + node.addChild(subnode) + table = TableWidget() + table.setData(data) + table.setMaximumHeight(200) + self.setItemWidget(subnode, 2, table) + self.tables.append(table) else: node.setText(2, str(data)) - - - #def mkNode(self, name, v): - #if type(v) is list and len(v) > 0 and isinstance(v[0], dict): - #inds = map(unicode, range(len(v))) - #v = OrderedDict(zip(inds, v)) - #if isinstance(v, dict): - ##print "\nadd tree", k, v - #node = QtGui.QTreeWidgetItem([name]) - #for k in v: - #newNode = self.mkNode(k, v[k]) - #node.addChild(newNode) - #else: - ##print "\nadd value", k, str(v) - #node = QtGui.QTreeWidgetItem([unicode(name), unicode(v)]) - #return node -