From a9049f1d4d37df71aee9198653f90ab263f73bd7 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Tue, 28 Jul 2020 10:01:15 +0200 Subject: [PATCH 1/3] Pop the 'parent' arg from ArrowItem opts parameter dict If not, then an `KeyError: 'Invalid arrow style option "parent"'` is raised in setStyle. --- pyqtgraph/graphicsItems/ArrowItem.py | 2 +- pyqtgraph/graphicsItems/tests/test_ArrowItem.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 pyqtgraph/graphicsItems/tests/test_ArrowItem.py diff --git a/pyqtgraph/graphicsItems/ArrowItem.py b/pyqtgraph/graphicsItems/ArrowItem.py index e0628d08..8dc5bba2 100644 --- a/pyqtgraph/graphicsItems/ArrowItem.py +++ b/pyqtgraph/graphicsItems/ArrowItem.py @@ -17,7 +17,7 @@ class ArrowItem(QtGui.QGraphicsPathItem): the setStyle() method. """ self.opts = {} - QtGui.QGraphicsPathItem.__init__(self, opts.get('parent', None)) + QtGui.QGraphicsPathItem.__init__(self, opts.pop('parent', None)) if 'size' in opts: opts['headLen'] = opts['size'] diff --git a/pyqtgraph/graphicsItems/tests/test_ArrowItem.py b/pyqtgraph/graphicsItems/tests/test_ArrowItem.py new file mode 100644 index 00000000..019aeeed --- /dev/null +++ b/pyqtgraph/graphicsItems/tests/test_ArrowItem.py @@ -0,0 +1,10 @@ +import pyqtgraph as pg + +app = pg.mkQApp() + + +def test_ArrowItem(): + parent = pg.GraphicsObject() + a = pg.ArrowItem(parent=parent, pos=(10, 10)) + assert a.parentItem() is parent + assert a.pos() == pg.Point(10, 10) From 52717fa8b7b6ce60ab2b6fc84c4a50bca5d8ea29 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Mon, 17 Aug 2020 09:25:37 +0200 Subject: [PATCH 2/3] Rename test --- pyqtgraph/graphicsItems/tests/test_ArrowItem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyqtgraph/graphicsItems/tests/test_ArrowItem.py b/pyqtgraph/graphicsItems/tests/test_ArrowItem.py index 019aeeed..f85e637c 100644 --- a/pyqtgraph/graphicsItems/tests/test_ArrowItem.py +++ b/pyqtgraph/graphicsItems/tests/test_ArrowItem.py @@ -3,7 +3,7 @@ import pyqtgraph as pg app = pg.mkQApp() -def test_ArrowItem(): +def test_ArrowItem_parent(): parent = pg.GraphicsObject() a = pg.ArrowItem(parent=parent, pos=(10, 10)) assert a.parentItem() is parent From 3d391d46e3878e32defc5b0a77499832edfa32f9 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Mon, 17 Aug 2020 09:27:23 +0200 Subject: [PATCH 3/3] Add `parent` to ArrowItem's constructor signature --- pyqtgraph/graphicsItems/ArrowItem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyqtgraph/graphicsItems/ArrowItem.py b/pyqtgraph/graphicsItems/ArrowItem.py index 8dc5bba2..a7cc831c 100644 --- a/pyqtgraph/graphicsItems/ArrowItem.py +++ b/pyqtgraph/graphicsItems/ArrowItem.py @@ -11,13 +11,13 @@ class ArrowItem(QtGui.QGraphicsPathItem): """ - def __init__(self, **opts): + def __init__(self, parent=None, **opts): """ Arrows can be initialized with any keyword arguments accepted by the setStyle() method. """ self.opts = {} - QtGui.QGraphicsPathItem.__init__(self, opts.pop('parent', None)) + QtGui.QGraphicsPathItem.__init__(self, parent) if 'size' in opts: opts['headLen'] = opts['size']