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 .GraphicsWidgetAnchor import GraphicsWidgetAnchor
|
||||
from .BarGraphItem import BarGraphItem
|
||||
|
||||
__all__ = ['LegendItem']
|
||||
|
||||
|
||||
@ -25,8 +26,10 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
||||
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:**
|
||||
@ -160,7 +163,8 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
||||
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):
|
||||
sample = item
|
||||
else:
|
||||
@ -189,9 +193,8 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
||||
self.layout.addItem(label, row, col + 1)
|
||||
|
||||
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:
|
||||
self.columnCount = columnCount
|
||||
self.rowCount = int(len(self.items) / columnCount)
|
||||
@ -202,17 +205,18 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
||||
self.updateSize()
|
||||
|
||||
def getLabel(self, plotItem):
|
||||
"""
|
||||
return the labelItem inside the legend for a given plotItem
|
||||
the label-text can be changed via labenItem.setText
|
||||
"""Return the labelItem inside the legend for a given plotItem
|
||||
|
||||
The label-text can be changed via labenItem.setText
|
||||
"""
|
||||
out = [(it, lab) for it, lab in self.items if it.item == plotItem]
|
||||
try: return out[0][1]
|
||||
except IndexError: return None
|
||||
try:
|
||||
return out[0][1]
|
||||
except IndexError:
|
||||
return None
|
||||
|
||||
def removeItem(self, item):
|
||||
"""
|
||||
Removes one item from the legend.
|
||||
"""Removes one item from the legend.
|
||||
|
||||
============== ========================================================
|
||||
**Arguments:**
|
||||
@ -278,11 +282,12 @@ class LegendItem(GraphicsWidget, GraphicsWidgetAnchor):
|
||||
|
||||
|
||||
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.
|
||||
"""
|
||||
## 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):
|
||||
GraphicsWidget.__init__(self)
|
||||
self.item = item
|
||||
@ -300,18 +305,21 @@ class ItemSample(GraphicsWidget):
|
||||
p.setPen(fn.mkPen(opts['pen']))
|
||||
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.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)
|
||||
if symbol is not None:
|
||||
if isinstance(self.item, PlotDataItem):
|
||||
opts = self.item.scatter.opts
|
||||
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):
|
||||
p.setBrush(fn.mkBrush(opts['brush']))
|
||||
|
Loading…
Reference in New Issue
Block a user