Skip to content

Commit eb630b5

Browse files
committed
Fixed #81: Signal disconnect error / PySide 6.5.3
1 parent 299aff2 commit eb630b5

File tree

3 files changed

+78
-116
lines changed

3 files changed

+78
-116
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# PythonQwt Releases
22

3+
## Version 0.10.5
4+
5+
- [Issue #81](https://github.com/PlotPyStack/PythonQwt/issues/81) - Signal disconnection issue with PySide 6.5.3
6+
37
## Version 0.10.4
48

59
- [Issue #80](https://github.com/PlotPyStack/PythonQwt/issues/80) - Print to PDF: AttributeError: 'NoneType' object has no attribute 'getContentsMargins'

qwt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
.. _GitHub: https://github.com/PlotPyStack/PythonQwt
2828
"""
2929

30-
__version__ = "0.10.4"
30+
__version__ = "0.10.5"
3131
QWT_VERSION_STR = "6.1.5"
3232

3333
import warnings

qwt/plot.py

Lines changed: 73 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@
4444
import numpy as np
4545

4646

47-
def qwtEnableLegendItems(plot, on):
48-
if on:
49-
plot.legendDataChanged.connect(plot.updateLegendItems)
50-
else:
51-
plot.legendDataChanged.disconnect(plot.updateLegendItems)
52-
53-
5447
def qwtSetTabOrder(first, second, with_children):
5548
tab_chain = [first, second]
5649
if with_children:
@@ -88,111 +81,10 @@ def removeItem(self, obj):
8881
self.sortItems()
8982

9083

91-
class QwtPlotDict_PrivateData(object):
92-
def __init__(self):
93-
self.itemList = ItemList()
94-
self.autoDelete = True
95-
96-
97-
class QwtPlotDict(object):
98-
"""
99-
A dictionary for plot items
100-
101-
`QwtPlotDict` organizes plot items in increasing z-order.
102-
If `autoDelete()` is enabled, all attached items will be deleted
103-
in the destructor of the dictionary.
104-
`QwtPlotDict` can be used to get access to all `QwtPlotItem` items - or
105-
all items of a specific type - that are currently on the plot.
106-
107-
.. seealso::
108-
109-
:py:meth:`QwtPlotItem.attach()`, :py:meth:`QwtPlotItem.detach()`,
110-
:py:meth:`QwtPlotItem.z()`
111-
"""
112-
113-
def __init__(self):
114-
self.__data = QwtPlotDict_PrivateData()
115-
116-
def setAutoDelete(self, autoDelete):
117-
"""
118-
En/Disable Auto deletion
119-
120-
If Auto deletion is on all attached plot items will be deleted
121-
in the destructor of `QwtPlotDict`. The default value is on.
122-
123-
:param bool autoDelete: enable/disable
124-
125-
.. seealso::
126-
127-
:py:meth:`autoDelete()`, :py:meth:`insertItem()`
128-
"""
129-
self.__data.autoDelete = autoDelete
130-
131-
def autoDelete(self):
132-
"""
133-
:return: true if auto deletion is enabled
134-
135-
.. seealso::
136-
137-
:py:meth:`setAutoDelete()`, :py:meth:`insertItem()`
138-
"""
139-
return self.__data.autoDelete
140-
141-
def insertItem(self, item):
142-
"""
143-
Insert a plot item
144-
145-
:param qwt.plot.QwtPlotItem item: PlotItem
146-
147-
.. seealso::
148-
149-
:py:meth:`removeItem()`
150-
"""
151-
self.__data.itemList.insertItem(item)
152-
153-
def removeItem(self, item):
154-
"""
155-
Remove a plot item
156-
157-
:param qwt.plot.QwtPlotItem item: PlotItem
158-
159-
.. seealso::
160-
161-
:py:meth:`insertItem()`
162-
"""
163-
self.__data.itemList.removeItem(item)
164-
165-
def detachItems(self, rtti=None):
166-
"""
167-
Detach items from the dictionary
168-
169-
:param rtti: In case of `QwtPlotItem.Rtti_PlotItem` or None (default) detach all items otherwise only those items of the type rtti.
170-
:type rtti: int or None
171-
"""
172-
for item in self.__data.itemList[:]:
173-
if rtti in (None, QwtPlotItem.Rtti_PlotItem) or item.rtti() == rtti:
174-
item.attach(None)
175-
176-
def itemList(self, rtti=None):
177-
"""
178-
A list of attached plot items.
179-
180-
Use caution when iterating these lists, as removing/detaching an
181-
item will invalidate the iterator. Instead you can place pointers
182-
to objects to be removed in a removal list, and traverse that list
183-
later.
184-
185-
:param int rtti: In case of `QwtPlotItem.Rtti_PlotItem` detach all items otherwise only those items of the type rtti.
186-
:return: List of all attached plot items of a specific type. If rtti is None, return a list of all attached plot items.
187-
"""
188-
if rtti is None or rtti == QwtPlotItem.Rtti_PlotItem:
189-
return self.__data.itemList
190-
return [item for item in self.__data.itemList if item.rtti() == rtti]
191-
192-
193-
class QwtPlot_PrivateData(QwtPlotDict_PrivateData):
84+
class QwtPlot_PrivateData(object):
19485
def __init__(self):
19586
super(QwtPlot_PrivateData, self).__init__()
87+
self.itemList = ItemList()
19688
self.titleLabel = None
19789
self.footerLabel = None
19890
self.canvas = None
@@ -217,7 +109,7 @@ def __init__(self):
217109
self.scaleWidget = None # QwtScaleWidget
218110

219111

220-
class QwtPlot(QwtPlotDict, QFrame):
112+
class QwtPlot(QFrame):
221113
"""
222114
A 2-D plotting widget
223115
@@ -300,7 +192,6 @@ def __init__(self, *args):
300192
"%s() takes 0, 1 or 2 argument(s) (%s given)"
301193
% (self.__class__.__name__, len(args))
302194
)
303-
QwtPlotDict.__init__(self)
304195
QFrame.__init__(self, parent)
305196

306197
self.__layout_state = None
@@ -359,7 +250,74 @@ def __init__(self, *args):
359250
for idx in range(len(focusChain) - 1):
360251
qwtSetTabOrder(focusChain[idx], focusChain[idx + 1], False)
361252

362-
qwtEnableLegendItems(self, True)
253+
self.legendDataChanged.connect(self.updateLegendItems)
254+
255+
def insertItem(self, item):
256+
"""
257+
Insert a plot item
258+
259+
:param qwt.plot.QwtPlotItem item: PlotItem
260+
261+
.. seealso::
262+
263+
:py:meth:`removeItem()`
264+
265+
.. note::
266+
267+
This was a member of QwtPlotDict in older versions.
268+
"""
269+
self.__data.itemList.insertItem(item)
270+
271+
def removeItem(self, item):
272+
"""
273+
Remove a plot item
274+
275+
:param qwt.plot.QwtPlotItem item: PlotItem
276+
277+
.. seealso::
278+
279+
:py:meth:`insertItem()`
280+
281+
.. note::
282+
283+
This was a member of QwtPlotDict in older versions.
284+
"""
285+
self.__data.itemList.removeItem(item)
286+
287+
def detachItems(self, rtti=None):
288+
"""
289+
Detach items from the dictionary
290+
291+
:param rtti: In case of `QwtPlotItem.Rtti_PlotItem` or None (default) detach all items otherwise only those items of the type rtti.
292+
:type rtti: int or None
293+
294+
.. note::
295+
296+
This was a member of QwtPlotDict in older versions.
297+
"""
298+
for item in self.__data.itemList[:]:
299+
if rtti in (None, QwtPlotItem.Rtti_PlotItem) or item.rtti() == rtti:
300+
item.attach(None)
301+
302+
def itemList(self, rtti=None):
303+
"""
304+
A list of attached plot items.
305+
306+
Use caution when iterating these lists, as removing/detaching an
307+
item will invalidate the iterator. Instead you can place pointers
308+
to objects to be removed in a removal list, and traverse that list
309+
later.
310+
311+
:param int rtti: In case of `QwtPlotItem.Rtti_PlotItem` detach all items otherwise only those items of the type rtti.
312+
:return: List of all attached plot items of a specific type. If rtti is None, return a list of all attached plot items.
313+
314+
.. note::
315+
316+
This was a member of QwtPlotDict in older versions.
317+
"""
318+
if rtti is None or rtti == QwtPlotItem.Rtti_PlotItem:
319+
return self.__data.itemList
320+
return [item for item in self.__data.itemList if item.rtti() == rtti]
363321

364322
def setFlatStyle(self, state):
365323
"""
@@ -1573,9 +1531,9 @@ def insertLegend(self, legend, pos=None, ratio=-1):
15731531
if self.__data.legend.parent() is not self:
15741532
self.__data.legend.setParent(self)
15751533

1576-
qwtEnableLegendItems(self, False)
1534+
self.blockSignals(True)
15771535
self.updateLegend()
1578-
qwtEnableLegendItems(self, True)
1536+
self.blockSignals(False)
15791537

15801538
lpos = self.__data.layout.legendPosition()
15811539

0 commit comments

Comments
 (0)