From ee0825d677977cfdee39729fec9112bc1fe92b7b Mon Sep 17 00:00:00 2001 From: Luke Campagnola Date: Wed, 22 May 2013 14:35:14 -0400 Subject: [PATCH] Allow custom ItemSamples in LegendItem. --- pyqtgraph/graphicsItems/LegendItem.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/pyqtgraph/graphicsItems/LegendItem.py b/pyqtgraph/graphicsItems/LegendItem.py index e2484ecf..a2fc0e04 100644 --- a/pyqtgraph/graphicsItems/LegendItem.py +++ b/pyqtgraph/graphicsItems/LegendItem.py @@ -63,21 +63,23 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): =========== ======================================================== Arguments item A PlotDataItem from which the line and point style - of the item will be determined + of the item will be determined or an instance of + ItemSample (or a subclass), allowing the item display + to be customized. title The title to display for this item. Simple HTML allowed. =========== ======================================================== """ label = LabelItem(name) - sample = ItemSample(item) + if isinstance(item, ItemSample): + sample = item + else: + sample = ItemSample(item) row = len(self.items) self.items.append((sample, label)) self.layout.addItem(sample, row, 0) self.layout.addItem(label, row, 1) self.updateSize() - # - # - # Ulrich def removeItem(self, name): """ Removes one item from the legend. @@ -87,6 +89,7 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): title The title displayed for this item. =========== ======================================================== """ + # Thanks, Ulrich! # cycle for a match for sample, label in self.items: print label.text, name @@ -98,12 +101,6 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor): label.close() self.updateSize() # redraq box - # hcirlU - # - # - - - def updateSize(self): if self.size is not None: