Merge pull request #1382 from dgoeries/code-quality-legend
LegendItem: A bit auto flake8
This commit is contained in:
commit
4946a57987
@ -8,6 +8,7 @@ from .ScatterPlotItem import ScatterPlotItem, drawSymbol
|
|||||||
from .PlotDataItem import PlotDataItem
|
from .PlotDataItem import PlotDataItem
|
||||||
from .GraphicsWidgetAnchor import GraphicsWidgetAnchor
|
from .GraphicsWidgetAnchor import GraphicsWidgetAnchor
|
||||||
from .BarGraphItem import BarGraphItem
|
from .BarGraphItem import BarGraphItem
|
||||||
|
|
||||||
__all__ = ['LegendItem']
|
__all__ = ['LegendItem']
|
||||||
|
|
||||||
|
|
||||||
@ -25,8 +26,10 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
|||||||
legend.setParentItem(plotItem)
|
legend.setParentItem(plotItem)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, size=None, offset=None, horSpacing=25, verSpacing=0, pen=None,
|
|
||||||
brush=None, labelTextColor=None, frame=True, rowCount=1, colCount=1, **kwargs):
|
def __init__(self, size=None, offset=None, horSpacing=25, verSpacing=0,
|
||||||
|
pen=None, brush=None, labelTextColor=None, frame=True,
|
||||||
|
rowCount=1, colCount=1, **kwargs):
|
||||||
"""
|
"""
|
||||||
============== ===============================================================
|
============== ===============================================================
|
||||||
**Arguments:**
|
**Arguments:**
|
||||||
@ -160,7 +163,8 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
|||||||
title The title to display for this item. Simple HTML allowed.
|
title The title to display for this item. Simple HTML allowed.
|
||||||
============== ========================================================
|
============== ========================================================
|
||||||
"""
|
"""
|
||||||
label = LabelItem(name, color=self.opts['labelTextColor'], justify='left')
|
label = LabelItem(name, color=self.opts['labelTextColor'],
|
||||||
|
justify='left')
|
||||||
if isinstance(item, ItemSample):
|
if isinstance(item, ItemSample):
|
||||||
sample = item
|
sample = item
|
||||||
else:
|
else:
|
||||||
@ -189,9 +193,8 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
|||||||
self.layout.addItem(label, row, col + 1)
|
self.layout.addItem(label, row, col + 1)
|
||||||
|
|
||||||
def setColumnCount(self, columnCount):
|
def setColumnCount(self, columnCount):
|
||||||
'''
|
"""change the orientation of all items of the legend
|
||||||
change the orientation of all items of the legend
|
"""
|
||||||
'''
|
|
||||||
if columnCount != self.columnCount:
|
if columnCount != self.columnCount:
|
||||||
self.columnCount = columnCount
|
self.columnCount = columnCount
|
||||||
self.rowCount = int(len(self.items) / columnCount)
|
self.rowCount = int(len(self.items) / columnCount)
|
||||||
@ -202,17 +205,18 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
|||||||
self.updateSize()
|
self.updateSize()
|
||||||
|
|
||||||
def getLabel(self, plotItem):
|
def getLabel(self, plotItem):
|
||||||
"""
|
"""Return the labelItem inside the legend for a given plotItem
|
||||||
return the labelItem inside the legend for a given plotItem
|
|
||||||
the label-text can be changed via labenItem.setText
|
The label-text can be changed via labenItem.setText
|
||||||
"""
|
"""
|
||||||
out = [(it, lab) for it, lab in self.items if it.item == plotItem]
|
out = [(it, lab) for it, lab in self.items if it.item == plotItem]
|
||||||
try: return out[0][1]
|
try:
|
||||||
except IndexError: return None
|
return out[0][1]
|
||||||
|
except IndexError:
|
||||||
|
return None
|
||||||
|
|
||||||
def removeItem(self, item):
|
def removeItem(self, item):
|
||||||
"""
|
"""Removes one item from the legend.
|
||||||
Removes one item from the legend.
|
|
||||||
|
|
||||||
============== ========================================================
|
============== ========================================================
|
||||||
**Arguments:**
|
**Arguments:**
|
||||||
@ -278,11 +282,12 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
|||||||
|
|
||||||
|
|
||||||
class ItemSample(GraphicsWidget):
|
class ItemSample(GraphicsWidget):
|
||||||
""" Class responsible for drawing a single item in a LegendItem (sans label).
|
"""Class responsible for drawing a single item in a LegendItem (sans label)
|
||||||
|
|
||||||
This may be subclassed to draw custom graphics in a Legend.
|
This may be subclassed to draw custom graphics in a Legend.
|
||||||
"""
|
"""
|
||||||
## Todo: make this more generic; let each item decide how it should be represented.
|
|
||||||
|
# TODO: make this more generic; let items decide how it should be look.
|
||||||
def __init__(self, item):
|
def __init__(self, item):
|
||||||
GraphicsWidget.__init__(self)
|
GraphicsWidget.__init__(self)
|
||||||
self.item = item
|
self.item = item
|
||||||
@ -300,18 +305,21 @@ class ItemSample(GraphicsWidget):
|
|||||||
p.setPen(fn.mkPen(opts['pen']))
|
p.setPen(fn.mkPen(opts['pen']))
|
||||||
p.drawLine(0, 11, 20, 11)
|
p.drawLine(0, 11, 20, 11)
|
||||||
|
|
||||||
if opts.get('fillLevel', None) is not None and opts.get('fillBrush', None) is not None:
|
if (opts.get('fillLevel', None) is not None and
|
||||||
|
opts.get('fillBrush', None) is not None):
|
||||||
p.setBrush(fn.mkBrush(opts['fillBrush']))
|
p.setBrush(fn.mkBrush(opts['fillBrush']))
|
||||||
p.setPen(fn.mkPen(opts['fillBrush']))
|
p.setPen(fn.mkPen(opts['fillBrush']))
|
||||||
p.drawPolygon(QtGui.QPolygonF([QtCore.QPointF(2, 18), QtCore.QPointF(18, 2), QtCore.QPointF(18, 18)]))
|
p.drawPolygon(QtGui.QPolygonF(
|
||||||
|
[QtCore.QPointF(2, 18), QtCore.QPointF(18, 2),
|
||||||
|
QtCore.QPointF(18, 18)]))
|
||||||
|
|
||||||
symbol = opts.get('symbol', None)
|
symbol = opts.get('symbol', None)
|
||||||
if symbol is not None:
|
if symbol is not None:
|
||||||
if isinstance(self.item, PlotDataItem):
|
if isinstance(self.item, PlotDataItem):
|
||||||
opts = self.item.scatter.opts
|
opts = self.item.scatter.opts
|
||||||
p.translate(10, 10)
|
p.translate(10, 10)
|
||||||
drawSymbol(p, symbol, opts['size'], fn.mkPen(opts['pen']), fn.mkBrush(opts['brush']))
|
drawSymbol(p, symbol, opts['size'], fn.mkPen(opts['pen']),
|
||||||
|
fn.mkBrush(opts['brush']))
|
||||||
|
|
||||||
if isinstance(self.item, BarGraphItem):
|
if isinstance(self.item, BarGraphItem):
|
||||||
p.setBrush(fn.mkBrush(opts['brush']))
|
p.setBrush(fn.mkBrush(opts['brush']))
|
||||||
|
Loading…
Reference in New Issue
Block a user