ItemSample: Allow toggle of visibility via mouse click in LegendItem (#1497)
* Legend toggle directly on ItemSample * Add invisible Eye icon * Include package data and remove username from svg * Allow svg and png in the setup.py and cleanup sg
This commit is contained in:
parent
3f02b30140
commit
5bb3800adc
@ -3,6 +3,7 @@ from .GraphicsWidget import GraphicsWidget
|
|||||||
from .LabelItem import LabelItem
|
from .LabelItem import LabelItem
|
||||||
from ..Qt import QtGui, QtCore
|
from ..Qt import QtGui, QtCore
|
||||||
from .. import functions as fn
|
from .. import functions as fn
|
||||||
|
from ..icons import invisibleEye
|
||||||
from ..Point import Point
|
from ..Point import Point
|
||||||
from .ScatterPlotItem import ScatterPlotItem, drawSymbol
|
from .ScatterPlotItem import ScatterPlotItem, drawSymbol
|
||||||
from .PlotDataItem import PlotDataItem
|
from .PlotDataItem import PlotDataItem
|
||||||
@ -339,10 +340,15 @@ class ItemSample(GraphicsWidget):
|
|||||||
|
|
||||||
def paint(self, p, *args):
|
def paint(self, p, *args):
|
||||||
opts = self.item.opts
|
opts = self.item.opts
|
||||||
|
|
||||||
if opts.get('antialias'):
|
if opts.get('antialias'):
|
||||||
p.setRenderHint(p.Antialiasing)
|
p.setRenderHint(p.Antialiasing)
|
||||||
|
|
||||||
|
visible = self.item.isVisible()
|
||||||
|
if not visible:
|
||||||
|
icon = invisibleEye.qicon
|
||||||
|
p.drawPixmap(QtCore.QPoint(1, 1), icon.pixmap(18, 18))
|
||||||
|
return
|
||||||
|
|
||||||
if not isinstance(self.item, ScatterPlotItem):
|
if not isinstance(self.item, ScatterPlotItem):
|
||||||
p.setPen(fn.mkPen(opts['pen']))
|
p.setPen(fn.mkPen(opts['pen']))
|
||||||
p.drawLine(0, 11, 20, 11)
|
p.drawLine(0, 11, 20, 11)
|
||||||
@ -366,3 +372,13 @@ class ItemSample(GraphicsWidget):
|
|||||||
if isinstance(self.item, BarGraphItem):
|
if isinstance(self.item, BarGraphItem):
|
||||||
p.setBrush(fn.mkBrush(opts['brush']))
|
p.setBrush(fn.mkBrush(opts['brush']))
|
||||||
p.drawRect(QtCore.QRectF(2, 2, 18, 18))
|
p.drawRect(QtCore.QRectF(2, 2, 18, 18))
|
||||||
|
|
||||||
|
def mouseClickEvent(self, event):
|
||||||
|
"""Use the mouseClick event to toggle the visibility of the plotItem
|
||||||
|
"""
|
||||||
|
if event.button() == QtCore.Qt.LeftButton:
|
||||||
|
visible = self.item.isVisible()
|
||||||
|
self.item.setVisible(not visible)
|
||||||
|
|
||||||
|
event.accept()
|
||||||
|
self.update()
|
||||||
|
38
pyqtgraph/icons/__init__.py
Normal file
38
pyqtgraph/icons/__init__.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import os.path as op
|
||||||
|
|
||||||
|
from ..Qt import QtGui
|
||||||
|
|
||||||
|
__all__ = ['getGraphIcon']
|
||||||
|
|
||||||
|
_ICON_REGISTRY = {}
|
||||||
|
|
||||||
|
|
||||||
|
class GraphIcon:
|
||||||
|
"""An icon place holder for lazy loading of QIcons"""
|
||||||
|
|
||||||
|
def __init__(self, path):
|
||||||
|
self._path = path
|
||||||
|
self._icon = None
|
||||||
|
name = path.split('.')[0]
|
||||||
|
_ICON_REGISTRY[name] = self
|
||||||
|
|
||||||
|
@property
|
||||||
|
def qicon(self):
|
||||||
|
if self._icon is None:
|
||||||
|
self._icon = QtGui.QIcon(op.join(op.dirname(__file__), self._path))
|
||||||
|
|
||||||
|
return self._icon
|
||||||
|
|
||||||
|
|
||||||
|
def getGraphIcon(name):
|
||||||
|
"""Return a `PyQtGraph` icon from the registry by `name`"""
|
||||||
|
icon = _ICON_REGISTRY[name]
|
||||||
|
if isinstance(icon, GraphIcon):
|
||||||
|
icon = icon.qicon
|
||||||
|
_ICON_REGISTRY[name] = icon
|
||||||
|
|
||||||
|
return icon
|
||||||
|
|
||||||
|
|
||||||
|
# Note: List all graph icons here ...
|
||||||
|
invisibleEye = GraphIcon("invisibleEye.svg")
|
35
pyqtgraph/icons/invisibleEye.svg
Normal file
35
pyqtgraph/icons/invisibleEye.svg
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="32"
|
||||||
|
height="32"
|
||||||
|
viewBox="0 0 32 32">
|
||||||
|
<g
|
||||||
|
transform="matrix(1.3011758,0,0,1.3175188,0.25361903,0.12274439)">
|
||||||
|
<rect
|
||||||
|
y="0.40677965"
|
||||||
|
x="0.30508474"
|
||||||
|
height="23.288136"
|
||||||
|
width="23.59322"
|
||||||
|
id="rect4138"
|
||||||
|
style="fill:#ffffff;fill-opacity:1;stroke:#2c6c90;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<ellipse
|
||||||
|
ry="1.573068"
|
||||||
|
rx="3.6511929"
|
||||||
|
cy="11.4375"
|
||||||
|
cx="12.140625"
|
||||||
|
id="path4198"
|
||||||
|
style="fill:#2c6c90;fill-opacity:1;stroke:#2c6c90;stroke-width:0.91636413;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
style="fill:#2c6c90;fill-opacity:1;fill-rule:evenodd;stroke:#2c6c90;stroke-width:0;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="path4"
|
||||||
|
d="m 8.6715201,17.080139 c 1.0521449,0.453004 2.1894259,0.698358 3.3632979,0.698358 3.690918,0 7.020113,-2.425624 8.47849,-6.104757 -0.649912,-1.639573 -1.671361,-3.0302023 -2.930787,-4.068156 -4.90545,5.220041 -5.550541,5.818812 -8.9110009,9.474555 z M 18.946736,6.1550929 c 1.638602,1.4150865 2.905626,3.322301 3.614424,5.5186471 -1.531105,4.744416 -5.667,8.139677 -10.526342,8.139677 -1.723817,0 -3.3565943,-0.427269 -4.8143441,-1.190462 l -1.7681422,1.879963 c -0.3737085,0.397342 -0.9796094,0.397342 -1.3533178,0 -0.3737083,-0.397341 -0.3737083,-1.041562 0,-1.438905 L 18.985511,3.2360555 c 0.373708,-0.3973428 0.979609,-0.3973428 1.353318,0 0.373708,0.3973426 0.373708,1.0415625 0,1.438905 z M 5.4511908,14.748511 4.0968206,16.188535 C 2.953543,14.923646 2.0612502,13.38662 1.5084746,11.67374 3.0395788,6.9293251 7.1754744,3.5340623 12.034818,3.5340623 c 1.191472,0 2.339452,0.2041205 3.416205,0.5822001 l -1.56112,1.6598495 C 13.287168,5.6399817 12.666286,5.5689817 12.034818,5.5689817 c -3.6909194,0 -7.0201146,2.4256237 -8.4784913,6.1047583 0.4607503,1.162362 1.1082345,2.199605 1.8948641,3.074771 z" />
|
||||||
|
</g>
|
||||||
|
<rect
|
||||||
|
style="fill:none;fill-opacity:1;stroke:#2c6c90;stroke-width:0;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect4148"
|
||||||
|
width="14.338983"
|
||||||
|
height="7.2203388"
|
||||||
|
x="16.576271"
|
||||||
|
y="-5.0169487" />
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.3 KiB |
4
setup.py
4
setup.py
@ -138,7 +138,9 @@ setup(
|
|||||||
packages=allPackages,
|
packages=allPackages,
|
||||||
python_requires=">=3.7",
|
python_requires=">=3.7",
|
||||||
package_dir={'pyqtgraph.examples': 'examples'}, ## install examples along with the rest of the source
|
package_dir={'pyqtgraph.examples': 'examples'}, ## install examples along with the rest of the source
|
||||||
package_data={'pyqtgraph.examples': ['optics/*.gz', 'relativity/presets/*.cfg']},
|
package_data={'pyqtgraph.examples': ['optics/*.gz', 'relativity/presets/*.cfg'],
|
||||||
|
"pyqtgraph.icons": ["*.svg", "*.png"],
|
||||||
|
},
|
||||||
install_requires = [
|
install_requires = [
|
||||||
'numpy>=1.17.0',
|
'numpy>=1.17.0',
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user